Skip to content

Commit

Permalink
fixes to data loader. reset sql transaction on rollback.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed May 27, 2012
1 parent 61d5304 commit 51b7fd1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 23 deletions.
Expand Up @@ -719,8 +719,10 @@ public Column[] getPrimaryKeyColumns() {
if (columns != null) {
List<Column> selectedColumns = new ArrayList<Column>();
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()]);
Expand Down Expand Up @@ -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);
}
}
}

Expand All @@ -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;
}
Expand All @@ -985,17 +989,31 @@ public static Column[] orderColumns(String[] columnNames, Table table) {
return orderedColumns;
}

@SuppressWarnings("unchecked")
public Table copy() {
try {
Table result = (Table) super.clone();
result.catalog = catalog;
result.schema = schema;
result.name = name;
result.type = type;
result.columns = (ArrayList<Column>) columns.clone();
result.foreignKeys = (ArrayList<ForeignKey>) foreignKeys.clone();
result.indices = (ArrayList<IIndex>) indices.clone();
result.columns = new ArrayList<Column>(columns.size());
for (Column col : columns) {
if (col != null) {
result.columns.add((Column) col.clone());
}
}
result.foreignKeys = new ArrayList<ForeignKey>(foreignKeys.size());
for (ForeignKey fk : foreignKeys) {
if (fk != null) {
result.foreignKeys.add((ForeignKey) fk.clone());
}
}
result.indices = new ArrayList<IIndex>(indices.size());
for (IIndex i : indices) {
if (i != null) {
result.indices.add((IIndex) i.clone());
}
}
return result;
} catch (CloneNotSupportedException ex) {
throw new RuntimeException(ex);
Expand All @@ -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);
}
}
}
}
Expand Down
Expand Up @@ -394,7 +394,7 @@ protected LoadStatus delete(CsvData data, boolean useConflictDetection) {
break;
}
}

if (lookupKeys == null || lookupKeys.length == 0) {
lookupKeys = targetTable.getColumns();
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down

0 comments on commit 51b7fd1

Please sign in to comment.