Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch '3.8' of https://github.com/JumpMind/symmetric-ds.git in…
…to 3.8
  • Loading branch information
jumpmind-josh committed Sep 8, 2017
2 parents 50558bb + e0a3589 commit 1778404
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 26 deletions.
Expand Up @@ -25,6 +25,7 @@

import java.lang.reflect.Field;
import java.sql.Types;
import java.util.Locale;
import java.util.Map;

import org.apache.commons.lang.NotImplementedException;
Expand Down Expand Up @@ -374,15 +375,15 @@ public String createTriggerDDL(DataEventType dml, Trigger trigger, TriggerHistor
Table table = originalTable.copyAndFilterColumns(history.getParsedColumnNames(),
history.getParsedPkColumnNames(), true);

String ddl = sqlTemplates.get(dml.name().toLowerCase() + "TriggerTemplate");
String ddl = sqlTemplates.get(dml.name().toLowerCase(Locale.US) + "TriggerTemplate");
if (trigger.isStreamRow()) {
String reloadDdl = sqlTemplates.get(dml.name().toLowerCase() + "ReloadTriggerTemplate");
String reloadDdl = sqlTemplates.get(dml.name().toLowerCase(Locale.US) + "ReloadTriggerTemplate");
if (reloadDdl != null && reloadDdl.length() > 0) {
ddl = reloadDdl;
}
}
if (dml.getDmlType().equals(DmlType.UPDATE) && trigger.isUseHandleKeyUpdates()) {
String temp = sqlTemplates.get(dml.name().toLowerCase() + "HandleKeyUpdates" + "TriggerTemplate");
String temp = sqlTemplates.get(dml.name().toLowerCase(Locale.US) + "HandleKeyUpdates" + "TriggerTemplate");
if (StringUtils.trimToNull(temp)!=null) {
ddl=temp;
}
Expand All @@ -402,7 +403,7 @@ public String createPostTriggerDDL(DataEventType dml, Trigger trigger, TriggerHi
Table table = originalTable.copyAndFilterColumns(history.getParsedColumnNames(),
history.getParsedPkColumnNames(), true);

String ddl = sqlTemplates.get(dml.name().toLowerCase() + "PostTriggerTemplate");
String ddl = sqlTemplates.get(dml.name().toLowerCase(Locale.US) + "PostTriggerTemplate");
return replaceTemplateVariables(dml, trigger, history, channel, tablePrefix, originalTable, table,
defaultCatalog, defaultSchema, ddl);
}
Expand Down
Expand Up @@ -167,6 +167,8 @@ public class DataLoaderService extends AbstractService implements IDataLoaderSer

private Date lastUpdateTime;

private CustomizableThreadFactory threadFactory = new CustomizableThreadFactory("dataloader");

public DataLoaderService(ISymmetricEngine engine) {
super(engine.getParameterService(), engine.getSymmetricDialect());
this.incomingBatchService = engine.getIncomingBatchService();
Expand Down Expand Up @@ -548,7 +550,8 @@ protected List<IncomingBatch> loadDataFromTransport(final ProcessInfo processInf
String targetNodeId = nodeService.findIdentityNodeId();
if (parameterService.is(ParameterConstants.STREAM_TO_FILE_ENABLED)) {
processInfo.setStatus(ProcessInfo.Status.TRANSFERRING);
ExecutorService executor = Executors.newFixedThreadPool(1, new CustomizableThreadFactory(String.format("dataloader-%s-%s", sourceNode.getNodeGroupId(), sourceNode.getNodeId())));
//ExecutorService executor = Executors.newFixedThreadPool(1, new UniqueThreadFactory("dataloader"));
ExecutorService executor = Executors.newFixedThreadPool(1, threadFactory);
LoadIntoDatabaseOnArrivalListener loadListener = new LoadIntoDatabaseOnArrivalListener(processInfo,
sourceNode.getNodeId(), listener, executor);
new SimpleStagingDataWriter(transport.openReader(), stagingManager, Constants.STAGING_CATEGORY_INCOMING,
Expand All @@ -566,8 +569,13 @@ protected List<IncomingBatch> loadDataFromTransport(final ProcessInfo processInf
outWriter.flush();
}
} else {
executor.awaitTermination(12, TimeUnit.HOURS);
long hours = 1;
while (!executor.awaitTermination(1, TimeUnit.HOURS)) {
log.info(String.format("Executor has been awaiting loader termination for %d hour(s).", hours));
hours++;
}
}

loadListener.isDone();
} else {
DataProcessor processor = new DataProcessor(new ProtocolDataReader(BatchType.LOAD,
Expand Down
Expand Up @@ -359,8 +359,8 @@ public Node findIdentity(boolean useCache, boolean logSqlError) {
cachedNodeIdentity = (Node) getFirstEntry(list);
} catch (SqlException ex) {
if (logSqlError) {
log.info("Failed to load the node identity because: {}. Returning {}",
ex.getMessage(), cachedNodeIdentity);
log.info("Failed to load the node identity because: {} {}. Returning {}",
ex.getClass().getName(), ex.getMessage(), cachedNodeIdentity);
}
}
}
Expand Down
Expand Up @@ -419,9 +419,9 @@ protected Object getObjectValue(String value, Column column, BinaryEncoding enco
objectValue = parseBigDecimal(value);
} else if (type == Types.BOOLEAN) {
objectValue = value.equals("1") ? Boolean.TRUE : Boolean.FALSE;
} else if (!(column.getJdbcTypeName() != null && column.getJdbcTypeName().toUpperCase()
} else if (!(column.getJdbcTypeName() != null && FormatUtils.upper(column.getJdbcTypeName())
.contains(TypeMap.GEOMETRY))
&& !(column.getJdbcTypeName() != null && column.getJdbcTypeName().toUpperCase()
&& !(column.getJdbcTypeName() != null && FormatUtils.upper(column.getJdbcTypeName())
.contains(TypeMap.GEOGRAPHY))
&& (type == Types.BLOB || type == Types.LONGVARBINARY || type == Types.BINARY
|| type == Types.VARBINARY ||
Expand Down Expand Up @@ -753,7 +753,7 @@ public void prefixDatabase(String prefix, Database targetTables) {
boolean storesUpperCaseIdentifiers = isStoresUpperCaseIdentifiers();
for (Table table : tables) {
String name = String.format("%s%s", prefix, table.getName());
table.setName(storesUpperCaseIdentifiers ? name.toUpperCase() : name.toLowerCase());
table.setName(storesUpperCaseIdentifiers ? FormatUtils.upper(name) : FormatUtils.lower(name));
prefixForeignKeys(table, prefix, storesUpperCaseIdentifiers);
prefixIndexes(table, prefix, storesUpperCaseIdentifiers);
prefixColumnNames(table, storesUpperCaseIdentifiers);
Expand All @@ -767,8 +767,8 @@ public void prefixDatabase(String prefix, Database targetTables) {
protected void prefixColumnNames(Table table, boolean storesUpperCaseIdentifiers) {
Column[] columns = table.getColumns();
for (Column column : columns) {
column.setName(storesUpperCaseIdentifiers ? column.getName().toUpperCase() : column
.getName().toLowerCase());
column.setName(storesUpperCaseIdentifiers ? FormatUtils.upper(column.getName()) :
FormatUtils.lower(column.getName()));
}
}

Expand All @@ -777,22 +777,20 @@ protected void prefixForeignKeys(Table table, String tablePrefix,
ForeignKey[] keys = table.getForeignKeys();
for (ForeignKey key : keys) {
String prefixedName = tablePrefix + key.getForeignTableName();
prefixedName = storesUpperCaseIdentifiers ? prefixedName.toUpperCase() : prefixedName
.toLowerCase();
prefixedName = storesUpperCaseIdentifiers ? FormatUtils.upper(prefixedName) :
FormatUtils.lower(prefixedName);
key.setForeignTableName(prefixedName);

String keyName = tablePrefix + key.getName();
keyName = storesUpperCaseIdentifiers ? keyName.toUpperCase() : keyName.toLowerCase();
keyName = storesUpperCaseIdentifiers ? FormatUtils.upper(keyName) : FormatUtils.lower(keyName);
key.setName(keyName);

Reference[] refs = key.getReferences();
for (Reference reference : refs) {
reference.setForeignColumnName(storesUpperCaseIdentifiers ? reference
.getForeignColumnName().toUpperCase() : reference.getForeignColumnName()
.toLowerCase());
reference.setLocalColumnName(storesUpperCaseIdentifiers ? reference
.getLocalColumnName().toUpperCase() : reference.getLocalColumnName()
.toLowerCase());
reference.setForeignColumnName(storesUpperCaseIdentifiers ? FormatUtils.upper(reference
.getForeignColumnName()) : FormatUtils.lower(reference.getForeignColumnName()));
reference.setLocalColumnName(storesUpperCaseIdentifiers ? FormatUtils.upper(reference
.getLocalColumnName()) : FormatUtils.lower(reference.getLocalColumnName()));
}
}
}
Expand All @@ -803,8 +801,8 @@ protected void prefixIndexes(Table table, String tablePrefix, boolean storesUppe
if (indexes != null) {
for (IIndex index : indexes) {
String prefixedName = tablePrefix + index.getName();
prefixedName = storesUpperCaseIdentifiers ? prefixedName.toUpperCase()
: prefixedName.toLowerCase();
prefixedName = storesUpperCaseIdentifiers ? FormatUtils.upper(prefixedName)
: FormatUtils.lower(prefixedName);
index.setName(prefixedName);
}
}
Expand All @@ -830,7 +828,7 @@ public String alterCaseToMatchDatabaseDefaultCase(String value) {
if (StringUtils.isNotBlank(value)) {
boolean storesUpperCase = isStoresUpperCaseIdentifiers();
if (!FormatUtils.isMixedCase(value)) {
value = storesUpperCase ? value.toUpperCase() : value.toLowerCase();
value = storesUpperCase ? FormatUtils.upper(value) : FormatUtils.lower(value);
}
}
return value;
Expand Down
29 changes: 29 additions & 0 deletions symmetric-util/src/main/java/org/jumpmind/util/FormatUtils.java
Expand Up @@ -27,6 +27,7 @@
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TimeZone;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -57,6 +58,12 @@ public final class FormatUtils {
public final static int MAX_CHARS_TO_LOG = 1000;

private static Pattern pattern = Pattern.compile("\\$\\((.+?)\\)");

private static boolean isInfamousTurkey = false;

static {
isInfamousTurkey = Locale.getDefault().getCountry().equalsIgnoreCase("tr");
}

private FormatUtils() {
}
Expand Down Expand Up @@ -313,4 +320,26 @@ public static String replaceCharsToShortenName(String name) {
return name.replaceAll("[^a-zA-Z0-9_]|[a|e|i|o|u|A|E|I|O|U]", "");
}

public static String lower(String str) {
if (isInfamousTurkey) {
return str.toLowerCase(Locale.US);
}
return str.toLowerCase();
}

public static String upper(String str) {
if (isInfamousTurkey) {
return str.toUpperCase(Locale.US);
}
return str.toUpperCase();
}

public static boolean isInfamousTurkey() {
return isInfamousTurkey;
}

public static String stripTurkeyDottedI(String str) {
return str.replace("\u0130", "I").replace("\u0131", "i");
}

}
Expand Up @@ -46,7 +46,6 @@ public class LinkedCaseInsensitiveMap<V> extends LinkedHashMap<String, V> {

private final Locale locale;


public LinkedCaseInsensitiveMap(Map<String, ? extends V> values) {
this();
putAll(values);
Expand Down Expand Up @@ -101,6 +100,9 @@ public LinkedCaseInsensitiveMap(int initialCapacity, Locale locale) {
@Override
public V put(String key, V value) {
this.caseInsensitiveKeys.put(convertKey(key), key);
if (FormatUtils.isInfamousTurkey()) {
this.caseInsensitiveKeys.put(FormatUtils.stripTurkeyDottedI(convertKey(key)), key);
}
return super.put(key, value);
}

Expand Down

0 comments on commit 1778404

Please sign in to comment.