Package com.healthmarketscience.jackcess
Class RelationshipBuilder
- java.lang.Object
-
- com.healthmarketscience.jackcess.RelationshipBuilder
-
public class RelationshipBuilder extends Object
Builder style class for constructing aRelationship, and, optionally, the associated backing foreign key (if referential integrity enforcement is enabled). A Relationship can only be constructed forTables which already exist in theDatabase. Additionally, if integrity enforcement is enabled, there must already be a unique index on the "from" Table for the relevant columns (same requirement as MS Access).Example:
Relationship rel = new RelationshipBuilder("FromTable", "ToTable") .addColumns("ID", "FK_ID") .setReferentialIntegrity() .setCascadeDeletes() .toRelationship(db);- Author:
- James Ahlborn
- See Also:
TableBuilder- Usage:
- General: This class is general use.
-
-
Constructor Summary
Constructors Constructor Description RelationshipBuilder(Table fromTable, Table toTable)RelationshipBuilder(String fromTable, String toTable)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RelationshipBuilderaddColumns(Column fromCol, Column toCol)Adds a pair of columns to the relationship.RelationshipBuilderaddColumns(String fromCol, String toCol)Adds a pair of columns to the relationship.intgetFlags()List<String>getFromColumns()StringgetFromTable()StringgetName()List<String>getToColumns()StringgetToTable()booleanhasReferentialIntegrity()RelationshipBuildersetCascadeDeletes()Enables deletes to be cascaded from the "from" table to the "to" table.RelationshipBuildersetCascadeNullOnDelete()Enables deletes in the "from" table to be cascaded as "null" to the "to" table.RelationshipBuildersetCascadeUpdates()Enables updates to be cascaded from the "from" table to the "to" table.RelationshipBuildersetJoinType(Relationship.JoinType joinType)Sets the preferred join type for this relationship.RelationshipBuildersetName(String relationshipName)Sets a specific name for this relationship.RelationshipBuildersetReferentialIntegrity()Enables referential integrity enforcement for this relationship.RelationshiptoRelationship(Database db)Creates a new Relationship in the given Database with the currently configured attributes.
-
-
-
Method Detail
-
addColumns
public RelationshipBuilder addColumns(String fromCol, String toCol)
Adds a pair of columns to the relationship.
-
addColumns
public RelationshipBuilder addColumns(Column fromCol, Column toCol)
Adds a pair of columns to the relationship.
-
setReferentialIntegrity
public RelationshipBuilder setReferentialIntegrity()
Enables referential integrity enforcement for this relationship. Note, this requires the "from" table to have an existing unique index on the relevant columns.
-
setCascadeDeletes
public RelationshipBuilder setCascadeDeletes()
Enables deletes to be cascaded from the "from" table to the "to" table. Note, this requires referential integrity to be enforced.
-
setCascadeUpdates
public RelationshipBuilder setCascadeUpdates()
Enables updates to be cascaded from the "from" table to the "to" table. Note, this requires referential integrity to be enforced.
-
setCascadeNullOnDelete
public RelationshipBuilder setCascadeNullOnDelete()
Enables deletes in the "from" table to be cascaded as "null" to the "to" table. Note, this requires referential integrity to be enforced.
-
setJoinType
public RelationshipBuilder setJoinType(Relationship.JoinType joinType)
Sets the preferred join type for this relationship.
-
setName
public RelationshipBuilder setName(String relationshipName)
Sets a specific name for this relationship. Default = null, meaning that the standard Access naming convention will be used.
-
hasReferentialIntegrity
public boolean hasReferentialIntegrity()
-
getFlags
public int getFlags()
-
getFromTable
public String getFromTable()
-
getToTable
public String getToTable()
-
getName
public String getName()
-
toRelationship
public Relationship toRelationship(Database db) throws IOException
Creates a new Relationship in the given Database with the currently configured attributes.- Throws:
IOException
-
-