From c0f012de1fe746d495a32da5fd1fd862eaf886c7 Mon Sep 17 00:00:00 2001 From: James Ahlborn Date: Fri, 19 Aug 2016 01:25:44 +0000 Subject: [PATCH] some fixups to get rel insert functional git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/mutateops@1007 f203690c-595d-4dc9-a70b-905162fa7fd2 --- .../jackcess/impl/DatabaseImpl.java | 3 ++- .../jackcess/impl/RelationshipCreator.java | 21 ++++++++++++------- .../jackcess/impl/RelationshipImpl.java | 15 +++++++++---- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java index 079f074..af79e1f 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java @@ -1191,7 +1191,7 @@ public class DatabaseImpl implements Database List rows = new ArrayList(numCols); for(int i = 0; i < numCols; ++i) { Object[] row = new Object[_relationships.getColumnCount()]; - ccol.setRowValue(row, ccol); + ccol.setRowValue(row, numCols); flagCol.setRowValue(row, newRel.getFlags()); icol.setRowValue(row, i); nameCol.setRowValue(row, name); @@ -1199,6 +1199,7 @@ public class DatabaseImpl implements Database fromColCol.setRowValue(row, newRel.getFromColumns().get(i).getName()); toTableCol.setRowValue(row, newRel.getToTable().getName()); toColCol.setRowValue(row, newRel.getToColumns().get(i).getName()); + rows.add(row); } _relationships.addRows(rows); diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/RelationshipCreator.java b/src/main/java/com/healthmarketscience/jackcess/impl/RelationshipCreator.java index 452c176..be40310 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/RelationshipCreator.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/RelationshipCreator.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; +import com.healthmarketscience.jackcess.Column; import com.healthmarketscience.jackcess.IndexBuilder; import com.healthmarketscience.jackcess.RelationshipBuilder; @@ -41,6 +42,7 @@ public class RelationshipCreator extends DBMutator private RelationshipBuilder _relationship; private List _primaryCols; private List _secondaryCols; + private int _flags; // - primary table must have unique index // - primary table index name ".rC", ".rD"... @@ -63,10 +65,8 @@ public class RelationshipCreator extends DBMutator public RelationshipImpl createRelationshipImpl(String name) { RelationshipImpl newRel = new RelationshipImpl( - name, _primaryTable, _secondaryTable, _relationship.getFlags(), - _primaryCols.size()); - newRel.getFromColumns().addAll(_primaryCols); - newRel.getToColumns().addAll(_secondaryCols); + name, _secondaryTable, _primaryTable, _flags, + _secondaryCols, _primaryCols); return newRel; } @@ -81,6 +81,11 @@ public class RelationshipCreator extends DBMutator validate(); + // FIXME determine the type of relationship + // FIXME what about "indeterminiate?" (not 1-1 or 1-n) + _flags = _relationship.getFlags(); + + getPageChannel().startExclusiveWrite(); try { @@ -98,7 +103,7 @@ public class RelationshipCreator extends DBMutator private void validate() throws IOException { _primaryTable = getDatabase().getTable(_relationship.getToTable()); - _secondaryTable = getDatabase().getTable(_relationship.getToTable()); + _secondaryTable = getDatabase().getTable(_relationship.getFromTable()); if((_primaryTable == null) || (_secondaryTable == null)) { throw new IllegalArgumentException(withErrorContext( @@ -238,9 +243,11 @@ public class RelationshipCreator extends DBMutator private String withErrorContext(String msg) { return msg + "(Rel=" + - getTableErrorContext(_primaryTable, _primaryCols, _relationship.getToTable(), + getTableErrorContext(_primaryTable, _primaryCols, + _relationship.getToTable(), _relationship.getToColumns()) + " <- " + - getTableErrorContext(_secondaryTable, _secondaryCols, _relationship.getFromTable(), + getTableErrorContext(_secondaryTable, _secondaryCols, + _relationship.getFromTable(), _relationship.getFromColumns()) + ")"; } } diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/RelationshipImpl.java b/src/main/java/com/healthmarketscience/jackcess/impl/RelationshipImpl.java index 4563992..0cc2b90 100644 --- a/src/main/java/com/healthmarketscience/jackcess/impl/RelationshipImpl.java +++ b/src/main/java/com/healthmarketscience/jackcess/impl/RelationshipImpl.java @@ -65,14 +65,21 @@ public class RelationshipImpl implements Relationship public RelationshipImpl(String name, Table fromTable, Table toTable, int flags, int numCols) + { + this(name, fromTable, toTable, flags, + Collections.nCopies(numCols, (Column)null), + Collections.nCopies(numCols, (Column)null)); + } + + public RelationshipImpl(String name, Table fromTable, Table toTable, int flags, + List fromCols, + List toCols) { _name = name; _fromTable = fromTable; - _fromColumns = new ArrayList( - Collections.nCopies(numCols, (Column)null)); + _fromColumns = new ArrayList(fromCols); _toTable = toTable; - _toColumns = new ArrayList( - Collections.nCopies(numCols, (Column)null)); + _toColumns = new ArrayList(toCols); _flags = flags; } -- 2.39.5