]> source.dussan.org Git - jackcess.git/commitdiff
some fixups to get rel insert functional
authorJames Ahlborn <jtahlborn@yahoo.com>
Fri, 19 Aug 2016 01:25:44 +0000 (01:25 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Fri, 19 Aug 2016 01:25:44 +0000 (01:25 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/mutateops@1007 f203690c-595d-4dc9-a70b-905162fa7fd2

src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java
src/main/java/com/healthmarketscience/jackcess/impl/RelationshipCreator.java
src/main/java/com/healthmarketscience/jackcess/impl/RelationshipImpl.java

index 079f074a2f664b4eeb5e5a1dfdb5381c755b632d..af79e1fbb12834fffb99e78b2c4aa8f3ec1721b4 100644 (file)
@@ -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);
 
index 452c176694cafd7a59106a03e8638f12fb8abc80..be403101e6f9eff3a270e812bd700b455dd25898 100644 (file)
@@ -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()) + ")";
   }
 }
index 456399264ef6c15f8f5266bf33df73952bcd2a6a..0cc2b906eb83d44cfa00c228f759dbfa13b40b48 100644 (file)
@@ -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<? 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;
   }