/** * Creates a friendly description of an object - that is, the class and the ID (if it has one). * * @param o the object to be described * @return a String description */ public static String getFriendlyDesc(Object o) { if (o instanceof InterMineObject) { return Util.getFriendlyName(o.getClass()) + ":" + ((InterMineObject) o).getId(); } else { return o.toString(); } }
/** * Creates a friendly description of an object - that is, the class and the ID (if it has one). * * @param o the object to be described * @return a String description */ public static String getFriendlyDesc(Object o) { if (o instanceof InterMineObject) { return Util.getFriendlyName(o.getClass()) + ":" + ((InterMineObject) o).getId(); } else { return o.toString(); } }
/** * Returns the result of decomposeClass if that is a single class, or throws an exception if * there are more than one. * * @param clazz the class * @return the corresponding non-dynamic class */ @SuppressWarnings("unchecked") public static Class<? extends FastPathObject> getSimpleClass( Class<? extends FastPathObject> clazz) { Set<Class<?>> decomposed = Util.decomposeClass(clazz); if (decomposed.size() > 1) { throw new IllegalArgumentException("No simple class for " + Util.getFriendlyName(clazz)); } return (Class) decomposed.iterator().next(); }
/** * Returns the result of decomposeClass if that is a single class, or throws an exception if * there are more than one. * * @param clazz the class * @return the corresponding non-dynamic class */ @SuppressWarnings("unchecked") public static Class<? extends FastPathObject> getSimpleClass( Class<? extends FastPathObject> clazz) { Set<Class<?>> decomposed = Util.decomposeClass(clazz); if (decomposed.size() > 1) { throw new IllegalArgumentException("No simple class for " + Util.getFriendlyName(clazz)); } return (Class) decomposed.iterator().next(); }
/** * Returns the simple class name for the given class or throws an exception if * there are more than one. * @param clazz the class * @return the simple class name */ public static synchronized String getSimpleClassName(Class<?> clazz) { String retval = simpleNameMap.get(clazz); if (retval == null) { Set<Class<?>> decomposedClass = Util.decomposeClass(clazz); if (decomposedClass.size() > 1) { throw new IllegalArgumentException("No simple name for class: " + Util.getFriendlyName(clazz)); } else { retval = decomposedClass.iterator().next().getName(); simpleNameMap.put(clazz, retval); } } return retval; }
/** * Returns the simple class name for the given class or throws an exception if * there are more than one. * @param clazz the class * @return the simple class name */ public static synchronized String getSimpleClassName(Class<?> clazz) { String retval = simpleNameMap.get(clazz); if (retval == null) { Set<Class<?>> decomposedClass = Util.decomposeClass(clazz); if (decomposedClass.size() > 1) { throw new IllegalArgumentException("No simple name for class: " + Util.getFriendlyName(clazz)); } else { retval = decomposedClass.iterator().next().getName(); simpleNameMap.put(clazz, retval); } } return retval; }
/** * Constructs a QueryClass representing the specified set of classes and ObjectStoreBag. * * @param types the Set of classes * @param osb the ObjectStoreBag */ public QueryClassBag(Set<Class<?>> types, ObjectStoreBag osb) { Class<?> clazz; if (types.size() == 1) { clazz = types.iterator().next(); } else { clazz = DynamicUtil.composeClass(types); } if (!InterMineObject.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("Cannot create a QueryClassBag with a class that" + " is not a subclass of InterMineObject: " + Util.getFriendlyName( clazz)); } @SuppressWarnings("unchecked") Class<? extends InterMineObject> thisType = (Class) clazz; this.type = thisType; this.osb = osb; this.ids = null; this.bag = null; }
/** * Constructs a QueryClass representing the specified set of classes and ObjectStoreBag. * * @param types the Set of classes * @param osb the ObjectStoreBag */ public QueryClassBag(Set<Class<?>> types, ObjectStoreBag osb) { Class<?> clazz; if (types.size() == 1) { clazz = types.iterator().next(); } else { clazz = DynamicUtil.composeClass(types); } if (!InterMineObject.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("Cannot create a QueryClassBag with a class that" + " is not a subclass of InterMineObject: " + Util.getFriendlyName( clazz)); } @SuppressWarnings("unchecked") Class<? extends InterMineObject> thisType = (Class) clazz; this.type = thisType; this.osb = osb; this.ids = null; this.bag = null; }
/** * Adds an element to a public or protected collection of an Object given the field name. * * @param o the Object * @param fieldName the name of the relevant collection * @param element the element to add to the collection */ public static void addCollectionElement(Object o, String fieldName, Object element) { try { getAdder(o.getClass(), fieldName).invoke(o, element); } catch (Exception e) { String type = null; try { type = getFieldInfo(o.getClass(), fieldName).getElementType().getName(); } catch (Exception e3) { IllegalArgumentException e2 = new IllegalArgumentException("Couldn't add element to" + " collection \"" + Util.getFriendlyName(o.getClass()) + "." + fieldName + "\"" + " - not an accessible collection"); e2.initCause(e); throw e2; } IllegalArgumentException e2 = new IllegalArgumentException("Couldn't add element to" + " collection \"" + Util.getFriendlyName(o.getClass()) + "." + fieldName + "\"" + " (a " + type + ") with \"" + element + "\" (a " + element.getClass().getName() + ")"); e2.initCause(e); throw e2; } }
/** * Adds an element to a public or protected collection of an Object given the field name. * * @param o the Object * @param fieldName the name of the relevant collection * @param element the element to add to the collection */ public static void addCollectionElement(Object o, String fieldName, Object element) { try { getAdder(o.getClass(), fieldName).invoke(o, element); } catch (Exception e) { String type = null; try { type = getFieldInfo(o.getClass(), fieldName).getElementType().getName(); } catch (Exception e3) { IllegalArgumentException e2 = new IllegalArgumentException("Couldn't add element to" + " collection \"" + Util.getFriendlyName(o.getClass()) + "." + fieldName + "\"" + " - not an accessible collection"); e2.initCause(e); throw e2; } IllegalArgumentException e2 = new IllegalArgumentException("Couldn't add element to" + " collection \"" + Util.getFriendlyName(o.getClass()) + "." + fieldName + "\"" + " (a " + type + ") with \"" + element + "\" (a " + element.getClass().getName() + ")"); e2.initCause(e); throw e2; } }
/** * Constructs a QueryClass representing the specified set of classes and bag of objects. * * @param types the Set of classes * @param bag the Collection of objects */ public QueryClassBag(Set<Class<?>> types, Collection<?> bag) { Class<?> clazz; if (types.size() == 1) { clazz = types.iterator().next(); } else { clazz = DynamicUtil.composeClass(types); } if (!InterMineObject.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("Cannot create a QueryClassBag with a class that" + " is not a subclass of InterMineObject: " + Util.getFriendlyName( clazz)); } @SuppressWarnings("unchecked") Class<? extends InterMineObject> thisType = (Class) clazz; this.type = thisType; this.bag = bag; ids = convertToIds(bag, this.type); this.osb = null; }
/** * Constructs a QueryClass representing the specified set of classes and bag of objects. * * @param types the Set of classes * @param bag the Collection of objects */ public QueryClassBag(Set<Class<?>> types, Collection<?> bag) { Class<?> clazz; if (types.size() == 1) { clazz = types.iterator().next(); } else { clazz = DynamicUtil.composeClass(types); } if (!InterMineObject.class.isAssignableFrom(clazz)) { throw new IllegalArgumentException("Cannot create a QueryClassBag with a class that" + " is not a subclass of InterMineObject: " + Util.getFriendlyName( clazz)); } @SuppressWarnings("unchecked") Class<? extends InterMineObject> thisType = (Class) clazz; this.type = thisType; this.bag = bag; ids = convertToIds(bag, this.type); this.osb = null; }
/** * {@inheritDoc} */ @Override public InterMineObject internalGetObjectById(Integer id, Class<? extends InterMineObject> clazz) throws ObjectStoreException { InterMineObject retval = super.internalGetObjectById(id, clazz); //Exception e = new Exception("internalGetObjectById called for " // + retval.getClass().toString() + " with id " + id); //e.fillInStackTrace(); //java.io.StringWriter sw = new java.io.StringWriter(); //java.io.PrintWriter pw = new java.io.PrintWriter(sw); //e.printStackTrace(pw); //pw.flush(); //LOG.error(sw.toString()); synchronized (cache) { Exception e = new Exception(); e.fillInStackTrace(); LOG.warn("Probable inefficiency: internalGetObjectById called " + (retval == null ? "" : "to fetch a " + Util.getFriendlyName(retval .getClass())) + " with id " + id + ", clazz " + clazz.toString() + ", cache size = " + cache.size() + " - maybe you should use" + " ObjectStoreFastCollectionsForTranslatorImpl", e); } internalGetObjectByIdCount++; if (internalGetObjectByIdCount % 1000 == 0) { LOG.info("internalGetObjectById run " + internalGetObjectByIdCount + " times"); } return retval; }
/** * {@inheritDoc} */ @Override public InterMineObject internalGetObjectById(Integer id, Class<? extends InterMineObject> clazz) throws ObjectStoreException { InterMineObject retval = super.internalGetObjectById(id, clazz); //Exception e = new Exception("internalGetObjectById called for " // + retval.getClass().toString() + " with id " + id); //e.fillInStackTrace(); //java.io.StringWriter sw = new java.io.StringWriter(); //java.io.PrintWriter pw = new java.io.PrintWriter(sw); //e.printStackTrace(pw); //pw.flush(); //LOG.error(sw.toString()); synchronized (cache) { Exception e = new Exception(); e.fillInStackTrace(); LOG.warn("Probable inefficiency: internalGetObjectById called " + (retval == null ? "" : "to fetch a " + Util.getFriendlyName(retval .getClass())) + " with id " + id + ", clazz " + clazz.toString() + ", cache size = " + cache.size() + " - maybe you should use" + " ObjectStoreFastCollectionsForTranslatorImpl", e); } internalGetObjectByIdCount++; if (internalGetObjectByIdCount % 1000 == 0) { LOG.info("internalGetObjectById run " + internalGetObjectByIdCount + " times"); } return retval; }
/** * Returns the element type of a collection given the field name. * * @param c the Class * @param fieldName the name of the relevant collection * @return the class of the field, or null if the field is not found * @throws IllegalArgumentException if the field is not a collection */ public static Class<? extends FastPathObject> getElementType(Class<?> c, String fieldName) { FieldInfo info = getFieldInfo(c, fieldName); if (info != null) { try { return info.getElementType(); } catch (NullPointerException e) { IllegalArgumentException e2 = new IllegalArgumentException("Field " + Util.getFriendlyName(c) + "." + fieldName + " is not a collection"); e2.initCause(e); throw e2; } } return null; }
/** * Returns the element type of a collection given the field name. * * @param c the Class * @param fieldName the name of the relevant collection * @return the class of the field, or null if the field is not found * @throws IllegalArgumentException if the field is not a collection */ public static Class<? extends FastPathObject> getElementType(Class<?> c, String fieldName) { FieldInfo info = getFieldInfo(c, fieldName); if (info != null) { try { return info.getElementType(); } catch (NullPointerException e) { IllegalArgumentException e2 = new IllegalArgumentException("Field " + Util.getFriendlyName(c) + "." + fieldName + " is not a collection"); e2.initCause(e); throw e2; } } return null; }
+ Util.getFriendlyName(o.getClass()) + "." + fieldName + "\"" + (type == null ? "" : " (a " + type + ")") + " to \"" + fieldValue + "\" (a " + fieldValue.getClass().getName() + ")");
+ Util.getFriendlyName(o.getClass()) + "." + fieldName + "\"" + (type == null ? "" : " (a " + type + ")") + " to \"" + fieldValue + "\" (a " + fieldValue.getClass().getName() + ")");
throw new TemplatePopulatorException("The constraint of type " + path.getEndType() + " can't be set to object of type " + Util.getFriendlyName(obj.getClass()) + " in template query " + template.getName() + ".");
throw new TemplatePopulatorException("The constraint of type " + path.getEndType() + " can't be set to object of type " + Util.getFriendlyName(obj.getClass()) + " in template query " + template.getName() + ".");