Skip to content

Commit

Permalink
0001409: The database uninstall feature does not remove the sym_ H2 t…
Browse files Browse the repository at this point in the history
…rigger tables.
  • Loading branch information
abrougher committed Aug 28, 2013
1 parent 2bffa4f commit 5be5bfe
Showing 1 changed file with 18 additions and 7 deletions.
Expand Up @@ -20,10 +20,13 @@
*/
package org.jumpmind.symmetric.db.h2;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.jumpmind.db.model.Table;
import org.jumpmind.db.platform.IDatabasePlatform;
import org.jumpmind.db.sql.ISqlTransaction;
import org.jumpmind.db.sql.mapper.StringMapper;
import org.jumpmind.db.util.BinaryEncoding;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.db.AbstractEmbeddedSymmetricDialect;
Expand All @@ -33,18 +36,18 @@
import org.jumpmind.symmetric.service.IParameterService;

/*
* Synchronization support for the H2 database platform.
* Synchronization support for the H2 database platform.
*/
public class H2SymmetricDialect extends AbstractEmbeddedSymmetricDialect implements ISymmetricDialect {

static final String SQL_DROP_FUNCTION = "DROP ALIAS $(functionName)";
static final String SQL_FUNCTION_INSTALLED = "select count(*) from INFORMATION_SCHEMA.FUNCTION_ALIASES where ALIAS_NAME='$(functionName)'" ;

public H2SymmetricDialect(IParameterService parameterService, IDatabasePlatform platform) {
super(parameterService, platform);
this.triggerTemplate = new H2TriggerTemplate(this);
}

@Override
protected boolean doesTriggerExistOnPlatform(String catalogName, String schemaName, String tableName,
String triggerName) {
Expand Down Expand Up @@ -86,17 +89,17 @@ public void removeTrigger(StringBuilder sqlBuffer, String catalogName, String sc
}
}
}

@Override
protected void createRequiredDatabaseObjects() {
protected void createRequiredDatabaseObjects() {
String encode = this.parameterService.getTablePrefix().toUpperCase() + "_" + "BASE64_ENCODE";
if (!installed(SQL_FUNCTION_INSTALLED, encode)) {
String sql = "CREATE ALIAS IF NOT EXISTS $(functionName) for \"org.jumpmind.symmetric.db.EmbeddedDbFunctions.encodeBase64\"; ";
install(sql, encode);
}

}

@Override
protected void dropRequiredDatabaseObjects() {
String encode = this.parameterService.getTablePrefix().toUpperCase() + "_" + "BASE64_ENCODE";
Expand Down Expand Up @@ -142,10 +145,18 @@ public BinaryEncoding getBinaryEncoding() {
return BinaryEncoding.BASE64;
}


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

@Override
public void cleanupTriggers() {
List<String> names = platform.getSqlTemplate().query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = SCHEMA() AND TABLE_NAME LIKE '"+parameterService.getTablePrefix().toUpperCase()+"_%_CONFIG'", new StringMapper());
for (String name : names) {
platform.getSqlTemplate().update("drop table " + name);
log.info("Dropped table {}", name);
}
}

}

0 comments on commit 5be5bfe

Please sign in to comment.