Skip to content

Commit

Permalink
0001183: Add new property db.init.sql that allows sql to be run again…
Browse files Browse the repository at this point in the history
…st a database connection right after it is created

0001053: Verify that NOCOUNT is off for SQL Server before starting SymmetricDS. When NOCOUNT is turned on SymmetricDS won't work.
  • Loading branch information
chenson42 committed Apr 24, 2013
1 parent 3e575d2 commit c305ce3
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 1 deletion.
Expand Up @@ -29,11 +29,13 @@

import org.jumpmind.db.platform.IDatabasePlatform;
import org.jumpmind.db.sql.IConnectionCallback;
import org.jumpmind.db.sql.ISqlTemplate;
import org.jumpmind.db.sql.ISqlTransaction;
import org.jumpmind.db.sql.JdbcSqlTemplate;
import org.jumpmind.db.sql.JdbcSqlTransaction;
import org.jumpmind.db.sql.SqlException;
import org.jumpmind.db.util.BinaryEncoding;
import org.jumpmind.symmetric.SymmetricException;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.db.AbstractSymmetricDialect;
import org.jumpmind.symmetric.db.ISymmetricDialect;
Expand Down Expand Up @@ -64,6 +66,15 @@ public MsSqlSymmetricDialect(IParameterService parameterService, IDatabasePlatfo
this.triggerTemplate = new MsSqlTriggerTemplate(this);
}

@Override
public void verifyDatabaseIsCompatible() {
super.verifyDatabaseIsCompatible();
ISqlTemplate template = getPlatform().getSqlTemplate();
if (template.queryForInt("select case when (512 & @@options) = 512 then 1 else 0 end") == 1) {
throw new SymmetricException("NOCOUNT is currently turned ON. SymmetricDS will not function with NOCOUNT turned ON.");
}
}

@Override
protected void createRequiredDatabaseObjects() {
String encode = this.parameterService.getTablePrefix() + "_" + "base64_encode";
Expand Down
Expand Up @@ -496,6 +496,7 @@ public synchronized boolean start(boolean startJobs) {
if (!starting && !started) {
try {
starting = true;
symmetricDialect.verifyDatabaseIsCompatible();
setup();
if (isConfigured()) {
Node node = nodeService.findIdentity();
Expand Down
Expand Up @@ -141,6 +141,9 @@ public int getMaxTriggerNameLength() {
return max < MAX_SYMMETRIC_SUPPORTED_TRIGGER_SIZE && max > 0 ? max
: MAX_SYMMETRIC_SUPPORTED_TRIGGER_SIZE;
}

public void verifyDatabaseIsCompatible() {
}

public void initTablesAndDatabaseObjects() {
createOrAlterTablesIfNecessary();
Expand Down
Expand Up @@ -54,7 +54,9 @@ public void createTrigger(StringBuilder sqlBuffer, DataEventType dml,
public void removeTrigger(StringBuilder sqlBuffer, String catalogName, String schemaName, String triggerName,
String tableName, TriggerHistory oldHistory);

public boolean doesTriggerExist(String catalogName, String schema, String tableName, String triggerName);
public boolean doesTriggerExist(String catalogName, String schema, String tableName, String triggerName);

public void verifyDatabaseIsCompatible();

public void initTablesAndDatabaseObjects();

Expand Down
Expand Up @@ -92,6 +92,11 @@ db.validation.query=
# Tags: database
db.connection.properties=

# Specify a SQL statement that will be run when a database connection is created
#
# Tags: database
db.init.sql=

# When symmetric tables are created and accessed, this is the prefix to use for the tables.
#
# Tags: database
Expand Down
Expand Up @@ -20,6 +20,9 @@
*/
package org.jumpmind.db.util;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.lang.StringUtils;
import org.jumpmind.properties.TypedProperties;
Expand Down Expand Up @@ -85,6 +88,13 @@ public static BasicDataSource create(TypedProperties properties,
}
}
}

String initSql = properties.get(BasicDataSourcePropertyConstants.DB_POOL_INIT_SQL, null);
if (StringUtils.isNotBlank(initSql)) {
List<String> initSqlList = new ArrayList<String>(1);
initSqlList.add(initSql);
dataSource.setConnectionInitSqls(initSqlList);
}
return dataSource;

}
Expand Down
Expand Up @@ -43,6 +43,7 @@ private BasicDataSourcePropertyConstants() {
public final static String DB_POOL_TEST_ON_BORROW = "db.test.on.borrow";
public final static String DB_POOL_TEST_ON_RETURN = "db.test.on.return";
public final static String DB_POOL_TEST_WHILE_IDLE = "db.test.while.idle";
public final static String DB_POOL_INIT_SQL = "db.init.sql";
public final static String DB_POOL_CONNECTION_PROPERTIES = "db.connection.properties";

}

0 comments on commit c305ce3

Please sign in to comment.