/** * Execute a query with a row handler. * The row handler is called once per row in the query results. * * @param sessionScope - the session scope * @param id - the statement ID * @param paramObject - the parameter object * @param rowHandler - the row handler * @throws SQLException - if the query fails */ public void queryWithRowHandler(SessionScope sessionScope, String id, Object paramObject, RowHandler rowHandler) throws SQLException { MappedStatement ms = getMappedStatement(id); Transaction trans = getTransaction(sessionScope); boolean autoStart = trans == null; try { trans = autoStartTransaction(sessionScope, autoStart, trans); StatementScope statementScope = beginStatementScope(sessionScope, ms); try { ms.executeQueryWithRowHandler(statementScope, trans, paramObject, rowHandler); } finally { endStatementScope(statementScope); } autoCommitTransaction(sessionScope, autoStart); } finally { autoEndTransaction(sessionScope, autoStart); } }
public void setTransactionManager(TransactionManager txManager) { delegate.setTxManager(txManager); }
errorContext.setMoreInfo("Check the result map name."); if (resultMapName != null) { statement.setResultMap(client.getDelegate().getResultMap(resultMapName)); if (additionalResultMapNames != null) { for (int i = 0; i < additionalResultMapNames.length; i++) { statement.addResultMap(client.getDelegate().getResultMap(additionalResultMapNames[i])); statement.setParameterMap(client.getDelegate().getParameterMap(parameterMapName)); errorContext.setObjectId(null); statement.setSqlMapClient(client); if (cacheModelName != null && cacheModelName.length() > 0 && client.getDelegate().isCacheModelsEnabled()) { CacheModel cacheModel = client.getDelegate().getCacheModel(cacheModelName); mappedStatement = new CachingStatement(statement, cacheModel); } else { delegate.addMappedStatement(mappedStatement);
/** * Gets a mapped statement by ID * * @param id - the ID * @return - the mapped statement */ public MappedStatement getMappedStatement(String id) { return delegate.getMappedStatement(id); }
private void wireUpCacheModels() { // Wire Up Cache Models Iterator cacheNames = client.getDelegate().getCacheModelNames(); while (cacheNames.hasNext()) { String cacheName = (String) cacheNames.next(); CacheModel cacheModel = client.getDelegate().getCacheModel(cacheName); Iterator statementNames = cacheModel.getFlushTriggerStatementNames(); while (statementNames.hasNext()) { String statementName = (String) statementNames.next(); MappedStatement statement = client.getDelegate().getMappedStatement(statementName); if (statement != null) { statement.addExecuteListener(cacheModel); } else { throw new RuntimeException("Could not find statement named '" + statementName + "' for use as a flush trigger for the cache model named '" + cacheName + "'."); } } } }
public SqlMapConfiguration() { errorContext = new ErrorContext(); delegate = new SqlMapExecutorDelegate(); typeHandlerFactory = delegate.getTypeHandlerFactory(); client = new SqlMapClientImpl(delegate); registerDefaultTypeAliases(); }
CacheModelConfig(SqlMapConfiguration config, String id, CacheController controller, boolean readOnly, boolean serialize) { this.errorContext = config.getErrorContext(); this.cacheModel = new CacheModel(); SqlMapClientImpl client = config.getClient(); errorContext.setActivity("building a cache model"); cacheModel.setReadOnly(readOnly); cacheModel.setSerialize(serialize); errorContext.setObjectId(id + " cache model"); errorContext.setMoreInfo("Check the cache model type."); cacheModel.setId(id); cacheModel.setResource(errorContext.getResource()); try { cacheModel.setCacheController(controller); } catch (Exception e) { throw new RuntimeException("Error setting Cache Controller Class. Cause: " + e, e); } errorContext.setMoreInfo("Check the cache model configuration."); if (client.getDelegate().isCacheModelsEnabled()) { client.getDelegate().addCacheModel(cacheModel); } errorContext.setMoreInfo(null); errorContext.setObjectId(null); }
errorContext.setMoreInfo("Check the extended result map."); if (extendsResultMap != null) { ResultMap extendedResultMap = (ResultMap) client.getDelegate().getResultMap(extendsResultMap); ResultMapping[] resultMappings = extendedResultMap.getResultMappings(); for (int i = 0; i < resultMappings.length; i++) { resultMappingIndex = resultMappingList.size(); resultMap.setResultMappingList(resultMappingList); client.getDelegate().addResultMap(resultMap);
/** * Apply the given iBATIS TransactionConfig to the SqlMapClient. * <p>Default implementation casts to ExtendedSqlMapClient, retrieves the maximum * number of concurrent transactions from the SqlMapExecutorDelegate, and sets * an iBATIS TransactionManager with the given TransactionConfig. * @param sqlMapClient the SqlMapClient to apply the TransactionConfig to * @param transactionConfig the iBATIS TransactionConfig to apply * @see com.ibatis.sqlmap.engine.impl.ExtendedSqlMapClient * @see com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate#getMaxTransactions * @see com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate#setTxManager */ protected void applyTransactionConfig(SqlMapClient sqlMapClient, TransactionConfig transactionConfig) { if (!(this.sqlMapClient instanceof ExtendedSqlMapClient)) { throw new IllegalArgumentException( "Cannot set TransactionConfig with DataSource for SqlMapClient if not of type " + "ExtendedSqlMapClient: " + this.sqlMapClient); } ExtendedSqlMapClient extendedClient = (ExtendedSqlMapClient) this.sqlMapClient; transactionConfig.setMaximumConcurrentTransactions(extendedClient.getDelegate().getMaxTransactions()); extendedClient.getDelegate().setTxManager(new TransactionManager(transactionConfig)); }
ParameterMapConfig(SqlMapConfiguration config, String id, Class parameterClass) { this.config = config; this.errorContext = config.getErrorContext(); this.client = config.getClient(); errorContext.setActivity("building a parameter map"); parameterMap = new ParameterMap(client.getDelegate()); parameterMap.setId(id); parameterMap.setResource(errorContext.getResource()); errorContext.setObjectId(id + " parameter map"); parameterMap.setParameterClass(parameterClass); errorContext.setMoreInfo("Check the parameter mappings."); this.parameterMappingList = new ArrayList(); client.getDelegate().addParameterMap(parameterMap); }
errorContext.setMoreInfo("Check the result map name."); if (resultMapName != null) { statement.setResultMap(client.getDelegate().getResultMap(resultMapName)); if (additionalResultMapNames != null) { for (int i = 0; i < additionalResultMapNames.length; i++) { statement.addResultMap(client.getDelegate().getResultMap(additionalResultMapNames[i])); statement.setParameterMap(client.getDelegate().getParameterMap(parameterMapName)); errorContext.setObjectId(null); statement.setSqlMapClient(client); if (cacheModelName != null && cacheModelName.length() > 0 && client.getDelegate().isCacheModelsEnabled()) { CacheModel cacheModel = client.getDelegate().getCacheModel(cacheModelName); mappedStatement = new CachingStatement(statement, cacheModel); } else { delegate.addMappedStatement(mappedStatement);
/** * Gets a mapped statement by ID * * @param id - the ID * @return - the mapped statement */ public MappedStatement getMappedStatement(String id) { return delegate.getMappedStatement(id); }
private void wireUpCacheModels() { // Wire Up Cache Models Iterator cacheNames = client.getDelegate().getCacheModelNames(); while (cacheNames.hasNext()) { String cacheName = (String) cacheNames.next(); CacheModel cacheModel = client.getDelegate().getCacheModel(cacheName); Iterator statementNames = cacheModel.getFlushTriggerStatementNames(); while (statementNames.hasNext()) { String statementName = (String) statementNames.next(); MappedStatement statement = client.getDelegate().getMappedStatement(statementName); if (statement != null) { statement.addExecuteListener(cacheModel); } else { throw new RuntimeException("Could not find statement named '" + statementName + "' for use as a flush trigger for the cache model named '" + cacheName + "'."); } } } }
public SqlMapConfiguration() { errorContext = new ErrorContext(); delegate = new SqlMapExecutorDelegate(); typeHandlerFactory = delegate.getTypeHandlerFactory(); client = new SqlMapClientImpl(delegate); registerDefaultTypeAliases(); }
CacheModelConfig(SqlMapConfiguration config, String id, CacheController controller, boolean readOnly, boolean serialize) { this.errorContext = config.getErrorContext(); this.cacheModel = new CacheModel(); SqlMapClientImpl client = config.getClient(); errorContext.setActivity("building a cache model"); cacheModel.setReadOnly(readOnly); cacheModel.setSerialize(serialize); errorContext.setObjectId(id + " cache model"); errorContext.setMoreInfo("Check the cache model type."); cacheModel.setId(id); cacheModel.setResource(errorContext.getResource()); try { cacheModel.setCacheController(controller); } catch (Exception e) { throw new RuntimeException("Error setting Cache Controller Class. Cause: " + e, e); } errorContext.setMoreInfo("Check the cache model configuration."); if (client.getDelegate().isCacheModelsEnabled()) { client.getDelegate().addCacheModel(cacheModel); } errorContext.setMoreInfo(null); errorContext.setObjectId(null); }
errorContext.setMoreInfo("Check the extended result map."); if (extendsResultMap != null) { ResultMap extendedResultMap = (ResultMap) client.getDelegate().getResultMap(extendsResultMap); ResultMapping[] resultMappings = extendedResultMap.getResultMappings(); for (int i = 0; i < resultMappings.length; i++) { resultMappingIndex = resultMappingList.size(); resultMap.setResultMappingList(resultMappingList); client.getDelegate().addResultMap(resultMap);
ParameterMapConfig(SqlMapConfiguration config, String id, Class parameterClass) { this.config = config; this.errorContext = config.getErrorContext(); this.client = config.getClient(); errorContext.setActivity("building a parameter map"); parameterMap = new ParameterMap(client.getDelegate()); parameterMap.setId(id); parameterMap.setResource(errorContext.getResource()); errorContext.setObjectId(id + " parameter map"); parameterMap.setParameterClass(parameterClass); errorContext.setMoreInfo("Check the parameter mappings."); this.parameterMappingList = new ArrayList(); client.getDelegate().addParameterMap(parameterMap); }
/** * Execute a query with a row handler. * The row handler is called once per row in the query results. * * @param sessionScope - the session scope * @param id - the statement ID * @param paramObject - the parameter object * @param rowHandler - the row handler * @throws SQLException - if the query fails */ public void queryWithRowHandler(SessionScope sessionScope, String id, Object paramObject, RowHandler rowHandler) throws SQLException { MappedStatement ms = getMappedStatement(id); Transaction trans = getTransaction(sessionScope); boolean autoStart = trans == null; try { trans = autoStartTransaction(sessionScope, autoStart, trans); StatementScope statementScope = beginStatementScope(sessionScope, ms); try { ms.executeQueryWithRowHandler(statementScope, trans, paramObject, rowHandler); } finally { endStatementScope(statementScope); } autoCommitTransaction(sessionScope, autoStart); } finally { autoEndTransaction(sessionScope, autoStart); } }
public MappedStatement getMappedStatement(String id) { return delegate.getMappedStatement(id); }
public void setTransactionManager(TransactionManager txManager) { delegate.setTxManager(txManager); }