public void addEntry(final OIdentifiable identifiable) { if (entries.length == entriesLength) { if (entriesLength == 0) { final int cfgValue = OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.getValueAsInteger(); entries = new Object[cfgValue > 0 ? Math.min(cfgValue, 40) : 40]; } else { final Object[] oldEntries = entries; entries = new Object[entries.length << 1]; System.arraycopy(oldEntries, 0, entries, 0, oldEntries.length); } } if (this.owner != null) ORecordInternal.track(this.owner, identifiable); entries[entriesLength] = identifiable; entriesLength++; }
public void convertLinks2Records() { final Iterator<Entry<OIdentifiable, Object>> all = map.entrySet().iterator(); while (all.hasNext()) { Entry<OIdentifiable, Object> entry = all.next(); if (entry.getValue() == ENTRY_REMOVAL) { try { ORecord record = entry.getKey().getRecord(); if (record != null) { ORecordInternal.unTrack(sourceRecord, entry.getKey()); ORecordInternal.track(sourceRecord, record); } entry.setValue(record); } catch (ORecordNotFoundException ignore) { // IGNORE THIS } } } }
@Override public void setOwner(ORecord owner) { if (owner != null && this.owner != null && !this.owner.equals(owner)) { throw new IllegalStateException("This data structure is owned by document " + owner + " if you want to use it in other document create new rid bag instance and copy content of current one."); } if (this.owner != null) { for (int i = 0; i < entriesLength; i++) { final Object entry = entries[i]; if (entry instanceof OIdentifiable) { ORecordInternal.unTrack(this.owner, (OIdentifiable) entry); } } } this.owner = owner; if (this.owner != null) { for (int i = 0; i < entriesLength; i++) { final Object entry = entries[i]; if (entry instanceof OIdentifiable) { ORecordInternal.track(this.owner, (OIdentifiable) entry); } } } }
@Override public void convertLinks2Records() { TreeMap<OIdentifiable, Change> newChanges = new TreeMap<>(); for (Map.Entry<OIdentifiable, Change> entry : changes.entrySet()) { final OIdentifiable key = entry.getKey().getRecord(); if (key != null && this.owner != null) { ORecordInternal.unTrack(this.owner, entry.getKey()); ORecordInternal.track(this.owner, key); } newChanges.put((key == null) ? entry.getKey() : key, entry.getValue()); } changes.clear(); changes.putAll(newChanges); }
public boolean add(final OIdentifiable e) { if (map.containsKey(e)) return false; map.put(e, ENTRY_REMOVAL); setDirty(); ORecordInternal.track(sourceRecord, e); if (e instanceof ODocument) ODocumentInternal.addOwner((ODocument) e, this); fireCollectionChangedEvent(new OMultiValueChangeEvent<OIdentifiable, OIdentifiable>(OMultiValueChangeEvent.OChangeType.ADD, e, e)); return true; }
@Override public void convertLinks2Records() { for (int i = 0; i < entriesLength; i++) { final Object entry = entries[i]; if (entry instanceof OIdentifiable) { final OIdentifiable identifiable = (OIdentifiable) entry; ORecord record = identifiable.getRecord(); if (record != null) { if (this.owner != null) { ORecordInternal.unTrack(this.owner, identifiable); ORecordInternal.track(this.owner, record); } entries[i] = record; } } } }
private void addOwnerToEmbeddedDoc(T e) { if (embeddedCollection && e instanceof ODocument && !((ODocument) e).getIdentity().isValid()) { ODocumentInternal.addOwner((ODocument) e, this); } if (e instanceof ODocument) ORecordInternal.track(sourceRecord, (ODocument) e); }
private void addOwnerToEmbeddedDoc(T e) { if (embeddedCollection && e instanceof ODocument && !((ODocument) e).getIdentity().isValid()) ODocumentInternal.addOwner((ODocument) e, this); if (e instanceof ODocument) ORecordInternal.track(sourceRecord, (ODocument) e); }
private void addOwnerToEmbeddedDoc(T e) { if (embeddedCollection && e instanceof ODocument && !((ODocument) e).getIdentity().isValid()) { ODocumentInternal.addOwner((ODocument) e, this); ORecordInternal.track(sourceRecord, (ODocument) e); } }
@Override public boolean add(OIdentifiable e) { if (map.containsKey(e)) return false; if (e == null) map.put(null, null); else if (e instanceof ORecord && e.getIdentity().isNew()) { ORecordInternal.addIdentityChangeListener((ORecord) e, this); ORecordInternal.track(sourceRecord, e); map.put(e, e); } else if (!e.getIdentity().isPersistent()) { ORecordInternal.track(sourceRecord, e); map.put(e, e); } else map.put(e, ENTRY_REMOVAL); setDirty(); fireCollectionChangedEvent( new OMultiValueChangeEvent<OIdentifiable, OIdentifiable>(OMultiValueChangeEvent.OChangeType.ADD, e, e)); return true; }
@Override public OIdentifiable next() { Entry<OIdentifiable, Object> entry = iter.next(); last = entry; if (entry.getValue() != ENTRY_REMOVAL) return (OIdentifiable) entry.getValue(); if (entry.getKey() instanceof ORecordId && autoConvertToRecord && ODatabaseRecordThreadLocal.instance().isDefined()) { try { final ORecord rec = entry.getKey().getRecord(); if (sourceRecord != null && rec != null) ORecordInternal.track(sourceRecord, rec); if (iter instanceof OLazyIterator<?>) { ((OLazyIterator<Entry<OIdentifiable, Object>>) iter).update(entry); } last = entry; } catch (Exception e) { OLogManager.instance().error(this, "Error on iterating record collection", e); entry = null; } } return entry == null ? null : entry.getKey(); }
@Override public void setOwner(ORecord owner) { if (owner != null && this.owner != null && !this.owner.equals(owner)) { throw new IllegalStateException("This data structure is owned by document " + owner + " if you want to use it in other document create new rid bag instance and copy content of current one."); } if (this.owner != null) { for (OIdentifiable entry : newEntries.keySet()) { ORecordInternal.unTrack(this.owner, entry); } for (OIdentifiable entry : changes.keySet()) { ORecordInternal.unTrack(this.owner, entry); } } this.owner = owner; if (this.owner != null) { for (OIdentifiable entry : newEntries.keySet()) { ORecordInternal.track(this.owner, entry); } for (OIdentifiable entry : changes.keySet()) { ORecordInternal.track(this.owner, entry); } } }
ORecordInternal.track(this.owner, identifiable);
@SuppressWarnings("unchecked") public OIdentifiable next() { OIdentifiable value = underlying.next(); if (value == null) return null; if (value instanceof ORecordId && autoConvert2Record && ODatabaseRecordThreadLocal.instance().isDefined()) { try { final ORecord rec = ((ORecordId) value).getRecord(); if (sourceRecord != null && rec != null) ORecordInternal.track(sourceRecord, rec); if (underlying instanceof OLazyIterator<?>) ((OLazyIterator<OIdentifiable>) underlying).update(rec); value = rec; } catch (Exception e) { OLogManager.instance().error(this, "Error on iterating record collection", e); value = null; } } return value; }
if(record != null){ ORecordInternal.unTrack(sourceRecord, rid); ORecordInternal.track(sourceRecord, record);
@Override public void add(int index, OIdentifiable e) { if (e != null) { ORecordInternal.track(sourceRecord, e); if ((ridOnly || contentType == MULTIVALUE_CONTENT_TYPE.ALL_RIDS) && e.getIdentity().isPersistent() && (e instanceof ODocument && !((ODocument) e).isDirty())) // IT'S BETTER TO LEAVE ALL RIDS AND EXTRACT ONLY THIS ONE e = e.getIdentity(); else contentType = ORecordMultiValueHelper.updateContentType(contentType, e); } lazyLoad(true); super.add(index, e); }
@Override public OIdentifiable set(int index, OIdentifiable e) { lazyLoad(true); if (e != null) { ORecordInternal.track(sourceRecord, e); if (e != null) if ((ridOnly || contentType == MULTIVALUE_CONTENT_TYPE.ALL_RIDS) && e.getIdentity().isPersistent() && ( e instanceof ODocument && !((ODocument) e).isDirty())) // IT'S BETTER TO LEAVE ALL RIDS AND EXTRACT ONLY THIS ONE e = e.getIdentity(); else contentType = ORecordMultiValueHelper.updateContentType(contentType, e); } return super.set(index, e); }
/** * Convert the item requested from link to record. * * @param iIndex Position of the item to convert */ private void convertLink2Record(final int iIndex) { if (ridOnly || !autoConvertToRecord) // PRECONDITIONS return; final OIdentifiable o = super.get(iIndex); if (contentType == MULTIVALUE_CONTENT_TYPE.ALL_RECORDS && !o.getIdentity().isNew()) // ALL RECORDS AND THE OBJECT IS NOT NEW, DO NOTHING return; if (o != null && o instanceof ORecordId) { final ORecordId rid = (ORecordId) o; marshalling = true; try { ORecord record = rid.getRecord(); if (record != null) { ORecordInternal.unTrack(sourceRecord, rid); ORecordInternal.track(sourceRecord, record); } super.set(iIndex, record); } catch (ORecordNotFoundException ignore) { // IGNORE THIS } finally { marshalling = false; } } }