Skip to content

Commit

Permalink
round of refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Apr 13, 2012
1 parent 3bd5290 commit 23004ce
Show file tree
Hide file tree
Showing 40 changed files with 324 additions and 351 deletions.
Expand Up @@ -639,7 +639,7 @@ public int getRouterDataPeekAheadCount() {
}

public void truncateTable(String tableName) {
String quote = platform.isDelimitedIdentifierModeOn() ? platform.getPlatformInfo()
String quote = platform.getDdlBuilder().isDelimitedIdentifierModeOn() ? platform.getPlatformInfo()
.getDelimiterToken() : "";
boolean success = false;
int tryCount = 5;
Expand Down
Expand Up @@ -89,15 +89,6 @@ public abstract class AbstractDatabasePlatform implements IDatabasePlatform {

protected long clearCacheModelTimeoutInMs = DateUtils.MILLIS_PER_HOUR;

/* Whether script mode is on. */
protected boolean scriptModeOn;

/* Whether SQL comments are generated or not. */
protected boolean sqlCommentsOn = false;

/* Whether delimited identifiers are used or not. */
protected boolean delimitedIdentifierModeOn;

/* Whether identity override is enabled. */
protected boolean identityOverrideOn;

Expand All @@ -117,7 +108,6 @@ public abstract class AbstractDatabasePlatform implements IDatabasePlatform {
protected boolean metadataIgnoreCase = true;

public AbstractDatabasePlatform() {
setDelimitedIdentifierModeOn(true);
}

abstract public ISqlTemplate getSqlTemplate();
Expand Down Expand Up @@ -154,36 +144,6 @@ public long getClearCacheModelTimeoutInMs() {
return clearCacheModelTimeoutInMs;
}

public boolean isScriptModeOn() {
return scriptModeOn;
}

public void setScriptModeOn(boolean scriptModeOn) {
this.scriptModeOn = scriptModeOn;
}

public boolean isSqlCommentsOn() {
return sqlCommentsOn;
}

public void setSqlCommentsOn(boolean sqlCommentsOn) {
if (!getPlatformInfo().isSqlCommentsSupported() && sqlCommentsOn) {
throw new DdlException("Platform does not support SQL comments");
}
this.sqlCommentsOn = sqlCommentsOn;
}

public boolean isDelimitedIdentifierModeOn() {
return delimitedIdentifierModeOn;
}

public void setDelimitedIdentifierModeOn(boolean delimitedIdentifierModeOn) {
if (!getPlatformInfo().isDelimitedIdentifiersSupported() && delimitedIdentifierModeOn) {
throw new DdlException("Platform does not support delimited identifier");
}
this.delimitedIdentifierModeOn = delimitedIdentifierModeOn;
}

public boolean isIdentityOverrideOn() {
return identityOverrideOn;
}
Expand Down

Large diffs are not rendered by default.

Expand Up @@ -73,57 +73,6 @@ public interface IDatabasePlatform {

public String getDefaultCatalog();

/*
* Determines whether script mode is on. This means that the generated SQL
* is not intended to be sent directly to the database but rather to be
* saved in a SQL script file. Per default, script mode is off.
*
* @return <code>true</code> if script mode is on
*/
public boolean isScriptModeOn();

/*
* Specifies whether script mode is on. This means that the generated SQL is
* not intended to be sent directly to the database but rather to be saved
* in a SQL script file.
*
* @param scriptModeOn <code>true</code> if script mode is on
*/
public void setScriptModeOn(boolean scriptModeOn);

/*
* Determines whether delimited identifiers are used or normal SQL92
* identifiers (which may only contain alphanumerical characters and the
* underscore, must start with a letter and cannot be a reserved keyword).
* Per default, delimited identifiers are not used
*
* @return <code>true</code> if delimited identifiers are used
*/
public boolean isDelimitedIdentifierModeOn();

/*
* Specifies whether delimited identifiers are used or normal SQL92
* identifiers.
*
* @param delimitedIdentifierModeOn <code>true</code> if delimited
* identifiers shall be used
*/
public void setDelimitedIdentifierModeOn(boolean delimitedIdentifierModeOn);

/*
* Determines whether SQL comments are generated.
*
* @return <code>true</code> if SQL comments shall be generated
*/
public boolean isSqlCommentsOn();

/*
* Specifies whether SQL comments shall be generated.
*
* @param sqlCommentsOn <code>true</code> if SQL comments shall be generated
*/
public void setSqlCommentsOn(boolean sqlCommentsOn);

/*
* Determines whether SQL insert statements can specify values for identity
* columns. This setting is only relevant if the database supports it
Expand Down
Expand Up @@ -24,5 +24,16 @@ public interface IDdlBuilder {
public String alterDatabase(Database currentModel, Database desiredModel);

public String dropTables(Database database);

/*
* Determines whether delimited identifiers are used or normal SQL92
* identifiers (which may only contain alphanumerical characters and the
* underscore, must start with a letter and cannot be a reserved keyword).
* Per default, delimited identifiers are not used
*
* @return <code>true</code> if delimited identifiers are used
*/
public boolean isDelimitedIdentifierModeOn();


}
Expand Up @@ -27,7 +27,7 @@ public boolean isLoadColumnTransform() {
}

public String getFullyQualifiedTableName(IDatabasePlatform platform, String schema, String catalog, String tableName) {
String quote = platform.isDelimitedIdentifierModeOn() ? platform
String quote = platform.getDdlBuilder().isDelimitedIdentifierModeOn() ? platform
.getPlatformInfo().getDelimiterToken() : "";
tableName = quote + tableName + quote;
if (!StringUtils.isBlank(schema)) {
Expand All @@ -52,7 +52,7 @@ public String transform(IDatabasePlatform platform, DataContext context,
newValue = numericValue.toString();
}

String quote = platform.isDelimitedIdentifierModeOn() ? platform
String quote = platform.getDdlBuilder().isDelimitedIdentifierModeOn() ? platform
.getPlatformInfo().getDelimiterToken() : "";
StringBuilder sql = new StringBuilder(String.format("update %s set %s=%s+%s where ",
getFullyQualifiedTableName(platform, data.getSchemaName(), data.getCatalogName(), data.getTableName()),
Expand Down
Expand Up @@ -50,7 +50,6 @@
import org.jumpmind.db.model.UniqueIndex;
import org.jumpmind.db.sql.IConnectionCallback;
import org.jumpmind.db.sql.JdbcSqlTemplate;
import org.jumpmind.util.FormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -705,7 +704,7 @@ protected void removeInternalForeignKeyIndex(Connection connection,
for (int columnIdx = 0; columnIdx < fk.getReferenceCount(); columnIdx++) {
String name = fk.getReference(columnIdx).getLocalColumnName();
Column localColumn = table
.findColumn(name, getPlatform().isDelimitedIdentifierModeOn());
.findColumn(name, getPlatform().getDdlBuilder().isDelimitedIdentifierModeOn());

if (mustBeUnique && !localColumn.isPrimaryKey()) {
mustBeUnique = false;
Expand Down Expand Up @@ -1149,11 +1148,11 @@ public void determineAutoIncrementFromResultSetMetaData(Connection conn, Table t
}

public StringBuilder appendIdentifier(StringBuilder query, String identifier) {
if (getPlatform().isDelimitedIdentifierModeOn()) {
if (getPlatform().getDdlBuilder().isDelimitedIdentifierModeOn()) {
query.append(getPlatformInfo().getDelimiterToken());
}
query.append(identifier);
if (getPlatform().isDelimitedIdentifierModeOn()) {
if (getPlatform().getDdlBuilder().isDelimitedIdentifierModeOn()) {
query.append(getPlatformInfo().getDelimiterToken());
}
return query;
Expand All @@ -1166,7 +1165,7 @@ public StringBuilder appendIdentifier(StringBuilder query, String identifier) {
*/
protected void sortForeignKeys(Database model) {
for (int tableIdx = 0; tableIdx < model.getTableCount(); tableIdx++) {
model.getTable(tableIdx).sortForeignKeys(getPlatform().isDelimitedIdentifierModeOn());
model.getTable(tableIdx).sortForeignKeys(getPlatform().getDdlBuilder().isDelimitedIdentifierModeOn());
}
}

Expand Down Expand Up @@ -1233,7 +1232,7 @@ public String determineSchemaOf(Connection connection, String schemaPattern, Tab

String tablePattern = table.getName();

if (getPlatform().isDelimitedIdentifierModeOn()) {
if (getPlatform().getDdlBuilder().isDelimitedIdentifierModeOn()) {
tablePattern = tablePattern.toUpperCase();
}

Expand All @@ -1254,7 +1253,7 @@ public String determineSchemaOf(Connection connection, String schemaPattern, Tab
while (found && columnData.next()) {
values = readColumns(columnData, getColumnsForColumn());

if (table.findColumn((String) values.get("COLUMN_NAME"), getPlatform()
if (table.findColumn((String) values.get("COLUMN_NAME"), getPlatform().getDdlBuilder()
.isDelimitedIdentifierModeOn()) == null) {
found = false;
}
Expand Down
Expand Up @@ -78,7 +78,7 @@ public Db2DatabasePlatform(DataSource dataSource, DatabasePlatformSettings setti
info.setEmptyStringNulled(false);

ddlReader = new Db2DdlReader(this);
ddlBuilder = new Db2DdlBuilder(this);
ddlBuilder = new Db2DdlBuilder(info);
}

@Override
Expand Down
Expand Up @@ -35,16 +35,16 @@
import org.jumpmind.db.model.Table;
import org.jumpmind.db.model.TypeMap;
import org.jumpmind.db.platform.AbstractDdlBuilder;
import org.jumpmind.db.platform.IDatabasePlatform;
import org.jumpmind.db.platform.DatabasePlatformInfo;
import org.jumpmind.db.platform.PlatformUtils;

/*
* The DDL Builder for DB2.
*/
public class Db2DdlBuilder extends AbstractDdlBuilder {

public Db2DdlBuilder(IDatabasePlatform platform) {
super(platform);
public Db2DdlBuilder(DatabasePlatformInfo platformInfo) {
super(platformInfo);
addEscapedCharSequence("'", "''");
}

Expand Down Expand Up @@ -96,7 +96,7 @@ protected void writeCastExpression(Column sourceColumn, Column targetColumn, Str
Object sizeSpec = targetColumn.getSize();

if (sizeSpec == null) {
sizeSpec = platform.getPlatformInfo()
sizeSpec = platformInfo
.getDefaultSize(targetColumn.getTypeCode());
}
type = "CHAR(" + sizeSpec.toString() + ")";
Expand Down Expand Up @@ -161,7 +161,7 @@ protected void processChange(Database currentModel, Database desiredModel,
ddl.append("ADD COLUMN ");
writeColumn(change.getChangedTable(), change.getNewColumn(), ddl);
printEndOfStatement(ddl);
change.apply(currentModel, platform.isDelimitedIdentifierModeOn());
change.apply(currentModel, delimitedIdentifierModeOn);
}

/*
Expand All @@ -175,7 +175,7 @@ protected void processChange(Database currentModel, Database desiredModel,
ddl.append("DROP COLUMN ");
printIdentifier(getColumnName(change.getColumn()), ddl);
printEndOfStatement(ddl);
change.apply(currentModel, platform.isDelimitedIdentifierModeOn());
change.apply(currentModel, delimitedIdentifierModeOn);
}

/*
Expand All @@ -188,7 +188,7 @@ protected void processChange(Database currentModel, Database desiredModel,
printIndent(ddl);
ddl.append("DROP PRIMARY KEY");
printEndOfStatement(ddl);
change.apply(currentModel, platform.isDelimitedIdentifierModeOn());
change.apply(currentModel, delimitedIdentifierModeOn);
}

/*
Expand All @@ -203,7 +203,7 @@ protected void processChange(Database currentModel, Database desiredModel,
printEndOfStatement(ddl);
writeExternalPrimaryKeysCreateStmt(change.getChangedTable(),
change.getNewPrimaryKeyColumns(), ddl);
change.apply(currentModel, platform.isDelimitedIdentifierModeOn());
change.apply(currentModel, delimitedIdentifierModeOn);
}

}
Expand Up @@ -80,7 +80,7 @@ public DerbyDatabasePlatform(DataSource dataSource, DatabasePlatformSettings set
info.setEmptyStringNulled(false);

ddlReader = new DerbyDdlReader(this);
ddlBuilder = new DerbyDdlBuilder(this);
ddlBuilder = new DerbyDdlBuilder(info);
}

@Override
Expand Down
Expand Up @@ -31,16 +31,16 @@
import org.jumpmind.db.model.Table;
import org.jumpmind.db.model.TypeMap;
import org.jumpmind.db.platform.AbstractDdlBuilder;
import org.jumpmind.db.platform.IDatabasePlatform;
import org.jumpmind.db.platform.DatabasePlatformInfo;
import org.jumpmind.db.platform.PlatformUtils;

/*
* The SQL Builder for Derby.
*/
public class DerbyDdlBuilder extends AbstractDdlBuilder {

public DerbyDdlBuilder(IDatabasePlatform platform) {
super(platform);
public DerbyDdlBuilder(DatabasePlatformInfo platformInfo) {
super(platformInfo);
addEscapedCharSequence("'", "''");
}

Expand Down Expand Up @@ -132,7 +132,7 @@ protected void processChange(Database currentModel, Database desiredModel,
ddl.append("ADD COLUMN ");
writeColumn(change.getChangedTable(), change.getNewColumn(), ddl);
printEndOfStatement(ddl);
change.apply(currentModel, platform.isDelimitedIdentifierModeOn());
change.apply(currentModel, delimitedIdentifierModeOn);
}

}
Expand Up @@ -86,7 +86,7 @@ public FirebirdDatabasePlatform(DataSource dataSource, DatabasePlatformSettings
info.setEmptyStringNulled(false);

ddlReader = new FirebirdDdlReader(this);
ddlBuilder = new FirebirdDdlBuilder(this);
ddlBuilder = new FirebirdDdlBuilder(info);
}

@Override
Expand Down
Expand Up @@ -32,15 +32,15 @@
import org.jumpmind.db.model.IIndex;
import org.jumpmind.db.model.Table;
import org.jumpmind.db.platform.AbstractDdlBuilder;
import org.jumpmind.db.platform.IDatabasePlatform;
import org.jumpmind.db.platform.DatabasePlatformInfo;
import org.jumpmind.db.platform.PlatformUtils;

/*
* The SQL Builder for the FireBird database.
*/
public class FirebirdDdlBuilder extends AbstractDdlBuilder {
public FirebirdDdlBuilder(IDatabasePlatform platform) {
super(platform);
public FirebirdDdlBuilder(DatabasePlatformInfo platformInfo) {
super(platformInfo);
addEscapedCharSequence("'", "''");
}

Expand Down Expand Up @@ -264,7 +264,7 @@ protected void processChange(Database currentModel, Database desiredModel,
printEndOfStatement(ddl);

Table curTable = currentModel.findTable(change.getChangedTable().getName(),
platform.isDelimitedIdentifierModeOn());
delimitedIdentifierModeOn);

if (!change.isAtEnd()) {
Column prevColumn = change.getPreviousColumn();
Expand All @@ -273,7 +273,7 @@ protected void processChange(Database currentModel, Database desiredModel,
// we need the corresponding column object from the current
// table
prevColumn = curTable.findColumn(prevColumn.getName(),
platform.isDelimitedIdentifierModeOn());
delimitedIdentifierModeOn);
}
// Even though Firebird can only add columns, we can move them later
// on
Expand All @@ -291,7 +291,7 @@ protected void processChange(Database currentModel, Database desiredModel,
if (change.getNewColumn().isAutoIncrement()) {
writeAutoIncrementCreateStmts(curTable, change.getNewColumn(), ddl);
}
change.apply(currentModel, platform.isDelimitedIdentifierModeOn());
change.apply(currentModel, delimitedIdentifierModeOn);
}

/*
Expand All @@ -308,6 +308,6 @@ protected void processChange(Database currentModel, Database desiredModel,
ddl.append("DROP ");
printIdentifier(getColumnName(change.getColumn()), ddl);
printEndOfStatement(ddl);
change.apply(currentModel, platform.isDelimitedIdentifierModeOn());
change.apply(currentModel, delimitedIdentifierModeOn);
}
}

0 comments on commit 23004ce

Please sign in to comment.