Skip to content

Commit

Permalink
sym_node_security column changed to "node_password", but old clients …
Browse files Browse the repository at this point in the history
…need "password"
  • Loading branch information
erilong committed Apr 2, 2008
1 parent b2f1c19 commit f5a5b25
Show file tree
Hide file tree
Showing 4 changed files with 178 additions and 2 deletions.
Expand Up @@ -38,7 +38,9 @@ public class CsvExtractor10 implements IDataExtractor {
private Map<String, IStreamDataCommand> dictionary = null;

private IRuntimeConfig runtimeConfiguration;


private String tablePrefix;

public void init(BufferedWriter writer, DataExtractorContext context)
throws IOException {
Util.write(writer, CsvConstants.NODEID, AbstractStreamDataCommand.DELIMITER, runtimeConfiguration.getExternalId());
Expand Down Expand Up @@ -79,7 +81,13 @@ public void preprocessTable(Data data, BufferedWriter out,
out.newLine();
Util.write(out, "keys, ", data.getAudit().getPkColumnNames());
out.newLine();
Util.write(out, "columns, ", data.getAudit().getColumnNames());
String columns = data.getAudit().getColumnNames();
if (data.getTableName().equalsIgnoreCase(tablePrefix + "_node_security")) {
// In 1.4 the column named changed to "node_password", but old clients need "password"
columns = columns.replaceFirst(",node_password,", ",password,");
columns = columns.replaceFirst(",NODE_PASSWORD,", ",PASSWORD,");
}
Util.write(out, "columns, ", columns);
out.newLine();
context.getAuditRecordsWritten().add(auditKey);
} else if (!context.isLastTable(data.getTableName())) {
Expand All @@ -98,4 +106,8 @@ public void setDictionary(Map<String, IStreamDataCommand> dictionary) {
this.dictionary = dictionary;
}

public void setTablePrefix(String tablePrefix) {
this.tablePrefix = tablePrefix;
}

}
@@ -0,0 +1,126 @@
/*
* SymmetricDS is an open source database synchronization solution.
*
* Copyright (C) Chris Henson <chenson42@users.sourceforge.net>
* Copyright (C) Andrew Wilcox <andrewbwilcox@users.sourceforge.net>
* Copyright (C) Eric Long <erilong@users.sourceforge.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*/

package org.jumpmind.symmetric.extract.csv;

import java.io.BufferedWriter;
import java.io.IOException;
import java.util.Map;

import org.jumpmind.symmetric.common.csv.CsvConstants;
import org.jumpmind.symmetric.config.IRuntimeConfig;
import org.jumpmind.symmetric.db.IDbDialect;
import org.jumpmind.symmetric.extract.DataExtractorContext;
import org.jumpmind.symmetric.extract.IDataExtractor;
import org.jumpmind.symmetric.model.Data;
import org.jumpmind.symmetric.model.OutgoingBatch;

public class CsvExtractor13 implements IDataExtractor {

private Map<String, IStreamDataCommand> dictionary = null;

private IRuntimeConfig runtimeConfiguration;

private IDbDialect dbDialect;

private String tablePrefix;

public void init(BufferedWriter writer, DataExtractorContext context)
throws IOException {
Util.write(writer, CsvConstants.NODEID, AbstractStreamDataCommand.DELIMITER, runtimeConfiguration.getExternalId());
writer.newLine();
}

public void begin(OutgoingBatch batch, BufferedWriter writer)
throws IOException {
Util.write(writer, CsvConstants.BATCH, AbstractStreamDataCommand.DELIMITER, batch.getBatchId());
writer.newLine();
Util.write(writer, CsvConstants.BINARY, AbstractStreamDataCommand.DELIMITER, dbDialect.getBinaryEncoding().name());
writer.newLine();
}

public void commit(OutgoingBatch batch, BufferedWriter writer)
throws IOException {
Util.write(writer, CsvConstants.COMMIT, AbstractStreamDataCommand.DELIMITER, batch.getBatchId());
writer.newLine();
}

public void write(BufferedWriter writer, Data data,
DataExtractorContext context) throws IOException {
preprocessTable(data, writer, context);
dictionary.get(data.getEventType().getCode()).execute(writer, data, context);
}

/**
* Writes the table metadata out to a stream only if it hasn't already been
* written out before
*
* @param tableName
* @param out
*/
public void preprocessTable(Data data, BufferedWriter out,
DataExtractorContext context) throws IOException {

if (data.getAudit() == null) {
throw new RuntimeException("Missing trigger_hist for table " + data.getTableName() +
": try running syncTriggers() or restarting SymmetricDS");
}
String auditKey = Integer.toString(data.getAudit().getTriggerHistoryId()).intern();
if (!context.getAuditRecordsWritten().contains(auditKey)) {
Util.write(out, "table, ", data.getTableName());
out.newLine();
Util.write(out, "keys, ", data.getAudit().getPkColumnNames());
out.newLine();
String columns = data.getAudit().getColumnNames();
if (data.getTableName().equalsIgnoreCase(tablePrefix + "_node_security")) {
// In 1.4 the column named changed to "node_password", but old clients need "password"
columns = columns.replaceFirst(",node_password,", ",password,");
columns = columns.replaceFirst(",NODE_PASSWORD,", ",PASSWORD,");
}
Util.write(out, "columns, ", columns);
out.newLine();
context.getAuditRecordsWritten().add(auditKey);
} else if (!context.isLastTable(data.getTableName())) {
Util.write(out, "table, ", data.getTableName());
out.newLine();
}

context.setLastTableName(data.getTableName());
}

public void setRuntimeConfiguration(IRuntimeConfig runtimeConfiguration) {
this.runtimeConfiguration = runtimeConfiguration;
}

public void setDictionary(Map<String, IStreamDataCommand> dictionary) {
this.dictionary = dictionary;
}

public void setDbDialect(IDbDialect dbDialect) {
this.dbDialect = dbDialect;
}

public void setTablePrefix(String tablePrefix) {
this.tablePrefix = tablePrefix;
}

}
Expand Up @@ -103,6 +103,8 @@ private IDataExtractor getDataExtractor(String version) {
// TODO: this should be versions[1] == 0 for 1.2 release
if (versions[0] == 1 && versions[1] <= 1) {
beanName += "10";
} else if (versions[0] == 1 && versions[1] <= 3) {
beanName += "13";
}
}
return (IDataExtractor) beanFactory.getBean(beanName);
Expand Down
36 changes: 36 additions & 0 deletions symmetric/src/main/resources/symmetric-services.xml
Expand Up @@ -634,8 +634,44 @@
</property>
</bean>

<bean id="dataExtractor" class="org.jumpmind.symmetric.extract.csv.CsvExtractor13">
<property name="dbDialect" ref="dbDialect" />
<property name="runtimeConfiguration" ref="runtimeConfiguration" />
<property name="tablePrefix" value="${sync.table.prefix}" />
<property name="dictionary">
<map>
<entry key="I">
<bean class="org.jumpmind.symmetric.extract.csv.StreamInsertDataCommand"></bean>
</entry>
<entry key="U">
<bean class="org.jumpmind.symmetric.extract.csv.StreamUpdateDataCommand"></bean>
</entry>
<entry key="D">
<bean class="org.jumpmind.symmetric.extract.csv.StreamDeleteDataCommand"></bean>
</entry>
<entry key="V">
<bean class="org.jumpmind.symmetric.extract.csv.StreamValidateDataCommand"></bean>
</entry>
<entry key="R">
<bean class="org.jumpmind.symmetric.extract.csv.StreamReloadDataCommand">
<property name="dataExtractorService" ref="dataExtractorService" />
<property name="configurationService" ref="configurationService" />
<property name="nodeService" ref="nodeService" />
</bean>
</entry>
<entry key="S">
<bean class="org.jumpmind.symmetric.extract.csv.StreamSQLDataCommand"></bean>
</entry>
<entry key="C">
<bean class="org.jumpmind.symmetric.extract.csv.StreamCreateDataCommand"></bean>
</entry>
</map>
</property>
</bean>

<bean id="dataExtractor10" class="org.jumpmind.symmetric.extract.csv.CsvExtractor10">
<property name="runtimeConfiguration" ref="runtimeConfiguration" />
<property name="tablePrefix" value="${sync.table.prefix}" />
<property name="dictionary">
<map>
<entry key="I">
Expand Down

0 comments on commit f5a5b25

Please sign in to comment.