aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJames Ahlborn <jtahlborn@yahoo.com>2016-08-30 13:19:01 +0000
committerJames Ahlborn <jtahlborn@yahoo.com>2016-08-30 13:19:01 +0000
commitf808a1be9a56f7da2986842b7315a70d38942bd1 (patch)
tree32d08e808bd10582946b3f82a5c7e72d99b2ae9e /src
parentf40b4f0cfd1e36da0f913e16a889d89a2cc8e329 (diff)
downloadjackcess-f808a1be9a56f7da2986842b7315a70d38942bd1.tar.gz
jackcess-f808a1be9a56f7da2986842b7315a70d38942bd1.zip
fix directionality of relationship
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/branches/mutateops@1017 f203690c-595d-4dc9-a70b-905162fa7fd2
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/RelationshipBuilder.java32
-rw-r--r--src/main/java/com/healthmarketscience/jackcess/impl/RelationshipCreator.java23
2 files changed, 28 insertions, 27 deletions
diff --git a/src/main/java/com/healthmarketscience/jackcess/RelationshipBuilder.java b/src/main/java/com/healthmarketscience/jackcess/RelationshipBuilder.java
index 795bbd9..f826a7c 100644
--- a/src/main/java/com/healthmarketscience/jackcess/RelationshipBuilder.java
+++ b/src/main/java/com/healthmarketscience/jackcess/RelationshipBuilder.java
@@ -39,30 +39,30 @@ public class RelationshipBuilder
/** relationship flags (default to "don't enforce") */
private int _flags = RelationshipImpl.NO_REFERENTIAL_INTEGRITY_FLAG;
- private String _toTable;
private String _fromTable;
- private List<String> _toCols = new ArrayList<String>();
+ private String _toTable;
private List<String> _fromCols = new ArrayList<String>();
+ private List<String> _toCols = new ArrayList<String>();
- public RelationshipBuilder(String toTable, String fromTable)
+ public RelationshipBuilder(String fromTable, String toTable)
{
- _toTable = toTable;
_fromTable = fromTable;
+ _toTable = toTable;
}
/**
* Adds a pair of columns to the relationship.
*/
- public RelationshipBuilder addColumns(String toCol, String fromCol) {
- _toCols.add(toCol);
+ public RelationshipBuilder addColumns(String fromCol, String toCol) {
_fromCols.add(fromCol);
+ _toCols.add(toCol);
return this;
}
/**
* Enables referential integrity enforcement for this relationship.
*
- * Note, this requires the "to" table to have an existing unique index on
+ * Note, this requires the "from" table to have an existing unique index on
* the relevant columns.
*/
public RelationshipBuilder setReferentialIntegrity() {
@@ -70,7 +70,7 @@ public class RelationshipBuilder
}
/**
- * Enables deletes to be cascaded from the "to" table to the "from" table.
+ * Enables deletes to be cascaded from the "from" table to the "to" table.
*
* Note, this requires referential integrity to be enforced.
*/
@@ -79,7 +79,7 @@ public class RelationshipBuilder
}
/**
- * Enables updates to be cascaded from the "to" table to the "from" table.
+ * Enables updates to be cascaded from the "from" table to the "to" table.
*
* Note, this requires referential integrity to be enforced.
*/
@@ -88,7 +88,7 @@ public class RelationshipBuilder
}
/**
- * Enables deletes in the "to" table to be cascaded as "null" to the "from"
+ * Enables deletes in the "from" table to be cascaded as "null" to the "to"
* table.
*
* Note, this requires referential integrity to be enforced.
@@ -126,21 +126,21 @@ public class RelationshipBuilder
return _flags;
}
- public String getToTable() {
- return _toTable;
- }
-
public String getFromTable() {
return _fromTable;
}
- public List<String> getToColumns() {
- return _toCols;
+ public String getToTable() {
+ return _toTable;
}
public List<String> getFromColumns() {
return _fromCols;
}
+
+ public List<String> getToColumns() {
+ return _toCols;
+ }
/**
* Creates a new Relationship in the given Database with the currently
diff --git a/src/main/java/com/healthmarketscience/jackcess/impl/RelationshipCreator.java b/src/main/java/com/healthmarketscience/jackcess/impl/RelationshipCreator.java
index a326700..b0659af 100644
--- a/src/main/java/com/healthmarketscience/jackcess/impl/RelationshipCreator.java
+++ b/src/main/java/com/healthmarketscience/jackcess/impl/RelationshipCreator.java
@@ -70,8 +70,8 @@ public class RelationshipCreator extends DBMutator
public RelationshipImpl createRelationshipImpl(String name) {
RelationshipImpl newRel = new RelationshipImpl(
- name, _secondaryTable, _primaryTable, _flags,
- _secondaryCols, _primaryCols);
+ name, _primaryTable, _secondaryTable, _flags,
+ _primaryCols, _secondaryCols);
return newRel;
}
@@ -145,16 +145,16 @@ public class RelationshipCreator extends DBMutator
private void validate() throws IOException {
- _primaryTable = getDatabase().getTable(_relationship.getToTable());
- _secondaryTable = getDatabase().getTable(_relationship.getFromTable());
+ _primaryTable = getDatabase().getTable(_relationship.getFromTable());
+ _secondaryTable = getDatabase().getTable(_relationship.getToTable());
if((_primaryTable == null) || (_secondaryTable == null)) {
throw new IllegalArgumentException(withErrorContext(
"Two valid tables are required in relationship"));
}
- _primaryCols = getColumns(_primaryTable, _relationship.getToColumns());
- _secondaryCols = getColumns(_secondaryTable, _relationship.getFromColumns());
+ _primaryCols = getColumns(_primaryTable, _relationship.getFromColumns());
+ _secondaryCols = getColumns(_secondaryTable, _relationship.getToColumns());
if((_primaryCols == null) || (_primaryCols.isEmpty()) ||
(_secondaryCols == null) || (_secondaryCols.isEmpty())) {
@@ -212,7 +212,7 @@ public class RelationshipCreator extends DBMutator
Object[] entryValues = new Object[_secondaryCols.size()];
for(Row row : _secondaryTable.newCursor().toCursor()
.newIterable().addColumns(_secondaryCols)) {
- // grab the from table values
+ // grab the secondary table values
boolean hasValues = false;
for(int i = 0; i < _secondaryCols.size(); ++i) {
entryValues[i] = _secondaryCols.get(i).getRowValue(row);
@@ -224,6 +224,7 @@ public class RelationshipCreator extends DBMutator
continue;
}
+ // check that they exist in the primary table
if(!primaryCursor.findFirstRowByEntry(entryValues)) {
throw new ConstraintViolationException(withErrorContext(
"Integrity constraint violation found for relationship"));
@@ -343,10 +344,10 @@ public class RelationshipCreator extends DBMutator
private String withErrorContext(String msg) {
return msg + "(Rel=" +
getTableErrorContext(_primaryTable, _primaryCols,
- _relationship.getToTable(),
- _relationship.getToColumns()) + " <- " +
- getTableErrorContext(_secondaryTable, _secondaryCols,
_relationship.getFromTable(),
- _relationship.getFromColumns()) + ")";
+ _relationship.getFromColumns()) + " -> " +
+ getTableErrorContext(_secondaryTable, _secondaryCols,
+ _relationship.getToTable(),
+ _relationship.getToColumns()) + ")";
}
}