Skip to content

Commit

Permalink
periodic checkin to make sure i don't break anything.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Dec 24, 2007
1 parent 753ca84 commit 73c3d07
Show file tree
Hide file tree
Showing 19 changed files with 337 additions and 74 deletions.
5 changes: 5 additions & 0 deletions symmetric/pom.xml
Expand Up @@ -497,6 +497,11 @@
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.7</version>
</dependency>
</dependencies>
</project>
Expand Up @@ -72,10 +72,14 @@ public class SymmetricEngine {
private IPurgeService purgeService;

private boolean started = false;

private IDbDialect dbDialect;

private Properties properties;

private static Map<String, SymmetricEngine> registeredEnginesByUrl = new HashMap<String, SymmetricEngine>();

private static Map<String, SymmetricEngine> registeredEnginesByName = new HashMap<String, SymmetricEngine>();

/**
* @param overridePropertiesResource1 Provide a Spring resource path to a properties file to be used for configuration
Expand Down Expand Up @@ -126,8 +130,8 @@ private void init(ApplicationContext applicationContext) {
registrationService = (IRegistrationService) applicationContext
.getBean(Constants.REGISTRATION_SERVICE);
purgeService = (IPurgeService) applicationContext
.getBean(Constants.PURGE_SERVICE);
IDbDialect dbDialect = (IDbDialect)applicationContext.getBean(Constants.DB_DIALECT);
.getBean(Constants.PURGE_SERVICE);
dbDialect = (IDbDialect)applicationContext.getBean(Constants.DB_DIALECT);
registerEngine();
logger.info("Initialized SymmetricDS externalId=" + runtimeConfig.getExternalId() + " version=" + Version.VERSION + " database="+dbDialect.getName());
}
Expand All @@ -138,6 +142,7 @@ private void init(ApplicationContext applicationContext) {
*/
private void registerEngine() {
registeredEnginesByUrl.put(runtimeConfig.getMyUrl(), this);
registeredEnginesByName.put(getEngineName(), this);
}

/**
Expand Down Expand Up @@ -174,6 +179,18 @@ private void startJobs() {
applicationContext.getBean(Constants.SYNC_TRIGGERS_JOB_TIMER);
}
}


/**
* Get a list of configured properties for Symmetric. Read-only.
*/
public Properties getProperties() {
return new Properties(properties);
}

public String getEngineName() {
return dbDialect.getEngineName();
}

/**
* Must be called to start symmetric.
Expand Down Expand Up @@ -288,5 +305,9 @@ public ApplicationContext getApplicationContext() {
public static SymmetricEngine findEngineByUrl(String url) {
return registeredEnginesByUrl.get(url);
}

public static SymmetricEngine findEngineByName(String name) {
return registeredEnginesByName.get(name);
}

}
Expand Up @@ -91,6 +91,8 @@ abstract public class AbstractDbDialect implements IDbDialect {

private TransactionTemplate transactionTemplate;

private String engineName;

protected AbstractDbDialect() {
_defaultSizes = new HashMap<Integer, String>();
_defaultSizes.put(new Integer(1), "254");
Expand Down Expand Up @@ -740,4 +742,12 @@ public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
this.transactionTemplate = transactionTemplate;
}

public String getEngineName() {
return engineName;
}

public void setEngineName(String engineName) {
this.engineName = engineName;
}

}
Expand Up @@ -29,6 +29,7 @@
import org.apache.ddlutils.Platform;
import org.apache.ddlutils.PlatformFactory;
import org.apache.ddlutils.platform.derby.DerbyPlatform;
import org.apache.ddlutils.platform.hsqldb.HsqlDbPlatform;
import org.apache.ddlutils.platform.mssql.MSSqlPlatform;
import org.apache.ddlutils.platform.mysql.MySqlPlatform;
import org.apache.ddlutils.platform.oracle.Oracle10Platform;
Expand Down Expand Up @@ -79,6 +80,8 @@ public Object getObject() throws Exception {
dialect = (AbstractDbDialect) beanFactory.getBean("postgresqlDialect");
} else if (pf instanceof DerbyPlatform) {
dialect = (AbstractDbDialect) beanFactory.getBean("derbyDialect");
} else if (pf instanceof HsqlDbPlatform) {
dialect = (AbstractDbDialect) beanFactory.getBean("hsqldbDialect");
} else {
throw new DbNotSupportedException();
}
Expand Down
Expand Up @@ -39,6 +39,11 @@ public void initTrigger(DataEventType dml, Trigger config,
@Deprecated
public void removeTrigger(String schemaName, String triggerName);

/**
* Get the name of this symmetric instance. This can be set in symmetric.properties using the symmetric.runtime.engine.name property.
*/
public String getEngineName();

public void removeTrigger(String schemaName, String triggerName, String tableName);

public void prepareTableForInserts(Table table);
Expand Down
Expand Up @@ -164,6 +164,7 @@ private String replaceTemplateVariables(IDbDialect dialect, DataEventType dml, T
ddl = replace("defaultSchema", defaultSchema != null && defaultSchema.length() > 0 ? defaultSchema + "." : "",
ddl);
ddl = replace("triggerName", trigger.getTriggerName(dml, triggerPrefix).toUpperCase(), ddl);
ddl = replace("engineName", dialect.getEngineName(), ddl);
ddl = replace("prefixName", tablePrefix, ddl);
ddl = replace("targetGroupId", trigger.getTargetGroupId(), ddl);
ddl = replace("channelName", trigger.getChannelId(), ddl);
Expand Down
@@ -0,0 +1,36 @@
/*
* SymmetricDS is an open source database synchronization solution.
*
* Copyright (C) Chris Henson <chenson42@users.sourceforge.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*/
package org.jumpmind.symmetric.db.hsqldb;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hsqldb.Trigger;

public class HsqlDbTrigger implements Trigger {

static final Log logger = LogFactory.getLog(HsqlDbTrigger.class);

public void fire(int type, String triggerName, String tableName, Object[] oldRow,
Object[] newRolw) {
logger.info("trigger " + triggerName + " fired for " + tableName);

}

}
3 changes: 2 additions & 1 deletion symmetric/src/main/resources/dialects/derby.xml
Expand Up @@ -8,7 +8,8 @@

<bean id="derbyDialect" class="org.jumpmind.symmetric.db.derby.DerbyDbDialect"
scope="prototype">
<property name="tablePrefix" value="${sync.table.prefix}" />
<property name="tablePrefix" value="${sync.table.prefix}" />
<property name="engineName" value="${symmetric.runtime.engine.name}"/>
<property name="streamingResultsFetchSize" value="${db.jdbc.streaming.results.fetch.size}" />
<property name="sqlTemplate">
<bean class="org.jumpmind.symmetric.db.SqlTemplate">
Expand Down
84 changes: 84 additions & 0 deletions symmetric/src/main/resources/dialects/hsqldb.xml
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
default-lazy-init="true">

<bean id="stringTemplate" class="java.lang.String">
<constructor-arg>
<value>
<![CDATA[ case when $(tableAlias).$(columnName) is null then '' else concat(concat('"',replace(replace($(tableAlias).$(columnName),'\','\\'),'"','\"')),'"') end ||','||]]>
</value>
</constructor-arg>
</bean>

<bean id="hsqldbDialect"
class="org.jumpmind.symmetric.db.hsqldb.HsqlDbDialect"
scope="prototype">
<property name="tablePrefix" value="${sync.table.prefix}" />
<property name="engineName"
value="${symmetric.runtime.engine.name}" />
<property name="streamingResultsFetchSize"
value="${db.jdbc.streaming.results.fetch.size}" />
<property name="sqlTemplate">
<bean class="org.jumpmind.symmetric.db.SqlTemplate">
<property name="triggerPrefix"
value="${symmetric.runtime.trigger.prefix}" />
<property name="stringColumnTemplate"
ref="stringTemplate" />
<property name="clobColumnTemplate"
ref="stringTemplate" />
<property name="blobColumnTemplate">
<value>
<![CDATA['unsupported'||','||]]>
</value>
</property>
<property name="numberColumnTemplate">
<value>
<![CDATA[coalesce(cast($(tableAlias).$(columnName) as varchar(50)), '')||','||]]>
</value>
</property>
<property name="datetimeColumnTemplate">
<value>
<![CDATA[ case when $(tableAlias).$(columnName) is null then '' else concat(concat('"',to_char($(tableAlias).$(columnName), 'YYYY-MM-DD HH24:MI:SS')),'"') end ||','||]]>
</value>
</property>

<property name="triggerConcatCharacter" value="||" />
<property name="sqlTemplates">

<map>
<entry key="insertTriggerTemplate">
<value>
<![CDATA[
CREATE TRIGGER $(triggerName)_$(engineName)_$(triggerHistoryId) AFTER INSERT ON $(tableName) FOR EACH ROW QUEUE 0 CALL "org.jumpmind.symmetric.db.hsqldb.HsqlDbTrigger"
]]>
</value>
</entry>
<entry key="updateTriggerTemplate">
<value>
<![CDATA[
]]>
</value>
</entry>
<entry key="deleteTriggerTemplate">
<value>
<![CDATA[
]]>
</value>
</entry>
<entry key="initialLoadSqlTemplate">
<value>
<![CDATA[select $(columns) from $(schemaName)$(tableName) t where $(whereClause)]]>
</value>
</entry>
</map>
</property>
</bean>
</property>
</bean>

</beans>
3 changes: 2 additions & 1 deletion symmetric/src/main/resources/dialects/mssql.xml
Expand Up @@ -17,7 +17,8 @@

<bean id="msSqlDialect" class="org.jumpmind.symmetric.db.mssql.MsSqlDbDialect"
scope="prototype">
<property name="tablePrefix" value="${sync.table.prefix}" />
<property name="tablePrefix" value="${sync.table.prefix}" />
<property name="engineName" value="${symmetric.runtime.engine.name}"/>
<property name="streamingResultsFetchSize" value="${db.jdbc.streaming.results.fetch.size}" />
<property name="sqlTemplate">
<bean class="org.jumpmind.symmetric.db.SqlTemplate">
Expand Down
2 changes: 1 addition & 1 deletion symmetric/src/main/resources/dialects/mysql.xml
Expand Up @@ -17,6 +17,7 @@
<bean id="mysqlDialect" class="org.jumpmind.symmetric.db.mysql.MySqlDbDialect"
scope="prototype">
<property name="tablePrefix" value="${sync.table.prefix}" />
<property name="engineName" value="${symmetric.runtime.engine.name}"/>
<property name="streamingResultsFetchSize" value="${db.jdbc.streaming.results.fetch.size}" />
<property name="sqlTemplate">
<bean class="org.jumpmind.symmetric.db.SqlTemplate">
Expand Down Expand Up @@ -74,7 +75,6 @@
<![CDATA[coalesce(cast($(tableAlias).$(columnName) as char), ''),',',]]>
</value>
</property>
<!-- TODO -->
<property name="datetimeColumnTemplate">
<value>
<![CDATA[if($(tableAlias).$(columnName) is null,'',concat('"',cast($(tableAlias).$(columnName) as char),'"')),',',]]>
Expand Down
1 change: 1 addition & 0 deletions symmetric/src/main/resources/dialects/oracle.xml
Expand Up @@ -9,6 +9,7 @@
<bean id="oracleDialect" class="org.jumpmind.symmetric.db.oracle.OracleDbDialect"
scope="prototype">
<property name="tablePrefix" value="${sync.table.prefix}" />
<property name="engineName" value="${symmetric.runtime.engine.name}"/>
<property name="streamingResultsFetchSize" value="${db.jdbc.streaming.results.fetch.size}" />
<property name="sqlTemplate">
<bean class="org.jumpmind.symmetric.db.SqlTemplate">
Expand Down
1 change: 1 addition & 0 deletions symmetric/src/main/resources/dialects/postgresql.xml
Expand Up @@ -9,6 +9,7 @@
<bean id="postgresqlDialect" class="org.jumpmind.symmetric.db.postgresql.PostgreSqlDbDialect"
scope="prototype">
<property name="tablePrefix" value="${sync.table.prefix}" />
<property name="engineName" value="${symmetric.runtime.engine.name}"/>
<property name="streamingResultsFetchSize" value="${db.jdbc.streaming.results.fetch.size}" />
<property name="sqlTemplate">
<bean class="org.jumpmind.symmetric.db.SqlTemplate">
Expand Down
2 changes: 1 addition & 1 deletion symmetric/src/main/resources/symmetric-default.properties
Expand Up @@ -68,7 +68,7 @@ symmetric.runtime.outgoing.batches.max.to.process=60
symmetric.runtime.incoming.batches.skip.duplicates=true

# This is the engine name. This should be set if you have more than one engine running in the same JVM.
# It is used to name the JMX management bean.
# It is used to name the JMX management bean. Please do not use underscores in this name.
symmetric.runtime.engine.name=Default

# Set this if you want to give your server a unique name to be used to identify which server did what action. Typically useful when running in
Expand Down
3 changes: 2 additions & 1 deletion symmetric/src/main/resources/symmetric-dialects.xml
Expand Up @@ -11,6 +11,7 @@
<import resource="classpath:/dialects/oracle.xml" />
<import resource="classpath:/dialects/mysql.xml" />
<import resource="classpath:/dialects/postgresql.xml" />
<import resource="classpath:/dialects/derby.xml" />
<import resource="classpath:/dialects/derby.xml" />
<import resource="classpath:/dialects/hsqldb.xml" />

</beans>
17 changes: 15 additions & 2 deletions symmetric/src/test/java/org/jumpmind/symmetric/AbstractTest.java
Expand Up @@ -7,6 +7,8 @@

import javax.sql.DataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ddlutils.Platform;
import org.apache.ddlutils.io.DatabaseIO;
import org.apache.ddlutils.model.Database;
Expand All @@ -16,9 +18,20 @@
import org.jumpmind.symmetric.db.SqlScript;

abstract public class AbstractTest {


static final Log logger = LogFactory.getLog(AbstractTest.class);

protected SymmetricEngine createEngine(File propertiesFile) {
return new SymmetricEngine("file:" + propertiesFile.getAbsolutePath(), null);
try {
return new SymmetricEngine("file:"
+ propertiesFile.getAbsolutePath(), null);
} catch (RuntimeException ex) {
logger.error(ex, ex);
throw ex;
} catch (Exception ex) {
logger.error(ex, ex);
throw new RuntimeException(ex);
}
}

protected void dropAndCreateDatabaseTables(String databaseType, SymmetricEngine engine) {
Expand Down

0 comments on commit 73c3d07

Please sign in to comment.