/** * {@inheritDoc} */ @Override public int relationType() { ReferenceDescriptor rd = getReverseReferenceDescriptor(); if (rd == null || rd instanceof CollectionDescriptor) { return M_N_RELATION; } else { return ONE_N_RELATION; } }
/** * {@inheritDoc} */ @Override public int relationType() { ReferenceDescriptor rd = getReverseReferenceDescriptor(); if (rd == null || rd instanceof CollectionDescriptor) { return M_N_RELATION; } else { return ONE_N_RELATION; } }
if (!indirections.contains(collection.getReverseReferenceDescriptor())) { indirections.add(collection);
if (!indirections.contains(collection.getReverseReferenceDescriptor())) { indirections.add(collection);
schema.getVersion()); if ((columnName.compareTo(columnName2) < 0) || (col.getReverseReferenceDescriptor() == null)) { addStatement(statements, tableName + "__" + columnName, tableName,
/** * Creates a column name for the "outward" key of a many-to-many collection descriptor. * * @param col CollectionDescriptor * @param version the database version number * @return a valid column name */ public static String getOutwardIndirectionColumnName(CollectionDescriptor col, int version) { if (FieldDescriptor.M_N_RELATION != col.relationType()) { throw new IllegalArgumentException("Argument must be a CollectionDescriptor for a " + "many-to-many relation"); } if (version == 0) { ReferenceDescriptor rd = col.getReverseReferenceDescriptor(); String colName = (rd == null ? TypeUtil.unqualifiedName(col.getClassDescriptor().getName()) : rd.getName()); return StringUtil.capitalise(generateSqlCompatibleName(colName)); } else if (version == 1) { return StringUtil.capitalise(generateSqlCompatibleName(col.getName())); } else { throw new IllegalArgumentException("Database version number " + version + " not recognised"); } }
/** * Creates a column name for the "inward" key of a many-to-many collection descriptor. * * @param col CollectionDescriptor * @param version the database version number * @return a valid column name */ public static String getInwardIndirectionColumnName(CollectionDescriptor col, int version) { if (FieldDescriptor.M_N_RELATION != col.relationType()) { throw new IllegalArgumentException("Argument must be a CollectionDescriptor for a " + "many-to-many relation"); } if (version == 0) { return StringUtil.capitalise(generateSqlCompatibleName(col.getName())); } else if (version == 1) { ReferenceDescriptor rd = col.getReverseReferenceDescriptor(); String colName = (rd == null ? TypeUtil.unqualifiedName(col.getClassDescriptor().getName()) : rd.getName()); return StringUtil.capitalise(generateSqlCompatibleName(colName)); } else { throw new IllegalArgumentException("Database version number " + version + " not recognised"); } }
schema.getVersion()); if ((columnName.compareTo(columnName2) < 0) || (col.getReverseReferenceDescriptor() == null)) { addStatement(statements, tableName + "__" + columnName, tableName,
/** * Creates a column name for the "inward" key of a many-to-many collection descriptor. * * @param col CollectionDescriptor * @param version the database version number * @return a valid column name */ public static String getInwardIndirectionColumnName(CollectionDescriptor col, int version) { if (FieldDescriptor.M_N_RELATION != col.relationType()) { throw new IllegalArgumentException("Argument must be a CollectionDescriptor for a " + "many-to-many relation"); } if (version == 0) { return StringUtil.capitalise(generateSqlCompatibleName(col.getName())); } else if (version == 1) { ReferenceDescriptor rd = col.getReverseReferenceDescriptor(); String colName = (rd == null ? TypeUtil.unqualifiedName(col.getClassDescriptor().getName()) : rd.getName()); return StringUtil.capitalise(generateSqlCompatibleName(colName)); } else { throw new IllegalArgumentException("Database version number " + version + " not recognised"); } }
/** * Creates a column name for the "outward" key of a many-to-many collection descriptor. * * @param col CollectionDescriptor * @param version the database version number * @return a valid column name */ public static String getOutwardIndirectionColumnName(CollectionDescriptor col, int version) { if (FieldDescriptor.M_N_RELATION != col.relationType()) { throw new IllegalArgumentException("Argument must be a CollectionDescriptor for a " + "many-to-many relation"); } if (version == 0) { ReferenceDescriptor rd = col.getReverseReferenceDescriptor(); String colName = (rd == null ? TypeUtil.unqualifiedName(col.getClassDescriptor().getName()) : rd.getName()); return StringUtil.capitalise(generateSqlCompatibleName(colName)); } else if (version == 1) { return StringUtil.capitalise(generateSqlCompatibleName(col.getName())); } else { throw new IllegalArgumentException("Database version number " + version + " not recognised"); } }
public void testReverseReferenceValid() throws Exception { // codd1 in Class1 points to Class2, cod2 in Class2 points to Class1 CollectionDescriptor cod1 = new CollectionDescriptor("cod1", "package.name.Class2", "cod2"); CollectionDescriptor cod2 = new CollectionDescriptor("cod2", "package.name.Class1", "cod1"); Set<CollectionDescriptor> cols1 = Collections.singleton(cod1); Set<CollectionDescriptor> cols2 = Collections.singleton(cod2); ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, false, noAttrs, noRefs, cols1); ClassDescriptor cld2 = new ClassDescriptor("package.name.Class2", null, false, noAttrs, noRefs, cols2); new Model("model", "package.name", Arrays.asList(cld1, cld2)); try { ReferenceDescriptor rfdReverse = cod1.getReverseReferenceDescriptor(); assertEquals(cod2, rfdReverse); assertEquals(cld1, rfdReverse.getReferencedClassDescriptor()); } catch (IllegalStateException e) { fail("Should have returned reverse ReferenceDescriptor"); } }