${database.allClassCopyright}package ${glPackageBaseCommon}; import javax.sql.DataSource; import org.seasar.dbflute.DBDef; import org.seasar.dbflute.bhv.core.BehaviorCommandInvoker; import org.seasar.dbflute.bhv.core.InvokerAssistant; import org.seasar.dbflute.bhv.core.supplement.SequenceCacheHandler; import org.seasar.dbflute.bhv.core.supplement.SequenceCacheKeyGenerator; import org.seasar.dbflute.cbean.sqlclause.SqlClauseCreator; import org.seasar.dbflute.dbmeta.DBMetaProvider; import org.seasar.dbflute.jdbc.DataSourceHandler; import org.seasar.dbflute.jdbc.HandlingDataSourceWrapper; import org.seasar.dbflute.jdbc.StatementConfig; import org.seasar.dbflute.jdbc.StatementFactory; import org.seasar.dbflute.resource.ResourceParameter; #if ($database.isTargetContainerSeasar()) import org.seasar.extension.jdbc.types.ValueTypes; import org.seasar.dbflute.helper.beans.factory.DfBeanDescFactory; #end import org.seasar.dbflute.s2dao.extension.TnBeanMetaDataFactoryExtension; import org.seasar.dbflute.s2dao.jdbc.TnStatementFactoryImpl; import org.seasar.dbflute.s2dao.metadata.TnBeanMetaDataFactory; import org.seasar.dbflute.s2dao.valuetype.TnValueTypeFactory; import org.seasar.dbflute.s2dao.valuetype.impl.TnValueTypeFactoryImpl; import org.seasar.dbflute.twowaysql.SqlAnalyzer; import org.seasar.dbflute.twowaysql.factory.SqlAnalyzerFactory; #if ($database.isTargetContainerSeasar()) import org.seasar.framework.util.Disposable; import org.seasar.framework.util.DisposableUtil; #end /** * @author ${database.classAuthor} */ public class ${glImplementedInvokerAssistant} implements InvokerAssistant { // =================================================================================== // Attribute // ========= // ----------------------------------------------------- // DI component // ------------ protected BehaviorCommandInvoker _behaviorCommandInvoker; protected DataSource _dataSource; // ----------------------------------------------------- // Lazy component // -------------- protected volatile DBMetaProvider _dbmetaProvider; protected volatile SqlClauseCreator _sqlClauseCreator; protected volatile StatementFactory _statementFactory; protected volatile TnBeanMetaDataFactory _beanMetaDataFactory; protected volatile TnValueTypeFactory _valueTypeFactory; protected volatile SequenceCacheHandler _sequenceCacheHandler; // ----------------------------------------------------- // Disposable Flag // --------------- protected volatile boolean _disposable; // =================================================================================== // Assistant Main Work // =================== // ----------------------------------------------------- // Current DBDef // ------------- public DBDef assistCurrentDBDef() { return ${glDBCurrent}.getInstance().currentDBDef(); } // ----------------------------------------------------- // Data Source // ----------- public DataSource assistDataSource() { // DI component DataSourceHandler dataSourceHandler = ${glDBFluteConfig}.getInstance().getDataSourceHandler(); if (dataSourceHandler != null) { return new HandlingDataSourceWrapper(_dataSource, dataSourceHandler); } return _dataSource; } // ----------------------------------------------------- // DBMeta Provider // --------------- public DBMetaProvider assistDBMetaProvider() { // Lazy component if (_dbmetaProvider != null) { return _dbmetaProvider; } synchronized (this) { if (_dbmetaProvider != null) { return _dbmetaProvider; } _dbmetaProvider = createDBMetaProvider(); } return _dbmetaProvider; } protected DBMetaProvider createDBMetaProvider() { return new ${glDBMetaInstanceHandler}(); } // ----------------------------------------------------- // SQL Clause Creator // ------------------ public SqlClauseCreator assistSqlClauseCreator() { // Lazy component if (_sqlClauseCreator != null) { return _sqlClauseCreator; } synchronized (this) { if (_sqlClauseCreator != null) { return _sqlClauseCreator; } _sqlClauseCreator = createSqlClauseCreator(); } return _sqlClauseCreator; } protected SqlClauseCreator createSqlClauseCreator() { return new ${glImplementedSqlClauseCreator}(); } // ----------------------------------------------------- // Statement Factory // ----------------- public StatementFactory assistStatementFactory() { // Lazy component if (_statementFactory != null) { return _statementFactory; } synchronized (this) { if (_statementFactory != null) { return _statementFactory; } _statementFactory = createStatementFactory(); } return _statementFactory; } protected StatementFactory createStatementFactory() { final TnStatementFactoryImpl factory = new TnStatementFactoryImpl(); factory.setDefaultStatementConfig(assistDefaultStatementConfig()); factory.setInternalDebug(${glDBFluteConfig}.getInstance().isInternalDebug()); return factory; } // ----------------------------------------------------- // Bean Meta Data Factory // ---------------------- public TnBeanMetaDataFactory assistBeanMetaDataFactory() { // Lazy component if (_beanMetaDataFactory != null) { return _beanMetaDataFactory; } synchronized (this) { if (_beanMetaDataFactory != null) { return _beanMetaDataFactory; } _beanMetaDataFactory = createBeanMetaDataFactory(); } return _beanMetaDataFactory; } protected TnBeanMetaDataFactory createBeanMetaDataFactory() { final TnBeanMetaDataFactoryExtension factory = new TnBeanMetaDataFactoryExtension(); factory.setDataSource(_dataSource); factory.setValueTypeFactory(assistValueTypeFactory()); return factory; } // ----------------------------------------------------- // Value Type Factory // ------------------ public TnValueTypeFactory assistValueTypeFactory() { // Lazy component if (_valueTypeFactory != null) { return _valueTypeFactory; } synchronized (this) { if (_valueTypeFactory != null) { return _valueTypeFactory; } _valueTypeFactory = createValueTypeFactory(); } return _valueTypeFactory; } protected TnValueTypeFactory createValueTypeFactory() { return new TnValueTypeFactoryImpl(); } // ----------------------------------------------------- // SQL Analyzer Factory // -------------------- /** * Assist the factory of SQL analyzer.
* This factory is also used on ConditionBean.toDisplaySql(). * So this method should not depend on the state of this class. * @return The factory of SQL analyzer. (NotNull) */ public SqlAnalyzerFactory assistSqlAnalyzerFactory() { return new SqlAnalyzerFactory() { public SqlAnalyzer create(String sql, boolean blockNullParameter) { return new SqlAnalyzer(sql, blockNullParameter); } }; } // ----------------------------------------------------- // Resource Parameter // ------------------ public ResourceParameter assistResourceParameter() { ResourceParameter resourceParameter = new ResourceParameter(); resourceParameter.setOutsideSqlPackage(${glDBFluteConfig}.getInstance().getOutsideSqlPackage()); resourceParameter.setLogDateFormat(${glDBFluteConfig}.getInstance().getLogDateFormat()); resourceParameter.setLogTimestampFormat(${glDBFluteConfig}.getInstance().getLogTimestampFormat()); return resourceParameter; } // ----------------------------------------------------- // SQL File Encoding // ----------------- public String assistSqlFileEncoding() { return "${database.sqlFileEncoding}"; } // ----------------------------------------------------- // Statement Configuration // ----------------------- public StatementConfig assistDefaultStatementConfig() { return ${glDBFluteConfig}.getInstance().getDefaultStatementConfig(); } // ----------------------------------------------------- // Sequence Cache // -------------- public SequenceCacheHandler assistSequenceCacheHandler() { if (_sequenceCacheHandler != null) { return _sequenceCacheHandler; } synchronized (this) { if (_sequenceCacheHandler != null) { return _sequenceCacheHandler; } _sequenceCacheHandler = createSequenceCacheHandler(); } return _sequenceCacheHandler; } protected SequenceCacheHandler createSequenceCacheHandler() { SequenceCacheHandler handler = new SequenceCacheHandler(); SequenceCacheKeyGenerator generator = ${glDBFluteConfig}.getInstance().getSequenceCacheKeyGenerator(); if (generator != null) { handler.setSequenceCacheKeyGenerator(generator); } return handler; } // =================================================================================== // Dispose // ======= public void toBeDisposable() { // for HotDeploy #if ($database.isTargetContainerSeasar()) if (_disposable) { return; } synchronized (this) { if (_disposable) { return; } // Register for BehaviorCommandInvoker DisposableUtil.add(new Disposable() { public void dispose() { if (_behaviorCommandInvoker != null) { _behaviorCommandInvoker.clearExecutionCache(); } _disposable = false; } }); // Register for BeanDescFactory DisposableUtil.add(new Disposable() { public void dispose() { DfBeanDescFactory.clear(); } }); // Register for ValueTypes DisposableUtil.add(new Disposable() { public void dispose() { ValueTypes.clear(); } }); _disposable = true; } #end } public boolean isDisposable() { return _disposable; } // =================================================================================== // Assert Helper // ============= protected void assertBehaviorCommandInvoker() { if (_behaviorCommandInvoker == null) { String msg = "The attribute 'behaviorCommandInvoker' should not be null!"; throw new IllegalStateException(msg); } } // =================================================================================== // Accessor // ======== public void setBehaviorCommandInvoker(BehaviorCommandInvoker behaviorCommandInvoker) { _behaviorCommandInvoker = behaviorCommandInvoker; } public void setDataSource(DataSource dataSource) { _dataSource = dataSource; } }