Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '3.9' of https://github.com/JumpMind/symmetric-ds.git in…
…to 3.9
- Loading branch information
Showing
5 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...etric-client/src/main/java/org/jumpmind/symmetric/db/mssql/MsSql2008SymmetricDialect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.jumpmind.symmetric.db.mssql; | ||
|
||
import org.jumpmind.db.platform.IDatabasePlatform; | ||
import org.jumpmind.symmetric.model.Trigger; | ||
import org.jumpmind.symmetric.service.IParameterService; | ||
|
||
public class MsSql2008SymmetricDialect extends MsSqlSymmetricDialect { | ||
public MsSql2008SymmetricDialect() { | ||
super(); | ||
} | ||
|
||
public MsSql2008SymmetricDialect(IParameterService parameterService, IDatabasePlatform platform) { | ||
super(parameterService, platform); | ||
this.triggerTemplate = new MsSql2008TriggerTemplate(this); | ||
} | ||
|
||
@Override | ||
protected String getDbSpecificDataHasChangedCondition(Trigger trigger) { | ||
/* gets filled/replaced by trigger template as it will compare by each column */ | ||
return "$(anyColumnChanged)"; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
symmetric-client/src/main/java/org/jumpmind/symmetric/db/mssql/MsSql2008TriggerTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.jumpmind.symmetric.db.mssql; | ||
|
||
import org.jumpmind.db.model.Column; | ||
import org.jumpmind.db.model.Table; | ||
import org.jumpmind.symmetric.db.ISymmetricDialect; | ||
import org.jumpmind.symmetric.io.data.DataEventType; | ||
import org.jumpmind.symmetric.model.Channel; | ||
import org.jumpmind.symmetric.model.Trigger; | ||
import org.jumpmind.symmetric.model.TriggerHistory; | ||
import org.jumpmind.util.FormatUtils; | ||
|
||
public class MsSql2008TriggerTemplate extends MsSqlTriggerTemplate { | ||
public MsSql2008TriggerTemplate(ISymmetricDialect symmetricDialect) { | ||
super(symmetricDialect); | ||
} | ||
|
||
@Override | ||
protected String replaceTemplateVariables(DataEventType dml, Trigger trigger, | ||
TriggerHistory history, Channel channel, String tablePrefix, Table originalTable, Table table, | ||
String defaultCatalog, String defaultSchema, String ddl) { | ||
ddl = super.replaceTemplateVariables(dml, trigger, history, channel, tablePrefix, originalTable, table, defaultCatalog, defaultSchema, ddl); | ||
ddl = FormatUtils.replace("anyColumnChanged", | ||
buildColumnsAreNotEqualString(table, newTriggerValue, oldTriggerValue), ddl); | ||
return ddl; | ||
} | ||
|
||
private String buildColumnsAreNotEqualString(Table table, String table1Name, String table2Name){ | ||
StringBuilder builder = new StringBuilder(); | ||
|
||
for(Column column : table.getColumns()){ | ||
if (builder.length() > 0) { | ||
builder.append(" or "); | ||
} | ||
|
||
if(isNotComparable(column)) { | ||
// Can't compare the value. | ||
// Let's use the UPDATE() function to see if it showed up in the SET list of the update statement | ||
builder.append(String.format("UPDATE(\"%1$s\")", column.getName())); | ||
} else { | ||
builder.append(String.format("((%1$s.\"%2$s\" IS NOT NULL AND %3$s.\"%2$s\" IS NOT NULL AND %1$s.\"%2$s\"<>%3$s.\"%2$s\") or " | ||
+ "(%1$s.\"%2$s\" IS NULL AND %3$s.\"%2$s\" IS NOT NULL) or " | ||
+ "(%1$s.\"%2$s\" IS NOT NULL AND %3$s.\"%2$s\" IS NULL))", table1Name, column.getName(), table2Name)); | ||
} | ||
} | ||
if (builder.length() == 0) { | ||
builder.append("1=1"); | ||
} | ||
return builder.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters