Skip to content

Commit

Permalink
Move SQL to java classes
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Jan 1, 2012
1 parent 9cd5e2e commit 1920f02
Show file tree
Hide file tree
Showing 71 changed files with 2,293 additions and 2,393 deletions.
Expand Up @@ -36,7 +36,6 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.codec.binary.Base64;
Expand Down Expand Up @@ -896,7 +895,7 @@ public boolean areDatabaseTransactionsPendingSince(long time) {
public long getDatabaseTime() {
try {
String sql = "select current_timestamp from " + tablePrefix + "_node_identity";
sql = FormatUtils.replaceTokens(sql, getSqlScriptReplacementTokens(), false);
sql = FormatUtils.replaceTokens(sql, platform.getSqlScriptReplacementTokens(), false);
return jdbcTemplate.queryForObject(sql, java.util.Date.class).getTime();

} catch (Exception ex) {
Expand All @@ -921,10 +920,6 @@ protected String getDbSpecificDataHasChangedCondition(Trigger trigger) {
return Constants.ALWAYS_TRUE_CONDITION;
}

public Map<String, String> getSqlScriptReplacementTokens() {
return null;
}

public boolean needsToSelectLobData() {
return false;
}
Expand All @@ -943,25 +938,7 @@ public String getDriverName() {

public String getDriverVersion() {
return driverVersion;
}

public String scrubSql(String sql) {
Map<String, String> replacementTokens = getSqlScriptReplacementTokens();
if (replacementTokens != null) {
return FormatUtils.replaceTokens(sql, replacementTokens, false).trim();
} else {
return sql;
}
}

public StringBuilder scrubSql(StringBuilder sql) {
Map<String, String> replacementTokens = getSqlScriptReplacementTokens();
if (replacementTokens != null) {
return new StringBuilder(scrubSql(sql.toString()));
} else {
return sql;
}
}
}

public String massageForLob(String sql, Channel channel) {
return sql;
Expand Down
Expand Up @@ -20,7 +20,6 @@
package org.jumpmind.symmetric.db;

import java.util.Date;
import java.util.Map;
import java.util.Set;

import org.jumpmind.db.BinaryEncoding;
Expand Down Expand Up @@ -219,12 +218,6 @@ public long insertWithGeneratedKey(JdbcTemplate jdbcTemplate, final String sql,
*/
public String getDataHasChangedCondition(Trigger trigger);

public Map<String, String> getSqlScriptReplacementTokens();

public String scrubSql(String sql);

public StringBuilder scrubSql(StringBuilder sql);

/*
* Indicates whether captured data can contain gaps.
*/
Expand Down
Expand Up @@ -20,22 +20,16 @@

package org.jumpmind.symmetric.db.informix;

import java.util.HashMap;
import java.util.Map;

import org.jumpmind.db.sql.ISqlTransaction;
import org.jumpmind.symmetric.db.AbstractSymmetricDialect;
import org.jumpmind.symmetric.db.ISymmetricDialect;
import org.jumpmind.symmetric.model.Trigger;

public class InformixSymmetricDialect extends AbstractSymmetricDialect implements ISymmetricDialect {

private Map<String, String> sqlScriptReplacementTokens;

public InformixSymmetricDialect() {
this.triggerText = new InformixTriggerText();
sqlScriptReplacementTokens = new HashMap<String, String>();
sqlScriptReplacementTokens.put("current_timestamp", "current");
}

@Override
Expand Down Expand Up @@ -95,9 +89,6 @@ public boolean allowsNullForIdentityColumn() {
}

public void purge() {
}
@Override
public Map<String, String> getSqlScriptReplacementTokens() {
return sqlScriptReplacementTokens;
}
}

}
Expand Down
Expand Up @@ -27,8 +27,6 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.Map;

import org.jumpmind.db.BinaryEncoding;
import org.jumpmind.db.sql.ISqlTransaction;
Expand All @@ -50,12 +48,10 @@
*/
public class SybaseSymmetricDialect extends AbstractSymmetricDialect implements ISymmetricDialect {

private Map<String, String> sqlScriptReplacementTokens;


public SybaseSymmetricDialect() {
this.triggerText = new SybaseTriggerText();
sqlScriptReplacementTokens = new HashMap<String, String>();
sqlScriptReplacementTokens.put("current_timestamp", "getdate()");
}

@Override
Expand Down Expand Up @@ -181,9 +177,4 @@ public boolean needsToSelectLobData() {
return true;
}

@Override
public Map<String, String> getSqlScriptReplacementTokens() {
return sqlScriptReplacementTokens;
}

}
Expand Up @@ -20,10 +20,12 @@

package org.jumpmind.symmetric.route;

import org.jumpmind.db.sql.AbstractSqlMap;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.service.IDataService;
import org.jumpmind.symmetric.service.ISqlProvider;
import org.jumpmind.symmetric.service.impl.AbstractService;
import org.jumpmind.symmetric.service.impl.RouterServiceSqlMap;

/**
* Factory that creates and initializes the correct {@link IDataToRouteReader}.
Expand Down Expand Up @@ -67,6 +69,11 @@ private RuntimeException unsupportedType(String type) {
return new UnsupportedOperationException("The data to route type of '" + type
+ "' is not supported");
}

@Override
public AbstractSqlMap createSqlMap() {
return new RouterServiceSqlMap(symmetricDialect.getPlatform(), createReplacementTokens());
}

public void setDataService(IDataService dataService) {
this.dataService = dataService;
Expand Down
Expand Up @@ -22,12 +22,14 @@
package org.jumpmind.symmetric.service.impl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.jumpmind.db.sql.AbstractSqlMap;
import org.jumpmind.symmetric.common.logging.ILog;
import org.jumpmind.symmetric.common.logging.LogFactory;
import org.jumpmind.symmetric.db.ISymmetricDialect;
Expand All @@ -52,9 +54,9 @@ abstract public class AbstractService implements IService, ISqlProvider {

protected ISymmetricDialect symmetricDialect;

protected String tablePrefix;

private Map<String, String> sql;
protected String tablePrefix;
private AbstractSqlMap sqlMap;

public void setJdbcTemplate(JdbcTemplate jdbc) {
this.jdbcTemplate = jdbc;
Expand Down Expand Up @@ -89,27 +91,25 @@ protected SQLException unwrapSqlException(Throwable e) {
}
}
return null;
}

public void setSql(Map<String, String> sql) {
this.sql = sql;
}
}

final protected AbstractSqlMap getSqlMap() {
if (sqlMap == null) {
sqlMap = createSqlMap();
}
return sqlMap;
}

abstract protected AbstractSqlMap createSqlMap();

protected Map<String,String> createReplacementTokens() {
Map<String,String> map = new HashMap<String, String>();
map.put("prefixName", this.tablePrefix);
return map;
}

public String getSql(String... keys) {
StringBuilder sqlBuffer = new StringBuilder();
if (keys != null) {
for (String key : keys) {
if (key != null) {
String value = sql.get(key);
sqlBuffer.append(value == null ? key : value);
}
}

if (symmetricDialect != null) {
sqlBuffer = symmetricDialect.scrubSql(sqlBuffer);
}
}
return sqlBuffer.toString();
return getSqlMap().getSql(keys);
}

public void setTablePrefix(String tablePrefix) {
Expand Down

0 comments on commit 1920f02

Please sign in to comment.