@Override public Object execute(Object iThis, OIdentifiable iCurrentRecord, OCommandContext iContext, Object ioResult, Object[] iParams) { if (iThis instanceof String) { if (iParams.length > 0) { final ODocument doc = new ODocument().fromJSON(iThis.toString(), iParams[0].toString()); if (iParams[0].toString().contains("embedded")) ODocumentInternal.addOwner(doc, iCurrentRecord.getRecord()); return doc; } return new ODocument().fromJSON(iThis.toString().toString()); } return null; } }
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; }
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); } }
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); }
/** * OBJECT OR MAP. CHECK THE TYPE ATTRIBUTE TO KNOW IT. */ private Object getValueAsObjectOrMap(ODocument iRecord, String iFieldValue, OType iType, OType iLinkedType, Map<String, Character> iFieldTypes, boolean iNoMap, String iOptions) { final String[] fields = OStringParser.getWords(iFieldValue.substring(1, iFieldValue.length() - 1), ":,", true); if (fields == null || fields.length == 0) if (iNoMap) { ODocument res = new ODocument(); ODocumentInternal.addOwner(res, iRecord); return res; } else return new HashMap<String, Object>(); if (iNoMap || hasTypeField(fields)) { return getValueAsRecord(iRecord, iFieldValue, iType, iOptions, fields); } else { return getValueAsMap(iRecord, iFieldValue, iLinkedType, iFieldTypes, false, iOptions, fields); } }
private void parseCollection(ODocument iRecord, String iFieldValue, OType iType, OType iLinkedType, Map<String, Character> iFieldTypes, boolean iNoMap, String iOptions, CollectionItemVisitor visitor) { if (!iFieldValue.isEmpty()) { for (String item : OStringSerializerHelper.smartSplit(iFieldValue, ',')) { final String itemValue = item.trim(); if (itemValue.length() == 0) continue; final Object collectionItem = getValue(iRecord, null, itemValue, OIOUtils.getStringContent(itemValue), iLinkedType, null, iFieldTypes, iNoMap, iOptions); // TODO redundant in some cases, owner is already added by getValue in some cases if (shouldBeDeserializedAsEmbedded(collectionItem, iType)) ODocumentInternal.addOwner((ODocument) collectionItem, iRecord); visitor.visitItem(collectionItem); } } }
protected Object deserializeEmbeddedAsDocument(final BytesContainer bytes, final ODocument ownerDocument) { Object value = new ODocument(); deserializeWithClassName((ODocument) value, bytes); if (((ODocument) value).containsField(ODocumentSerializable.CLASS_NAME)) { String className = ((ODocument) value).field(ODocumentSerializable.CLASS_NAME); try { Class<?> clazz = Class.forName(className); ODocumentSerializable newValue = (ODocumentSerializable) clazz.newInstance(); newValue.fromDocument((ODocument) value); value = newValue; } catch (Exception e) { throw new RuntimeException(e); } } else ODocumentInternal.addOwner((ODocument) value, ownerDocument); return value; }
public ODocument getIndexChanges() { final ODocument result = new ODocument().setAllowChainedAccess(false).setTrackingChanges(false); for (Entry<String, OTransactionIndexChanges> indexEntry : indexEntries.entrySet()) { final ODocument indexDoc = new ODocument().setTrackingChanges(false); ODocumentInternal.addOwner(indexDoc, result); result.field(indexEntry.getKey(), indexDoc, OType.EMBEDDED); if (indexEntry.getValue().cleared) indexDoc.field("clear", Boolean.TRUE); final List<ODocument> entries = new ArrayList<ODocument>(); indexDoc.field("entries", entries, OType.EMBEDDEDLIST); // STORE INDEX ENTRIES for (OTransactionIndexChangesPerKey entry : indexEntry.getValue().changesPerKey.values()) { if (!entry.clientTrackOnly) entries.add(serializeIndexChangeEntry(entry, indexDoc)); } indexDoc.field("nullEntries", serializeIndexChangeEntry(indexEntry.getValue().nullKeyChanges, indexDoc)); } indexEntries.clear(); return result; }
ODocumentInternal.addOwner((ODocument) objectToAdd, (ORecordElement) coll);
ODocumentInternal.addOwner((ODocument) embeddedObject, iSourceRecord);
public static Object resolveFieldValue(final ODocument iDocument, final String iFieldName, final Object iFieldValue, final OCommandParameters iArguments, final OCommandContext iContext) { if (iFieldValue instanceof OSQLFilterItemField) { final OSQLFilterItemField f = (OSQLFilterItemField) iFieldValue; if (f.getRoot().equals("?")) // POSITIONAL PARAMETER return iArguments.getNext(); else if (f.getRoot().startsWith(":")) // NAMED PARAMETER return iArguments.getByName(f.getRoot().substring(1)); } if (iFieldValue instanceof ODocument && !((ODocument) iFieldValue).getIdentity().isValid()) // EMBEDDED DOCUMENT ODocumentInternal.addOwner((ODocument) iFieldValue, iDocument); // can't use existing getValue with iContext if (iFieldValue == null) return null; if (iFieldValue instanceof OSQLFilterItem) return ((OSQLFilterItem) iFieldValue).getValue(iDocument, null, iContext); return iFieldValue; }
ODocumentInternal.addOwner((ODocument) mapValueObject, iSourceDocument); } else mapValueObject = null;
private ORecordLazyList unserializeList(final ODocument iSourceRecord, final String value) { final ORecordLazyList coll = new ORecordLazyList(iSourceRecord); final List<String> items = OStringSerializerHelper.smartSplit(value, OStringSerializerHelper.RECORD_SEPARATOR); for (String item : items) { if (item.length() == 0) coll.add(new ORecordId()); else { if (item.startsWith("#")) coll.add(new ORecordId(item)); else { final ORecord doc = fromString(item); if (doc instanceof ODocument) ODocumentInternal.addOwner((ODocument) doc, iSourceRecord); coll.add(doc); } } } return coll; }
private ORecordLazySet unserializeSet(final ODocument iSourceRecord, final String value) { final ORecordLazySet coll = new ORecordLazySet(iSourceRecord); final List<String> items = OStringSerializerHelper.smartSplit(value, OStringSerializerHelper.RECORD_SEPARATOR); for (String item : items) { if (item.length() == 0) coll.add(new ORecordId()); else { if (item.startsWith("#")) coll.add(new ORecordId(item)); else { final ORecord doc = fromString(item); if (doc instanceof ODocument) ODocumentInternal.addOwner((ODocument) doc, iSourceRecord); coll.add(doc); } } } return coll; } }
synchronized void updateConfiguration(String type, String name, int version, OIndexDefinition indexDefinition, Set<String> clustersToIndex, String algorithm, String valueContainerAlgorithm) { document.field(OIndexInternal.CONFIG_TYPE, type); document.field(OIndexInternal.CONFIG_NAME, name); document.field(OIndexInternal.INDEX_VERSION, version); if (indexDefinition != null) { final ODocument indexDefDocument = indexDefinition.toStream(); if (!indexDefDocument.hasOwners()) ODocumentInternal.addOwner(indexDefDocument, document); document.field(OIndexInternal.INDEX_DEFINITION, indexDefDocument, OType.EMBEDDED); document.field(OIndexInternal.INDEX_DEFINITION_CLASS, indexDefinition.getClass().getName()); } else { document.removeField(OIndexInternal.INDEX_DEFINITION); document.removeField(OIndexInternal.INDEX_DEFINITION_CLASS); } document.field(CONFIG_CLUSTERS, clustersToIndex, OType.EMBEDDEDSET); document.field(ALGORITHM, algorithm); document.field(VALUE_CONTAINER_ALGORITHM, valueContainerAlgorithm); } }
private Object getValueAsRecord(ODocument iRecord, String iFieldValue, OType iType, String iOptions, String[] fields) { ORID rid = new ORecordId(OIOUtils.getStringContent(getFieldValue("@rid", fields))); boolean shouldReload = rid.isTemporary(); final ODocument recordInternal = (ODocument) fromString(iFieldValue, new ODocument(), null, iOptions, shouldReload); if (shouldBeDeserializedAsEmbedded(recordInternal, iType)) ODocumentInternal.addOwner(recordInternal, iRecord); else { ODatabaseDocument database = ODatabaseRecordThreadLocal.instance().getIfDefined(); if (rid.isPersistent() && database != null) { ODocument documentToMerge = database.load(rid); documentToMerge.merge(recordInternal, false, false); return documentToMerge; } } return recordInternal; }