/** * Return true if and only if the argument names a possible collection for this Item. ie. the * ClassDescriptor for this Item contains a CollectionDescriptor for this name. * * @param name the field name * @return Return true if and only if this Item has a collection of the given name in the model */ public boolean canHaveCollection(String name) { return classDescriptor.getCollectionDescriptorByName(name, true) != null; }
/** * Gets a CollectionDescriptor for a collection of the given name. Returns null if * not found. Does NOT search in any superclasses or interfaces. * * @param name the name of a CollectionDescriptor to find * @return a CollectionDescriptor */ public CollectionDescriptor getCollectionDescriptorByName(String name) { return getCollectionDescriptorByName(name, false); }
/** * Return true if and only if the argument names a possible collection for this Item. ie. the * ClassDescriptor for this Item contains a CollectionDescriptor for this name. * * @param name the field name * @return Return true if and only if this Item has a collection of the given name in the model */ public boolean canHaveCollection(String name) { return classDescriptor.getCollectionDescriptorByName(name, true) != null; }
/** * Gets a CollectionDescriptor for a collection of the given name. Returns null if * not found. Does NOT search in any superclasses or interfaces. * * @param name the name of a CollectionDescriptor to find * @return a CollectionDescriptor */ public CollectionDescriptor getCollectionDescriptorByName(String name) { return getCollectionDescriptorByName(name, false); }
/** * Throw a RuntimeException if the name parameter isn't an collection in the class set by * setClassName() in the Model set by setModel(). Returns immediately if the Model or the * className of this Item haven't been set. * * @param name the collection name */ protected void checkCollection(String name) { if (model == null || classDescriptor == null) { return; } if (classDescriptor.getCollectionDescriptorByName(name, true) == null) { throw new RuntimeException("class \"" + classDescriptor.getName() + "\" has no \"" + name + "\" collection"); } }
/** * Throw a RuntimeException if the name parameter isn't an collection in the class set by * setClassName() in the Model set by setModel(). Returns immediately if the Model or the * className of this Item haven't been set. * * @param name the collection name */ protected void checkCollection(String name) { if (model == null || classDescriptor == null) { return; } if (classDescriptor.getCollectionDescriptorByName(name, true) == null) { throw new RuntimeException("class \"" + classDescriptor.getName() + "\" has no \"" + name + "\" collection"); } }
private static void verifyClassAndField(String className, String fieldName, Model model) { String checkFileMsg = "Please check modelUpdate.properties file"; if ("".equals(className)) { throw new BuildException("Class " + className + " can not be blank. " + checkFileMsg); } ClassDescriptor cd = model.getClassDescriptorByName(className); if (cd == null) { if (fieldName != null) { throw new BuildException("Class " + className + " containing " + fieldName + " not defined in the model " + model.getName() + ". " + checkFileMsg); } else { throw new BuildException("Class " + className + " not defined in the model " + model.getName() + ". " + checkFileMsg); } } if (fieldName != null) { if ("".equals(fieldName)) { throw new BuildException("Attribute " + fieldName + " in the class " + className + " can not be blank. " + checkFileMsg); } if (cd.getAttributeDescriptorByName(fieldName) == null && cd.getReferenceDescriptorByName(fieldName) == null && cd.getCollectionDescriptorByName(fieldName) == null) { throw new BuildException("The " + fieldName + " in the class " + className + " not defined in the model " + model.getName() + ". " + checkFileMsg); } } }
private static void verifyClassAndField(String className, String fieldName, Model model) { String checkFileMsg = "Please check modelUpdate.properties file"; if ("".equals(className)) { throw new BuildException("Class " + className + " can not be blank. " + checkFileMsg); } ClassDescriptor cd = model.getClassDescriptorByName(className); if (cd == null) { if (fieldName != null) { throw new BuildException("Class " + className + " containing " + fieldName + " not defined in the model " + model.getName() + ". " + checkFileMsg); } else { throw new BuildException("Class " + className + " not defined in the model " + model.getName() + ". " + checkFileMsg); } } if (fieldName != null) { if ("".equals(fieldName)) { throw new BuildException("Attribute " + fieldName + " in the class " + className + " can not be blank. " + checkFileMsg); } if (cd.getAttributeDescriptorByName(fieldName) == null && cd.getReferenceDescriptorByName(fieldName) == null && cd.getCollectionDescriptorByName(fieldName) == null) { throw new BuildException("The " + fieldName + " in the class " + className + " not defined in the model " + model.getName() + ". " + checkFileMsg); } } }
private void setRefsAndCollections(List<String> parents, Item feature) { String clsName = feature.getClassName(); Map<String, String> refsAndCollections = handler.getRefsAndCollections(); if (refsAndCollections != null && refsAndCollections.containsKey(clsName) && parents != null && !parents.isEmpty()) { ClassDescriptor cld = tgtModel.getClassDescriptorByName(tgtModel.getPackageName() + "." + clsName); String refName = refsAndCollections.get(clsName); Iterator<String> parentIter = parents.iterator(); if (cld.getReferenceDescriptorByName(refName, true) != null) { String parent = parentIter.next(); feature.setReference(refName, getRefId(parent)); if (parentIter.hasNext()) { String primaryIdent = feature.getAttribute("primaryIdentifier").getValue(); throw new RuntimeException("Feature has multiple relations for reference: " + refName + " for feature: " + feature.getClassName() + ", " + feature.getIdentifier() + ", " + primaryIdent); } } else if (cld.getCollectionDescriptorByName(refName, true) != null) { List<String> refIds = new ArrayList<String>(); while (parentIter.hasNext()) { refIds.add(getRefId(parentIter.next())); } feature.setCollection(refName, refIds); } else if (parentIter.hasNext()) { throw new RuntimeException("No '" + refName + "' reference/collection found in " + "class: " + clsName + " - is map configured correctly?"); } } }
&& (startCld.getCollectionDescriptorByName(refName, true) == null)) { throw new IllegalArgumentException("Cannot find descriptor for " + refName + " in " + startCld.getName());
&& (startCld.getCollectionDescriptorByName(refName, true) == null)) { throw new IllegalArgumentException("Cannot find descriptor for " + refName + " in " + startCld.getName());
public void testMultiInheritanceLegalCol() throws Exception { CollectionDescriptor coll1 = new CollectionDescriptor("atd1", "package.name.Class2", null); CollectionDescriptor coll2 = new CollectionDescriptor("atd1", "package.name.Class2", null); Set<CollectionDescriptor> colls1 = Collections.singleton(coll1); Set<CollectionDescriptor> colls2 = Collections.singleton(coll2); ClassDescriptor cld1 = new ClassDescriptor("package.name.Class1", null, true, noAttrs, noRefs, colls1); ClassDescriptor cld2 = new ClassDescriptor("package.name.Class2", null, true, noAttrs, noRefs, colls2); ClassDescriptor cld3 = makeClass("package.name.Class3", "package.name.Class1 package.name.Class2"); new Model("model", "package.name", Arrays.asList(cld1, cld2, cld3)); ReferenceDescriptor rd = cld3.getCollectionDescriptorByName("atd1", true); assertEquals("package.name.Class2", rd.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 "
queryClass); constraints.addConstraint(cc); } else if (parentClassDescriptor.getCollectionDescriptorByName(fieldName, true) != null) { LOG.info(parentClassDescriptor.getType().getSimpleName() + " -> " + fieldName
queryClass); constraints.addConstraint(cc); } else if (parentClassDescriptor.getCollectionDescriptorByName(fieldName, true) != null) { LOG.info(parentClassDescriptor.getType().getSimpleName() + " -> " + fieldName
for (CollectionDescriptor merg : merge.getCollectionDescriptors()) { CollectionDescriptor orig = original.getCollectionDescriptorByName(merg.getName());
for (CollectionDescriptor merg : merge.getCollectionDescriptors()) { CollectionDescriptor orig = original.getCollectionDescriptorByName(merg.getName());
if (reverseRefDesc == null) { reverseRefDesc = referencedClassDesc .getCollectionDescriptorByName(reverseRefName);
if (reverseRefDesc == null) { reverseRefDesc = referencedClassDesc .getCollectionDescriptorByName(reverseRefName);
@Test public void testLazyCollectionMtoN2() throws Exception { osFastCollections.flushObjectById(); FieldDescriptor fd = osFastCollections.getModel().getClassDescriptorByName( "org.intermine.model.testmodel.Company").getCollectionDescriptorByName("contractors"); Assert.assertNotNull(fd); osFastCollections.setFetchFields(true, Collections.singleton(fd)); // query for company and check contractors QueryClass c1 = new QueryClass(Company.class); Query q1 = new Query(); q1.addFrom(c1); q1.addToSelect(c1); Results r = osFastCollections.execute(q1); ResultsRow rr = (ResultsRow) r.get(0); Company c = (Company) rr.get(0); Collection coll = c.getContractors(); Assert.assertTrue("Expected " + coll.getClass() + " to be a ProxyCollection object", coll instanceof ProxyCollection); Collection matColl = ((ProxyCollection) coll).getMaterialisedCollection(); Assert.assertNull("Expected collection to not be materialised, but was: " + (matColl == null ? "" : "" + matColl.getClass()), matColl); coll = c.getDepartments(); Assert.assertTrue("Expected " + coll.getClass() + " to be a ProxyCollection object", coll instanceof ProxyCollection); matColl = ((ProxyCollection) coll).getMaterialisedCollection(); Assert.assertNotNull("Expected collection to be materialised", matColl); } }