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

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

Introduction

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

Prototype

@Override
void close();

Source Link

Document

Closes the session.

Usage

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

License:GNU General Public License

@Test
public void testDeleteImagesByElementMainCharactersWithInexistentIdCharacter() {

    ContextManager.getInstance().setIdProject(AllTests.TEST_PROJECT_ID);

    SqlSessionFactory lSqlSessionFactory = AllTests.getProjectSqlSessionFactoryById(AllTests.TEST_PROJECT_ID);
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    ImageManager.deleteImagesByElement(lSqlSession, new Integer(1), ElementType.CHARACTERS);
    lSqlSession.commit();/*from  w  w  w  . j a va 2s.c o m*/
    lSqlSession.close();

    List<Images> lListImages;
    lSqlSession = lSqlSessionFactory.openSession();
    try {
        ImagesMapper lImagesMapper = lSqlSession.getMapper(ImagesMapper.class);
        lListImages = lImagesMapper.selectByExample(new ImagesExample());
    } finally {
        lSqlSession.close();
    }

    Assert.assertEquals(9, lListImages.size());
}

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

License:GNU General Public License

@Test
public void testDeleteImagesByElementMainCharacters() throws IOException {
    ContextManager.getInstance().setIdProject(AllTests.TEST_PROJECT_ID);
    SqlSessionFactory lSqlSessionFactory = AllTests.getProjectSqlSessionFactoryById(AllTests.TEST_PROJECT_ID);
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    ImageManager.deleteImagesByElement(lSqlSession, new Integer(67), ElementType.CHARACTERS);
    lSqlSession.commit();/*from w  w w .  j  a  va2  s  .c  o m*/
    lSqlSession.close();

    List<Images> lListImages;
    lSqlSession = lSqlSessionFactory.openSession();
    try {
        ImagesMapper lImagesMapper = lSqlSession.getMapper(ImagesMapper.class);
        ImagesExample lImagesExample = new ImagesExample();
        lImagesExample.createCriteria().andIdElementEqualTo(new Integer(67))
                .andElementTypeEqualTo(ElementType.CHARACTERS.getValue());
        lListImages = lImagesMapper.selectByExample(lImagesExample);
    } finally {
        lSqlSession.close();
    }

    Assert.assertEquals(0, lListImages.size());
    String lStrImagesFolder = AllTests.BIBISCO_INTERNAL_PROJECTS_DIR + AllTests.getPathSeparator()
            + AllTests.TEST_PROJECT_ID + AllTests.getPathSeparator();

    Assert.assertFalse((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_1)).exists());
    Assert.assertFalse((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_2)).exists());
    Assert.assertFalse((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_3)).exists());
    Assert.assertTrue((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_4)).exists());
    Assert.assertTrue((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_5)).exists());
    Assert.assertTrue((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_6)).exists());
    Assert.assertTrue((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_7)).exists());
    Assert.assertTrue((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_8)).exists());
    Assert.assertTrue((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_9)).exists());

    AllTests.cleanTestProjectDB();
}

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

License:GNU General Public License

@Test
public void testDeleteImagesByElementSecondaryCharacters() throws IOException {
    ContextManager.getInstance().setIdProject(AllTests.TEST_PROJECT_ID);
    SqlSessionFactory lSqlSessionFactory = AllTests.getProjectSqlSessionFactoryById(AllTests.TEST_PROJECT_ID);
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    ImageManager.deleteImagesByElement(lSqlSession, new Integer(70), ElementType.CHARACTERS);
    lSqlSession.commit();//from  w  ww. j a  v a 2s . com
    lSqlSession.close();

    List<Images> lListImages;
    lSqlSession = lSqlSessionFactory.openSession();
    try {
        ImagesMapper lImagesMapper = lSqlSession.getMapper(ImagesMapper.class);
        ImagesExample lImagesExample = new ImagesExample();
        lImagesExample.createCriteria().andIdElementEqualTo(new Integer(70))
                .andElementTypeEqualTo(ElementType.CHARACTERS.getValue());
        lListImages = lImagesMapper.selectByExample(lImagesExample);
    } finally {
        lSqlSession.close();
    }

    Assert.assertEquals(0, lListImages.size());
    String lStrImagesFolder = AllTests.BIBISCO_INTERNAL_PROJECTS_DIR + AllTests.getPathSeparator()
            + AllTests.TEST_PROJECT_ID + AllTests.getPathSeparator();

    Assert.assertTrue((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_1)).exists());
    Assert.assertTrue((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_2)).exists());
    Assert.assertTrue((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_3)).exists());
    Assert.assertFalse((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_4)).exists());
    Assert.assertFalse((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_5)).exists());
    Assert.assertFalse((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_6)).exists());
    Assert.assertTrue((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_7)).exists());
    Assert.assertTrue((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_8)).exists());
    Assert.assertTrue((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_9)).exists());

    AllTests.cleanTestProjectDB();
}

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

License:GNU General Public License

@Test
public void testUpdateLocale() {

    //update locale
    Locale lLocaleCanada = new Locale(Locale.CANADA.getCountry(), Locale.CANADA.getLanguage());
    LocaleManager lLocaleManager = LocaleManager.getInstance();
    lLocaleManager.saveLocale(lLocaleCanada.toString());

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    Properties lProperties;/*  w  w  w.  j  a v a2 s .  c o m*/
    try {
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        lProperties = lPropertiesMapper.selectByPrimaryKey("locale");
    } finally {
        lSqlSession.close();
    }

    Assert.assertEquals(lProperties.getValue(), lLocaleCanada.toString());
}

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

License:GNU General Public License

@Before
@After/*from w  ww.j a v a2s  .c o  m*/
public void init() {

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);

        Properties lProperties = new Properties();
        lProperties.setProperty("locale");
        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

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

    AllTests.cleanProjectsDirectory();/*from  www.  j  a va2s . 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 {//ww  w.  j a v  a 2 s .  c  o 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_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  a  v  a  2  s .  c o 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_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 {/* w  w w. j  a  va  2 s .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 w  w  w .j av a2s. c om*/
        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();
}