/** * Creates a column name for a field descriptor * * @param fd FieldDescriptor * @return a valid column name */ public static String getColumnName(FieldDescriptor fd) { if (fd instanceof AttributeDescriptor) { return generateSqlCompatibleName(fd.getName()); } if (fd instanceof CollectionDescriptor) { return null; } if (fd instanceof ReferenceDescriptor) { return fd.getName() + "Id"; } return null; }
/** * Return true if and only if the end of the path is a reference . * @return the end-is-reference flag */ public boolean endIsReference() { if (endFld == null) { return false; } return endFld.isReference(); }
/** * Return true if and only if the end of the path is a collection. * @return the end-is-collection flag */ public boolean endIsCollection() { if (endFld == null) { return false; } return endFld.isCollection(); }
private static void addFields(StringBuffer sb, Collection<? extends FieldDescriptor> fields) { Iterator<? extends FieldDescriptor> iter = fields.iterator(); while (iter.hasNext()) { FieldDescriptor fld = iter.next(); sb.append("\"" + fld.getName() + "\":"); sb.append(fld.toJSONString()); if (iter.hasNext()) { sb.append(","); } } }
/** * For a given class/field return true if it is an 'identifying' field. An * identifying field is an attribute (not a reference or collection) of the * class that is part of any key defined for that class. * * @param classKeys * map of classname to set of keys * @param clsName * the class name to look up * @param fieldName * the field name to look up * @return true if the field is an 'identifying' field for the class. */ public static boolean isKeyField(Map<String, List<FieldDescriptor>> classKeys, String clsName, String fieldName) { String className = TypeUtil.unqualifiedName(clsName); List<FieldDescriptor> keys = classKeys.get(className); if (keys != null) { for (FieldDescriptor key : keys) { if (key.getName().equals(fieldName) && key.isAttribute()) { return true; } } } return false; }
body.append("objectText = '$_^" + c.getName() + "';\n"); for (FieldDescriptor fD : classFD) { if (fD.isAttribute() && !"id".equals(fD.getName()) ) { body.append("IF ( NEW." + getDBName(fD.getName()) + " IS NOT NULL ) THEN objectText := objectText || " + "'$_^a" + fD.getName() + "$_^'||NEW." + getDBName(fD.getName()) + "; END IF;\n"); } else if (fD.isReference()) { body.append("IF ( NEW." + fD.getName() + "id IS NOT NULL ) THEN objectText := objectText || " + "'$_^r" + fD.getName() + "$_^'||NEW." + fD.getName() + "id; END IF;\n");
.append(INDENT + INDENT); for (FieldDescriptor field : cld.getAllFieldDescriptors()) { sb.append("if (\"" + field.getName() + "\".equals(fieldName)) {\n"); String fieldName = field.getName(); if ("value".equals(fieldName)) { fieldName = "this.value"; .append(fieldName + " = (" + attribute.getType() + ") value;\n"); } else if (field.isReference()) { sb.append(INDENT + INDENT + INDENT) .append(fieldName + " = (org.intermine.model.InterMineObject) value;\n");
/** * Attach the model. Throws IllegalArgumentExceptions if node doesn't map onto the model. * * @param model model to attach * @throws IllegalArgumentException if class or field are not found in the model */ public void setModel(Model model) { ClassDescriptor cld = model.getClassDescriptorByName(getParentType()); if (cld == null) { throw new IllegalArgumentException("No class '" + getParentType() + "' found in model '" + model.getName() + "'."); } fd = cld.getFieldDescriptorByName(fieldName); if (fd == null) { throw new IllegalArgumentException("Class '" + cld.getName() + "' does not have field '" + fieldName + "'."); } type = TypeUtil.unqualifiedName(fd.isAttribute() ? ((AttributeDescriptor) fd).getType() : ((ReferenceDescriptor) fd) .getReferencedClassDescriptor().getName()); attribute = fd.isAttribute(); reference = fd.isReference(); collection = fd.isCollection(); this.model = model; }
.append("public Class<?> getElementType(final String fieldName) {\n"); for (FieldDescriptor field : cld.getAllFieldDescriptors()) { if (field.isCollection()) { sb.append(INDENT + INDENT) .append("if (\"" + field.getName() + "\".equals(fieldName)) {\n") .append(INDENT + INDENT + INDENT) .append("return " + ((CollectionDescriptor) field).getReferencedClassName()
"org.intermine.model.testmodel.Company").getAllFieldDescriptors()) { if (fd.isReference()) { ReferenceDescriptor ref = (ReferenceDescriptor) fd; DisplayReference dr = new DisplayReference(null, ref, webConfig, im.getClassKeys(), null); m.put(fd.getName(), dr); if (fd.isCollection()) { Object fieldValue = company.getFieldValue(fd.getName()); DisplayCollection dc = new DisplayCollection((Collection<?>) fieldValue, (CollectionDescriptor) fd, webConfig, null, im.getClassKeys(), null); m.put(fd.getName(), dc);
AttributeDescriptor origField = attributeMap.get(field.getName()); if (origField == null) { attributeMap.put(field.getName(), (AttributeDescriptor) field); } else if (origField != field) { String type = ((AttributeDescriptor) field).getType(); if (!compatible(type, origType)) { throw new ObjectStoreException("Fields " + field.getClassDescriptor().getName() + "." + field.getName() + " (a " + type + ") and " + origField.getClassDescriptor().getName() + "." + origField.getName() + " (a " + origType } else if (!field.isCollection()) { referenceMap.put(field.getName(), (ReferenceDescriptor) field); if ((!added.contains(field.getClassDescriptor())) && (!cld.getSuperDescriptors() .contains(field.getClassDescriptor()))) { LOG.warn("Field included in truncated class " + cld.getName() + " " + field.getClassDescriptor() .getName() + "." + field.getName() + " is from" + " outside the class. This may result in a table" + " with lots of columns - consider changing the" if (f instanceof AttributeDescriptor) { attributes.add((AttributeDescriptor) f); } else if (!f.isCollection()) { references.add((ReferenceDescriptor) f);
Source source, Source skelSource, FieldDescriptor field, int type) throws IllegalAccessException, ObjectStoreException { String fieldName = field.getName(); if (!"id".equals(fieldName)) { switch (field.relationType()) { case FieldDescriptor.NOT_RELATION: Object value = srcObj.getFieldValue(fieldName); throw new NullPointerException("reverseRef must be null: " + reverseRef + ", forward ref is " + field.getClassDescriptor().getName() + "." + field.getName() + ", type is " + field.relationType()); String brokenOneToMany = field.getClassDescriptor().getUnqualifiedName() + "." + field.getName(); if (!seenBrokenOneToMany.contains(brokenOneToMany)) { @SuppressWarnings("unchecked") Collection<InterMineObject> col = LOG.warn("fieldName:" + field.getName() + " classDescriptionName:" + field.getClassDescriptor().getName(), bob); throw bob; throw new Error("Unrecognised relation type " + field.relationType());
FieldDescriptor fieldDescriptor = elementClassDescriptors.get(i) .getFieldDescriptorByName(fieldName); if (fieldDescriptor.isReference() || fieldDescriptor.isCollection()) { String referencedClassName = ((ReferenceDescriptor) fieldDescriptor).getReferencedClassName();
Map<String, FieldDescriptor> toAdd = superDesc.findAllFieldDescriptors(); for (FieldDescriptor fd : toAdd.values()) { FieldDescriptor fdAlready = map.get(fd.getName()); if ((fdAlready != null) && (fd != fdAlready)) { if (fd.relationType() != fdAlready.relationType()) { throw new MetaDataException("Incompatible similarly named fields (" + fd.getName() + ") inherited" + " from multiple superclasses and interfaces in " + getName()); if (!ad.getType().equals(((AttributeDescriptor) fdAlready).getType())) { throw new MetaDataException("Incompatible similarly named fields (" + fd.getName() + ") inherited" + " from multiple superclasses and interfaces in " + getName()); || !Util.equals(reverseFieldName, alreadyRevFieldName)) { throw new MetaDataException("Incompatible similarly named fields (" + fd.getName() + ") inherited" + " from multiple superclasses and interfaces [" + alreadyRevFieldName + " instead of " + reverseFieldName map.put(fd.getName(), fd);
fieldDescriptor.setClassDescriptor(this); fieldDescriptors.put(fieldDescriptor.getName(), fieldDescriptor); } catch (IllegalStateException e) { throw new IllegalArgumentException("FieldDescriptor '" + fieldDescriptor.getName() + "' has already had ClassDescriptor set");
/** * Return true if and only if the end of the path is an attribute. * @return the end-is-attribute flag */ public boolean endIsAttribute() { if (endFld == null) { return false; } return endFld.isAttribute(); }
/** * Is this FieldDescriptor a collection? * * @return true if this FieldDescriptor describes a collection */ public boolean isCollection() { return (relationType() == ONE_N_RELATION) || (relationType() == M_N_RELATION); }
public void testSetClassDescriptorTwice() throws Exception { FieldDescriptor fd = new TestFieldDescriptor("name"); ClassDescriptor cld = makeClass("Class1"); fd.setClassDescriptor(cld); try { fd.setClassDescriptor(cld); fail("Expected IllegalStateException"); } catch (IllegalStateException e) { } }
body.append("objectText = '$_^" + c.getName() + "';\n"); for (FieldDescriptor fD : classFD) { if (fD.isAttribute() && !"id".equals(fD.getName()) ) { body.append("IF ( NEW." + getDBName(fD.getName()) + " IS NOT NULL ) THEN objectText := objectText || " + "'$_^a" + fD.getName() + "$_^'||NEW." + getDBName(fD.getName()) + "; END IF;\n"); } else if (fD.isReference()) { body.append("IF ( NEW." + fD.getName() + "id IS NOT NULL ) THEN objectText := objectText || " + "'$_^r" + fD.getName() + "$_^'||NEW." + fD.getName() + "id; END IF;\n");
for (FieldDescriptor field : cld.getAllFieldDescriptors()) { sb.append(INDENT + INDENT) .append("if (\"" + field.getName() + "\".equals(fieldName)) {\n"); String fieldName = field.getName(); if ("fieldName".equals(fieldName)) { fieldName = "this.fieldName"; .append("return " + fieldName + ";\n"); } else if (field.isReference()) { sb.append(INDENT + INDENT + INDENT); if (proxy) {