當前位置: 首頁>>代碼示例>>Java>>正文


Java ExecutorType類代碼示例

本文整理匯總了Java中org.apache.ibatis.session.ExecutorType的典型用法代碼示例。如果您正苦於以下問題:Java ExecutorType類的具體用法?Java ExecutorType怎麽用?Java ExecutorType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ExecutorType類屬於org.apache.ibatis.session包,在下文中一共展示了ExecutorType類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: batchInsert

import org.apache.ibatis.session.ExecutorType; //導入依賴的package包/類
protected int batchInsert(List<T> insertObjects , String statement , Integer batchSize){
    SqlSession sqlSession = this.sqlSessionTemplate.getSqlSessionFactory().openSession(ExecutorType.BATCH);
    if (batchSize == null || batchSize == 0){
        batchSize = BATCH_SIZE ;
    }
    int execCount = 0;
    for (int i = 0 , size = insertObjects.size(); i < size ; i++){
        sqlSession.insert(statement , insertObjects);
        if ((i != 0 && i % batchSize == 0) || i == size -1){
            List<BatchResult> batchResults = sqlSession.flushStatements();
            execCount = batchResults.size() ;
            sqlSession.commit();
            sqlSession.clearCache();
            LOGGER.debug("batch insert , current commit size : {} " , execCount );
        }
    }
    sqlSession.close();
    return execCount ;
}
 
開發者ID:tryndamere,項目名稱:bpm-adapter,代碼行數:20,代碼來源:BpmBaseDao.java

示例2: beforeCommit

import org.apache.ibatis.session.ExecutorType; //導入依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void beforeCommit(boolean readOnly) {
  // Flush BATCH statements so they are actually executed before the connection is committed.
  // If there is no tx active data will be rolled back so there is no need to flush batches
  if (this.holder.getExecutorType() == ExecutorType.BATCH && isActualTransactionActive()) {
    try {
      if (logger.isDebugEnabled()) {
        logger.debug("Transaction synchronization flushing SqlSession [" + this.holder.getSqlSession() + "]");
      }
      this.holder.getSqlSession().flushStatements();
    } catch (PersistenceException p) {
      if (this.holder.getPersistenceExceptionTranslator() != null) {
        DataAccessException translated = this.holder.getPersistenceExceptionTranslator().translateExceptionIfPossible(p);
        if (translated != null) {
          throw translated;
        }
      }
      throw p;
    }
  }
}
 
開發者ID:moishalo,項目名稱:MybatisSpring2.5.X,代碼行數:25,代碼來源:SqlSessionUtils.java

示例3: testUpdateShouldFlushLocalCache

import org.apache.ibatis.session.ExecutorType; //導入依賴的package包/類
@Test
public void testUpdateShouldFlushLocalCache() throws SQLException {
  SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.SIMPLE);
  try {
    PersonMapper personMapper = sqlSession.getMapper(PersonMapper.class);
    Person person = personMapper.selectByIdNoFlush(1);
    person.setLastName("Perez"); //it is ignored in update
    personMapper.update(person);
    Person updatedPerson = personMapper.selectByIdNoFlush(1);
    assertEquals("Smith", updatedPerson.getLastName());
    assertNotSame(person, updatedPerson);
    sqlSession.commit();
  } finally {
    sqlSession.close();
  }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:17,代碼來源:ForceFlushOnSelectTest.java

示例4: shouldGetAUserNoException

import org.apache.ibatis.session.ExecutorType; //導入依賴的package包/類
@Test
public void shouldGetAUserNoException() {
  SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH,false);
  try {
    Mapper mapper = sqlSession.getMapper(Mapper.class);

    User user   = mapper.getUser(1);

    user.setId(2);
    user.setName("User2");
    mapper.insertUser(user);
    Assert.assertEquals("Dept1", mapper.getUser(2).getDept().getName());
  }
  catch (Exception e)
  {
    Assert.fail(e.getMessage());

  }

  finally {
    sqlSession.commit();
    sqlSession.close();
  }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:25,代碼來源:BatchTest.java

示例5: shouldAcceptDifferentTypeInTheSameBatch

import org.apache.ibatis.session.ExecutorType; //導入依賴的package包/類
@Test
public void shouldAcceptDifferentTypeInTheSameBatch() {
  SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
  try {
    ObjA a = new ObjA();
    a.setId(1);
    a.setName(111);
    sqlSession.insert("insertUser", a);
    ObjB b = new ObjB();
    b.setId(2);
    b.setName("222");
    sqlSession.insert("insertUser", b);
    List<BatchResult> batchResults = sqlSession.flushStatements();
    batchResults.clear();
    sqlSession.clearCache();
    sqlSession.commit();
    List<User> users = sqlSession.selectList("selectUser");
    assertEquals(2, users.size());
  } finally {
    sqlSession.close();
  }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:23,代碼來源:NoParamTypeTest.java

示例6: testInsertMappedBatch

import org.apache.ibatis.session.ExecutorType; //導入依賴的package包/類
@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");
    mapper.insertNameMapped(name);
    Name name2 = new Name();
    name2.setFirstName("Wilma");
    name2.setLastName("Flintstone");
    mapper.insertNameMapped(name2);
    List<BatchResult> batchResults = sqlSession.flushStatements();
    assertNotNull(name.getId());
    assertNotNull(name2.getId());
    assertEquals(1, batchResults.size());
  } finally {
    sqlSession.close();
  }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:25,代碼來源:InsertTest.java

示例7: testInsert

import org.apache.ibatis.session.ExecutorType; //導入依賴的package包/類
@Test
public void testInsert() throws Exception {
  SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
  try {
    User user1 = new User(null, "Pocoyo");
    sqlSession.insert("insert", user1);
    User user2 = new User(null, "Valentina");
    sqlSession.insert("insert", user2);
    sqlSession.flushStatements();
    assertEquals(new Integer(50), user1.getId());
    assertEquals(new Integer(50), user2.getId());
    sqlSession.commit();
  } finally {
    sqlSession.close();
  }
  try {
    sqlSession = sqlSessionFactory.openSession();
    List<User> users = sqlSession.selectList("select");
    Assert.assertTrue(users.size() == 2);
  } finally {
    sqlSession.close();
  }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:24,代碼來源:BatchKeysTest.java

示例8: testInsertJdbc3

import org.apache.ibatis.session.ExecutorType; //導入依賴的package包/類
@Test
public void testInsertJdbc3() throws Exception {
  SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
  try {
    User user1 = new User(null, "Pocoyo");
    sqlSession.insert("insertIdentity", user1);
    User user2 = new User(null, "Valentina");
    sqlSession.insert("insertIdentity", user2);
    sqlSession.flushStatements();
    assertEquals(Integer.valueOf(0), user1.getId());
    assertEquals(Integer.valueOf(1), user2.getId());
    sqlSession.commit();
  } finally {
    sqlSession.close();
  }

  try {
    sqlSession = sqlSessionFactory.openSession();
    List<User> users = sqlSession.selectList("selectIdentity");
    Assert.assertTrue(users.size() == 2);
  } finally {
    sqlSession.close();
  }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:25,代碼來源:BatchKeysTest.java

示例9: testInsertWithMapper

import org.apache.ibatis.session.ExecutorType; //導入依賴的package包/類
@Test
public void testInsertWithMapper() throws Exception {
  SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
  try {
    Mapper userMapper = sqlSession.getMapper(Mapper.class);
    User user1 = new User(null, "Pocoyo");
    userMapper.insert(user1);
    User user2 = new User(null, "Valentina");
    userMapper.insert(user2);
    sqlSession.flushStatements();
    assertEquals(new Integer(50), user1.getId());
    assertEquals(new Integer(50), user2.getId());
    sqlSession.commit();
  } finally {
    sqlSession.close();
  }

  try {
    sqlSession = sqlSessionFactory.openSession();
    List<User> users = sqlSession.selectList("select");
    Assert.assertTrue(users.size() == 2);
  } finally {
    sqlSession.close();
  }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:26,代碼來源:BatchKeysTest.java

示例10: testInsertMapperJdbc3

import org.apache.ibatis.session.ExecutorType; //導入依賴的package包/類
@Test
public void testInsertMapperJdbc3() throws Exception {
  SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
  try {
    Mapper userMapper = sqlSession.getMapper(Mapper.class);
    User user1 = new User(null, "Pocoyo");
    userMapper.insertIdentity(user1);
    User user2 = new User(null, "Valentina");
    userMapper.insertIdentity(user2);
    sqlSession.flushStatements();
    assertEquals(Integer.valueOf(0), user1.getId());
    assertEquals(Integer.valueOf(1), user2.getId());
    sqlSession.commit();
  } finally {
    sqlSession.close();
  }

  try {
    sqlSession = sqlSessionFactory.openSession();
    List<User> users = sqlSession.selectList("selectIdentity");
    Assert.assertTrue(users.size() == 2);
  } finally {
    sqlSession.close();
  }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:26,代碼來源:BatchKeysTest.java

示例11: testSameUpdateAfterCommitSimple

import org.apache.ibatis.session.ExecutorType; //導入依賴的package包/類
@Test
public void testSameUpdateAfterCommitSimple() {
    SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.SIMPLE);
    try {
        PersonMapper personMapper = sqlSession.getMapper(PersonMapper.class);
        Person person = personMapper.selectById(1);
        person.setFirstName("Simone");
        
        // Execute first update then commit.
        personMapper.update(person);
        sqlSession.commit();
        
        // Execute same update a second time. This used to raise an NPE.
        personMapper.update(person);
        sqlSession.commit();
    } finally {
        sqlSession.close();
    }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:20,代碼來源:FlushStatementNpeTest.java

示例12: testSameUpdateAfterCommitReuse

import org.apache.ibatis.session.ExecutorType; //導入依賴的package包/類
@Test
public void testSameUpdateAfterCommitReuse() {
    SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.REUSE);
    try {
        PersonMapper personMapper = sqlSession.getMapper(PersonMapper.class);
        Person person = personMapper.selectById(1);
        person.setFirstName("Simone");
        
        // Execute first update then commit.
        personMapper.update(person);
        sqlSession.commit();
        
        // Execute same update a second time. This used to raise an NPE.
        personMapper.update(person);
        sqlSession.commit();
    } finally {
        sqlSession.close();
    }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:20,代碼來源:FlushStatementNpeTest.java

示例13: testSameUpdateAfterCommitBatch

import org.apache.ibatis.session.ExecutorType; //導入依賴的package包/類
@Test
public void testSameUpdateAfterCommitBatch() {
    SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
    try {
        PersonMapper personMapper = sqlSession.getMapper(PersonMapper.class);
        Person person = personMapper.selectById(1);
        person.setFirstName("Simone");
        
        // Execute first update then commit.
        personMapper.update(person);
        sqlSession.commit();
        
        // Execute same update a second time. This used to raise an NPE.
        personMapper.update(person);
        sqlSession.commit();
    } finally {
        sqlSession.close();
    }
}
 
開發者ID:yuexiahandao,項目名稱:MybatisCode,代碼行數:20,代碼來源:FlushStatementNpeTest.java

示例14: openSessionFromDataSource

import org.apache.ibatis.session.ExecutorType; //導入依賴的package包/類
/**
   * 源碼解析: 從數據源創建會話
   *
   * @param execType 執行類型
   * @param level 數據庫隔離級別
   * @param autoCommit 是否自動提交
   * @return
   */
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) {
  Transaction tx = null;
  try {
    // 源碼解析: 獲取環境
    final Environment environment = configuration.getEnvironment();
    // 源碼解析: 獲取事務工廠
    final TransactionFactory transactionFactory = getTransactionFactoryFromEnvironment(environment);
    // 源碼解析: 創建一個新的事務
    tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit);
    // 源碼解析: 創建執行器
    final Executor executor = configuration.newExecutor(tx, execType);
    // 源碼解析: 創建一個新的sql會話
    return new DefaultSqlSession(configuration, executor, autoCommit);
  } catch (Exception e) {
    // 源碼解析: 關閉事務
    closeTransaction(tx); // may have fetched a connection so lets call close()
    throw ExceptionFactory.wrapException("Error opening session.  Cause: " + e, e);
  } finally {
    // 源碼解析: 錯誤上下文清空重置
    ErrorContext.instance().reset();
  }
}
 
開發者ID:txazo,項目名稱:mybatis,代碼行數:31,代碼來源:DefaultSqlSessionFactory.java

示例15: settingsElement

import org.apache.ibatis.session.ExecutorType; //導入依賴的package包/類
private void settingsElement(Properties props) throws Exception {
  configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL")));
  configuration.setAutoMappingUnknownColumnBehavior(AutoMappingUnknownColumnBehavior.valueOf(props.getProperty("autoMappingUnknownColumnBehavior", "NONE")));
  configuration.setCacheEnabled(booleanValueOf(props.getProperty("cacheEnabled"), true));
  configuration.setProxyFactory((ProxyFactory) createInstance(props.getProperty("proxyFactory")));
  configuration.setLazyLoadingEnabled(booleanValueOf(props.getProperty("lazyLoadingEnabled"), false));
  configuration.setAggressiveLazyLoading(booleanValueOf(props.getProperty("aggressiveLazyLoading"), true));
  configuration.setMultipleResultSetsEnabled(booleanValueOf(props.getProperty("multipleResultSetsEnabled"), true));
  configuration.setUseColumnLabel(booleanValueOf(props.getProperty("useColumnLabel"), true));
  configuration.setUseGeneratedKeys(booleanValueOf(props.getProperty("useGeneratedKeys"), false));
  configuration.setDefaultExecutorType(ExecutorType.valueOf(props.getProperty("defaultExecutorType", "SIMPLE")));
  configuration.setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"), null));
  configuration.setDefaultFetchSize(integerValueOf(props.getProperty("defaultFetchSize"), null));
  configuration.setMapUnderscoreToCamelCase(booleanValueOf(props.getProperty("mapUnderscoreToCamelCase"), false));
  configuration.setSafeRowBoundsEnabled(booleanValueOf(props.getProperty("safeRowBoundsEnabled"), false));
  configuration.setLocalCacheScope(LocalCacheScope.valueOf(props.getProperty("localCacheScope", "SESSION")));
  configuration.setJdbcTypeForNull(JdbcType.valueOf(props.getProperty("jdbcTypeForNull", "OTHER")));
  configuration.setLazyLoadTriggerMethods(stringSetValueOf(props.getProperty("lazyLoadTriggerMethods"), "equals,clone,hashCode,toString"));
  configuration.setSafeResultHandlerEnabled(booleanValueOf(props.getProperty("safeResultHandlerEnabled"), true));
  configuration.setDefaultScriptingLanguage(resolveClass(props.getProperty("defaultScriptingLanguage")));
  configuration.setCallSettersOnNulls(booleanValueOf(props.getProperty("callSettersOnNulls"), false));
  configuration.setLogPrefix(props.getProperty("logPrefix"));
  configuration.setLogImpl(resolveClass(props.getProperty("logImpl")));
  configuration.setConfigurationFactory(resolveClass(props.getProperty("configurationFactory")));
}
 
開發者ID:txazo,項目名稱:mybatis,代碼行數:26,代碼來源:XMLConfigBuilder.java


注:本文中的org.apache.ibatis.session.ExecutorType類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。