Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/osgiBuildProblem' into osgiBuild…
Browse files Browse the repository at this point in the history
…Problem
  • Loading branch information
ssuehs-shango committed Aug 28, 2012
2 parents f1e987c + 2538c8d commit 05c3d39
Show file tree
Hide file tree
Showing 62 changed files with 877 additions and 425 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,5 +1,6 @@
target
.project
.settings
.classpath
liquibase.iws
out
out
Expand Up @@ -5,6 +5,7 @@
import liquibase.change.ChangeMetaData;
import liquibase.change.ChangeProperty;
import liquibase.database.Database;
import liquibase.database.structure.Table;
import liquibase.exception.DatabaseException;
import liquibase.exception.UnexpectedLiquibaseException;
import liquibase.executor.Executor;
Expand Down Expand Up @@ -94,7 +95,7 @@ private void generateChildren(Database database) {
(String) result.get(FindForeignKeyConstraintsStatement.RESULT_COLUMN_BASE_TABLE_NAME);
String constraintName =
(String) result.get(FindForeignKeyConstraintsStatement.RESULT_COLUMN_CONSTRAINT_NAME);
if (getBaseTableName().equalsIgnoreCase(baseTableName)) {
if (new Table(getBaseTableName()).equals(new Table(baseTableName), database)) {
if( !handledConstraints.contains(constraintName)) {
DropForeignKeyConstraintChange dropForeignKeyConstraintChange =
new DropForeignKeyConstraintChange();
Expand Down
Expand Up @@ -133,7 +133,7 @@ public SqlStatement[] generateStatements(Database database) {
if (columnConfig != null) {
columnName = columnConfig.getName();

if (columnConfig.getType().equalsIgnoreCase("SKIP")) {
if ("skip".equalsIgnoreCase(columnConfig.getType())) {
continue;
}

Expand Down
Expand Up @@ -66,7 +66,7 @@ private String getWhereClause(InsertOrUpdateStatement insertOrUpdateStatement, D
{
where.append(database.escapeColumnName(insertOrUpdateStatement.getCatalogName(), insertOrUpdateStatement.getSchemaName(), insertOrUpdateStatement.getTableName(), thisPkColumn) + " = " );
Object newValue = insertOrUpdateStatement.getColumnValues().get(thisPkColumn);
where.append(DataTypeFactory.getInstance().fromObject(newValue, database));
where.append(DataTypeFactory.getInstance().fromObject(newValue, database).objectToString(newValue, database));

where.append(" AND ");
}
Expand Down
164 changes: 135 additions & 29 deletions liquibase-core/src/main/java/liquibase/database/AbstractDatabase.java
Expand Up @@ -31,6 +31,7 @@
import java.io.Writer;
import java.math.BigInteger;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -195,31 +196,84 @@ protected String doGetDefaultCatalogName() throws DatabaseException {
}

public Schema correctSchema(Schema schema) {
if (schema instanceof Schema.DatabaseSpecific && ((Schema.DatabaseSpecific) schema).getDatabase().equals(this)) {
return schema;
}
if (schema == null) {
schema = new Schema(getDefaultCatalogName(), getDefaultSchemaName());
return new Schema.DatabaseSpecific(getDefaultCatalogName(), getDefaultSchemaName(), this);
}
String catalogName = schema.getCatalogName();
String schemaName = schema.getName();

if (catalogName == null) {
catalogName = getDefaultCatalogName();
} else {
catalogName = correctObjectName(catalogName);
}
if (supportsCatalogs() && supportsSchemas()) {
if (catalogName.equals(Catalog.DEFAULT_NAME)) {
catalogName = getDefaultCatalogName();
} else {
catalogName = correctObjectName(catalogName);
}

if (supportsSchemas()) {
if (schemaName == null) {
if (schemaName.equals(Schema.DEFAULT_NAME)) {
schemaName = getDefaultSchemaName();
} else {
schemaName = correctObjectName(schemaName);
}
} else {
} else if (!supportsCatalogs() && !supportsSchemas()) {
return new Schema.DatabaseSpecific("DEFAULT", "DEFAULT", this);
} else if (supportsCatalogs()) { //schema is null
if (catalogName.equals(Catalog.DEFAULT_NAME)) {
if (Schema.DEFAULT_NAME.equals(schemaName)) {
catalogName = getDefaultCatalogName();
} else {
catalogName = schemaName;
}
}
schemaName = catalogName;
} else if (supportsSchemas()) {
if (schemaName.equals(Schema.DEFAULT_NAME)) {
if (Catalog.DEFAULT_NAME.equals(catalogName)) {
schemaName = getDefaultSchemaName();
} else {
schemaName = catalogName;
}
}
catalogName = schemaName;
}
return new Schema.DatabaseSpecific(catalogName, schemaName, this);

return new Schema(catalogName, schemaName);
}

public String getAssumedCatalogName(String catalogName, String schemaName) {
if (this.supportsCatalogs()) {
if (catalogName == null) {
if (this.supportsSchemas()) {
return null;
} else {
return schemaName;
}
} else {
return catalogName;
}
} else {
return null;
}
}

public String getAssumedSchemaName(String catalogName, String schemaName) {
if (this.supportsSchemas()) {
if (schemaName == null) {
if (this.supportsCatalogs()) {
return null;
} else {
return catalogName;
}
} else {
return schemaName;
}
} else {
return null;
}
}

public String correctTableName(String tableName) {
return correctObjectName(tableName);
}
Expand Down Expand Up @@ -283,9 +337,17 @@ public void setDefaultSchemaName(String schemaName) {
}

/**
* Returns system (undroppable) tables and views.
* Returns system (undroppable) views.
*/
protected Set<String> getSystemTablesAndViews() {
protected Set<String> getSystemTables() {
return new HashSet<String>();
}


/**
* Returns system (undroppable) views.
*/
protected Set<String> getSystemViews() {
return new HashSet<String>();
}

Expand Down Expand Up @@ -683,6 +745,18 @@ public void checkDatabaseChangeLogLockTable() throws DatabaseException {
}
}

public boolean isCaseSensitive() {
if (connection != null) {
try {
return ((JdbcConnection) connection).getUnderlyingConnection().getMetaData().supportsMixedCaseIdentifiers();
} catch (SQLException e) {
LogFactory.getLogger().warning("Cannot determine case sensitivity from JDBC driver", e);
return false;
}
}
return false;
}

public boolean isReservedWord(String string) {
return false;
}
Expand Down Expand Up @@ -788,31 +862,31 @@ public boolean supportsDropTableCascadeConstraints() {

public boolean isSystemTable(Schema schema, String tableName) {
schema = correctSchema(schema);
if ("information_schema".equalsIgnoreCase(schema.getName())) {
return true;
} else if (tableName.equalsIgnoreCase(getDatabaseChangeLogLockTableName())) {
return true;
} else if (getSystemTablesAndViews().contains(tableName)) {
return true;
}
return false;
return "information_schema".equalsIgnoreCase(schema.getName()) || getSystemTables().contains(tableName);
}

public boolean isSystemView(Schema schema, String viewName) {
schema = correctSchema(schema);
if ("information_schema".equalsIgnoreCase(schema.getName())) {
return true;
} else if (getSystemTablesAndViews().contains(viewName)) {
} else if (getSystemViews().contains(viewName)) {
return true;
}
return false;
}

public boolean isLiquibaseTable(String tableName) {
return tableName.equalsIgnoreCase(this.getDatabaseChangeLogTableName()) || tableName.equalsIgnoreCase(this.getDatabaseChangeLogLockTableName());
public boolean isLiquibaseTable(Schema schema, String tableName) {
if (!schema.equals(correctSchema(new Schema(getLiquibaseCatalogName(), getLiquibaseSchemaName())), this)) {
return false;
}
if (isCaseSensitive()) {
return tableName.equals(this.getDatabaseChangeLogTableName()) || tableName.equals(this.getDatabaseChangeLogLockTableName());
} else {
return tableName.equalsIgnoreCase(this.getDatabaseChangeLogTableName()) || tableName.equalsIgnoreCase(this.getDatabaseChangeLogLockTableName());
}
}

// ------- DATABASE TAGGING METHODS ---- //
// ------- DATABASE TAGGING METHODS ---- //

/**
* Tags the database changelog with the given string.
Expand Down Expand Up @@ -865,14 +939,30 @@ public String getViewDefinition(Schema schema, String viewName) throws DatabaseE
}

public String escapeTableName(String catalogName, String schemaName, String tableName) {
if (schemaName == null) {
schemaName = getDefaultSchemaName();
if (catalogName == null && schemaName == null) {
return escapeDatabaseObject(tableName);
}

if (StringUtils.trimToNull(schemaName) == null || !supportsSchemas()) {
if (!supportsCatalogs() && !supportsSchemas()) {
return escapeDatabaseObject(tableName);
} else if (supportsCatalogs() && supportsSchemas()) {
// Schema schema = correctSchema(new Schema(catalogName, schemaName));
// return escapeDatabaseObject(schema.getCatalogName())+"."+escapeDatabaseObject(schema.getName())+"."+escapeDatabaseObject(tableName);
catalogName = StringUtils.trimToNull(catalogName);
schemaName = StringUtils.trimToNull(schemaName);
if (catalogName == null && schemaName == null) {
return escapeDatabaseObject(tableName);
} else if (catalogName == null) {
return escapeDatabaseObject(schemaName)+"."+escapeDatabaseObject(tableName);
} else {
return escapeDatabaseObject(catalogName)+"."+escapeDatabaseObject(schemaName)+"."+escapeDatabaseObject(tableName);
}
} else {
return escapeDatabaseObject(schemaName) + "." + escapeDatabaseObject(tableName);
catalogName = getAssumedCatalogName(catalogName, schemaName);
if (StringUtils.trimToNull(catalogName) == null) {
return escapeDatabaseObject(tableName);
} else {
return escapeDatabaseObject(catalogName)+"."+escapeDatabaseObject(tableName);
}
}
}

Expand All @@ -888,6 +978,14 @@ public String escapeIndexName(String catalogName, String schemaName, String inde
}
}

public String escapeSchemaName(String schemaName) {
return escapeDatabaseObject(schemaName);
}

public String escapeCatalogName(String name) {
return escapeDatabaseObject(name);
}

public String escapeSequenceName(String catalogName, String schemaName, String sequenceName) {
if (schemaName == null) {
schemaName = getDefaultSchemaName();
Expand Down Expand Up @@ -1251,4 +1349,12 @@ public boolean disableForeignKeyChecks() throws DatabaseException {
public void enableForeignKeyChecks() throws DatabaseException {
throw new DatabaseException("ForeignKeyChecks Management not supported");
}

public boolean equals(DatabaseObject otherObject, Database accordingTo) {
return otherObject.getClass().equals(this.getClass());
}

public boolean equals(String otherObject, Database accordingTo) {
return this.getName().equals(otherObject);
}
}
13 changes: 12 additions & 1 deletion liquibase-core/src/main/java/liquibase/database/Database.java
Expand Up @@ -146,7 +146,7 @@ public interface Database extends DatabaseObject, PrioritizedService {

boolean isSystemTable(Schema schema, String tableName);

boolean isLiquibaseTable(String tableName);
boolean isLiquibaseTable(Schema schema, String tableName);

boolean shouldQuoteValue(String value);

Expand Down Expand Up @@ -175,6 +175,10 @@ public interface Database extends DatabaseObject, PrioritizedService {

String escapeDatabaseObject(String objectName);

String escapeSchemaName(String schemaName);

String escapeCatalogName(String name);

/**
* Escapes a single column name in a database-dependent manner so reserved words can be used as a column
* name (i.e. "return").
Expand Down Expand Up @@ -270,6 +274,8 @@ public interface Database extends DatabaseObject, PrioritizedService {

void enableForeignKeyChecks() throws DatabaseException;

public boolean isCaseSensitive();

public boolean isReservedWord(String string);

Schema correctSchema(Schema schema);
Expand All @@ -285,4 +291,9 @@ public interface Database extends DatabaseObject, PrioritizedService {
String correctForeignKeyName(String fkName);

String correctIndexName(String indexName);

String getAssumedSchemaName(String catalogName, String schemaName);

String getAssumedCatalogName(String catalogName, String schemaName);

}
Expand Up @@ -37,6 +37,16 @@ public Integer getDefaultPort() {
return 446;
}

@Override
public boolean supportsSchemas() {
return false;
}

@Override
public boolean supportsCatalogs() {
return true;
}

@Override
protected String getDefaultDatabaseProductName() {
return "DB2";
Expand All @@ -47,7 +57,7 @@ public String getTypeName() {
}

@Override
public String getDefaultSchemaName() {
public String getDefaultCatalogName() {
if( defaultSchemaName == null ) {
Statement stmt = null;
ResultSet rs = null;
Expand All @@ -73,11 +83,6 @@ public String getDefaultSchemaName() {
return defaultSchemaName;
}

@Override
public Schema correctSchema(Schema schema) {
return schema;
}

@Override
protected String correctObjectName(String objectName) {
return objectName.toUpperCase();
Expand Down Expand Up @@ -196,4 +201,8 @@ public String escapeIndexName(String catalogName, String schemaName, String inde
return super.escapeIndexName(null, null, indexName);
}

@Override
public String getAssumedCatalogName(String catalogName, String schemaName) {
return schemaName;
}
}
Expand Up @@ -58,6 +58,11 @@ protected String correctObjectName(String objectName) {
return objectName.toUpperCase();
}

@Override
public boolean supportsCatalogs() {
return false;
}

@Override
public boolean supportsSequences() {
return true;
Expand Down

0 comments on commit 05c3d39

Please sign in to comment.