Skip to content

Commit

Permalink
Removed getJdbcTemplate() from the IDbDialect interface
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Nov 15, 2009
1 parent c9d826b commit 5ba18ff
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 25 deletions.
Expand Up @@ -37,6 +37,7 @@
import org.jumpmind.symmetric.util.AppUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;

public abstract class AbstractSymmetricEngine implements ISymmetricEngine {

Expand All @@ -53,8 +54,9 @@ public abstract class AbstractSymmetricEngine implements ISymmetricEngine {
private IUpgradeService upgradeService;
private IClusterService clusterService;
private IPurgeService purgeService;
private ITriggerRouterService triggerService;
private ITriggerRouterService triggerService;
private IDataService dataService;
private JdbcTemplate jdbcTemplate;
private boolean started = false;
private boolean starting = false;
private boolean setup = false;
Expand Down Expand Up @@ -143,7 +145,7 @@ public synchronized void stop() {
jobManager.stopJobs();
removeMeFromMap(registeredEnginesByName);
removeMeFromMap(registeredEnginesByUrl);
DataSource ds = dbDialect.getJdbcTemplate().getDataSource();
DataSource ds = jdbcTemplate.getDataSource();
if (ds instanceof BasicDataSource) {
try {
((BasicDataSource) ds).close();
Expand All @@ -161,6 +163,7 @@ public synchronized void stop() {
registrationService = null;
purgeService = null;
dataService = null;
jdbcTemplate = null;
dbDialect = null;
started = false;
starting = false;
Expand Down Expand Up @@ -217,6 +220,7 @@ protected void init(ApplicationContext applicationContext) {
triggerService = AppUtils.find(Constants.TRIGGER_ROUTER_SERVICE, this);
dbDialect = AppUtils.find(Constants.DB_DIALECT, this);
jobManager = AppUtils.find(Constants.JOB_MANAGER, this);
jdbcTemplate = AppUtils.find(Constants.JDBC_TEMPLATE, this);
}

private ApplicationContext createContext(ApplicationContext parentContext) {
Expand Down
Expand Up @@ -164,7 +164,7 @@ private Constants() {

public static final String PURGE_SERVICE = "purgeService";

public static final String JDBC = "jdbcTemplate";
public static final String JDBC_TEMPLATE = "jdbcTemplate";

public static final String PARENT_PROPERTY_PREFIX = "parent.";

Expand Down
Expand Up @@ -1223,10 +1223,6 @@ public void setStreamingResultsFetchSize(int streamingResultsFetchSize) {
this.streamingResultsFetchSize = streamingResultsFetchSize;
}

public JdbcTemplate getJdbcTemplate() {
return jdbcTemplate;
}

public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
this.transactionTemplate = transactionTemplate;
}
Expand Down Expand Up @@ -1325,6 +1321,6 @@ public void setDefaultSchema(String currentSchema) {
}

public void truncateTable(String tableName) {
getJdbcTemplate().update("truncate table " + tableName);
jdbcTemplate.update("truncate table " + tableName);
}
}
Expand Up @@ -166,8 +166,6 @@ public void removeTrigger(StringBuilder sqlBuffer, String catalogName, String sc

public int getStreamingResultsFetchSize();

public JdbcTemplate getJdbcTemplate();

public String getCreateSymmetricDDL();

public String getCreateTableXML(TriggerRouter triggerRouter);
Expand Down
Expand Up @@ -157,7 +157,7 @@ public String getIdentifierQuoteString() {

@Override
public void truncateTable(String tableName) {
getJdbcTemplate().update("delete from " + tableName);
jdbcTemplate.update("delete from " + tableName);
}

}
Expand Up @@ -130,7 +130,7 @@ public String getDefaultSchema() {

@Override
public void truncateTable(String tableName) {
getJdbcTemplate().update("delete from " + tableName);
jdbcTemplate.update("delete from " + tableName);
}

}
Expand Up @@ -152,7 +152,7 @@ public boolean supportsTransactionId() {

@Override
public void truncateTable(String tableName) {
getJdbcTemplate().update("delete from " + tableName);
jdbcTemplate.update("delete from " + tableName);
}

}
Expand Up @@ -176,7 +176,7 @@ protected boolean allowsNullForIdentityColumn() {

@Override
public void truncateTable(String tableName) {
getJdbcTemplate().update("delete from " + tableName);
jdbcTemplate.update("delete from " + tableName);
}

}
Expand Up @@ -340,7 +340,7 @@ private boolean loadFromScriptIfProvided() {
}

if (fileUrl != null) {
new SqlScript(fileUrl, dbDialect.getJdbcTemplate().getDataSource(), true).execute();
new SqlScript(fileUrl, dataSource, true).execute();
loaded = true;
}
}
Expand Down
Expand Up @@ -152,7 +152,7 @@ protected void registerAndLoad(SymmetricWebServer registrationServer,
}

protected JdbcTemplate getTemplate(SymmetricWebServer server) {
JdbcTemplate t = AppUtils.find(Constants.JDBC, server.getEngine());
JdbcTemplate t = AppUtils.find(Constants.JDBC_TEMPLATE, server.getEngine());
return t;
}

Expand Down
Expand Up @@ -23,7 +23,6 @@
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.jdbc.core.JdbcTemplate;

public class LoadFromClientIntegrationTest extends AbstractIntegrationTest {

Expand All @@ -43,8 +42,7 @@ public void registerClientWithRoot() {
String result = getClientEngine().reloadNode("00000");
Assert.assertTrue(result, result.startsWith("Successfully opened initial load for node"));
getClientEngine().push();
JdbcTemplate jdbcTemplate = getClientDbDialect().getJdbcTemplate();
int initialLoadEnabled = jdbcTemplate.queryForInt("select initial_load_enabled from sym_node_security where node_id='00000'");
int initialLoadEnabled = clientJdbcTemplate.queryForInt("select initial_load_enabled from sym_node_security where node_id='00000'");
Assert.assertEquals(0, initialLoadEnabled);
}

Expand Down
Expand Up @@ -59,6 +59,7 @@
import org.junit.Test;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ConnectionCallback;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;

public class SimpleIntegrationTest extends AbstractIntegrationTest {
Expand Down Expand Up @@ -151,8 +152,8 @@ public void initialLoad() {
IDbDialect rootDialect = getRootDbDialect();
rootJdbcTemplate.update(insertCustomerSql, new Object[] { 301, "Linus", "1", "42 Blanket Street",
"Santa Claus", "IN", 90009, new Date(), new Date(), "This is a test", BINARY_DATA });
insertIntoTestTriggerTable(rootDialect, new Object[] { 1, "wow", "mom" });
insertIntoTestTriggerTable(rootDialect, new Object[] { 2, "mom", "wow" });
insertIntoTestTriggerTable(rootJdbcTemplate, rootDialect, new Object[] { 1, "wow", "mom" });
insertIntoTestTriggerTable(rootJdbcTemplate, rootDialect, new Object[] { 2, "mom", "wow" });

INodeService rootNodeService = AppUtils.find(Constants.NODE_SERVICE, getRootEngine());
INodeService clientNodeService = AppUtils.find(Constants.NODE_SERVICE, getClientEngine());
Expand Down Expand Up @@ -192,11 +193,11 @@ public void initialLoad() {
"Initial load was not successful accordign to the root");
}

private void insertIntoTestTriggerTable(IDbDialect dialect, Object[] values) {
private void insertIntoTestTriggerTable(JdbcTemplate jdbcTemplate, IDbDialect dialect, Object[] values) {
Table testTriggerTable = dialect.getTable(null, null, "test_triggers_table", true);
try {
dialect.prepareTableForDataLoad(testTriggerTable);
dialect.getJdbcTemplate().update(insertTestTriggerTableSql, values);
jdbcTemplate.update(insertTestTriggerTableSql, values);
} finally {
dialect.cleanupAfterDataLoad(testTriggerTable);
}
Expand Down Expand Up @@ -584,7 +585,7 @@ public void syncToRootAutoGeneratedPrimaryKey() {
logTestRunning();
final String NEW_VALUE = "unique new value one value";
IDbDialect clientDialect = getClientDbDialect();
insertIntoTestTriggerTable(clientDialect, new Object[] { 3, "value one", "value \" two" });
insertIntoTestTriggerTable(clientJdbcTemplate, clientDialect, new Object[] { 3, "value one", "value \" two" });
getClientEngine().push();
clientJdbcTemplate.update(updateTestTriggerTableSql, new Object[] { NEW_VALUE });
final String verifySql = "select count(*) from test_triggers_table where string_one_value=?";
Expand All @@ -598,7 +599,7 @@ public void reopenRegistration() {
logTestRunning();
getRootEngine().reOpenRegistration(TestConstants.TEST_CLIENT_EXTERNAL_ID);
getClientEngine().pull();
Assert.assertEquals(1, getRootDbDialect().getJdbcTemplate().queryForInt(isRegistrationClosedSql,
Assert.assertEquals(1, rootJdbcTemplate.queryForInt(isRegistrationClosedSql,
new Object[] { TestConstants.TEST_CLIENT_EXTERNAL_ID }, new int[] { Types.VARCHAR }));
}

Expand Down

0 comments on commit 5ba18ff

Please sign in to comment.