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

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

Introduction

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

Prototype

void clearCache();

Source Link

Document

Clears local session cache.

Usage

From source file:com.beginner.core.dao.DaoSupport.java

License:Apache License

/** 
 * {@inheritDoc}//from  w  w w  .  j a  va 2  s .com
 */
@Override
public void batchSave(String str, List objs) throws Exception {
    SqlSessionFactory sqlSessionFactory = sqlSessionTemplate.getSqlSessionFactory();
    //?
    SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
    try {
        if (objs != null) {
            for (int i = 0, size = objs.size(); i < size; i++) {
                sqlSession.insert(str, objs.get(i));
            }
            sqlSession.flushStatements();
            sqlSession.commit();
            sqlSession.clearCache();
        }
    } finally {
        sqlSession.close();
    }
}

From source file:com.beginner.core.dao.DaoSupport.java

License:Apache License

/** 
 * {@inheritDoc}//w  ww  .  java 2  s. c  o m
 */
@Override
public void batchUpdate(String str, List objs) throws Exception {
    SqlSessionFactory sqlSessionFactory = sqlSessionTemplate.getSqlSessionFactory();
    //?
    SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
    try {
        if (objs != null) {
            for (int i = 0, size = objs.size(); i < size; i++) {
                sqlSession.update(str, objs.get(i));
            }
            sqlSession.flushStatements();
            sqlSession.commit();
            sqlSession.clearCache();
        }
    } finally {
        sqlSession.close();
    }
}

From source file:com.beginner.core.dao.DaoSupport.java

License:Apache License

/** 
 * {@inheritDoc}//from ww  w  .jav  a  2  s .  c  o  m
 */
@Override
public void batchDelete(String str, List objs) throws Exception {
    SqlSessionFactory sqlSessionFactory = sqlSessionTemplate.getSqlSessionFactory();
    //?
    SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false);
    try {
        if (objs != null) {
            for (int i = 0, size = objs.size(); i < size; i++) {
                sqlSession.delete(str, objs.get(i));
            }
            sqlSession.flushStatements();
            sqlSession.commit();
            sqlSession.clearCache();
        }
    } finally {
        sqlSession.close();
    }
}

From source file:com.yimidida.shards.session.impl.ShardedSqlSessionImpl.java

License:Open Source License

@Override
public void clearCache() {
    for (Shard shard : this.getShards()) {
        SqlSession session = shard.establishSqlSession();
        if (session != null) {
            session.clearCache();
        }/*from  w  ww.  j  a  v a2  s  .  co  m*/
    }
}

From source file:org.jessma.dao.mybatis.MyBatisSessionMgr.java

License:Apache License

/** ? {@link SqlSession}  {@link ExecutorType}  {@literal type} */
public void changeSessionExecutorType(ExecutorType type) {
    SqlSession session = localSession.get();

    if (session == null)
        localExecutorType.set(type);//from ww  w  . j av a 2s. co  m
    else {
        if (type == null)
            type = getDefaultExecutorType();

        ExecutorType currentType = localExecutorType.get();

        if (type != currentType) {
            SqlSession newSession = sessionFactory.openSession(type, session.getConnection());

            session.clearCache();
            localSession.set(newSession);
            localExecutorType.set(type);
        }
    }
}

From source file:org.mybatis.guice.session.DbSessionManager.java

License:Apache License

public void clearCache() {
    final SqlSession sqlSession = localSqlSession.get();
    if (sqlSession == null)
        throw new SqlSessionException("Error:  Cannot clear the cache.  No managed session is started.");
    sqlSession.clearCache();
}