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

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

Introduction

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

Prototype

void commit();

Source Link

Document

Flushes batch statements and commits database connection.

Usage

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

License:GNU General Public License

@Before
@After/*from   ww w . j  a  va 2 s. c o m*/
public void init() throws ConfigurationException, IOException {

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        Properties lProperties = new Properties();
        lProperties.setProperty("projectsDirectory");
        lProperties.setValue("C:/temp/bibisco/projects");
        lPropertiesMapper.updateByPrimaryKey(lProperties);
        lSqlSession.commit();
    } catch (Throwable t) {
        lSqlSession.rollback();
    } finally {
        lSqlSession.close();
    }

    PropertiesManager.getInstance().reload();
}

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

License:GNU General Public License

@Test
public void testDeleteImagesByElementLocation() 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(71), ElementType.LOCATIONS);
    lSqlSession.commit();
    lSqlSession.close();/*from  www  . jav a 2s .co  m*/

    List<Images> lListImages;
    lSqlSession = lSqlSessionFactory.openSession();
    try {
        ImagesMapper lImagesMapper = lSqlSession.getMapper(ImagesMapper.class);
        ImagesExample lImagesExample = new ImagesExample();
        lImagesExample.createCriteria().andIdElementEqualTo(new Integer(71))
                .andElementTypeEqualTo(ElementType.LOCATIONS.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.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.assertFalse((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_7)).exists());
    Assert.assertFalse((new File(lStrImagesFolder + AllTests.TEST_PROJECT_IMAGE_8)).exists());
    Assert.assertFalse((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 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();
    lSqlSession.close();//from   w  w w .  j  av a  2  s . c o  m

    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();
    lSqlSession.close();/*from   w ww.ja va 2s  .  co  m*/

    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();
    lSqlSession.close();/*w w w.  j  av a 2  s  .co  m*/

    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

@Before
@After/*from  www .j a  va 2  s . c om*/
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  w ww.j  a  v  a2s .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 av a2  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_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 {/* w w  w  . j a v a2  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  ww.  j ava 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_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();
}