Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Solve my way of exception on liquibase.dropAll(),using H2database(MODE=MYSQL)
import liquibase.CatalogAndSchema;
import liquibase.database.ObjectQuotingStrategy;
import liquibase.database.core.H2Database;
import liquibase.exception.LiquibaseException;
/*
* [Summary]
* Exception on liquibase.dropAll(),using H2database(MODE=MYSQL).
*
* [Log]
* liquibase.exception.DatabaseException: Error executing SQL ALTER TABLE "PUBLIC"."bbs" DROP CONSTRAINT "contributor": Table "bbs" not found;
* SQL statement: ALTER TABLE "PUBLIC"."bbs" DROP CONSTRAINT "contributor" [42102-187]
* ...
* at liquibase.database.AbstractJdbcDatabase.dropDatabaseObjects(AbstractJdbcDatabase.java:733)
* at liquibase.Liquibase.dropAll(Liquibase.java:678)
* at liquibase.Liquibase.dropAll(Liquibase.java:665)
* ...
* [Probrem]
* Names of schema and table are quoted, only dropAll() function. ( other processes works )
*
* [My Solution]
* Invalidate process In "liquibase.database.AbstractJdbcDatabase.dropDatabaseObjects(AbstractJdbcDatabase.java:733)".
* [ this.setObjectQuotingStrategy(ObjectQuotingStrategy.QUOTE_ALL_OBJECTS); ]
* Override H2database.java, and do nothing setObjectQuotingStrategy() in dropDatabaseObjects() for it.
*/
/**
* Liquibase, H2database(MODE=MYSQL)でliquibase.dropAll()できない場合の自己流解決策
* Usage:
* <ul>
* <li>liquibase.database.DatabaseFactory fac = DatabaseFactory.getInstance();</li>
* <li>fac.register(new H2DatabaseEx());</li>
* <li>database = fac.findCorrectDatabaseImplementation(liquibase.database.jvm.JdbcConnection);</li>
* </ul>
*
* @author taketsuru-devel
* @version 1.0
*/
public class H2DatabaseEx extends H2Database {
private boolean isDropFunction;
public H2DatabaseEx(){
super();
this.isDropFunction = false;
}
@Override
public void dropDatabaseObjects(CatalogAndSchema schemaToDrop)
throws LiquibaseException {
this.isDropFunction = true;
try {
super.dropDatabaseObjects(schemaToDrop);
} catch ( LiquibaseException e ){
throw e;
} finally {
this.isDropFunction = false;
}
}
@Override
public void setObjectQuotingStrategy(ObjectQuotingStrategy quotingStrategy) {
if ( !this.isDropFunction ){
super.setObjectQuotingStrategy(quotingStrategy);
}
}
@Override
public int getPriority() {
/* let choose this from H2database */
return super.getPriority()+1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.