/** * 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; } }
/** * 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; } }
.append(StringUtil.reverseCapitalisation(name)) .append("(final ") .append(((CollectionDescriptor) field).getReferencedClassDescriptor().getName()) .append(" arg)"); if (fieldPresent) {
.append(StringUtil.reverseCapitalisation(name)) .append("(final ") .append(((CollectionDescriptor) field).getReferencedClassDescriptor().getName()) .append(" arg)"); if (fieldPresent) {
CollectionDescriptor cd = (CollectionDescriptor) fd; @SuppressWarnings("unchecked") Collection lazyColl = new ProxyCollection(os, (InterMineObject) retval, cd.getName(), cd.getReferencedClassDescriptor() .getType()); retval.setFieldValue(cd.getName(), lazyColl);
CollectionDescriptor cd = (CollectionDescriptor) fd; @SuppressWarnings("unchecked") Collection lazyColl = new ProxyCollection(os, (InterMineObject) retval, cd.getName(), cd.getReferencedClassDescriptor() .getType()); retval.setFieldValue(cd.getName(), lazyColl);
CollectionDescriptor coll = (CollectionDescriptor) maybeColl; Collection<Object> lazyColl = new ProxyCollection<Object>(os, retval, coll.getName(), coll.getReferencedClassDescriptor().getType()); retval.setFieldValue(coll.getName(), lazyColl);
CollectionDescriptor coll = (CollectionDescriptor) maybeColl; Collection<Object> lazyColl = new ProxyCollection<Object>(os, retval, coll.getName(), coll.getReferencedClassDescriptor().getType()); retval.setFieldValue(coll.getName(), lazyColl);
public void testReferencedClassNotSet() throws Exception { CollectionDescriptor cod1 = new CollectionDescriptor("cod1", "Class2", null); Set<CollectionDescriptor> collections = Collections.singleton(cod1); // cld1 has a CollectionDescriptor that contains objects of type Class2 new ClassDescriptor("Class1", null, false, noAttrs, noRefs, collections); new ClassDescriptor("Class2", null, false, noAttrs, noRefs, noColls); try { cod1.getReferencedClassDescriptor(); fail("Expected IllegalStateException, model has not yet been set"); } catch (IllegalStateException e) { } }
public void testGetReferencedClass() throws Exception { CollectionDescriptor cod1 = new CollectionDescriptor("cod1", "package.name.Class2", null); Set<CollectionDescriptor> collections = Collections.singleton(cod1); // cld1 has a ReferenceDescriptor that points to Class2 ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, false, noAttrs, noRefs, collections); ClassDescriptor cld2 = new ClassDescriptor("package.name.Class2", null, false, noAttrs, noRefs, noColls); new Model("model", "package.name", Arrays.asList(cld1, cld2)); try { ClassDescriptor refCld = cod1.getReferencedClassDescriptor(); assertTrue("ClassDescriptor was null", refCld != null); assertTrue("Expected ClassDescriptor to be Class2", refCld.getName().equals("package.name.Class2")); } catch (IllegalStateException e) { fail("Should have returned a ClassDescriptor"); } }
if (coll.relationType() == FieldDescriptor.ONE_N_RELATION) { QueryClass qc = new QueryClass(coll .getReferencedClassDescriptor().getType()); subQ.addFrom(qc); QueryForeignKey qfk = new QueryForeignKey(qc, QueryClass qc1 = new QueryClass(clazz); QueryClass qc2 = new QueryClass(coll .getReferencedClassDescriptor().getType()); subQ.addFrom(qc1); subQ.addFrom(qc2); QueryClass qc1 = new QueryClass(clazz); QueryClass qc2 = new QueryClass(coll .getReferencedClassDescriptor().getType()); subQ.addFrom(qc1); subQ.addFrom(qc2);
if (coll.relationType() == FieldDescriptor.ONE_N_RELATION) { QueryClass qc = new QueryClass(coll .getReferencedClassDescriptor().getType()); subQ.addFrom(qc); QueryForeignKey qfk = new QueryForeignKey(qc, QueryClass qc1 = new QueryClass(clazz); QueryClass qc2 = new QueryClass(coll .getReferencedClassDescriptor().getType()); subQ.addFrom(qc1); subQ.addFrom(qc2); QueryClass qc1 = new QueryClass(clazz); QueryClass qc2 = new QueryClass(coll .getReferencedClassDescriptor().getType()); subQ.addFrom(qc1); subQ.addFrom(qc2);
/** * If the last element in the path is a reference or collection return the ClassDescriptor that * the reference or collection references. If the path has one element (eg. "Employee"), * return its ClassDescriptor. If the last element in the path is an attribute, return null. * @return the ClassDescriptor */ public ClassDescriptor getEndClassDescriptor() { if (getEndFieldDescriptor() == null) { return getStartClassDescriptor(); } if (!getEndFieldDescriptor().isAttribute()) { if (getEndFieldDescriptor().isCollection()) { CollectionDescriptor collDesc = (CollectionDescriptor) getEndFieldDescriptor(); return collDesc.getReferencedClassDescriptor(); } if (getEndFieldDescriptor().isReference()) { ReferenceDescriptor refDesc = (ReferenceDescriptor) getEndFieldDescriptor(); return refDesc.getReferencedClassDescriptor(); } } return null; }
/** * If the last element in the path is a reference or collection return the ClassDescriptor that * the reference or collection references. If the path has one element (eg. "Employee"), * return its ClassDescriptor. If the last element in the path is an attribute, return null. * @return the ClassDescriptor */ public ClassDescriptor getEndClassDescriptor() { if (getEndFieldDescriptor() == null) { return getStartClassDescriptor(); } if (!getEndFieldDescriptor().isAttribute()) { if (getEndFieldDescriptor().isCollection()) { CollectionDescriptor collDesc = (CollectionDescriptor) getEndFieldDescriptor(); return collDesc.getReferencedClassDescriptor(); } if (getEndFieldDescriptor().isReference()) { ReferenceDescriptor refDesc = (ReferenceDescriptor) getEndFieldDescriptor(); return refDesc.getReferencedClassDescriptor(); } } return null; }