private String translateStatementName(String statementName) { return translatedStatementNames.computeIfAbsent(statementName, statementName1 -> { if (systemEnvironment.isDefaultDbProvider()) { return statementName1; } String forExternalDb = String.format("%s-%s", statementName1, database.getType()); MappedStatement statement; try { statement = delegate.getConfiguration().getMappedStatement(forExternalDb); } catch (Exception e) { statement = null; } return statement != null ? forExternalDb : statementName1; }); }
public MybatisRepositoryFactory(SqlSessionTemplate sqlSessionTemplate, MappingContext<?, ?> mappingContext) { Assert.notNull(sqlSessionTemplate, "SqlSessionTemplate must not be null!"); this.sqlSessionTemplate = sqlSessionTemplate; addRepositoryProxyPostProcessor(new MybatisMapperBuildProcessor( sqlSessionTemplate.getConfiguration(), mappingContext)); addQueryCreationListener(new MybatisQueryCreationListener( sqlSessionTemplate.getConfiguration(), mappingContext)); }
@Override public void afterPropertiesSet() throws Exception { this.sqlSessionTemplate.getConfiguration() .addInterceptor(new AuditingInterceptor(this)); }
@Override public void afterPropertiesSet() throws Exception { Assert.state(sqlSessionTemplate != null, "SqlSessionTemplate must not be null!"); if (null != this.dialect) { return; } DataSource dataSource = sqlSessionTemplate.getConfiguration().getEnvironment().getDataSource(); Connection conn = null; try { conn = dataSource.getConnection(); DatabaseMetaData metaData = conn.getMetaData(); this.dialect = getDialect(metaData); log.info("Using dialect: " + this.dialect); } finally { if (null != conn) { conn.close(); } } }
@Override protected void findPropertiesByIds(List<Long> ids, final PropertyFinderCallback callback) { ResultHandler valueResultHandler = new ResultHandler() { public void handleResult(ResultContext context) { PropertyIdQueryResult result = (PropertyIdQueryResult) context.getResultObject(); Long id = result.getPropId(); // Make the serializable value List<PropertyIdSearchRow> rows = result.getPropValues(); Serializable value = convertPropertyIdSearchRows(rows); callback.handleProperty(id, value); } }; // A row handler to roll up individual rows Configuration configuration = template.getConfiguration(); RollupResultHandler rollupResultHandler = new RollupResultHandler( configuration, KEY_COLUMNS_FINDBYIDS, "propValues", valueResultHandler); // Query using the IDs PropertyIdQueryParameter params = new PropertyIdQueryParameter(); params.setRootPropIds(ids); template.select(SELECT_PROPERTIES_BY_IDS, params, rollupResultHandler); // Process any remaining results rollupResultHandler.processLastResults(); // Done }
@Override protected void findPropertiesByIds(List<Long> ids, final PropertyFinderCallback callback) { ResultHandler valueResultHandler = new ResultHandler() { public void handleResult(ResultContext context) { PropertyIdQueryResult result = (PropertyIdQueryResult) context.getResultObject(); Long id = result.getPropId(); // Make the serializable value List<PropertyIdSearchRow> rows = result.getPropValues(); Serializable value = convertPropertyIdSearchRows(rows); callback.handleProperty(id, value); } }; // A row handler to roll up individual rows Configuration configuration = template.getConfiguration(); RollupResultHandler rollupResultHandler = new RollupResultHandler( configuration, KEY_COLUMNS_FINDBYIDS, "propValues", valueResultHandler); // Query using the IDs PropertyIdQueryParameter params = new PropertyIdQueryParameter(); params.setRootPropIds(ids); template.select(SELECT_PROPERTIES_BY_IDS, params, rollupResultHandler); // Process any remaining results rollupResultHandler.processLastResults(); // Done }
public void setUp() throws Exception sqlSessionTemplate.getConfiguration().setCacheEnabled(false); sqlSessionTemplate.getConfiguration().setLocalCacheScope(LocalCacheScope.STATEMENT); assertFalse("expected myBatis cache to be disabled", sqlSessionTemplate.getConfiguration().isCacheEnabled());