Skip to content

Commit

Permalink
moved more oracle create functions to the oracle.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Dec 19, 2007
1 parent 3229569 commit 86c3391
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 51 deletions.
Expand Up @@ -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;
Expand All @@ -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";

Expand All @@ -43,34 +43,27 @@ 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) {
logger.error("Error while initializing Oracle.", ex);
}
}

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() {
Expand Down
@@ -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);
Expand Down
23 changes: 22 additions & 1 deletion symmetric/src/main/resources/dialects/oracle.xml
Expand Up @@ -15,7 +15,7 @@
<property name="triggerPrefix" value="${symmetric.runtime.trigger.prefix}" />
<property name="functionInstalledSql">
<value>
<![CDATA[select count(*) from user_source where line = 1 and type = 'FUNCTION' and name=upper('$(functionName)')]]>
<![CDATA[select count(*) from user_source where line = 1 and (type = 'FUNCTION' or type = 'PACKAGE') and name=upper('$(functionName)')]]>
</value>
</property>
<property name="functionTemplatesToInstall">
Expand Down Expand Up @@ -45,6 +45,27 @@
]]>
</value>
</entry>
<entry key="fn_transaction_id">
<value>
<![CDATA[
CREATE OR REPLACE function fn_transaction_id
return varchar is
begin
return DBMS_TRANSACTION.local_transaction_id(false);
end;
]]>
</value>
</entry>
<entry key="fn_trigger_disabled">
<value>
<![CDATA[
CREATE OR REPLACE function fn_trigger_disabled return varchar is
begin
return pack_symmetric.disable_trigger;
end;
]]>
</value>
</entry>
</map>
</property>

Expand Down
Expand Up @@ -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());
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
}
}

0 comments on commit 86c3391

Please sign in to comment.