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.ProjectManagerTest.java

License:GNU General Public License

private void setNonExistentProjectDir() {
    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {/*w  w  w .  java  2  s.  co 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 testImportProjectsFromProjectsDirectory()
        throws ConfigurationException, IOException, ParseException {

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {/*from w ww. j  a v  a2  s.co  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 {// ww  w.ja  va 2  s . com
        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   ww  w . j a v a 2s.c  om
        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.PropertiesManagerTest.java

License:GNU General Public License

@Before
@After//www .j a  va 2s.  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("projectsDirectory");
        lProperties.setValue("");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

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

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

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

    PropertiesManager.getInstance().reload();
}

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

License:GNU General Public License

@Before
@After//from w  ww  . j  a  v a 2s.  co  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("font");
        lProperties.setValue("courier");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

        lProperties = new Properties();
        lProperties.setProperty("font-size");
        lProperties.setValue("medium");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

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

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

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

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

    PropertiesManager.getInstance().reload();
}

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

License:GNU General Public License

@Test
public void testDonationTip29DaysFromNow() {

    DateFormat lDateFormat = new SimpleDateFormat(DATE_FORMAT);
    Date lDate29DaysFromNow = DateUtils.addDays(new Date(), -29);

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {//  w  w  w  . j a v a  2 s  .co  m
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        Properties lProperties = new Properties();
        lProperties.setProperty("donationTip");
        lProperties.setValue(lDateFormat.format(lDate29DaysFromNow));
        lPropertiesMapper.updateByPrimaryKey(lProperties);
        lSqlSession.commit();
    } catch (Throwable t) {
        lSqlSession.rollback();
    } finally {
        lSqlSession.close();
    }
    PropertiesManager.getInstance().reload();
    TipSettings lTipSettings = TipManager.load();
    Assert.assertEquals(lTipSettings.isDonationTip(), false);
}

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

License:GNU General Public License

@Test
public void testDonationTip30DaysFromNow() {

    DateFormat lDateFormat = new SimpleDateFormat(DATE_FORMAT);
    Date lDate29DaysFromNow = DateUtils.addDays(new Date(), -30);

    SqlSessionFactory lSqlSessionFactory = AllTests.getBibiscoSqlSessionFactory();
    SqlSession lSqlSession = lSqlSessionFactory.openSession();
    try {/*from   w w w .  j  ava  2  s .c  o  m*/
        PropertiesMapper lPropertiesMapper = lSqlSession.getMapper(PropertiesMapper.class);
        Properties lProperties = new Properties();
        lProperties.setProperty("donationTip");
        lProperties.setValue(lDateFormat.format(lDate29DaysFromNow));
        lPropertiesMapper.updateByPrimaryKey(lProperties);
        lSqlSession.commit();
    } catch (Throwable t) {
        lSqlSession.rollback();
    } finally {
        lSqlSession.close();
    }
    PropertiesManager.getInstance().reload();
    TipSettings lTipSettings = TipManager.load();
    Assert.assertEquals(lTipSettings.isDonationTip(), true);
}

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

License:GNU General Public License

@Before
@After// ww w . j a v  a 2 s . 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("sceneTip");
        lProperties.setValue("true");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

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

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

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

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

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

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

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

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

    PropertiesManager.getInstance().reload();
}

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

License:GNU General Public License

@Before
@After//from  w  w  w .java2  s.  co  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("version");
        lProperties.setValue("1.3.0");
        lPropertiesMapper.updateByPrimaryKey(lProperties);

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

    PropertiesManager.getInstance().reload();
}