ODocumentEntry docEntry = entry.getValue().clone(); destination._fields.put(entry.getKey(), docEntry); docEntry.value = ODocumentHelper.cloneValue(destination, entry.getValue().value);
makeDbCall(iMyDb, new ODbRelatedCall<Object>() { public Object call(ODatabaseDocumentInternal database) { if (iCurrent.getInternalStatus() == STATUS.NOT_LOADED) makeDbCall(iOtherDb, new ODbRelatedCall<Object>() { public Object call(ODatabaseDocumentInternal database) { if (iOther.getInternalStatus() == STATUS.NOT_LOADED) makeDbCall(iMyDb, new ODbRelatedCall<Object>() { public Object call(ODatabaseDocumentInternal database) { iCurrent.checkForFields(); makeDbCall(iOtherDb, new ODbRelatedCall<Object>() { public Object call(ODatabaseDocumentInternal database) { iOther.checkForFields(); if (!compareSets(iMyDb, (Set<?>) myFieldValue, iOtherDb, (Set<?>) otherFieldValue, ridMapper)) return false; } else if (myFieldValue instanceof Collection && otherFieldValue instanceof Collection) { if (!compareCollections(iMyDb, (Collection<?>) myFieldValue, iOtherDb, (Collection<?>) otherFieldValue, ridMapper)) return false; } else if (myFieldValue instanceof ORidBag && otherFieldValue instanceof ORidBag) { if (!compareBags(iMyDb, (ORidBag) myFieldValue, iOtherDb, (ORidBag) otherFieldValue, ridMapper)) return false; } else if (myFieldValue instanceof Map && otherFieldValue instanceof Map) { if (!compareMaps(iMyDb, (Map<Object, Object>) myFieldValue, iOtherDb, (Map<Object, Object>) otherFieldValue, ridMapper)) return false; } else if (myFieldValue instanceof ODocument && otherFieldValue instanceof ODocument) { if (!hasSameContentOf((ODocument) myFieldValue, iMyDb, (ODocument) otherFieldValue, iOtherDb, ridMapper))
/** * Reads the field value forcing the return type. Use this method to force return of ORID instead of the entire document by * passing ORID.class as iFieldType. * * @param iFieldName field name * @param iFieldType Forced type. * * @return field value if defined, otherwise null */ public <RET> RET field(final String iFieldName, final Class<?> iFieldType) { RET value = this.rawField(iFieldName); if (value != null) value = ODocumentHelper.convertField(this, iFieldName, OType.getTypeByClass(iFieldType), iFieldType, value); return value; }
final Iterator<Entry<Object, Object>> myEntryIterator = makeDbCall(iMyDb, new ODbRelatedCall<Iterator<Entry<Object, Object>>>() { public Iterator<Entry<Object, Object>> call(ODatabaseDocumentInternal database) { while (makeDbCall(iMyDb, new ODbRelatedCall<Boolean>() { public Boolean call(ODatabaseDocumentInternal database) { return myEntryIterator.hasNext(); final Entry<Object, Object> myEntry = makeDbCall(iMyDb, new ODbRelatedCall<Entry<Object, Object>>() { public Entry<Object, Object> call(ODatabaseDocumentInternal database) { return myEntryIterator.next(); final Object myKey = makeDbCall(iMyDb, new ODbRelatedCall<Object>() { public Object call(ODatabaseDocumentInternal database) { return myEntry.getKey(); if (makeDbCall(iOtherDb, new ODbRelatedCall<Boolean>() { public Boolean call(ODatabaseDocumentInternal database) { return !otherMap.containsKey(myKey); if (!hasSameContentOf(makeDbCall(iMyDb, new ODbRelatedCall<ODocument>() { public ODocument call(ODatabaseDocumentInternal database) { return (ODocument) myEntry.getValue(); }), iMyDb, makeDbCall(iOtherDb, new ODbRelatedCall<ODocument>() { public ODocument call(ODatabaseDocumentInternal database) { return (ODocument) otherMap.get(myEntry.getKey()); return false;
public static boolean hasSameContentItem(final Object iCurrent, ODatabaseDocumentInternal iMyDb, final Object iOther, final ODatabaseDocumentInternal iOtherDb, RIDMapper ridMapper) { if (iCurrent instanceof ODocument) { final ODocument current = (ODocument) iCurrent; if (iOther instanceof ORID) { if (!current.isDirty()) { ORID id; if (ridMapper != null) { ORID mappedId = ridMapper.map(current.getIdentity()); if (mappedId != null) id = mappedId; else id = current.getIdentity(); } else id = current.getIdentity(); if (!id.equals(iOther)) { return false; } } else { final ODocument otherDoc = iOtherDb.load((ORID) iOther); if (!ODocumentHelper.hasSameContentOf(current, iMyDb, otherDoc, iOtherDb, ridMapper)) return false; } } else if (!ODocumentHelper.hasSameContentOf(current, iMyDb, (ODocument) iOther, iOtherDb, ridMapper)) return false; } else if (!compareScalarValues(iCurrent, iMyDb, iOther, iOtherDb, ridMapper)) return false; return true; }
if (fieldName != null && fieldName.length() > 0) { if (currentRecord != null) value = getIdentifiableValue(currentRecord, fieldName); else if (value instanceof Map<?, ?>) value = getMapEntry((Map<String, ?>) value, fieldName); else if (OMultiValue.isMultiValue(value)) { final HashSet<Object> temp = new LinkedHashSet<Object>(); for (Object o : OMultiValue.getMultiValueIterable(value, false)) { if (o instanceof OIdentifiable) { Object r = getFieldValue(o, iFieldName); if (r != null) OMultiValue.add(temp, r); final int end = findClosingBracketPosition(iFieldName, nextSeparatorPos); if (end == -1) throw new IllegalArgumentException("Missed closed ']'"); final Object index = getIndexPart(iContext, indexPart); final String indexAsString = index != null ? index.toString() : null; final Object fieldValue = getFieldValue(currentRecord, conditionFieldName); final Object index = getIndexPart(iContext, indexPart); final String indexAsString = index != null ? index.toString() : null; final Object index = getIndexPart(iContext, indexPart); final String indexAsString = index != null ? index.toString() : null; if (isFieldName(indexAsString)) {
final OIndexManager indexManagerOne = makeDbCall(databaseOne, new ODbRelatedCall<OIndexManager>() { public OIndexManager call(ODatabaseDocumentInternal database) { return database.getMetadata().getIndexManager(); final OIndexManager indexManagerTwo = makeDbCall(databaseTwo, new ODbRelatedCall<OIndexManager>() { public OIndexManager call(ODatabaseDocumentInternal database) { return database.getMetadata().getIndexManager(); final Collection<? extends OIndex<?>> indexesOne = makeDbCall(databaseOne, new ODbRelatedCall<Collection<? extends OIndex<?>>>() { public Collection<? extends OIndex<?>> call(ODatabaseDocumentInternal database) { int indexesSizeOne = makeDbCall(databaseTwo, new ODbRelatedCall<Integer>() { public Integer call(ODatabaseDocumentInternal database) { return indexesOne.size(); int indexesSizeTwo = makeDbCall(databaseTwo, new ODbRelatedCall<Integer>() { public Integer call(ODatabaseDocumentInternal database) { return indexManagerTwo.getIndexes().size(); final Iterator<? extends OIndex<?>> iteratorOne = makeDbCall(databaseOne, new ODbRelatedCall<Iterator<? extends OIndex<?>>>() { public Iterator<? extends OIndex<?>> call(ODatabaseDocumentInternal database) { return indexesOne.iterator(); while (makeDbCall(databaseOne, new ODbRelatedCall<Boolean>() { public Boolean call(ODatabaseDocumentInternal database) { return iteratorOne.hasNext(); final OIndex indexOne = makeDbCall(databaseOne, new ODbRelatedCall<OIndex<?>>() {
final Object indexPartObject = ODocumentHelper.getIndexPart(null, indexPart); final String indexAsString = indexPartObject == null ? null : indexPartObject.toString(); iPropertyValue = ODocumentHelper.convertField(this, iFieldName, fieldType, null, iPropertyValue); } else if (iPropertyValue instanceof Enum) iPropertyValue = iPropertyValue.toString();
public static void deleteCrossRefs(final ORID iRid, final ODocument iContent) { for (String fieldName : iContent.fieldNames()) { final Object fieldValue = iContent.field(fieldName); if (fieldValue != null) { if (fieldValue.equals(iRid)) { // REMOVE THE LINK iContent.field(fieldName, (ORID) null); iContent.save(); } else if (fieldValue instanceof ODocument && ((ODocument) fieldValue).isEmbedded()) { // EMBEDDED DOCUMENT: GO RECURSIVELY deleteCrossRefs(iRid, (ODocument) fieldValue); } else if (OMultiValue.isMultiValue(fieldValue)) { // MULTI-VALUE (COLLECTION, ARRAY OR MAP), CHECK THE CONTENT for (final Iterator<?> it = OMultiValue.getMultiValueIterator(fieldValue); it.hasNext(); ) { final Object item = it.next(); if (fieldValue.equals(iRid)) { // DELETE ITEM it.remove(); } else if (item instanceof ODocument && ((ODocument) item).isEmbedded()) { // EMBEDDED DOCUMENT: GO RECURSIVELY deleteCrossRefs(iRid, (ODocument) item); } } } } } }
newValue = new Date((Long) value); else if ((iFieldType == OType.EMBEDDEDSET || iFieldType == OType.LINKSET) && value instanceof List) newValue = Collections.unmodifiableSet((Set<?>) ODocumentHelper.convertField(this, iFieldName, iFieldType, null, value)); else if ((iFieldType == OType.EMBEDDEDLIST || iFieldType == OType.LINKLIST) && value instanceof Set) newValue = Collections.unmodifiableList((List<?>) ODocumentHelper.convertField(this, iFieldName, iFieldType, null, value)); else if ((iFieldType == OType.EMBEDDEDMAP || iFieldType == OType.LINKMAP) && value instanceof Map) newValue = Collections.unmodifiableMap((Map<?, ?>) ODocumentHelper.convertField(this, iFieldName, iFieldType, null, value)); else newValue = OType.convert(value, iFieldType.getDefaultJavaType());
iPropertyValue = ODocumentHelper.convertField(this, iPropetyName, fieldType, null, iPropertyValue); } else if (iPropertyValue instanceof Enum) iPropertyValue = iPropertyValue.toString();
/** * Checks and convert the field of the document matching the types specified by the class. **/ private void convertFieldsToClass(final OClass _clazz) { for (OProperty prop : _clazz.properties()) { ODocumentEntry entry = _fields != null ? _fields.get(prop.getName()) : null; if (entry != null && entry.exist()) { if (entry.type == null || entry.type != prop.getType()) { boolean preChanged = entry.changed; boolean preCreated = entry.created; ; field(prop.getName(), entry.value, prop.getType()); if (_recordId.isNew()) { entry.changed = preChanged; entry.created = preCreated; } } } else { String defValue = prop.getDefaultValue(); if (defValue != null && /*defValue.length() > 0 && */!containsField(prop.getName())) { Object curFieldValue = OSQLHelper.parseDefaultValue(this, defValue); Object fieldValue = ODocumentHelper.convertField(this, prop.getName(), prop.getType(), null, curFieldValue); rawField(prop.getName(), fieldValue, prop.getType()); } } } }