Permalink
Browse files

Fixing various failing integration database tests, especially around …

…catalog/schema logic
  • Loading branch information...
1 parent 4c9f4e4 commit 8e9c63ba04976834544cf9490d51ac4840da68c5 @nvoxland nvoxland committed Aug 28, 2012
Showing with 364 additions and 182 deletions.
  1. +1 −1 liquibase-core/src/main/java/liquibase/change/core/LoadUpdateDataChange.java
  2. +87 −14 liquibase-core/src/main/java/liquibase/database/AbstractDatabase.java
  3. +9 −0 liquibase-core/src/main/java/liquibase/database/Database.java
  4. +7 −3 liquibase-core/src/main/java/liquibase/database/core/DB2Database.java
  5. +5 −0 liquibase-core/src/main/java/liquibase/database/core/HsqlDatabase.java
  6. +18 −0 liquibase-core/src/main/java/liquibase/database/core/MSSQLDatabase.java
  7. +0 −21 liquibase-core/src/main/java/liquibase/database/core/MySQLDatabase.java
  8. +3 −0 liquibase-core/src/main/java/liquibase/database/structure/DatabaseObjectImpl.java
  9. +1 −1 liquibase-core/src/main/java/liquibase/database/structure/Schema.java
  10. +24 −0 liquibase-core/src/main/java/liquibase/datatype/core/NCharType.java
  11. +21 −19 liquibase-core/src/main/java/liquibase/datatype/core/{NumericType.java → NumberType.java}
  12. +18 −4 liquibase-core/src/main/java/liquibase/diff/output/DiffToChangeLog.java
  13. +5 −5 liquibase-core/src/main/java/liquibase/lockservice/LockService.java
  14. +15 −0 liquibase-core/src/main/java/liquibase/snapshot/jvm/DB2DatabaseSnapshotGenerator.java
  15. +1 −0 liquibase-core/src/main/java/liquibase/snapshot/jvm/H2DatabaseSnapshotGenerator.java
  16. +7 −0 liquibase-core/src/main/java/liquibase/snapshot/jvm/HsqlDatabaseSnapshotGenerator.java
  17. +64 −45 liquibase-core/src/main/java/liquibase/snapshot/jvm/JdbcDatabaseSnapshotGenerator.java
  18. +1 −1 liquibase-core/src/main/java/liquibase/sqlgenerator/core/AddColumnGenerator.java
  19. +1 −1 liquibase-core/src/main/java/liquibase/sqlgenerator/core/CreateTableGenerator.java
  20. +6 −5 liquibase-core/src/main/java/liquibase/sqlgenerator/core/CreateViewGenerator.java
  21. +21 −8 liquibase-core/src/main/java/liquibase/sqlgenerator/core/GetViewDefinitionGenerator.java
  22. +1 −1 liquibase-core/src/main/java/liquibase/sqlgenerator/core/GetViewDefinitionGeneratorDB2.java
  23. +1 −1 liquibase-core/src/main/java/liquibase/sqlgenerator/core/GetViewDefinitionGeneratorHsql.java
  24. +0 −33 ...e/src/main/java/liquibase/sqlgenerator/core/GetViewDefinitionGeneratorInformationSchemaViews.java
  25. +1 −1 liquibase-core/src/main/java/liquibase/sqlgenerator/core/SelectSequencesGeneratorDB2.java
  26. +9 −3 liquibase-core/src/main/java/liquibase/sqlgenerator/core/StoredProcedureGenerator.java
  27. +16 −0 liquibase-core/src/test/java/liquibase/database/core/MockDatabase.java
  28. +14 −3 liquibase-integration-tests/src/test/java/liquibase/dbtest/AbstractIntegrationTest.java
  29. +0 −10 liquibase-integration-tests/src/test/java/liquibase/dbtest/hsqldb/HsqlIntegrationTest.java
  30. +6 −1 liquibase-integration-tests/src/test/java/liquibase/dbtest/mssql/MssqlIntegrationTest.java
  31. +1 −1 liquibase-integration-tests/src/test/resources/changelogs/oracle/rollback/rollbackable.changelog.xml
@@ -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 ");
}
@@ -200,34 +200,80 @@ public Schema correctSchema(Schema schema) {
return schema;
}
if (schema == null) {
- schema = new Schema.DatabaseSpecific(getDefaultCatalogName(), getDefaultSchemaName(), this);
+ return new Schema.DatabaseSpecific(getDefaultCatalogName(), getDefaultSchemaName(), this);
}
String catalogName = schema.getCatalogName();
String schemaName = schema.getName();
- if (supportsCatalogs()) {
+ if (supportsCatalogs() && supportsSchemas()) {
if (catalogName.equals(Catalog.DEFAULT_NAME)) {
catalogName = getDefaultCatalogName();
} else {
catalogName = correctObjectName(catalogName);
}
- } else {
- catalogName = null;
- }
- if (supportsSchemas()) {
if (schemaName.equals(Schema.DEFAULT_NAME)) {
schemaName = getDefaultSchemaName();
} else {
schemaName = correctObjectName(schemaName);
}
- } else {
- schemaName = null;
+ } 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);
}
+
+ 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);
}
@@ -830,6 +876,9 @@ public boolean isSystemView(Schema schema, String viewName) {
}
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 {
@@ -890,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);
+ }
}
}
@@ -913,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();
@@ -175,6 +175,10 @@
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").
@@ -287,4 +291,9 @@
String correctForeignKeyName(String fkName);
String correctIndexName(String indexName);
+
+ String getAssumedSchemaName(String catalogName, String schemaName);
+
+ String getAssumedCatalogName(String catalogName, String schemaName);
+
}
@@ -39,12 +39,12 @@ public Integer getDefaultPort() {
@Override
public boolean supportsSchemas() {
- return true;
+ return false;
}
@Override
public boolean supportsCatalogs() {
- return false;
+ return true;
}
@Override
@@ -57,7 +57,7 @@ public String getTypeName() {
}
@Override
- public String getDefaultSchemaName() {
+ public String getDefaultCatalogName() {
if( defaultSchemaName == null ) {
Statement stmt = null;
ResultSet rs = null;
@@ -201,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;
+ }
}
@@ -59,6 +59,11 @@ protected String correctObjectName(String objectName) {
}
@Override
+ public boolean supportsCatalogs() {
+ return false;
+ }
+
+ @Override
public boolean supportsSequences() {
return true;
}
@@ -15,6 +15,7 @@
import java.util.regex.Pattern;
import liquibase.database.jvm.JdbcConnection;
import liquibase.logging.LogFactory;
+import liquibase.util.StringUtils;
/**
* Encapsulates MS-SQL database support.
@@ -275,4 +276,21 @@ public String getViewDefinition(Schema schema, String viewName) throws DatabaseE
}
return CREATE_VIEW_AS_PATTERN.matcher(definition).replaceFirst("");
}
+
+ /**
+ * SQLServer does not support specifying teh database name as a prefix to the object name
+ * @return
+ */
+ @Override
+ public String escapeViewName(String catalogName, String schemaName, String viewName) {
+ schemaName = getAssumedSchemaName(catalogName, schemaName);
+ if (StringUtils.trimToNull(schemaName) == null) {
+ return escapeDatabaseObject(viewName);
+ } else {
+ return escapeDatabaseObject(schemaName)+"."+escapeDatabaseObject(viewName);
+ }
+
+ }
+
+
}
@@ -147,27 +147,6 @@ public String escapeIndexName(String catalogName, String schemaName, String inde
return escapeDatabaseObject(indexName);
}
-
- @Override
- public String escapeTableName(String catalogName, String schemaName, String tableName) {
- return getPrefix(catalogName, schemaName)+tableName;
- }
-
- private String getPrefix(String catalogName, String schemaName) {
- String prefix = "";
- if (catalogName != null) {
- prefix = catalogName+".";
- } else if (schemaName != null) {
- prefix = schemaName + ".";
- }
- return prefix;
- }
-
- @Override
- public String escapeViewName(String catalogName, String schemaName, String viewName) {
- return getPrefix(catalogName, schemaName)+viewName;
- }
-
@Override
public boolean supportsForeignKeyDisable() {
return true;
@@ -9,6 +9,9 @@ public boolean equals(DatabaseObject otherObject, Database accordingTo) {
}
public boolean equals(String otherObjectName, Database accordingTo) {
+ if (this.getName() == null) {
+ return otherObjectName == null;
+ }
if (otherObjectName == null) {
return false;
}
@@ -26,7 +26,7 @@ public Schema(String catalog, String schemaName) {
if (schemaName.equals(Schema.DEFAULT_NAME)) {
catalog = Catalog.DEFAULT_NAME;
} else {
- catalog = schemaName;
+ catalog = Catalog.DEFAULT_NAME;
}
} else if (catalog != null && schemaName == null) {
if (catalog.equals(Catalog.DEFAULT_NAME)) {
@@ -0,0 +1,24 @@
+package liquibase.datatype.core;
+
+import liquibase.database.Database;
+import liquibase.database.core.HsqlDatabase;
+import liquibase.database.core.OracleDatabase;
+import liquibase.datatype.DataTypeInfo;
+import liquibase.datatype.DatabaseDataType;
+import liquibase.datatype.LiquibaseDataType;
+
+@DataTypeInfo(name="nchar", aliases = "java.sql.Types.NCHAR", minParameters = 0, maxParameters = 1, priority = LiquibaseDataType.PRIORITY_DEFAULT)
+public class NCharType extends CharType {
+
+ @Override
+ public DatabaseDataType toDatabaseDataType(Database database) {
+ if (database instanceof HsqlDatabase) {
+ return new DatabaseDataType("CHAR", getParameters());
+ }
+ if (database instanceof OracleDatabase) {
+ return new DatabaseDataType("NCHAR2", getParameters());
+ }
+ return super.toDatabaseDataType(database);
+ }
+
+}
@@ -1,19 +1,21 @@
-package liquibase.datatype.core;
-
-import liquibase.database.Database;
-import liquibase.database.core.DB2Database;
-import liquibase.database.core.MySQLDatabase;
-import liquibase.datatype.DataTypeInfo;
-import liquibase.datatype.DatabaseDataType;
-import liquibase.datatype.LiquibaseDataType;
-
-@DataTypeInfo(name="number", aliases = {"numeric", "java.sql.Types.NUMERIC"}, minParameters = 0, maxParameters = 0, priority = LiquibaseDataType.PRIORITY_DEFAULT)
-public class NumericType extends LiquibaseDataType {
- @Override
- public DatabaseDataType toDatabaseDataType(Database database) {
- if (database instanceof MySQLDatabase || database instanceof DB2Database) {
- return new DatabaseDataType("numeric", getParameters());
- }
- return super.toDatabaseDataType(database);
- }
-}
+package liquibase.datatype.core;
+
+import liquibase.database.Database;
+import liquibase.database.core.DB2Database;
+import liquibase.database.core.HsqlDatabase;
+import liquibase.database.core.MSSQLDatabase;
+import liquibase.database.core.MySQLDatabase;
+import liquibase.datatype.DataTypeInfo;
+import liquibase.datatype.DatabaseDataType;
+import liquibase.datatype.LiquibaseDataType;
+
+@DataTypeInfo(name="number", aliases = {"numeric", "java.sql.Types.NUMERIC"}, minParameters = 0, maxParameters = 0, priority = LiquibaseDataType.PRIORITY_DEFAULT)
+public class NumberType extends LiquibaseDataType {
+ @Override
+ public DatabaseDataType toDatabaseDataType(Database database) {
+ if (database instanceof MySQLDatabase || database instanceof DB2Database|| database instanceof MSSQLDatabase || database instanceof HsqlDatabase) {
+ return new DatabaseDataType("numeric", getParameters());
+ }
+ return super.toDatabaseDataType(database);
+ }
+}
Oops, something went wrong.

0 comments on commit 8e9c63b

Please sign in to comment.