/** * Takes a Class, and generates a Map of all FieldDescriptors that are the class fields * 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 of FieldDescriptor objects */ public Map<String, FieldDescriptor> getFieldDescriptorsForClass(Class<?> c) { synchronized (classToFieldDescriptorMap) { Map<String, FieldDescriptor> retval = classToFieldDescriptorMap.get(c); if (retval == null) { retval = new LinkedHashMap<String, FieldDescriptor>(); for (ClassDescriptor cld : getClassDescriptorsForClass(c)) { for (FieldDescriptor fd : cld.getFieldDescriptors()) { retval.put(fd.getName(), fd); } } classToFieldDescriptorMap.put(c, retval); } return retval; } }
/** * Takes a Class, and generates a Map of all FieldDescriptors that are the class fields * 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 of FieldDescriptor objects */ public Map<String, FieldDescriptor> getFieldDescriptorsForClass(Class<?> c) { synchronized (classToFieldDescriptorMap) { Map<String, FieldDescriptor> retval = classToFieldDescriptorMap.get(c); if (retval == null) { retval = new LinkedHashMap<String, FieldDescriptor>(); for (ClassDescriptor cld : getClassDescriptorsForClass(c)) { for (FieldDescriptor fd : cld.getFieldDescriptors()) { retval.put(fd.getName(), fd); } } classToFieldDescriptorMap.put(c, retval); } return retval; } }
/** * Returns true if the given field is a member of any primary key on the given class, for the * given source. * * @param model the Model in which to find ClassDescriptors * @param clazz the Class in which to look * @param fieldName the name of the field to check * @param source the Source that the keys belong to * @return true if the field is a primary key */ public static boolean fieldIsPrimaryKey(Model model, Class<?> clazz, String fieldName, Source source) { Map<PrimaryKeyCacheKey, Set<String>> cache = primaryKeyCache.get(); PrimaryKeyCacheKey key = new PrimaryKeyCacheKey(model, clazz, source); Set<String> fields = cache.get(key); if (fields == null) { fields = new HashSet<String>(); for (ClassDescriptor cld : model.getClassDescriptorsForClass(clazz)) { for (PrimaryKey pk : getPrimaryKeys(cld, source, null)) { fields.addAll(pk.getFieldNames()); } } cache.put(key, fields); } return fields.contains(fieldName); }
/** * Returns true if the given field is a member of any primary key on the given class, for the * given source. * * @param model the Model in which to find ClassDescriptors * @param clazz the Class in which to look * @param fieldName the name of the field to check * @param source the Source that the keys belong to * @return true if the field is a primary key */ public static boolean fieldIsPrimaryKey(Model model, Class<?> clazz, String fieldName, Source source) { Map<PrimaryKeyCacheKey, Set<String>> cache = primaryKeyCache.get(); PrimaryKeyCacheKey key = new PrimaryKeyCacheKey(model, clazz, source); Set<String> fields = cache.get(key); if (fields == null) { fields = new HashSet<String>(); for (ClassDescriptor cld : model.getClassDescriptorsForClass(clazz)) { for (PrimaryKey pk : getPrimaryKeys(cld, source, null)) { fields.addAll(pk.getFieldNames()); } } cache.put(key, fields); } return fields.contains(fieldName); }
Set<ClassDescriptor> classDescriptors = model.getClassDescriptorsForClass(summaryClass); for (ClassDescriptor cld : classDescriptors) { if (source == null) {
private void setClassDescriptors() throws UnknownBagTypeException { try { Class<?> cls = Class.forName(getQualifiedType()); classDescriptors = os.getModel().getClassDescriptorsForClass(cls); } catch (ClassNotFoundException e) { throw new UnknownBagTypeException("bag type " + getQualifiedType() + " not known", e); } }
private void setClassDescriptors() throws UnknownBagTypeException { try { Class<?> cls = Class.forName(getQualifiedType()); classDescriptors = os.getModel().getClassDescriptorsForClass(cls); } catch (ClassNotFoundException e) { throw new UnknownBagTypeException("bag type " + getQualifiedType() + " not known", e); } }
allPkClassesEmpty = Boolean.TRUE; Set<ClassDescriptor> classDescriptors = lookupOs.getModel() .getClassDescriptorsForClass(obj.getClass()); Iterator<ClassDescriptor> cldIter = classDescriptors.iterator(); while (cldIter.hasNext() && allPkClassesEmpty.booleanValue()) {
allPkClassesEmpty = Boolean.TRUE; Set<ClassDescriptor> classDescriptors = lookupOs.getModel() .getClassDescriptorsForClass(obj.getClass()); Iterator<ClassDescriptor> cldIter = classDescriptors.iterator(); while (cldIter.hasNext() && allPkClassesEmpty.booleanValue()) {
public void testGetClassDescriptorsForClass() throws Exception { Model model = Model.getInstanceByName("basicmodel"); Set<ClassDescriptor> cds = model.getClassDescriptorsForClass(org.intermine.model.basicmodel.Employee.class); Set<String> expectedCdNames = new HashSet<String>(); expectedCdNames.add("org.intermine.model.basicmodel.Employee"); Set<String> cdNames = new HashSet<String>(); for (ClassDescriptor cd: cds) { cdNames.add(cd.getName()); } assertEquals(expectedCdNames, cdNames); }
/** * Test whether the given type can be added to this bag, type can be a * qualified or un-qualified string. * @param testType type to check * @return true if type can be added to the bag */ public boolean isOfType(String testType) { Model model = os.getModel(); // this method works with qualified and unqualified class names ClassDescriptor testCld = model.getClassDescriptorByName(testType); if (testCld == null) { throw new IllegalArgumentException("Class not found in model: " + testType); } Set<ClassDescriptor> clds = model.getClassDescriptorsForClass(testCld .getType()); for (ClassDescriptor cld : clds) { String className = cld.getName(); if (TypeUtil.unqualifiedName(className).equals(getType())) { return true; } } return false; }
/** * Test whether the given type can be added to this bag, type can be a * qualified or un-qualified string. * @param testType type to check * @return true if type can be added to the bag */ public boolean isOfType(String testType) { Model model = os.getModel(); // this method works with qualified and unqualified class names ClassDescriptor testCld = model.getClassDescriptorByName(testType); if (testCld == null) { throw new IllegalArgumentException("Class not found in model: " + testType); } Set<ClassDescriptor> clds = model.getClassDescriptorsForClass(testCld .getType()); for (ClassDescriptor cld : clds) { String className = cld.getName(); if (TypeUtil.unqualifiedName(className).equals(getType())) { return true; } } return false; }
Model model = path.getModel(); if (path.getStartClassDescriptor() != null) { Set<ClassDescriptor> clds = model.getClassDescriptorsForClass(o.getClass()); if (!clds.contains(path.getStartClassDescriptor())) { throw new PathException("ClassDescriptor from the start of path: " + path
Model model = path.getModel(); if (path.getStartClassDescriptor() != null) { Set<ClassDescriptor> clds = model.getClassDescriptorsForClass(o.getClass()); if (!clds.contains(path.getStartClassDescriptor())) { throw new PathException("ClassDescriptor from the start of path: " + path
public void testGetDirectSubs() throws Exception { Model model = Model.getInstanceByName("basicmodel"); Set<ClassDescriptor> hasAddressCds = model.getClassDescriptorsForClass(org.intermine.model.basicmodel.Thing.class); assertEquals(1, hasAddressCds.size()); ClassDescriptor addressCld = (ClassDescriptor) hasAddressCds.iterator().next(); if (addressCld.getName() == "org.intermine.model.InterMineObject") { // we want org.intermine.model.basicmodel.HasAddress addressCld = (ClassDescriptor) hasAddressCds.iterator().next(); } Set<ClassDescriptor> resultCds = model.getDirectSubs(addressCld); Set<String> expectedCdNames = new HashSet<String>(); expectedCdNames.add("org.intermine.model.basicmodel.Employable"); expectedCdNames.add("org.intermine.model.basicmodel.Address"); expectedCdNames.add("org.intermine.model.basicmodel.Department"); Set<String> resultCdNames = new HashSet<String>(); for (ClassDescriptor cld : resultCds) { resultCdNames.add(cld.getName()); } assertEquals(expectedCdNames, resultCdNames); }
public void testGetAllSubs() throws Exception { Model model = Model.getInstanceByName("basicmodel"); Set<ClassDescriptor> hasAddressCds = model.getClassDescriptorsForClass(org.intermine.model.basicmodel.Thing.class); assertEquals(1, hasAddressCds.size()); ClassDescriptor addressCld = (ClassDescriptor) hasAddressCds.iterator().next(); if (addressCld.getName() == "org.intermine.model.InterMineObject") { // we want org.intermine.model.basicmodel.HasAddress addressCld = (ClassDescriptor) hasAddressCds.iterator().next(); } Set<ClassDescriptor> resultCds = model.getAllSubs(addressCld); Set<String> expectedCdNames = new HashSet<String>(); expectedCdNames.add("org.intermine.model.basicmodel.Employable"); expectedCdNames.add("org.intermine.model.basicmodel.Address"); expectedCdNames.add("org.intermine.model.basicmodel.Employee"); expectedCdNames.add("org.intermine.model.basicmodel.Manager"); expectedCdNames.add("org.intermine.model.basicmodel.Department"); expectedCdNames.add("org.intermine.model.basicmodel.Contractor"); Set<String> resultCdNames = new HashSet<String>(); for (ClassDescriptor cld : resultCds) { resultCdNames.add(cld.getName()); } assertEquals(expectedCdNames, resultCdNames); }
for (ClassDescriptor cld : model.getClassDescriptorsForClass(o.getClass())) { ClassDescriptor tableMaster = schema.getTableMaster(cld); String tableName = DatabaseUtil.getTableName(tableMaster);
for (ClassDescriptor cld : model.getClassDescriptorsForClass(o.getClass())) { ClassDescriptor tableMaster = schema.getTableMaster(cld); String tableName = DatabaseUtil.getTableName(tableMaster);
Query onlyQ = null; Set<ClassDescriptor> classDescriptors = model.getClassDescriptorsForClass(obj.getClass()); boolean valid = classDescriptors.isEmpty(); boolean invalid = false;
Query onlyQ = null; Set<ClassDescriptor> classDescriptors = model.getClassDescriptorsForClass(obj.getClass()); boolean valid = classDescriptors.isEmpty(); boolean invalid = false;