private String _fromTable;
private String _toTable;
private List<String> _fromCols = new ArrayList<String>();
- private List<String> _toCols = new ArrayList<String>();
+ private List<String> _toCols = new ArrayList<String>();
+ private String _name = null;
public RelationshipBuilder(Table fromTable, Table toTable) {
this(fromTable.getName(), toTable.getName());
}
return this;
}
+
+ /**
+ * Sets a specific name for this relationship.
+ *
+ * Default = null, meaning that the standard Access naming convention will be used.
+ */
+ public RelationshipBuilder setName(String relationshipName) {
+ _name = relationshipName;
+ return this;
+ }
public boolean hasReferentialIntegrity() {
return !hasFlag(RelationshipImpl.NO_REFERENTIAL_INTEGRITY_FLAG);
return _toCols;
}
+ public String getName() {
+ return _name;
+ }
+
/**
* Creates a new Relationship in the given Database with the currently
* configured attributes.
// - the total name is limited to (max - 3)
int maxIdLen = getFormat().MAX_INDEX_NAME_LENGTH;
int limit = (maxIdLen / 2) - 3;
- String origName = creator.getPrimaryTable().getName();
- if(origName.length() > limit) {
- origName = origName.substring(0, limit);
+ String origName = creator.getName();
+ if (origName == null) {
+ origName = creator.getPrimaryTable().getName();
+ if(origName.length() > limit) {
+ origName = origName.substring(0, limit);
+ }
+ origName += creator.getSecondaryTable().getName();
}
limit = maxIdLen - 3;
- origName += creator.getSecondaryTable().getName();
if(origName.length() > limit) {
origName = origName.substring(0, limit);
}
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
Database db = create(fileFormat);
- doTestUpdating(db, false, true);
+ doTestUpdating(db, false, true, null);
db.close();
}
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
Database db = create(fileFormat);
- doTestUpdating(db, true, true);
+ doTestUpdating(db, true, true, null);
db.close();
}
for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
Database db = create(fileFormat);
- doTestUpdating(db, false, false);
+ doTestUpdating(db, false, false, null);
db.close();
}
}
- private void doTestUpdating(Database db, boolean oneToOne, boolean enforce)
+ public void testTableUpdatingNamedRelationship() throws Exception {
+ for (final FileFormat fileFormat : SUPPORTED_FILEFORMATS) {
+ Database db = create(fileFormat);
+
+ doTestUpdating(db, false, true, "FKnun3jvv47l9kyl74h85y8a0if");
+
+ db.close();
+ }
+ }
+
+ private void doTestUpdating(Database db, boolean oneToOne, boolean enforce, String relationshipName)
throws Exception
{
Table t1 = new TableBuilder("TestTable")
rb.setReferentialIntegrity()
.setCascadeDeletes();
}
+
+ if (relationshipName != null) {
+ rb.setName(relationshipName);
+ }
Relationship rel = rb.toRelationship(db);
- assertEquals("TestTableTestTable2", rel.getName());
+ if (relationshipName == null) {
+ assertEquals("TestTableTestTable2", rel.getName());
+ } else {
+ assertEquals(relationshipName, rel.getName());
+ }
assertSame(t1, rel.getFromTable());
assertEquals(Arrays.asList(t1.getColumn("id")), rel.getFromColumns());
assertSame(t2, rel.getToTable());