${database.allClassCopyright}package ${glPackageBaseCommon};

import org.seasar.dbflute.DBDef;
import org.seasar.dbflute.cbean.ConditionBean;
import org.seasar.dbflute.cbean.sqlclause.*;
import org.seasar.dbflute.dbmeta.DBMetaProvider;

/**
 * The creator of SQL clause.
 * @author ${database.classAuthor}
 */
public class ${glImplementedSqlClauseCreator} implements SqlClauseCreator {

	/**
	 * Create SQL clause. {for condition-bean}
	 * @param cb Condition-bean. (NotNull) 
	 * @return SQL clause. (NotNull)
	 */
    public SqlClause createSqlClause(ConditionBean cb) {
        String tableDbName = cb.getTableDbName();
		SqlClause sqlClause = createSqlClause(tableDbName);
        return sqlClause;
    }

	/**
	 * Create SQL clause.
	 * @param tableDbName The DB name of table. (NotNull) 
	 * @return SQL clause. (NotNull)
	 */
    public SqlClause createSqlClause(String tableDbName) {
        DBMetaProvider dbmetaProvider = new ${glDBMetaInstanceHandler}();
        SqlClause sqlClause;
        if (isCurrentDBDef(DBDef.MySQL)) {
            sqlClause = new SqlClauseMySql(tableDbName).provider(dbmetaProvider);
        } else if (isCurrentDBDef(DBDef.PostgreSQL)) {
            sqlClause = new SqlClausePostgreSql(tableDbName).provider(dbmetaProvider);
        } else if (isCurrentDBDef(DBDef.Oracle)) {
            sqlClause = new SqlClauseOracle(tableDbName).provider(dbmetaProvider);
        } else if (isCurrentDBDef(DBDef.DB2)) {
            sqlClause = new SqlClauseDb2(tableDbName).provider(dbmetaProvider);
        } else if (isCurrentDBDef(DBDef.SQLServer)) {
            sqlClause = new SqlClauseSqlServer(tableDbName).provider(dbmetaProvider);
        } else if (isCurrentDBDef(DBDef.FireBird)) {
            sqlClause = new SqlClauseFirebird(tableDbName).provider(dbmetaProvider);
        } else if (isCurrentDBDef(DBDef.H2)) {
            sqlClause = new SqlClauseH2(tableDbName).provider(dbmetaProvider);
        } else if (isCurrentDBDef(DBDef.Derby)) {
            sqlClause = new SqlClauseDerby(tableDbName).provider(dbmetaProvider);
        } else {
            sqlClause = new SqlClause${database.generateDbName}(tableDbName).provider(dbmetaProvider);
        }
        if (isDisableSelectIndex()) {
            sqlClause.disableSelectIndex();
        }
        return sqlClause;
    }

    protected boolean isCurrentDBDef(DBDef currentDBDef) {
	    return ${glDBCurrent}.getInstance().isCurrentDBDef(currentDBDef);
    }

    protected boolean isDisableSelectIndex() {
	    return ${glDBFluteConfig}.getInstance().isDisableSelectIndex();
    }
}
