diff options
author | James Ahlborn <jtahlborn@yahoo.com> | 2016-08-19 01:25:44 +0000 |
---|---|---|
committer | James Ahlborn <jtahlborn@yahoo.com> | 2016-08-19 01:25:44 +0000 |
commit | c0f012de1fe746d495a32da5fd1fd862eaf886c7 (patch) | |
tree | c48744d624e2d21d4f351c15d76ab55de11c7e2f /src/main/java | |
parent | 75b8acd8a2f33964b0fa800909484da1dd9c6cb4 (diff) | |
download | jackcess-c0f012de1fe746d495a32da5fd1fd862eaf886c7.tar.gz jackcess-c0f012de1fe746d495a32da5fd1fd862eaf886c7.zip |
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
Diffstat (limited to 'src/main/java')
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<Object[]> rows = new ArrayList<Object[]>(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<ColumnImpl> _primaryCols; private List<ColumnImpl> _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 @@ -66,13 +66,20 @@ 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<? extends Column> fromCols, + List<? extends Column> toCols) + { _name = name; _fromTable = fromTable; - _fromColumns = new ArrayList<Column>( - Collections.nCopies(numCols, (Column)null)); + _fromColumns = new ArrayList<Column>(fromCols); _toTable = toTable; - _toColumns = new ArrayList<Column>( - Collections.nCopies(numCols, (Column)null)); + _toColumns = new ArrayList<Column>(toCols); _flags = flags; } |