Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sym_node_security column changed to "node_password", but old clients …
…need "password"
- Loading branch information
Showing
4 changed files
with
178 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
126 changes: 126 additions & 0 deletions
126
symmetric/src/main/java/org/jumpmind/symmetric/extract/csv/CsvExtractor13.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,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; | ||
} | ||
|
||
} |
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