From 86c3391a4047171e65a66d5cdcc6e3fcda717a32 Mon Sep 17 00:00:00 2001 From: chenson42 Date: Wed, 19 Dec 2007 13:43:42 +0000 Subject: [PATCH] moved more oracle create functions to the oracle.xml --- .../symmetric/db/oracle/OracleDbDialect.java | 29 +++++++------------ .../{oracle-transactionid.sql => oracle.sql} | 11 ------- .../src/main/resources/dialects/oracle.xml | 23 ++++++++++++++- .../symmetric/AbstractIntegrationTest.java | 25 +++------------- 4 files changed, 37 insertions(+), 51 deletions(-) rename symmetric/src/main/resources/dialects/{oracle-transactionid.sql => oracle.sql} (51%) diff --git a/symmetric/src/main/java/org/jumpmind/symmetric/db/oracle/OracleDbDialect.java b/symmetric/src/main/java/org/jumpmind/symmetric/db/oracle/OracleDbDialect.java index 2434c4e0a1..95612e75b5 100644 --- a/symmetric/src/main/java/org/jumpmind/symmetric/db/oracle/OracleDbDialect.java +++ b/symmetric/src/main/java/org/jumpmind/symmetric/db/oracle/OracleDbDialect.java @@ -21,8 +21,6 @@ package org.jumpmind.symmetric.db.oracle; import java.net.URL; -import java.text.SimpleDateFormat; -import java.util.Date; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -35,6 +33,8 @@ public class OracleDbDialect extends AbstractDbDialect implements IDbDialect { static final Log logger = LogFactory.getLog(OracleDbDialect.class); static final String TRANSACTION_ID_FUNCTION_NAME = "fn_transaction_id"; + + static final String PACKAGE = "pack_symmetric"; static final String ORACLE_OBJECT_TYPE = "FUNCTION"; @@ -43,11 +43,11 @@ public class OracleDbDialect extends AbstractDbDialect implements IDbDialect { @Override protected void initForSpecificDialect() { try { - if (!isFunctionUpToDate(TRANSACTION_ID_FUNCTION_NAME)) { + if (!isPackageUpToDate(PACKAGE)) { logger - .info("Creating function " - + TRANSACTION_ID_FUNCTION_NAME); - new SqlScript(getTransactionIdSqlUrl(), getPlatform() + .info("Creating package " + + PACKAGE); + new SqlScript(getSqlScriptUrl(), getPlatform() .getDataSource(), '/').execute(); } } catch (Exception ex) { @@ -55,22 +55,15 @@ protected void initForSpecificDialect() { } } - private URL getTransactionIdSqlUrl() { - return getClass().getResource("/dialects/oracle-transactionid.sql"); + private URL getSqlScriptUrl() { + return getClass().getResource("/dialects/oracle.sql"); } - public boolean isFunctionUpToDate(String name) throws Exception { - long lastModified = getTransactionIdSqlUrl().openConnection() - .getLastModified(); - - SimpleDateFormat dateFormat = new SimpleDateFormat( - "yyyy-MM-dd':'HH:mm:ss"); - + private boolean isPackageUpToDate(String name) throws Exception { return jdbcTemplate .queryForInt( - "select count(*) from all_objects where timestamp < ? and object_name= upper(?) ", - new Object[] { - dateFormat.format(new Date(lastModified)), name }) > 0; + "select count(*) from all_objects where object_name= upper(?) ", + new Object[] { name }) > 0; } public boolean isCharSpacePadded() { diff --git a/symmetric/src/main/resources/dialects/oracle-transactionid.sql b/symmetric/src/main/resources/dialects/oracle.sql similarity index 51% rename from symmetric/src/main/resources/dialects/oracle-transactionid.sql rename to symmetric/src/main/resources/dialects/oracle.sql index 65e7564615..5dc6f1215b 100644 --- a/symmetric/src/main/resources/dialects/oracle-transactionid.sql +++ b/symmetric/src/main/resources/dialects/oracle.sql @@ -1,14 +1,3 @@ -CREATE OR REPLACE function fn_transaction_id - return varchar is - begin - return DBMS_TRANSACTION.local_transaction_id(false); - end; -/ -CREATE OR REPLACE function fn_trigger_disabled return varchar is - begin - return pack_symmetric.disable_trigger; - end; -/ CREATE OR REPLACE package pack_symmetric as disable_trigger pls_integer; procedure setValue (a IN number); diff --git a/symmetric/src/main/resources/dialects/oracle.xml b/symmetric/src/main/resources/dialects/oracle.xml index c2c356da80..d6ceeae2e3 100644 --- a/symmetric/src/main/resources/dialects/oracle.xml +++ b/symmetric/src/main/resources/dialects/oracle.xml @@ -15,7 +15,7 @@ - + @@ -45,6 +45,27 @@ ]]> + + + + + + + + + + diff --git a/symmetric/src/test/java/org/jumpmind/symmetric/AbstractIntegrationTest.java b/symmetric/src/test/java/org/jumpmind/symmetric/AbstractIntegrationTest.java index 681c8b0268..7c23b2a08c 100644 --- a/symmetric/src/test/java/org/jumpmind/symmetric/AbstractIntegrationTest.java +++ b/symmetric/src/test/java/org/jumpmind/symmetric/AbstractIntegrationTest.java @@ -19,10 +19,6 @@ abstract public class AbstractIntegrationTest extends AbstractTest { private SymmetricEngine rootEngine; - private String clientDatabaseType; - - private String rootDatabaseType; - protected SymmetricEngine getClientEngine() { if (this.clientEngine == null) { this.clientEngine = createEngine(getClientFile()); @@ -32,19 +28,13 @@ protected SymmetricEngine getClientEngine() { } protected String getRootDatabaseName() { - if (rootDatabaseType == null) { - IDbDialect dialect = (IDbDialect) getRootEngine().getApplicationContext().getBean(Constants.DB_DIALECT); - rootDatabaseType = dialect.getName().toLowerCase(); - } - return rootDatabaseType; + IDbDialect dialect = (IDbDialect) getRootEngine().getApplicationContext().getBean(Constants.DB_DIALECT); + return dialect.getName().toLowerCase(); } protected String getClientDatabaseName() { - if (clientDatabaseType == null) { - IDbDialect dialect = (IDbDialect) getClientEngine().getApplicationContext().getBean(Constants.DB_DIALECT); - clientDatabaseType = dialect.getName().toLowerCase(); - } - return clientDatabaseType; + IDbDialect dialect = (IDbDialect) getClientEngine().getApplicationContext().getBean(Constants.DB_DIALECT); + return dialect.getName().toLowerCase(); } protected SymmetricEngine getRootEngine() { @@ -72,11 +62,4 @@ File getRootFile() { return MultiDatabaseTestFactory.writeTempPropertiesFileFor(databaseTypes[0], DatabaseRole.ROOT); } - public void setClientDatabaseType(String clientDatabaseType) { - this.clientDatabaseType = clientDatabaseType; - } - - public void setRootDatabaseType(String rootDatabaseType) { - this.rootDatabaseType = rootDatabaseType; - } }