/** * INTERNAL: Compares two Collections as sets (ignoring the order of the elements). Note that the * passed Collections are cloned. Used for testing only. */ public static boolean areCollectionsEqualAsSets(Collection col1, Collection col2) { if (col1 == col2) { return true; } if (col1.size() != col2.size()) { return false; } Collection c1 = new ArrayList(col1); Collection c2 = new ArrayList(col2); for (Iterator i = c1.iterator(); i.hasNext(); ) { Object o = i.next(); c2.remove(o); } return c2.isEmpty(); }
/** INTERNAL: Transform the object-level value into a database-level value */ public Object getFieldValue(Object objectValue, AbstractSession session) { DatabaseMapping mapping = getMapping(); Object fieldValue = objectValue; if ((mapping != null) && (mapping.isDirectToFieldMapping() || mapping.isDirectCollectionMapping())) { // CR#3623207, check for IN Collection here not in mapping. if (objectValue instanceof Collection) { // This can actually be a collection for IN within expressions... however it would be better // for expressions to handle this. Collection values = (Collection) objectValue; Vector fieldValues = new Vector(values.size()); for (Iterator iterator = values.iterator(); iterator.hasNext(); ) { Object value = iterator.next(); if (!(value instanceof Expression)) { value = getFieldValue(value, session); } fieldValues.add(value); } fieldValue = fieldValues; } else { if (mapping.isDirectToFieldMapping()) { fieldValue = ((AbstractDirectMapping) mapping).getFieldValue(objectValue, session); } else if (mapping.isDirectCollectionMapping()) { fieldValue = ((DirectCollectionMapping) mapping).getFieldValue(objectValue, session); } } } return fieldValue; }