/** * Given a ClassDescriptor find names of all related indirection tables. * @param cld class to find tables for * @return a set of all indirection table names */ public static Set<String> getIndirectionTableNames(ClassDescriptor cld) { Set<String> tables = new HashSet<String>(); for (CollectionDescriptor col : cld.getAllCollectionDescriptors()) { if (FieldDescriptor.M_N_RELATION == col.relationType()) { tables.add(getIndirectionTableName(col)); } } return tables; }
/** * Given a ClassDescriptor find names of all related indirection tables. * @param cld class to find tables for * @return a set of all indirection table names */ public static Set<String> getIndirectionTableNames(ClassDescriptor cld) { Set<String> tables = new HashSet<String>(); for (CollectionDescriptor col : cld.getAllCollectionDescriptors()) { if (FieldDescriptor.M_N_RELATION == col.relationType()) { tables.add(getIndirectionTableName(col)); } } return tables; }
/** * Creates an indirection table name for a many-to-many collection descriptor * * @param col CollectionDescriptor * @return a valid table name */ public static String getIndirectionTableName(CollectionDescriptor col) { if (FieldDescriptor.M_N_RELATION != col.relationType()) { throw new IllegalArgumentException("Argument must be a CollectionDescriptor for a " + "many-to-many relation"); } String name1 = getInwardIndirectionColumnName(col, 0); String name2 = getOutwardIndirectionColumnName(col, 0); return name1.compareTo(name2) < 0 ? name1 + name2 : name2 + name1; }
/** * Creates an indirection table name for a many-to-many collection descriptor * * @param col CollectionDescriptor * @return a valid table name */ public static String getIndirectionTableName(CollectionDescriptor col) { if (FieldDescriptor.M_N_RELATION != col.relationType()) { throw new IllegalArgumentException("Argument must be a CollectionDescriptor for a " + "many-to-many relation"); } String name1 = getInwardIndirectionColumnName(col, 0); String name2 = getOutwardIndirectionColumnName(col, 0); return name1.compareTo(name2) < 0 ? name1 + name2 : name2 + name1; }
if (FieldDescriptor.M_N_RELATION == collection.relationType()) { if (!indirections.contains(collection.getReverseReferenceDescriptor())) { indirections.add(collection);
if (FieldDescriptor.M_N_RELATION == collection.relationType()) { if (!indirections.contains(collection.getReverseReferenceDescriptor())) { indirections.add(collection);
public void testRelationTypeUnidirectional() throws Exception { CollectionDescriptor col = new CollectionDescriptor("col1", "package.name.Class1", null); Set<CollectionDescriptor> cols = Collections.singleton(col); ClassDescriptor cld = new ClassDescriptor("package.name.Class1", null, false, noAttrs, noRefs, cols); new Model("model1", "package.name", Collections.singleton(cld)); assertEquals(FieldDescriptor.M_N_RELATION, col.relationType()); }
public void testRelationTypeOneToMany() throws Exception { CollectionDescriptor col = new CollectionDescriptor("col1", "package.name.Class1", "ref1"); ReferenceDescriptor ref = new ReferenceDescriptor("ref1", "package.name.Class1", null); Set<CollectionDescriptor> cols = Collections.singleton(col); Set<ReferenceDescriptor> refs = Collections.singleton(ref); ClassDescriptor cld = new ClassDescriptor("package.name.Class1", null, false, noAttrs, refs, cols); new Model("model1", "package.name", Collections.singleton(cld)); assertEquals(FieldDescriptor.ONE_N_RELATION, col.relationType()); }
public void testRelationTypeManyToMany() throws Exception { CollectionDescriptor col1 = new CollectionDescriptor("col1", "package.name.Class1", "col2"); CollectionDescriptor col2 = new CollectionDescriptor("col2", "package.name.Class1", null); Set<CollectionDescriptor> cols = new HashSet<CollectionDescriptor>(Arrays.asList(col1, col2)); ClassDescriptor cld = new ClassDescriptor("package.name.Class1", null, false, noAttrs, noRefs, cols); new Model("model1", "package.name", Collections.singleton(cld)); assertEquals(FieldDescriptor.M_N_RELATION, col1.relationType()); }
if (FieldDescriptor.M_N_RELATION == col.relationType()) { String tableName = DatabaseUtil.getIndirectionTableName(col).toLowerCase(); String columnName = DatabaseUtil.getInwardIndirectionColumnName(col,
if (FieldDescriptor.M_N_RELATION == col.relationType()) { String tableName = DatabaseUtil.getIndirectionTableName(col).toLowerCase(); String columnName = DatabaseUtil.getInwardIndirectionColumnName(col,
if (collection.relationType() == FieldDescriptor.M_N_RELATION) { String indirectTableName = DatabaseUtil.getIndirectionTableName(collection);
if (collection.relationType() == FieldDescriptor.M_N_RELATION) { String indirectTableName = DatabaseUtil.getIndirectionTableName(collection);
/** * 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"); } }
/** * 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"); } }
if (coll.relationType() == FieldDescriptor.ONE_N_RELATION) { QueryClass qc = new QueryClass(coll .getReferencedClassDescriptor().getType()); ConstraintOp.LESS_THAN_EQUALS, new QueryValue(new Integer(highestId)))); if (coll.relationType() == FieldDescriptor.ONE_N_RELATION) { QueryForeignKey reverseIdField = new QueryForeignKey(qc2, coll.getReverseReferenceFieldName());
if (coll.relationType() == FieldDescriptor.ONE_N_RELATION) { QueryClass qc = new QueryClass(coll .getReferencedClassDescriptor().getType()); ConstraintOp.LESS_THAN_EQUALS, new QueryValue(new Integer(highestId)))); if (coll.relationType() == FieldDescriptor.ONE_N_RELATION) { QueryForeignKey reverseIdField = new QueryForeignKey(qc2, coll.getReverseReferenceFieldName());