/** * * @param fpo fastpath object * @param path path * @return object */ public static Object resolveValue(FastPathObject fpo, String path) { FastPathObject o = fpo; String[] parts = path.split("\\."); Object res = null; for (int i = 0; i < parts.length; i++) { if (o == null) { return res; } try { res = o.getFieldValue(parts[i]); } catch (IllegalAccessException e) { throw new ServiceException("Could not read object value.", e); } if (i + 1 < parts.length && res instanceof FastPathObject) { o = (FastPathObject) res; } } return res; } }
Class<?> expectedType = retval.getFieldType(fieldName); if ((value instanceof Long) && Date.class.equals(expectedType)) { value = new Date(((Long) value).longValue()); retval.setFieldValue(fieldName, value); } catch (Exception e) { throw new IllegalArgumentException(e); (InterMineObject) retval, cd.getName(), cd.getReferencedClassDescriptor() .getType()); retval.setFieldValue(cd.getName(), lazyColl); } else if (fd instanceof ReferenceDescriptor) { ReferenceDescriptor rd = (ReferenceDescriptor) fd; (Class) rd.getReferencedClassDescriptor().getType(); if (id == null) { retval.setFieldValue(fieldName, null); } else { retval.setFieldValue(fieldName, new ProxyReference(os, id, refType));
switch (field.relationType()) { case FieldDescriptor.NOT_RELATION: Object value = srcObj.getFieldValue(fieldName); if (value instanceof ClobAccess) { dest.setFieldValue(fieldName, value); dest.setFieldValue(fieldName, value); dest.getClass(), fieldName, source)) { if (type == FROM_DB) { dest.setFieldValue(fieldName, srcObj.getFieldProxy(fieldName)); } else { InterMineObject sourceTarget = (InterMineObject) srcObj.getFieldProxy(fieldName); if (sourceTarget instanceof ProxyReference) { if (idMap.get(sourceTarget.getId()) == null) { long time2 = System.currentTimeMillis(); timeSpentRecursing += time2 - time1; dest.setFieldValue(fieldName, target); case FieldDescriptor.ONE_ONE_RELATION: if ((type == FROM_DB) || (type == SOURCE)) { InterMineObject loser = (InterMineObject) dest.getFieldValue(fieldName); ReferenceDescriptor reverseRef = ((ReferenceDescriptor) field) .getReverseReferenceDescriptor(); target = (InterMineObject) srcObj.getFieldProxy(fieldName);
Class<?> attrClass; try { attrClass = obj.getFieldType(attrName); if (attrClass == null) { String message = "Class '" + attrClass + "' not found for " obj.setFieldValue(attr.getName(), new PendingClob(attr.getValue())); } else { String value = attr.getValue(); if (value != null) { obj.setFieldValue(attr.getName(), TypeUtil.stringToObject(attrClass, value)); } else { obj.setFieldValue("id", TypeUtil.stringToObject(Integer.class, item.getIdentifier())); Class<?> refClass; try { refClass = obj.getFieldType(refName); } catch (IllegalArgumentException e) { String message = "Field " + ref.getName() + " not found in " } else { try { obj.setFieldValue(ref.getName(), refObj); } catch (IllegalArgumentException e) { if (abortOnError) {
objToPopulate.setFieldValue(collectionName, substituteCollection);
FastPathObject o = (FastPathObject) row.get(startingPoint); try { InterMineObject ref = (InterMineObject) o.getFieldProxy(qope.getFieldName()); if (ref != null) { idsToFetch.add(ref.getId()); Integer refId = null; try { InterMineObject ref = (InterMineObject) o.getFieldProxy(qope.getFieldName()); if (ref != null) { refId = ref.getId();
switch (field.relationType()) { case FieldDescriptor.NOT_RELATION: Object value = srcObj.getFieldValue(fieldName); if (value instanceof ClobAccess) { dest.setFieldValue(fieldName, value); dest.setFieldValue(fieldName, value); dest.getClass(), fieldName, source)) { if (type == FROM_DB) { dest.setFieldValue(fieldName, srcObj.getFieldProxy(fieldName)); } else { InterMineObject sourceTarget = (InterMineObject) srcObj.getFieldProxy(fieldName); if (sourceTarget instanceof ProxyReference) { if (idMap.get(sourceTarget.getId()) == null) { long time2 = System.currentTimeMillis(); timeSpentRecursing += time2 - time1; dest.setFieldValue(fieldName, target); case FieldDescriptor.ONE_ONE_RELATION: if ((type == FROM_DB) || (type == SOURCE)) { InterMineObject loser = (InterMineObject) dest.getFieldValue(fieldName); ReferenceDescriptor reverseRef = ((ReferenceDescriptor) field) .getReverseReferenceDescriptor(); target = (InterMineObject) srcObj.getFieldProxy(fieldName);
Class<?> attrClass; try { attrClass = obj.getFieldType(attrName); if (attrClass == null) { String message = "Class '" + attrClass + "' not found for " obj.setFieldValue(attr.getName(), new PendingClob(attr.getValue())); } else { String value = attr.getValue(); if (value != null) { obj.setFieldValue(attr.getName(), TypeUtil.stringToObject(attrClass, value)); } else { obj.setFieldValue("id", TypeUtil.stringToObject(Integer.class, item.getIdentifier())); Class<?> refClass; try { refClass = obj.getFieldType(refName); } catch (IllegalArgumentException e) { String message = "Field " + ref.getName() + " not found in " } else { try { obj.setFieldValue(ref.getName(), refObj); } catch (IllegalArgumentException e) { if (abortOnError) {
objToPopulate.setFieldValue(collectionName, substituteCollection);
FastPathObject o = (FastPathObject) row.get(startingPoint); try { InterMineObject ref = (InterMineObject) o.getFieldProxy(qope.getFieldName()); if (ref != null) { idsToFetch.add(ref.getId()); Integer refId = null; try { InterMineObject ref = (InterMineObject) o.getFieldProxy(qope.getFieldName()); if (ref != null) { refId = ref.getId();
FieldDescriptor field = fieldEntry.getValue(); if (field.relationType() == FieldDescriptor.M_N_RELATION) { Object sr = o.getFieldValue(fieldName); if (sr instanceof SingletonResults) { Query existingQ = ((SingletonResults) sr).getQuery(); || (field.relationType() == FieldDescriptor .N_ONE_RELATION)) { Object proxyObj = o.getFieldProxy(fieldName); if (proxyObj instanceof ProxyReference) { Integer id = ((ProxyReference) proxyObj).getId(); idToObj.get(id); if (objToAdd != null) { objToPopulate.setFieldValue(collectionName, objToAdd);
/** * * @param fpo fastpath object * @param path path * @return object */ public static Object resolveValue(FastPathObject fpo, String path) { FastPathObject o = fpo; String[] parts = path.split("\\."); Object res = null; for (int i = 0; i < parts.length; i++) { if (o == null) { return res; } try { res = o.getFieldValue(parts[i]); } catch (IllegalAccessException e) { throw new ServiceException("Could not read object value.", e); } if (i + 1 < parts.length && res instanceof FastPathObject) { o = (FastPathObject) res; } } return res; } }
public void testGetKeyFieldValue() throws Exception { Map<String, List<FieldDescriptor>> classKeys = getClassKeys(); // class keys for Company: name, vatNumber FastPathObject obj = DynamicUtil.instantiateObject("org.intermine.model.testmodel.Company", null); obj.setFieldValue("vatNumber", 1234); assertEquals(1234, ClassKeyHelper.getKeyFieldValue(obj, classKeys)); obj.setFieldValue("name", "CompanyA"); assertEquals("CompanyA", ClassKeyHelper.getKeyFieldValue(obj, classKeys)); FastPathObject manager = DynamicUtil.instantiateObject("org.intermine.model.testmodel.Manager", null); assertEquals(null, ClassKeyHelper.getKeyFieldValue(manager, classKeys)); manager.setFieldValue("title", "Sir"); assertEquals("Sir", ClassKeyHelper.getKeyFieldValue(manager, classKeys)); manager.setFieldValue("name", "Geoff"); assertEquals("Geoff", ClassKeyHelper.getKeyFieldValue(manager, classKeys)); }
Class<?> expectedType = retval.getFieldType(fieldName); if ((value instanceof Long) && Date.class.equals(expectedType)) { value = new Date(((Long) value).longValue()); retval.setFieldValue(fieldName, value); } catch (Exception e) { throw new IllegalArgumentException(e); (InterMineObject) retval, cd.getName(), cd.getReferencedClassDescriptor() .getType()); retval.setFieldValue(cd.getName(), lazyColl); } else if (fd instanceof ReferenceDescriptor) { ReferenceDescriptor rd = (ReferenceDescriptor) fd; (Class) rd.getReferencedClassDescriptor().getType(); if (id == null) { retval.setFieldValue(fieldName, null); } else { retval.setFieldValue(fieldName, new ProxyReference(os, id, refType));
FieldDescriptor field = fieldEntry.getValue(); if (field.relationType() == FieldDescriptor.M_N_RELATION) { Object sr = o.getFieldValue(fieldName); if (sr instanceof SingletonResults) { Query existingQ = ((SingletonResults) sr).getQuery(); || (field.relationType() == FieldDescriptor .N_ONE_RELATION)) { Object proxyObj = o.getFieldProxy(fieldName); if (proxyObj instanceof ProxyReference) { Integer id = ((ProxyReference) proxyObj).getId(); idToObj.get(id); if (objToAdd != null) { objToPopulate.setFieldValue(collectionName, objToAdd);
/** * Get a list of key field values for the given object. This will return null if there are no * key fields for the object's class or if there are no non-null values for the key fields. * The key fields are kept in a consistent order with inherited fields appearing before those * defined in a subclass. * @param obj an object from the model * @param classKeys the key field definition for this model * @return the first available key field value or null */ public static List<Object> getKeyFieldValues(FastPathObject obj, Map<String, List<FieldDescriptor>> classKeys) { String clsName = DynamicUtil.getSimpleClass(obj).getSimpleName(); List<Object> fieldValueList = new ArrayList<Object>(); try { for (String keyField : getKeyFieldNames(classKeys, clsName)) { Object valueFromObject = obj.getFieldValue(keyField); if (valueFromObject != null) { fieldValueList.add(valueFromObject); } } return fieldValueList; } catch (IllegalAccessException e) { // this shouldn't happen because objects conform to the model LOG.error("Error fetching a key field value from object: " + obj); } return null; } }
obj.setFieldValue("id", identifierToId(item.getIdentifier())); } catch (IllegalArgumentException e) { + ") for item with id " + item.getIdentifier() + " was null"); obj.setFieldValue(attr.getName(), value); obj.setFieldValue(refName, new ProxyReference(os, identifier, InterMineObject.class)); } else { obj.setFieldValue(refsName, os.executeSingleton(q)); } else { String message = "Collection not found in class: "
/** * Get a key field value for the given object. This will return null if there are no key fields * for the object's class or if there are no non-null values for the key fields. The key fields * are kept in a consistent order with inherited fields appearing before those defined in a * subclass. * @param obj an object from the model * @param classKeys the key field definition for this model * @return the first available key field value or null */ public static Object getKeyFieldValue(FastPathObject obj, Map<String, List<FieldDescriptor>> classKeys) { String clsName = DynamicUtil.getSimpleClass(obj).getSimpleName(); try { for (String keyField : getKeyFieldNames(classKeys, clsName)) { Object valueFromObject = obj.getFieldValue(keyField); if (valueFromObject != null) { return valueFromObject; } } } catch (IllegalAccessException e) { // this shouldn't happen because objects conform to the model LOG.error("Error fetching a key field value from object: " + obj); } return null; }
obj.setFieldValue("id", identifierToId(item.getIdentifier())); } catch (IllegalArgumentException e) { + ") for item with id " + item.getIdentifier() + " was null"); obj.setFieldValue(attr.getName(), value); obj.setFieldValue(refName, new ProxyReference(os, identifier, InterMineObject.class)); } else { obj.setFieldValue(refsName, os.executeSingleton(q)); } else { String message = "Collection not found in class: "
/** * Constructs a new ResultCell object * @param imObj the InterMineObject or SimpleObject to wrap * @param path the Path * @param isKeyField should be true if this is an identifying field */ public ResultElement(FastPathObject imObj, Path path, boolean isKeyField) { this.imObj = imObj; this.keyField = isKeyField; this.path = path; if (imObj != null) { try { field = imObj.getFieldValue(path.getEndFieldDescriptor().getName()); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } else { field = null; } }