use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.
the class ProtocolDataReader method nextData.
public CsvData nextData() {
if (next instanceof CsvData) {
CsvData data = (CsvData) next;
next = null;
return data;
} else {
do {
next = readNext();
if (next instanceof CsvData) {
CsvData data = (CsvData) next;
next = null;
return data;
}
} while (next != null && !(next instanceof Batch) && !(next instanceof Table));
}
return null;
}
use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.
the class DefaultTransformWriterConflictResolver method performFallbackToInsert.
@Override
protected void performFallbackToInsert(AbstractDatabaseWriter writer, CsvData data, Conflict conflict, boolean retransform) {
TransformedData transformedData = data.getAttribute(TransformedData.class.getName());
if (transformedData != null && retransform) {
List<TransformedData> newlyTransformedDatas = transformWriter.transform(DataEventType.INSERT, writer.getContext(), transformedData.getTransformation(), transformedData.getSourceKeyValues(), transformedData.getOldSourceValues(), transformedData.getSourceValues());
if (newlyTransformedDatas.size() > 0) {
boolean matchedTransform = false;
for (TransformedData newlyTransformedData : newlyTransformedDatas) {
/*
* If there is only one transform, then process it.
* Otherwise, we need to attempt to match the key values to
* choose the correct transform.
*/
if (newlyTransformedDatas.size() == 1 || newlyTransformedData.hasSameKeyValues(transformedData.getKeyValues()) || newlyTransformedData.isGeneratedIdentityNeeded()) {
matchedTransform = true;
Table table = newlyTransformedData.buildTargetTable();
CsvData newData = newlyTransformedData.buildTargetCsvData();
if (newlyTransformedData.isGeneratedIdentityNeeded()) {
if (log.isDebugEnabled()) {
log.debug("Enabling generation of identity for {}", newlyTransformedData.getTableName());
}
writer.allowInsertIntoAutoIncrementColumns(false, table);
} else if (table.hasAutoIncrementColumn()) {
writer.allowInsertIntoAutoIncrementColumns(true, table);
}
writer.start(table);
super.performFallbackToInsert(writer, newData, conflict, retransform);
writer.end(table);
}
}
if (!matchedTransform) {
log.warn("The attempt to retransform resulted in more than one transform. We tried to choose one " + "by matching on the ordered key values, but could not find a match. Please check that the " + "transformation is configured so that it will return keys in the same order regardless of DML type. " + "The original key values that we tried to match on were: {}" + ArrayUtils.toString(transformedData.getKeyValues()));
}
}
} else {
super.performFallbackToInsert(writer, data, conflict, retransform);
}
}
use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.
the class DatabaseWriterTest method testLargeDouble.
@Test
public void testLargeDouble() throws Exception {
String[] values = new String[TEST_COLUMNS.length];
values[0] = getNextId();
values[10] = "-0.0747663551401869";
String[] expectedValues = (String[]) ArrayUtils.clone(values);
massageExpectectedResultsForDialect(expectedValues);
if (platform.getDatabaseInfo().isRequiredCharColumnEmptyStringSameAsNull()) {
expectedValues[4] = AbstractDatabasePlatform.REQUIRED_FIELD_NULL_SUBSTITUTE;
}
writeData(new CsvData(DataEventType.INSERT, values), expectedValues);
}
use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.
the class DatabaseWriterTest method testStringBackslash.
@Test
public void testStringBackslash() throws Exception {
String[] values = new String[TEST_COLUMNS.length];
values[0] = getNextId();
values[1] = "Here's a \\, a (backslash)";
values[2] = "Fix TODO";
// TODO: Fix backslashing alphanumeric
// values[2] = "\\a\\b\\c\\ \\1\\2\\3";
values[3] = "Tick quote \\'\\\"";
values[4] = "Comma quote \\,\\\"";
writeData(new CsvData(DataEventType.INSERT, values), values);
}
use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.
the class DatabaseWriterTest method testUpdateDetectVersionNewWins.
@Test
public void testUpdateDetectVersionNewWins() {
Conflict setting = new Conflict();
setting.setConflictId("unit.test");
setting.setDetectType(DetectConflict.USE_VERSION);
setting.setDetectExpression("integer_value");
setting.setResolveRowOnly(true);
setting.setResolveChangesOnly(false);
setting.setResolveType(ResolveConflict.NEWER_WINS);
writerSettings.setDefaultConflictSetting(setting);
String id = getNextId();
String[] originalValues = massageExpectectedResultsForDialect(new String[] { id, "string2", "string not null2", "char2", "char not null2", "2007-01-02 03:20:10.000", "2012-03-12 07:00:00.000", "0", "47", "67.89", "-0.0747663" });
CsvData data = new CsvData(DataEventType.INSERT, originalValues);
writeData(data, originalValues);
String[] updateShouldNotBeApplied = CollectionUtils.copyOfRange(originalValues, 0, originalValues.length);
updateShouldNotBeApplied[2] = "updated string";
updateShouldNotBeApplied[8] = "46";
data = new CsvData(DataEventType.UPDATE, massageExpectectedResultsForDialect(updateShouldNotBeApplied));
writeData(data, originalValues);
String[] updateShouldBeApplied = CollectionUtils.copyOfRange(originalValues, 0, originalValues.length);
updateShouldBeApplied[2] = "string3";
updateShouldBeApplied[8] = "48";
data = new CsvData(DataEventType.UPDATE, massageExpectectedResultsForDialect(updateShouldBeApplied));
writeData(data, updateShouldBeApplied);
}
Aggregations