Browse Source

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
tags/jackcess-2.1.5
James Ahlborn 7 years ago
parent
commit
c0f012de1f

+ 2
- 1
src/main/java/com/healthmarketscience/jackcess/impl/DatabaseImpl.java View 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);


+ 14
- 7
src/main/java/com/healthmarketscience/jackcess/impl/RelationshipCreator.java View 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()) + ")";
}
}

+ 11
- 4
src/main/java/com/healthmarketscience/jackcess/impl/RelationshipImpl.java View 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;
}


Loading…
Cancel
Save