Package org.apache.ibatis.session

Examples of org.apache.ibatis.session.SqlSessionFactory.openSession()


      sqlSessionFactory = new SqlSessionFactoryBuilder().build(batisConfigReader);
    } catch(Exception anException) {
      throw new RuntimeException("Mapper configuration failed, expected this to work: " + anException.getMessage(), anException);
    }

    SqlSession session = sqlSessionFactory.openSession();

    Connection conn = session.getConnection();
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.setErrorLogWriter(null);
View Full Code Here


    runner.setLogWriter(null);
    runner.setErrorLogWriter(null);
    Reader createScriptReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/inline_association_with_dot/create.sql");
    runner.runScript(createScriptReader);

    sqlSession = sqlSessionFactory.openSession();
  }

  @After
  public void closeSession() {
    if (sqlSession != null) {
View Full Code Here

        }
    }
    @Test
    public void testSelectNoName() {
        SqlSessionFactory sqlSessionFactory = getSqlSessionFactoryWithConstructor();
        SqlSession sqlSession = sqlSessionFactory.openSession();
        try {
            StudentConstructorMapper studentConstructorMapper = sqlSession.getMapper(StudentConstructorMapper.class);
            StudentConstructor testStudent = studentConstructorMapper.selectNoNameById(1);
            assertEquals(1, testStudent.getConstructors().size());
            assertTrue(testStudent.getConstructors().contains(StudentConstructor.Constructor.ID));
View Full Code Here

    String resource = "org/apache/ibatis/submitted/association_nested/mybatis-config.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

    SqlSession session = sqlSessionFactory.openSession();
    FolderMapper postMapper = session.getMapper(FolderMapper.class);

    List<FolderFlatTree> folders = postMapper.findWithSubFolders("Root");

    Assert.assertEquals(3, folders.size());
View Full Code Here

  @Test
  public void testInsertAnnotated() throws Exception {
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/keycolumn/MapperConfig.xml");
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
      InsertMapper mapper = sqlSession.getMapper(InsertMapper.class);
      Name name = new Name();
      name.setFirstName("Fred");
      name.setLastName("Flintstone");
View Full Code Here

  @Test
  public void testInsertMapped() throws Exception {
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/keycolumn/MapperConfig.xml");
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
      InsertMapper mapper = sqlSession.getMapper(InsertMapper.class);
      Name name = new Name();
      name.setFirstName("Fred");
      name.setLastName("Flintstone");
View Full Code Here

  @Ignore // Not supported yet in PostgreSQL
  @Test
  public void testInsertMappedBatch() throws Exception {
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/keycolumn/MapperConfig.xml");
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
    try {
      InsertMapper mapper = sqlSession.getMapper(InsertMapper.class);
      Name name = new Name();
      name.setFirstName("Fred");
      name.setLastName("Flintstone");
View Full Code Here

     */
    @Test
    public void testSelectListWithNestedResultMap() throws Exception {
        String xmlConfig = "org/apache/ibatis/submitted/custom_collection_handling/MapperConfig.xml";
        SqlSessionFactory sqlSessionFactory = getSqlSessionFactoryXmlConfig(xmlConfig);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        try {
            List<Person> list = sqlSession.selectList("org.apache.ibatis.submitted.custom_collection_handling.PersonMapper.findWithResultMap");
            assertEquals(2, list.size());
            assertEquals(2, list.get(0).getContacts().size());
            assertEquals(1, list.get(1).getContacts().size());
View Full Code Here

     */
    @Test
    public void testSelectListWithNestedSelect() throws Exception {
        String xmlConfig = "org/apache/ibatis/submitted/custom_collection_handling/MapperConfig.xml";
        SqlSessionFactory sqlSessionFactory = getSqlSessionFactoryXmlConfig(xmlConfig);
        SqlSession sqlSession = sqlSessionFactory.openSession();
        try {
            List<Person> list = sqlSession.selectList("org.apache.ibatis.submitted.custom_collection_handling.PersonMapper.findWithSelect");
            assertEquals(2, list.size());
            assertEquals(2, list.get(0).getContacts().size());
            assertEquals(1, list.get(1).getContacts().size());
View Full Code Here

  private SqlSession createSession(boolean anAggressiveLazyLoading) throws Exception {
    String xmlConfig = anAggressiveLazyLoading ?
        "org/apache/ibatis/submitted/serializecircular/MapperConfigWithAggressiveLazyLoading.xml":
        "org/apache/ibatis/submitted/serializecircular/MapperConfigWithoutAggressiveLazyLoading.xml";
      SqlSessionFactory sqlSessionFactory = getSqlSessionFactoryXmlConfig(xmlConfig);
      SqlSession sqlSession = sqlSessionFactory.openSession();
    return sqlSession;
  }

  private void testSerializeWithPreloadingAttribute(SqlSession sqlSession) {
    testSerialize(sqlSession, true);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.