Example usage for org.apache.ibatis.session SqlSession getMapper

List of usage examples for org.apache.ibatis.session SqlSession getMapper

Introduction

In this page you can find the example usage for org.apache.ibatis.session SqlSession getMapper.

Prototype

<T> T getMapper(Class<T> type);

Source Link

Document

Retrieves a mapper.

Usage

From source file:com.bibisco.test.ProjectManagerTest.java

License:GNU General Public License

@Before
public void init() throws ConfigurationException, IOException, InterruptedException {

    AllTests.cleanProjectsDirectory();/*  w w  w  .ja va 2  s.  c  o  m*/
    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        Properties lProperties = new Properties();
        lProperties.setProperty("projectsDirectory");
        lProperties.setValue(AllTests.BIBISCO_PROJECTS_DIR);
        lPropertiesMapper.updateByPrimaryKey(lProperties);
        lSqlSession.commit();
    } catch (Throwable t) {
        lSqlSession.rollback();
    } finally {
        lSqlSession.close();
    }

    PropertiesManager.getInstance().reload();
}

From source file:com.bibisco.test.ProjectManagerTest.java

License:GNU General Public License

@Test
public void testSetProjectsDirectoryWithExistingDirectory() {

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {//from   www. j a  v a  2 s. c  om
        ProjectsMapper lProjectMapper = lSqlSession.getMapper(ProjectsMapper.class);
        lProjectMapper.deleteByExample(new ProjectsExample());
        lSqlSession.commit();
    } finally {
        lSqlSession.close();
    }

    Assert.assertEquals(SET_PROJECTS_DIRECTORY_RESULT.CREATED,
            ProjectManager.setProjectsDirectory(AllTests.BIBISCO_PROJECTS_DIR));

    lSqlSession = lSqlSessionFactory.openSession();
    Properties lProperties;
    try {
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        lProperties = lPropertiesMapper.selectByPrimaryKey("projectsDirectory");
    } finally {
        lSqlSession.close();
    }

    Assert.assertEquals(lProperties.getValue(), AllTests.BIBISCO_PROJECTS_DIR);

    File lFile = new File(AllTests.BIBISCO_INTERNAL_PROJECTS_DIR);
    Assert.assertTrue(lFile.exists());
}

From source file:com.bibisco.test.ProjectManagerTest.java

License:GNU General Public License

@Test
public void testSetProjectsDirectoryWithBibiscoInternalProjectsDirectory() {

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {/*from  w  w  w  . j  ava  2s  .  c om*/
        ProjectsMapper lProjectMapper = lSqlSession.getMapper(ProjectsMapper.class);
        lProjectMapper.deleteByExample(new ProjectsExample());
        lSqlSession.commit();
    } finally {
        lSqlSession.close();
    }

    Assert.assertEquals(SET_PROJECTS_DIRECTORY_RESULT.CREATED,
            ProjectManager.setProjectsDirectory(AllTests.BIBISCO_INTERNAL_PROJECTS_DIR));

    lSqlSession = lSqlSessionFactory.openSession();
    Properties lProperties;
    try {
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        lProperties = lPropertiesMapper.selectByPrimaryKey("projectsDirectory");
    } finally {
        lSqlSession.close();
    }

    Assert.assertEquals(lProperties.getValue(), AllTests.BIBISCO_PROJECTS_DIR);

    File lFile = new File(AllTests.BIBISCO_INTERNAL_PROJECTS_DIR);
    Assert.assertTrue(lFile.exists());
}

From source file:com.bibisco.test.ProjectManagerTest.java

License:GNU General Public License

@Test
public void testSetProjectsDirectoryWithNewDirectory() {

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {//from  w  w  w. ja  v a  2s.  co m
        ProjectsMapper lProjectMapper = lSqlSession.getMapper(ProjectsMapper.class);
        lProjectMapper.deleteByExample(new ProjectsExample());
        lSqlSession.commit();
    } finally {
        lSqlSession.close();
    }

    Assert.assertEquals(SET_PROJECTS_DIRECTORY_RESULT.CREATED,
            ProjectManager.setProjectsDirectory(AllTests.BIBISCO_NEW_PROJECTS_DIR));

    lSqlSession = lSqlSessionFactory.openSession();
    Properties lProperties;
    try {
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        lProperties = lPropertiesMapper.selectByPrimaryKey("projectsDirectory");
    } finally {
        lSqlSession.close();
    }

    Assert.assertEquals(lProperties.getValue(), AllTests.BIBISCO_NEW_PROJECTS_DIR);

    File lFile = new File(AllTests.BIBISCO_INTERNAL_PROJECTS_DIR_NEW_PROJECTS);

    Assert.assertTrue(lFile.exists());

    lFile.delete();
}

From source file:com.bibisco.test.ProjectManagerTest.java

License:GNU General Public License

private void setNonExistentProjectDir() {
    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {/*from  ww w.  j a va 2s.  c  o  m*/
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        Properties lProperties = new Properties();
        lProperties.setProperty("projectsDirectory");
        lProperties.setValue("C:/temp/bibiscotto/projects");
        lPropertiesMapper.updateByPrimaryKey(lProperties);
        lSqlSession.commit();
    } catch (Throwable t) {
        lSqlSession.rollback();
    } finally {
        lSqlSession.close();
    }

    PropertiesManager.getInstance().reload();
}

From source file:com.bibisco.test.ProjectManagerTest.java

License:GNU General Public License

@Test
public void testInsertProject() throws IOException {
    ProjectDTO lProjectDTO = new ProjectDTO();
    lProjectDTO.setName("Test Insert");
    lProjectDTO.setLanguage(LocaleManager.getInstance().getLocale().getLanguage());
    lProjectDTO.setBibiscoVersion(VersionManager.getInstance().getVersion());
    lProjectDTO = ProjectManager.insert(lProjectDTO);

    Assert.assertNotNull(lProjectDTO.getIdProject());
    Assert.assertEquals(lProjectDTO.getName(), "Test Insert");
    Assert.assertEquals(lProjectDTO.getLanguage(), LocaleManager.getInstance().getLocale().getLanguage());
    Assert.assertEquals(lProjectDTO.getBibiscoVersion(), VersionManager.getInstance().getVersion());
    Assert.assertNotNull(lProjectDTO.getArchitecture());
    Assert.assertEquals(lProjectDTO.getArchitecture().getPremiseTaskStatus(), TaskStatus.TODO);
    Assert.assertEquals(lProjectDTO.getArchitecture().getFabulaTaskStatus(), TaskStatus.TODO);
    Assert.assertEquals(lProjectDTO.getArchitecture().getSettingTaskStatus(), TaskStatus.TODO);
    Assert.assertNull(lProjectDTO.getArchitecture().getStrandList());
    Assert.assertNull(lProjectDTO.getChapterList());
    Assert.assertNull(lProjectDTO.getLocationList());
    Assert.assertNull(lProjectDTO.getMainCharacterList());
    Assert.assertNull(lProjectDTO.getSecondaryCharacterList());

    SqlSessionFactory lSqlSessionFactory = AllTests.getProjectSqlSessionFactoryById(lProjectDTO.getIdProject());
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    List<Project> lListProject;
    try {/*from   w ww .j  a  v a  2s .c o  m*/
        ProjectMapper lProjectMapper = lSqlSession.getMapper(ProjectMapper.class);
        ProjectExample lProjectExample = new ProjectExample();
        lProjectExample.createCriteria().andNameEqualTo("Test Insert")
                .andLanguageEqualTo(LocaleManager.getInstance().getLocale().getLanguage())
                .andBibiscoVersionEqualTo(VersionManager.getInstance().getVersion());
        lListProject = lProjectMapper.selectByExample(lProjectExample);
    } finally {
        lSqlSession.close();
    }
    Assert.assertEquals(lListProject.size(), 1);

    lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    lSqlSession = lSqlSessionFactory.openSession();
    List<Projects> lListProjects;
    try {
        ProjectsMapper lProjectsMapper = lSqlSession.getMapper(ProjectsMapper.class);
        ProjectsExample lProjectsExample = new ProjectsExample();
        lProjectsExample.createCriteria().andIdProjectEqualTo(lProjectDTO.getIdProject())
                .andNameEqualTo("Test Insert");
        lListProjects = lProjectsMapper.selectByExample(lProjectsExample);
    } finally {
        lSqlSession.close();
    }
    Assert.assertEquals(lListProjects.size(), 1);
}

From source file:com.bibisco.test.ProjectManagerTest.java

License:GNU General Public License

@Test
public void testImportProjectsFromProjectsDirectory()
        throws ConfigurationException, IOException, ParseException {

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {//from w w w .j  av a 2 s  .  c  o m
        ProjectsMapper lProjectMapper = lSqlSession.getMapper(ProjectsMapper.class);
        lProjectMapper.deleteByExample(new ProjectsExample());
        lSqlSession.commit();
    } finally {
        lSqlSession.close();
    }

    int lIntResult = ProjectManager.importProjectsFromProjectsDirectory();
    Assert.assertEquals(3, lIntResult);

    List<Projects> lListProjects;
    lSqlSession = lSqlSessionFactory.openSession();
    try {
        ProjectsMapper lProjectMapper = lSqlSession.getMapper(ProjectsMapper.class);
        ProjectsExample lProjectsExample = new ProjectsExample();
        lProjectsExample.setOrderByClause("id_project");
        lListProjects = lProjectMapper.selectByExample(lProjectsExample);
    } finally {
        lSqlSession.close();
    }

    Assert.assertEquals(AllTests.TEST_PROJECT_ID, lListProjects.get(0).getIdProject());
    Assert.assertEquals(AllTests.TEST_PROJECT2_ID, lListProjects.get(1).getIdProject());
    Assert.assertEquals(AllTests.TEST_PROJECT3_ID, lListProjects.get(2).getIdProject());

    checkTestProjectDB();

    Project lProject;
    lSqlSessionFactory = AllTests.getProjectSqlSessionFactoryById(AllTests.TEST_PROJECT2_ID);
    lSqlSession = lSqlSessionFactory.openSession();
    try {
        ProjectMapper lProjectMapper = lSqlSession.getMapper(ProjectMapper.class);
        lProject = lProjectMapper.selectByPrimaryKey(AllTests.TEST_PROJECT2_ID);
    } finally {
        lSqlSession.close();
    }
    Assert.assertEquals(AllTests.TEST_PROJECT2_ID, lProject.getIdProject());
    Assert.assertEquals(TaskStatus.TODO.getValue(), lProject.getFabulaTaskStatus());
    Assert.assertEquals("1.5.1", lProject.getBibiscoVersion());
    Assert.assertEquals("en_US", lProject.getLanguage());
    Assert.assertEquals("Test 2", lProject.getName());
    Assert.assertEquals(TaskStatus.TODO.getValue(), lProject.getPremiseTaskStatus());
    Assert.assertEquals(TaskStatus.TODO.getValue(), lProject.getSettingTaskStatus());
    Assert.assertEquals(TaskStatus.TODO.getValue(), lProject.getStrandTaskStatus());

    lSqlSessionFactory = AllTests.getProjectSqlSessionFactoryById(AllTests.TEST_PROJECT3_ID);
    lSqlSession = lSqlSessionFactory.openSession();
    try {
        ProjectMapper lProjectMapper = lSqlSession.getMapper(ProjectMapper.class);
        lProject = lProjectMapper.selectByPrimaryKey(AllTests.TEST_PROJECT3_ID);
    } finally {
        lSqlSession.close();
    }
    Assert.assertEquals(AllTests.TEST_PROJECT3_ID, lProject.getIdProject());
    Assert.assertEquals(TaskStatus.TODO.getValue(), lProject.getFabulaTaskStatus());
    Assert.assertEquals("1.4.2", lProject.getBibiscoVersion());
    Assert.assertEquals("en_US", lProject.getLanguage());
    Assert.assertEquals("Test 3       $ ! /", lProject.getName());
    Assert.assertEquals(TaskStatus.TODO.getValue(), lProject.getPremiseTaskStatus());
    Assert.assertEquals(TaskStatus.TODO.getValue(), lProject.getSettingTaskStatus());
    Assert.assertEquals(TaskStatus.TODO.getValue(), lProject.getStrandTaskStatus());

}

From source file:com.bibisco.test.ProjectManagerTest.java

License:GNU General Public License

public void emptyProjectsDirectory() {

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {/*from  www.j av a  2s.  c  o m*/
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);

        Properties lProperties = new Properties();
        lProperties.setProperty("projectsDirectory");
        lProperties.setValue("");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

        lSqlSession.commit();
    } catch (Throwable t) {
        lSqlSession.rollback();
    } finally {
        lSqlSession.close();
    }

    PropertiesManager.getInstance().reload();
}

From source file:com.bibisco.test.ProjectManagerTest.java

License:GNU General Public License

@Test
public void testLoadAllWithNoProjects() {

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {/*from  w  ww. j  ava  2  s  . c o  m*/
        ProjectsMapper lProjectMapper = lSqlSession.getMapper(ProjectsMapper.class);
        lProjectMapper.deleteByExample(new ProjectsExample());
        lSqlSession.commit();
    } finally {
        lSqlSession.close();
    }

    List<ProjectDTO> lListProjectDTOs = ProjectManager.loadAll();
    checkTestProjectsDB(lListProjectDTOs);
}

From source file:com.bibisco.test.ProjectManagerTest.java

License:GNU General Public License

@Test
public void testDeleteProject() throws ConfigurationException, IOException, SQLException {

    File lFile = new File(AllTests.BIBISCO_INTERNAL_PROJECTS_DIR + System.getProperty("file.separator")
            + AllTests.TEST_PROJECT3_ID);
    Assert.assertTrue(lFile.exists());/*from   w  w  w. j  av a 2 s.c o  m*/

    ProjectManager.delete(AllTests.TEST_PROJECT3_ID);

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    Projects lProjects;
    try {
        ProjectsMapper lProjectMapper = lSqlSession.getMapper(ProjectsMapper.class);
        lProjects = lProjectMapper.selectByPrimaryKey(AllTests.TEST_PROJECT3_ID);
    } finally {
        lSqlSession.close();
    }
    Assert.assertNull(lProjects);
    Assert.assertFalse(lFile.exists());
}