Skip to content

Commit

Permalink
SYMMETRICDS-337 - work around setQueryTImeout() not being implemented…
Browse files Browse the repository at this point in the history
… on postgres
  • Loading branch information
chenson42 committed Sep 7, 2010
1 parent d3ccba7 commit 3223446
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 18 deletions.
Expand Up @@ -123,6 +123,7 @@ private ParameterConstants() {

public final static String DB_NATIVE_EXTRACTOR = "db.native.extractor";
public final static String DB_METADATA_IGNORE_CASE = "db.metadata.ignore.case";
public final static String DB_QUERY_TIMEOUT_SECS = "db.sql.query.timeout.seconds";

public final static String RUNTIME_CONFIG_TABLE_PREFIX = "sync.table.prefix";

Expand Down
Expand Up @@ -146,6 +146,8 @@ abstract public class AbstractDbDialect implements IDbDialect {
protected LobHandler lobHandler;

protected boolean supportsTransactionViews = false;

protected int queryTimeout = 0;

protected AbstractDbDialect() {
_defaultSizes = new HashMap<Integer, String>();
Expand Down Expand Up @@ -207,9 +209,11 @@ public int getMaxTriggerNameLength() {
: MAX_SYMMETRIC_SUPPORTED_TRIGGER_SIZE;
}

public void init(Platform pf) {
public void init(Platform pf, int queryTimeout) {
log.info("DbDialectInUse", this.getClass().getName());
this.jdbcTemplate = new JdbcTemplate(pf.getDataSource());
this.queryTimeout = queryTimeout;
this.jdbcTemplate.setQueryTimeout(queryTimeout);
this.platform = pf;
this.identifierQuoteString = "\"";
jdbcTemplate.execute(new ConnectionCallback<Object>() {
Expand Down Expand Up @@ -1139,9 +1143,9 @@ public long insertWithGeneratedKey(final String sql, final SequenceIdentifier se
return insertWithGeneratedKey(jdbcTemplate, sql, sequenceId, callback);
}

public long insertWithGeneratedKey(final JdbcTemplate template, final String sql,
public long insertWithGeneratedKey(final JdbcTemplate jdbcTemplate, final String sql,
final SequenceIdentifier sequenceId, final PreparedStatementCallback<Object> callback) {
return template.execute(new ConnectionCallback<Long>() {
return jdbcTemplate.execute(new ConnectionCallback<Long>() {
public Long doInConnection(Connection conn) throws SQLException, DataAccessException {

long key = 0;
Expand All @@ -1167,7 +1171,7 @@ public Long doInConnection(Connection conn) throws SQLException, DataAccessExcep
ps = conn.prepareStatement(replaceSql);
}
}
ps.setQueryTimeout(template.getQueryTimeout());
ps.setQueryTimeout(jdbcTemplate.getQueryTimeout());
if (callback != null) {
callback.doInPreparedStatement(ps);
}
Expand Down
Expand Up @@ -59,6 +59,8 @@ public class DbDialectFactory implements FactoryBean<IDbDialect>, BeanFactoryAwa
private JdbcTemplate jdbcTemplate;

private BeanFactory beanFactory;

private int queryTimeout;

public IDbDialect getObject() throws Exception {

Expand All @@ -80,6 +82,7 @@ public IDbDialect getObject() throws Exception {
dialect = (AbstractDbDialect) beanFactory.getBean("msSqlDialect");
} else if (pf instanceof PostgreSqlPlatform) {
dialect = (AbstractDbDialect) beanFactory.getBean("postgresqlDialect");
queryTimeout = 0;
} else if (pf instanceof DerbyPlatform) {
dialect = (AbstractDbDialect) beanFactory.getBean("derbyDialect");
} else if (pf instanceof H2Platform) {
Expand Down Expand Up @@ -110,7 +113,8 @@ public IDbDialect getObject() throws Exception {
throw new DbNotSupportedException();
}

dialect.init(pf);
dialect.init(pf, queryTimeout);
jdbcTemplate.setQueryTimeout(queryTimeout);
dialect.setTransactionTemplate((TransactionTemplate) beanFactory
.getBean("currentTransactionTemplate"));
return dialect;
Expand Down Expand Up @@ -159,5 +163,9 @@ public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
public void setDb2zSeriesProductVersion(String version) {
this.db2zSeriesProductVersion = version;
}

public void setQueryTimeout(int queryTimeout) {
this.queryTimeout = queryTimeout;
}

}
Expand Up @@ -35,8 +35,8 @@ public class HsqlDbDialect extends AbstractEmbeddedDbDialect implements IDbDiale
private boolean enforceStrictSize = true;

@Override
public void init(Platform pf) {
super.init(pf);
public void init(Platform pf, int queryTimeout) {
super.init(pf, queryTimeout);
jdbcTemplate.update("SET WRITE_DELAY 100 MILLIS");
jdbcTemplate.update("SET PROPERTY \"hsqldb.default_table_type\" 'cached'");
jdbcTemplate.update("SET PROPERTY \"sql.enforce_strict_size\" " + enforceStrictSize);
Expand Down
Expand Up @@ -31,11 +31,6 @@ public class HsqlDb2Dialect extends AbstractDbDialect implements IDbDialect {
public static String DUAL_TABLE = "DUAL";

boolean dualTableCreated = false;

public void init(org.jumpmind.symmetric.ddl.Platform pf) {
super.init(pf);
};


@Override
protected boolean doesTriggerExistOnPlatform(String catalogName, String schemaName,
Expand Down
Expand Up @@ -49,11 +49,10 @@ public class OracleDbDialect extends AbstractDbDialect implements IDbDialect {
String selectTriggerSql;

String selectTransactionsSql;


@Override
public void init(Platform pf) {
super.init(pf);
public void init(Platform pf, int queryTimeout) {
super.init(pf, queryTimeout);
try {
areDatabaseTransactionsPendingSince(System.currentTimeMillis());
supportsTransactionViews = true;
Expand Down
Expand Up @@ -71,7 +71,7 @@ public AbstractDataToRouteReader(DataSource dataSource, int queryTimeout, int ma
public Data take() {
Data data = null;
try {
data = dataQueue.poll(queryTimeout, TimeUnit.SECONDS);
data = dataQueue.poll(queryTimeout == 0 ? 600 : queryTimeout, TimeUnit.SECONDS);
} catch (InterruptedException e) {
log.warn(e);
}
Expand Down
Expand Up @@ -48,7 +48,6 @@

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource" />
<property name="queryTimeout" value="$[sym.db.sql.query.timeout.seconds]"/>
</bean>

<!-- Data Loader without query timeout to fix memory problems with MySQL 5 driver -->
Expand All @@ -73,6 +72,7 @@
<bean id="dbDialect" class="org.jumpmind.symmetric.db.DbDialectFactory" scope="singleton">
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="db2zSeriesProductVersion" value="$[sym.db2.zseries.version]" />
<property name="queryTimeout" value="$[sym.db.sql.query.timeout.seconds]"/>
</bean>

</beans>
Expand Up @@ -203,7 +203,7 @@ private void insertIntoTestTriggerTable(JdbcTemplate jdbcTemplate, IDbDialect di
}
}

@Test(timeout = 120000)
@Test//(timeout = 120000)
public void syncToClient() {
logTestRunning();
// test pulling no data
Expand Down

0 comments on commit 3223446

Please sign in to comment.