protected ODocumentEntry clone() { final ODocumentEntry entry = new ODocumentEntry(); entry.type = type; entry.property = property; entry.value = value; entry.changed = changed; entry.created = created; entry.exist = exist; return entry; }
protected void clearTrackData() { if (_fields != null) { // FREE RESOURCES Iterator<Entry<String, ODocumentEntry>> iter = _fields.entrySet().iterator(); while (iter.hasNext()) { Entry<String, ODocumentEntry> cur = iter.next(); if (!cur.getValue().exist()) iter.remove(); else { cur.getValue().setCreated(false); cur.getValue().setChanged(false); cur.getValue().original = null; cur.getValue().timeLine = null; if (cur.getValue().changeListener == null && cur.getValue().value instanceof OTrackedMultiValue<?, ?>) { addCollectionChangeListener(cur.getValue()); } } } } }
public void remove() { if (_trackingChanges) { if (current.getValue().isChanged()) current.getValue().original = current.getValue().value; current.getValue().value = null; current.getValue().setExist(false); current.getValue().setChanged(true); } else iterator.remove(); _fieldSize--; removeCollectionChangeListener(current.getValue(), current.getValue().value); } };
final OType oldType; if (entry == null) { entry = new ODocumentEntry(); _fieldSize++; _fields.put(iPropetyName, entry); entry.setCreated(true); knownProperty = false; oldValue = null; oldType = null; } else { knownProperty = entry.exist(); oldValue = entry.value; oldType = entry.type; if (!entry.exist()) { entry.setExist(true); _fieldSize++; if (!entry.isChanged()) { entry.original = oldValue; entry.setChanged(true);
return null; Object oldValue = entry.value; if (entry.exist() && _trackingChanges) { entry.setExist(false); entry.setChanged(true); } else { _fields.remove(iFieldName);
public boolean hasNext() { while (iterator.hasNext()) { current = iterator.next(); if (current.getValue().exist()) { read = false; return true; } } return false; }
/** * Returns list of changed fields. There are two types of changes: <ol> <li>Value of field itself was changed by calling of {@link * #field(String, Object)} method for example.</li> <li>Internal state of field was changed but was not saved. This case currently * is applicable for for collections only.</li> </ol> * * @return List of fields, values of which were changed. */ public String[] getDirtyFields() { if (_fields == null || _fields.isEmpty()) return EMPTY_STRINGS; final Set<String> dirtyFields = new HashSet<>(); for (Entry<String, ODocumentEntry> entry : _fields.entrySet()) { if (entry.getValue().isChanged() || entry.getValue().timeLine != null) dirtyFields.add(entry.getKey()); } return dirtyFields.toArray(new String[dirtyFields.size()]); }
destination._fields = _fields instanceof LinkedHashMap ? new LinkedHashMap<>() : new HashMap<>(); for (Entry<String, ODocumentEntry> entry : _fields.entrySet()) { ODocumentEntry docEntry = entry.getValue().clone(); destination._fields.put(entry.getKey(), docEntry); docEntry.value = ODocumentHelper.cloneValue(destination, entry.getValue().value);
final OType oldType; if (entry == null) { entry = new ODocumentEntry(); _fieldSize++; _fields.put(iFieldName, entry); entry.setCreated(true); knownProperty = false; oldValue = null; oldType = null; } else { knownProperty = entry.exist(); oldValue = entry.value; oldType = entry.type; if (!entry.exist()) { entry.setExist(true); _fieldSize++; if (!entry.isChanged()) { entry.original = oldValue; entry.setChanged(true);
return null; Object oldValue = entry.value; if (entry.exist() && _trackingChanges) { entry.setExist(false); entry.setChanged(true); } else { _fields.remove(iFieldName);
/** * Checks if a field exists. * * @return True if exists, otherwise false. */ public boolean containsField(final String iFieldName) { if (iFieldName == null) return false; checkForLoading(); checkForFields(iFieldName); ODocumentEntry entry = _fields.get(iFieldName); return entry != null && entry.exist(); }
public void onAfterRecordChanged(final OMultiValueChangeEvent<K, V> event) { ODocument document = oDocument.get(); if (document == null) //doc not alive anymore, do nothing. return; if (document.getInternalStatus() != STATUS.UNMARSHALLING) { if (event.isChangesOwnerContent()) document.setDirty(); else document.setDirtyNoChanged(); } if (!(document._trackingChanges && document.getIdentity().isValid()) || document.getInternalStatus() == STATUS.UNMARSHALLING) return; if (entry == null || entry.isChanged()) return; if (entry.timeLine == null) { entry.timeLine = new OMultiValueChangeTimeLine<Object, Object>(); } entry.timeLine.addCollectionChangeEvent((OMultiValueChangeEvent<Object, Object>) event); } }
/** * Enabled or disabled the tracking of changes in the document. This is needed by some triggers like {@link * com.orientechnologies.orient.core.index.OClassIndexManager} to determine what fields are changed to update indexes. * * @param iTrackingChanges True to enable it, otherwise false * * @return this */ public ODocument setTrackingChanges(final boolean iTrackingChanges) { this._trackingChanges = iTrackingChanges; if (!iTrackingChanges && _fields != null) { // FREE RESOURCES Iterator<Entry<String, ODocumentEntry>> iter = _fields.entrySet().iterator(); while (iter.hasNext()) { Entry<String, ODocumentEntry> cur = iter.next(); if (!cur.getValue().exist()) iter.remove(); else { cur.getValue().setCreated(false); cur.getValue().setChanged(false); cur.getValue().original = null; cur.getValue().timeLine = null; } } removeAllCollectionChangeListeners(); } else { addAllMultiValueChangeListeners(); } return this; }
@Override public Set<String> getPropertyNames() { checkForLoading(); if (_status == ORecordElement.STATUS.LOADED && _source != null && ODatabaseRecordThreadLocal.instance().isDefined() && !ODatabaseRecordThreadLocal.instance().get().isClosed()) { // DESERIALIZE FIELD NAMES ONLY (SUPPORTED ONLY BY BINARY SERIALIZER) final String[] fieldNames = _recordFormat.getFieldNamesRoot(this, _source); if (fieldNames != null) { Set<String> result = new HashSet<>(); Collections.addAll(result, fieldNames); return result; } } checkForFields(); if (_fields == null || _fields.size() == 0) return Collections.EMPTY_SET; return _fields.entrySet().stream().filter(s -> s.getValue().exist()).map(Entry::getKey).collect(Collectors.toSet()); }
protected ODocumentEntry getOrCreate(String key) { ODocumentEntry entry = _fields.get(key); if (entry == null) { entry = new ODocumentEntry(); _fieldSize++; _fields.put(key, entry); } return entry; }
public <RET> RET rawField(final String iFieldName) { if (iFieldName == null || iFieldName.length() == 0) return null; checkForLoading(); if (!checkForFields(iFieldName)) // NO FIELDS return null; // OPTIMIZATION if (!_allowChainedAccess || (iFieldName.charAt(0) != '@' && OStringSerializerHelper.indexOf(iFieldName, 0, '.', '[') == -1)) { ODocumentEntry entry = _fields.get(iFieldName); if (entry != null && entry.exist()) return (RET) entry.value; else return null; } // NOT FOUND, PARSE THE FIELD NAME return (RET) ODocumentHelper.getFieldValue(this, iFieldName); }
/** * Returns the set of field names. */ public String[] fieldNames() { checkForLoading(); if (_status == ORecordElement.STATUS.LOADED && _source != null && ODatabaseRecordThreadLocal.instance().isDefined() && !ODatabaseRecordThreadLocal.instance().get().isClosed()) { // DESERIALIZE FIELD NAMES ONLY (SUPPORTED ONLY BY BINARY SERIALIZER) final String[] fieldNames = _recordFormat.getFieldNamesRoot(this, _source); if (fieldNames != null) return fieldNames; } checkForFields(); if (_fields == null || _fields.size() == 0) return EMPTY_STRINGS; final List<String> names = new ArrayList<>(_fields.size()); for (Entry<String, ODocumentEntry> entry : _fields.entrySet()) { if (entry.getValue().exist()) names.add(entry.getKey()); } return names.toArray(new String[names.size()]); }
if (!field.getValue().exist()) { continue;
for (Entry<String, ODocumentEntry> entry : fields) { ODocumentEntry docEntry = entry.getValue(); if (!docEntry.exist()) continue; writeString(bytes, entry.getKey());