/** * Generates code for a single collection. * * @param col the CollectionDescriptor * @param field true if the class should have the associated field, or false if the field is in * the superclass * @return java code */ protected String generate(CollectionDescriptor col, boolean field) { String type = "java.util.Set<" + col.getReferencedClassName() + ">"; String impl = "java.util.HashSet<" + col.getReferencedClassName() + ">"; StringBuffer sb = new StringBuffer(); if (field) { sb.append(INDENT + "// Col: " + col.getClassDescriptor().getName() + "." + col.getName() + ENDL) .append(INDENT) .append("protected ") .append(type) .append(" ") .append(col.getName()) .append(" = new ") .append(impl) .append("();" + ENDL); } sb.append(generateGetSet(col, field)) .append(ENDL); return sb.toString(); }
/** * Takes a Class, and generates a Map of all the collections that are in the Class or any of its * parents. The Class may be a dynamic class - ie not in the model, although at least one of its * parents are in the model. * * @param c a Class * @return a Map from String collection name to Class element type */ public Map<String, Class<?>> getCollectionsForClass(Class<?> c) { synchronized (classToCollectionsMap) { Map<String, Class<?>> retval = classToCollectionsMap.get(c); if (retval == null) { retval = new LinkedHashMap<String, Class<?>>(); for (FieldDescriptor fd : getFieldDescriptorsForClass(c).values()) { if (fd instanceof CollectionDescriptor) { CollectionDescriptor cd = (CollectionDescriptor) fd; retval.put(cd.getName(), cd.getReferencedClassDescriptor().getType()); } } classToCollectionsMap.put(c, retval); } return retval; } }
/** * Generates code for a single collection. * * @param col the CollectionDescriptor * @param field true if the class should have the associated field, or false if the field is in * the superclass * @return java code */ protected String generate(CollectionDescriptor col, boolean field) { String type = "java.util.Set<" + col.getReferencedClassName() + ">"; String impl = "java.util.HashSet<" + col.getReferencedClassName() + ">"; StringBuffer sb = new StringBuffer(); if (field) { sb.append(INDENT + "// Col: " + col.getClassDescriptor().getName() + "." + col.getName() + ENDL) .append(INDENT) .append("protected ") .append(type) .append(" ") .append(col.getName()) .append(" = new ") .append(impl) .append("();" + ENDL); } sb.append(generateGetSet(col, field)) .append(ENDL); return sb.toString(); }
/** * Takes a Class, and generates a Map of all the collections that are in the Class or any of its * parents. The Class may be a dynamic class - ie not in the model, although at least one of its * parents are in the model. * * @param c a Class * @return a Map from String collection name to Class element type */ public Map<String, Class<?>> getCollectionsForClass(Class<?> c) { synchronized (classToCollectionsMap) { Map<String, Class<?>> retval = classToCollectionsMap.get(c); if (retval == null) { retval = new LinkedHashMap<String, Class<?>>(); for (FieldDescriptor fd : getFieldDescriptorsForClass(c).values()) { if (fd instanceof CollectionDescriptor) { CollectionDescriptor cd = (CollectionDescriptor) fd; retval.put(cd.getName(), cd.getReferencedClassDescriptor().getType()); } } classToCollectionsMap.put(c, retval); } return retval; } }
private static CollectionDescriptor cloneCollectionDescriptor(CollectionDescriptor ref) { return new CollectionDescriptor(ref.getName(), ref.getReferencedClassName(), ref.getReverseReferenceFieldName()); }
private static CollectionDescriptor cloneCollectionDescriptor(CollectionDescriptor ref) { return new CollectionDescriptor(ref.getName(), ref.getReferencedClassName(), ref.getReverseReferenceFieldName()); }
CollectionDescriptor cd = (CollectionDescriptor) fd; @SuppressWarnings("unchecked") Collection lazyColl = new ProxyCollection(os, (InterMineObject) retval, cd.getName(), cd.getReferencedClassDescriptor() .getType()); retval.setFieldValue(cd.getName(), lazyColl); } else if (fd instanceof ReferenceDescriptor) { ReferenceDescriptor rd = (ReferenceDescriptor) fd;
for (CollectionDescriptor merg : merge.getCollectionDescriptors()) { CollectionDescriptor orig = original.getCollectionDescriptorByName(merg.getName()); && orig.getReverseReferenceFieldName() == null) { removeFieldDescriptor(newSet, orig.getName()); newSet.add(cloneCollectionDescriptor(merg)); continue; String fldName = original.getName() + "." + orig.getName(); throw new ModelMergerException("mismatch between reverse reference field name: " + fldName + "<-" + merg.getReverseReferenceFieldName() + " != " String fldName = original.getName() + "." + orig.getName(); throw new ModelMergerException("type mismatch between collection types: " + fldName + ":" + merg.getReferencedClassName() + " != "
for (CollectionDescriptor merg : merge.getCollectionDescriptors()) { CollectionDescriptor orig = original.getCollectionDescriptorByName(merg.getName()); && orig.getReverseReferenceFieldName() == null) { removeFieldDescriptor(newSet, orig.getName()); newSet.add(cloneCollectionDescriptor(merg)); continue; String fldName = original.getName() + "." + orig.getName(); throw new ModelMergerException("mismatch between reverse reference field name: " + fldName + "<-" + merg.getReverseReferenceFieldName() + " != " String fldName = original.getName() + "." + orig.getName(); throw new ModelMergerException("type mismatch between collection types: " + fldName + ":" + merg.getReferencedClassName() + " != "
CollectionDescriptor cold = citer.next(); CollectionDescriptor scdDescriptor = scd.getCollectionDescriptorByName(cold.getName()); if (scd.getCollectionDescriptorByName(cold.getName()) != null) { LOG.info("removing collection " + cold.getName() + " redefinition in " + cd.getName() + " (is now defined in " + scd.getName() + ")"); citer.remove(); } else { String message = "replacing the \"" + sup + "." + cold.getName() + "\" collection with " + cd.getName() + "." + cold.getName() + " failed because the reverse references differ"; throw new ModelMergerException(message);
@SuppressWarnings("unchecked") Collection<InterMineObject> coll = (Collection<InterMineObject>) ((InterMineObject) o) .getFieldValue(collection.getName()); boolean needToStoreCollection = true;
@SuppressWarnings("unchecked") Collection<InterMineObject> coll = (Collection<InterMineObject>) ((InterMineObject) o) .getFieldValue(collection.getName()); boolean needToStoreCollection = true;
/** * 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"); } }
/** * 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"); } }
for (CollectionDescriptor desc : getAllCollectionDescriptors()) { ClassDescriptor cld = desc.getClassDescriptor(); table.addRow(new String[] {desc.getName(), "collection of " + terseClass(desc.getReferencedClassName()), (cld == this ? "" : "from " + terseClass(cld.getName()))});
for (CollectionDescriptor desc : getAllCollectionDescriptors()) { ClassDescriptor cld = desc.getClassDescriptor(); table.addRow(new String[] {desc.getName(), "collection of " + terseClass(desc.getReferencedClassName()), (cld == this ? "" : "from " + terseClass(cld.getName()))});