diff --git a/symmetric/symmetric-db/src/main/java/org/jumpmind/db/model/Table.java b/symmetric/symmetric-db/src/main/java/org/jumpmind/db/model/Table.java index 78fb261d1f..0248ff4ae4 100644 --- a/symmetric/symmetric-db/src/main/java/org/jumpmind/db/model/Table.java +++ b/symmetric/symmetric-db/src/main/java/org/jumpmind/db/model/Table.java @@ -719,8 +719,10 @@ public Column[] getPrimaryKeyColumns() { if (columns != null) { List selectedColumns = new ArrayList(); for (Column column : columns) { - if (column.isPrimaryKey()) { - selectedColumns.add(column); + if (column != null) { + if (column.isPrimaryKey()) { + selectedColumns.add(column); + } } } return selectedColumns.toArray(new Column[selectedColumns.size()]); @@ -966,7 +968,9 @@ public void orderColumns(String[] columnNames) { Column[] orderedColumns = orderColumns(columnNames, this); this.columns.clear(); for (Column column : orderedColumns) { - this.columns.add(column); + if (column != null) { + this.columns.add(column); + } } } @@ -976,7 +980,7 @@ public static Column[] orderColumns(String[] columnNames, Table table) { for (int i = 0; i < columnNames.length; i++) { String name = columnNames[i]; for (Column column : unorderedColumns) { - if (column.getName().equalsIgnoreCase(name)) { + if (column != null && column.getName().equalsIgnoreCase(name)) { orderedColumns[i] = column; break; } @@ -985,7 +989,6 @@ public static Column[] orderColumns(String[] columnNames, Table table) { return orderedColumns; } - @SuppressWarnings("unchecked") public Table copy() { try { Table result = (Table) super.clone(); @@ -993,9 +996,24 @@ public Table copy() { result.schema = schema; result.name = name; result.type = type; - result.columns = (ArrayList) columns.clone(); - result.foreignKeys = (ArrayList) foreignKeys.clone(); - result.indices = (ArrayList) indices.clone(); + result.columns = new ArrayList(columns.size()); + for (Column col : columns) { + if (col != null) { + result.columns.add((Column) col.clone()); + } + } + result.foreignKeys = new ArrayList(foreignKeys.size()); + for (ForeignKey fk : foreignKeys) { + if (fk != null) { + result.foreignKeys.add((ForeignKey) fk.clone()); + } + } + result.indices = new ArrayList(indices.size()); + for (IIndex i : indices) { + if (i != null) { + result.indices.add((IIndex) i.clone()); + } + } return result; } catch (CloneNotSupportedException ex) { throw new RuntimeException(ex); @@ -1005,18 +1023,22 @@ public Table copy() { public Table copyAndFilterColumns(String[] orderedColumnNames, String[] pkColumnNames, boolean setPrimaryKeys) { Table table = copy(); - orderColumns(orderedColumnNames); + table.orderColumns(orderedColumnNames); - if (setPrimaryKeys) { - for (Column column : columns) { - column.setPrimaryKey(false); + if (setPrimaryKeys && columns != null) { + for (Column column : table.columns) { + if (column != null) { + column.setPrimaryKey(false); + } } if (pkColumnNames != null) { - for (Column column : columns) { - for (String pkColumnName : pkColumnNames) { - if (column.getName().equals(pkColumnName)) { - column.setPrimaryKey(true); + for (Column column : table.columns) { + if (column != null) { + for (String pkColumnName : pkColumnNames) { + if (column.getName().equalsIgnoreCase(pkColumnName)) { + column.setPrimaryKey(true); + } } } } diff --git a/symmetric/symmetric-io/src/main/java/org/jumpmind/symmetric/io/data/writer/DatabaseWriter.java b/symmetric/symmetric-io/src/main/java/org/jumpmind/symmetric/io/data/writer/DatabaseWriter.java index b58317d6f2..5d8078ee29 100644 --- a/symmetric/symmetric-io/src/main/java/org/jumpmind/symmetric/io/data/writer/DatabaseWriter.java +++ b/symmetric/symmetric-io/src/main/java/org/jumpmind/symmetric/io/data/writer/DatabaseWriter.java @@ -394,7 +394,7 @@ protected LoadStatus delete(CsvData data, boolean useConflictDetection) { break; } } - + if (lookupKeys == null || lookupKeys.length == 0) { lookupKeys = targetTable.getColumns(); } @@ -501,11 +501,11 @@ protected LoadStatus update(CsvData data, boolean applyChangesOnly, boolean useC break; } } - + if (lookupKeys == null || lookupKeys.length == 0) { lookupKeys = targetTable.getColumns(); } - + this.currentDmlStatement = platform .createDmlStatement(DmlType.UPDATE, targetTable.getCatalog(), targetTable.getSchema(), targetTable.getName(), lookupKeys, @@ -797,10 +797,12 @@ protected Table lookupTableAtTarget(Table sourceTable) { Column[] columns = table.getColumns(); for (Column column : columns) { - int typeCode = column.getMappedTypeCode(); - if (this.writerSettings.isTreatDateTimeFieldsAsVarchar() - && (typeCode == Types.DATE || typeCode == Types.TIME || typeCode == Types.TIMESTAMP)) { - column.setMappedTypeCode(Types.VARCHAR); + if (column != null) { + int typeCode = column.getMappedTypeCode(); + if (this.writerSettings.isTreatDateTimeFieldsAsVarchar() + && (typeCode == Types.DATE || typeCode == Types.TIME || typeCode == Types.TIMESTAMP)) { + column.setMappedTypeCode(Types.VARCHAR); + } } } }