Skip to content

Commit

Permalink
Only call reorg on DB2 databases >= 9
Browse files Browse the repository at this point in the history
git-svn-id: http://liquibase.jira.com/svn/CORE/trunk@843 e6edf6fb-f266-4316-afb4-e53d95876a76
  • Loading branch information
nvoxland committed Mar 6, 2009
1 parent e44087a commit b57e8d1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
9 changes: 9 additions & 0 deletions core/src/java-test/liquibase/database/MockDatabase.java
Expand Up @@ -65,6 +65,15 @@ public String getDatabaseProductVersion() throws JDBCException {
return null;
}


public int getDatabaseMajorVersion() throws JDBCException {
return 0;
}

public int getDatabaseMinorVersion() throws JDBCException {
return 0;
}

public String getProductName() {
return null;
}
Expand Down
16 changes: 16 additions & 0 deletions core/src/java/liquibase/database/AbstractDatabase.java
Expand Up @@ -119,6 +119,22 @@ public String getDatabaseProductVersion() throws JDBCException {
}
}

public int getDatabaseMajorVersion() throws JDBCException {
try {
return connection.getMetaData().getDatabaseMajorVersion();
} catch (SQLException e) {
throw new JDBCException(e);
}
}

public int getDatabaseMinorVersion() throws JDBCException {
try {
return connection.getMetaData().getDatabaseMinorVersion();
} catch (SQLException e) {
throw new JDBCException(e);
}
}

public String getDriverName() throws JDBCException {
try {
return connection.getMetaData().getDriverName();
Expand Down
3 changes: 3 additions & 0 deletions core/src/java/liquibase/database/Database.java
Expand Up @@ -50,6 +50,9 @@ public interface Database extends DatabaseObject {

String getDatabaseProductVersion() throws JDBCException;

int getDatabaseMajorVersion() throws JDBCException;

int getDatabaseMinorVersion() throws JDBCException;
/**
* Returns the full database product name. May be different than what the JDBC connection reports (getDatabaseProductName())
*/
Expand Down
8 changes: 8 additions & 0 deletions core/src/java/liquibase/database/HibernateDatabase.java
Expand Up @@ -79,6 +79,14 @@ public String getDatabaseProductVersion() throws JDBCException {
return "N/A";
}

public int getDatabaseMajorVersion() throws JDBCException {
return -1;
}

public int getDatabaseMinorVersion() throws JDBCException {
return -1;
}

public String getProductName() {
return "Hibernate Mapping";
}
Expand Down
Expand Up @@ -3,6 +3,7 @@
import liquibase.database.DB2Database;
import liquibase.database.Database;
import liquibase.exception.StatementNotSupportedOnDatabaseException;
import liquibase.exception.JDBCException;

public class ReorganizeTableStatement implements SqlStatement {
private String schemaName;
Expand All @@ -25,7 +26,15 @@ public String getSqlStatement(Database database) throws StatementNotSupportedOnD
if (!supportsDatabase(database)) {
throw new StatementNotSupportedOnDatabaseException("Cannot reorganize table", this, database);
}
return "CALL SYSPROC.ADMIN_CMD ('REORG TABLE " + database.escapeTableName(getSchemaName(), getTableName()) + "')";
try {
if (database.getDatabaseMajorVersion() >= 9) {
return "CALL SYSPROC.ADMIN_CMD ('REORG TABLE " + database.escapeTableName(getSchemaName(), getTableName()) + "')";
} else {
return null;
}
} catch (JDBCException e) {
throw new RuntimeException(e);
}
}

public String getEndDelimiter(Database database) {
Expand Down

0 comments on commit b57e8d1

Please sign in to comment.