Skip to content

Commit

Permalink
Foreign Key auto-resolver now works correctly with uncommon types mor…
Browse files Browse the repository at this point in the history
…e than a single layer deep

API was updated: IDdlReader now requires a BinaryEncoding for getImportedForeignTableRows
  • Loading branch information
JJStarrett committed Jul 9, 2019
1 parent 1fe5b42 commit d260a69
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -1,2 +1,5 @@
/.DS_Store
/.project
*.iml

/.idea/*
Expand Up @@ -2341,7 +2341,7 @@ public void reloadMissingForeignKeyRowsReverse(String sourceNodeId, Table table,
log.info("Could not find table " + table.getFullyQualifiedTableName());
}
tableRows.add(new TableRow(localTable, row, null, null, null));
List<TableRow> foreignTableRows = platform.getDdlReader().getImportedForeignTableRows(tableRows, new HashSet<TableRow>());
List<TableRow> foreignTableRows = platform.getDdlReader().getImportedForeignTableRows(tableRows, new HashSet<TableRow>(), symmetricDialect.getBinaryEncoding());

if (foreignTableRows.isEmpty()) {
log.info("Could not determine foreign table rows to fix foreign key violation for "
Expand Down Expand Up @@ -2412,7 +2412,7 @@ public void reloadMissingForeignKeyRows(String nodeId, long dataId) {
Row row = new Row(dataMap.size());
row.putAll(dataMap);
tableRows.add(new TableRow(table, row, null, null, null));
List<TableRow> foreignTableRows = platform.getDdlReader().getImportedForeignTableRows(tableRows, new HashSet<TableRow>());
List<TableRow> foreignTableRows = platform.getDdlReader().getImportedForeignTableRows(tableRows, new HashSet<TableRow>(), symmetricDialect.getBinaryEncoding());

if (foreignTableRows.isEmpty()) {
log.info("Could not determine foreign table rows to fix foreign key violation for "
Expand Down
Expand Up @@ -30,6 +30,7 @@
import org.jumpmind.db.model.Table;
import org.jumpmind.db.model.Trigger;
import org.jumpmind.db.sql.ISqlTransaction;
import org.jumpmind.db.util.BinaryEncoding;
import org.jumpmind.db.util.TableRow;

public interface IDdlReader {
Expand All @@ -56,6 +57,6 @@ public interface IDdlReader {

public List<TableRow> getExportedForeignTableRows(ISqlTransaction transaction, List<TableRow> tableRows, Set<TableRow> visited);

public List<TableRow> getImportedForeignTableRows(List<TableRow> tableRows, Set<TableRow> visited);
public List<TableRow> getImportedForeignTableRows(List<TableRow> tableRows, Set<TableRow> visited, BinaryEncoding encoding);

}
Expand Up @@ -12,6 +12,7 @@
import org.jumpmind.db.platform.IDatabasePlatform;
import org.jumpmind.db.platform.IDdlReader;
import org.jumpmind.db.sql.ISqlTransaction;
import org.jumpmind.db.util.BinaryEncoding;
import org.jumpmind.db.util.TableRow;

public class CassandraDdlReader implements IDdlReader {
Expand Down Expand Up @@ -79,7 +80,7 @@ public List<TableRow> getExportedForeignTableRows(ISqlTransaction transaction, L
}

@Override
public List<TableRow> getImportedForeignTableRows(List<TableRow> tableRows, Set<TableRow> visited) {
public List<TableRow> getImportedForeignTableRows(List<TableRow> tableRows, Set<TableRow> visited, BinaryEncoding encoding) {
return null;
}

Expand Down
Expand Up @@ -11,6 +11,7 @@
import org.jumpmind.db.platform.IDatabasePlatform;
import org.jumpmind.db.platform.IDdlReader;
import org.jumpmind.db.sql.ISqlTransaction;
import org.jumpmind.db.util.BinaryEncoding;
import org.jumpmind.db.util.TableRow;

public class KafkaDdlReader implements IDdlReader {
Expand Down Expand Up @@ -76,7 +77,7 @@ public List<TableRow> getExportedForeignTableRows(ISqlTransaction transaction, L
}

@Override
public List<TableRow> getImportedForeignTableRows(List<TableRow> tableRows, Set<TableRow> visited) {
public List<TableRow> getImportedForeignTableRows(List<TableRow> tableRows, Set<TableRow> visited, BinaryEncoding encoding) {
return null;
}

Expand Down
Expand Up @@ -48,6 +48,7 @@
import org.jumpmind.db.sql.SqlConstants;
import org.jumpmind.db.sql.SqlException;
import org.jumpmind.db.sql.mapper.RowMapper;
import org.jumpmind.db.util.BinaryEncoding;
import org.jumpmind.db.util.TableRow;

public class SqliteDdlReader implements IDdlReader {
Expand Down Expand Up @@ -289,7 +290,7 @@ public List<TableRow> getExportedForeignTableRows(ISqlTransaction transaction, L
}

@Override
public List<TableRow> getImportedForeignTableRows(List<TableRow> tableRows, Set<TableRow> visited) {
public List<TableRow> getImportedForeignTableRows(List<TableRow> tableRows, Set<TableRow> visited, BinaryEncoding encoding) {
return null;
}

Expand Down
Expand Up @@ -1724,7 +1724,7 @@ public List<TableRow> getExportedForeignTableRows(ISqlTransaction transaction, L
}

@Override
public List<TableRow> getImportedForeignTableRows(List<TableRow> tableRows, Set<TableRow> visited) {
public List<TableRow> getImportedForeignTableRows(List<TableRow> tableRows, Set<TableRow> visited, BinaryEncoding encoding) {
List<TableRow> fkDepList = new ArrayList<TableRow>();
for (TableRow tableRow : tableRows) {
if (!visited.contains(tableRow)) {
Expand Down Expand Up @@ -1759,7 +1759,9 @@ public List<TableRow> getImportedForeignTableRows(List<TableRow> tableRows, Set<
Row foreignRow = new Row(foreignTable.getColumnCount());
if (foreignTable.getForeignKeyCount() > 0) {
DmlStatement selectSt = platform.createDmlStatement(DmlType.SELECT, foreignTable, null);
Object[] keys = whereRow.toArray(foreignTable.getPrimaryKeyColumnNames());
String[] keysAsStrings = whereRow.toStringArray(foreignTable.getPrimaryKeyColumnNames());

Object[] keys = platform.getObjectValues(encoding, keysAsStrings, foreignTable.getColumns());
Map<String, Object> values = platform.getSqlTemplateDirty().queryForMap(selectSt.getSql(), keys);
if (values == null) {
log.warn(
Expand All @@ -1780,7 +1782,7 @@ public List<TableRow> getImportedForeignTableRows(List<TableRow> tableRows, Set<
log.debug("Foreign table '{}' not found for foreign key '{}'", fk.getForeignTableName(), fk.getName());
}
if (fkDepList.size() > 0) {
fkDepList.addAll(getImportedForeignTableRows(fkDepList, visited));
fkDepList.addAll(getImportedForeignTableRows(fkDepList, visited, encoding));
}
}
}
Expand Down

0 comments on commit d260a69

Please sign in to comment.