Skip to content

Commit

Permalink
SYMMETRICDS-105: allow functions to be placed in different schema. th…
Browse files Browse the repository at this point in the history
…is affects just postgresql at this point.
  • Loading branch information
erilong committed Jun 4, 2009
1 parent ece9b9d commit 69ca27d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
Expand Up @@ -210,8 +210,8 @@ final public boolean doesTriggerExist(String catalogName, String schema, String
protected void createRequiredFunctions() {
String[] functions = sqlTemplate.getFunctionsToInstall();
for (String funcName : functions) {
if (jdbcTemplate.queryForInt(sqlTemplate.getFunctionInstalledSql(funcName)) == 0) {
jdbcTemplate.update(sqlTemplate.getFunctionSql(funcName));
if (jdbcTemplate.queryForInt(sqlTemplate.getFunctionInstalledSql(funcName, defaultSchema)) == 0) {
jdbcTemplate.update(sqlTemplate.getFunctionSql(funcName, defaultSchema));
logger.info("Just installed " + funcName);
}
}
Expand Down
Expand Up @@ -688,20 +688,24 @@ public void setNewColumnPrefix(String newColumnPrefix) {
this.newColumnPrefix = newColumnPrefix;
}

public String getFunctionSql(String functionName) {
public String getFunctionSql(String functionName, String defaultSchema) {
if (this.functionTemplatesToInstall != null) {
String ddl = replace("functionName", functionName, this.functionTemplatesToInstall.get(functionName));
ddl = replace("version", Version.versionWithUnderscores(), ddl);
ddl = replace("defaultSchema",
defaultSchema != null && defaultSchema.length() > 0 ? defaultSchema + "." : "", ddl);
return ddl;
} else {
return null;
}
}

public String getFunctionInstalledSql(String functionName) {
public String getFunctionInstalledSql(String functionName, String defaultSchema) {
if (functionInstalledSql != null) {
String ddl = replace("functionName", functionName, functionInstalledSql);
ddl = replace("version", Version.versionWithUnderscores(), ddl);
ddl = replace("defaultSchema",
defaultSchema != null && defaultSchema.length() > 0 ? defaultSchema + "." : "", ddl);
return ddl;
} else {
return null;
Expand Down
Expand Up @@ -69,8 +69,8 @@ protected void createRequiredFunctions() {
String[] functions = sqlTemplate.getFunctionsToInstall();
for (String funcName : functions) {
if (! funcName.equals("fn_transaction_id") || supportsTransactionId) {
if (jdbcTemplate.queryForInt(sqlTemplate.getFunctionInstalledSql(funcName)) == 0) {
jdbcTemplate.update(sqlTemplate.getFunctionSql(funcName));
if (jdbcTemplate.queryForInt(sqlTemplate.getFunctionInstalledSql(funcName, defaultSchema)) == 0) {
jdbcTemplate.update(sqlTemplate.getFunctionSql(funcName, defaultSchema));
logger.info("Just installed " + funcName);
}
}
Expand Down
7 changes: 4 additions & 3 deletions symmetric/src/main/resources/dialects/postgresql.xml
Expand Up @@ -17,15 +17,16 @@
<property name="triggerPrefix" value="$[sym.trigger.prefix]" />
<property name="functionInstalledSql">
<value>
<![CDATA[select count(*) from information_schema.routines where routine_name = '$(functionName)']]>
<![CDATA[select count(*) from information_schema.routines
where routine_name = '$(functionName)' and specific_schema = '$(defaultSchema)']]>
</value>
</property>
<property name="functionTemplatesToInstall">
<map>
<entry key="fn_sym_triggers_disabled">
<value>
<![CDATA[
CREATE or REPLACE FUNCTION fn_sym_triggers_disabled() RETURNS INTEGER AS $$
CREATE or REPLACE FUNCTION $(defaultSchema)fn_sym_triggers_disabled() RETURNS INTEGER AS $$
DECLARE
triggerDisabled INTEGER;
BEGIN
Expand All @@ -41,7 +42,7 @@
<entry key="fn_sym_node_disabled">
<value>
<![CDATA[
CREATE or REPLACE FUNCTION fn_sym_node_disabled() RETURNS VARCHAR AS $$
CREATE or REPLACE FUNCTION $(defaultSchema)fn_sym_node_disabled() RETURNS VARCHAR AS $$
DECLARE
nodeId VARCHAR(50);
BEGIN
Expand Down

0 comments on commit 69ca27d

Please sign in to comment.