mapKeyPosition = cmd.getAbsolutePositionOfMember(ammd.getKeyMetaData().getMappedBy());
}
}
// Reset column to the related field
ColumnImpl column = table.getColumnFor(cmd, ammd);
String relationshipName = column.getSelectFieldName();
Iterator<XmlObject> rel = sobject.getChildren(relationshipName);
while (rel.hasNext()) {
Iterator<XmlObject> subs = rel.next().getChildren("records");
// This is used for Native query
int[] fieldsToLoad = cmd != null ? cmd.getDFGMemberPositions() : null;
try {
while (subs.hasNext()) {
final XmlObject child = subs.next();
Object value = ec.findObjectUsingAID(new Type(ec.getClassLoaderResolver().
classForName(cmd.getFullClassName())),
ForceQueryUtils.getFieldValues2(cmd, fieldsToLoad, mconn, storeManager, child, query),
query == null ? true : query.getIgnoreCache(), true);
if (childrenColl != null) {
childrenColl.add(value);
} else {
childrenMap.put(PersistenceUtils.getMemberValue(cmd, mapKeyPosition, value), value);
}
}
} catch (Exception e) {
throw new NucleusUserException(e.getMessage(), e);
}
}
if (objectProvider != null) {
Object ret = childrenColl != null ? childrenColl : childrenMap;
return SCOUtils.newSCOInstance(objectProvider, ammd, ammd.getType(),
(ret != null ? ret.getClass() : null), ret, false, false, false);
} else {
// This is for Collection MEMBEROF and Map Key, Value, Entry operation only. The collection will be read only.
return childrenColl != null ? Collections.unmodifiableCollection(childrenColl)
: Collections.unmodifiableMap(childrenMap);
}
} else if (ammd.getEmbeddedMetaData() != null) {
return fetchEmbeddedObject(ammd);
}
ColumnImpl column = table.getColumnFor(acmd, ammd);
Object o = valueOverride != null ? valueOverride : sobject.getField(column.getSelectFieldName());
if (o == null) return null;
Calendar cal;
Object tvalue;
switch (column.getType()) {
case _boolean:
return Boolean.parseBoolean((String) o);
case _int:
case percent:
if (ammd.getType() == Long.class || ammd.getType() == long.class) {
try {
return Long.parseLong((String) o);
} catch (NumberFormatException ne) {
return Double.valueOf((String) o).longValue();
}
} else if (ammd.getType() == Short.class || ammd.getType() == short.class)
return Double.valueOf((String) o).shortValue();
else if (ammd.getType() == Float.class || ammd.getType() == float.class)
return Float.parseFloat((String) o);
else if (ammd.getType() == Double.class || ammd.getType() == double.class)
return Double.parseDouble((String) o);
else if (ammd.getType() == BigInteger.class) {
DecimalFormat f = new DecimalFormat("0.##################E0");
f.setGroupingUsed(false);
return new BigInteger(f.parse((String) o, new ParsePosition(0)).toString());
} else {
return Double.valueOf((String) o).intValue();
}
case _double:
if (ammd.getType() == Float.class || ammd.getType() == float.class) {
return Float.parseFloat((String) o);
} else {
return Double.parseDouble((String) o);
}
case currency:
return new BigDecimal((String) o, new MathContext(column.getField().getPrecision()))
.setScale(column.getField().getScale(), RoundingMode.HALF_DOWN);
case date:
tvalue = new DateCodec().deserialize((String) o).getTime();
return objectProvider != null ? SCOUtils.newSCOInstance(objectProvider, ammd, ammd.getType(),
(tvalue != null ? tvalue.getClass() : null), tvalue, false, false, false) : tvalue;
case datetime: