protected boolean checkForFields(final String... iFields) { if (_fields == null) _fields = _ordered ? new LinkedHashMap<>() : new HashMap<>(); if (_status == ORecordElement.STATUS.LOADED && _source != null) // POPULATE FIELDS LAZY return deserializeFields(iFields); return true; }
private Object copy(final ODocument document, final Object[] iFieldNames) { final ODocument doc = document.copy(); for (Object iFieldName : iFieldNames) { if (iFieldName != null) { final String fieldName = iFieldName.toString(); if (fieldName.endsWith("*")) { final String fieldPart = fieldName.substring(0, fieldName.length() - 1); final List<String> toExclude = new ArrayList<String>(); for (String f : doc.fieldNames()) { if (f.startsWith(fieldPart)) toExclude.add(f); } for (String f : toExclude) doc.removeField(f); } else doc.removeField(fieldName); } } doc.deserializeFields(); return doc; }
/** * Read entity from document. */ public T readEntity(final ODocument document) { checkNotNull(document); T entity = newEntity(); if (!partialLoading) { document.deserializeFields(); } try { readFields(document, entity); } catch (Exception e) { Throwables.throwIfUnchecked(e); throw new RuntimeException(e); } attachMetadata(entity, document); return entity; }
/** * Detaches all the connected records. If new records are linked to the document the detaching cannot be completed and false will * be returned. RidBag types cannot be fully detached when the database is connected using "remote" protocol. * * @return true if the record has been detached, otherwise false */ public boolean detach() { deserializeFields(); boolean fullyDetached = true; if (_fields != null) { Object fieldValue; for (Map.Entry<String, ODocumentEntry> entry : _fields.entrySet()) { fieldValue = entry.getValue().value; if (fieldValue instanceof ORecord) if (((ORecord) fieldValue).getIdentity().isNew()) fullyDetached = false; else entry.getValue().value = ((ORecord) fieldValue).getIdentity(); if (fieldValue instanceof ODetachable) { if (!((ODetachable) fieldValue).detach()) fullyDetached = false; } } } return fullyDetached; }
public Object getValue(final OIdentifiable iRecord, final Object iCurrentResult, final OCommandContext iContext) { if (iRecord == null) throw new OCommandExecutionException("expression item '" + name + "' cannot be resolved because current record is NULL"); if (preLoadedFields != null && preLoadedFields.size() == 1) { if ("@rid".equalsIgnoreCase(preLoadedFields.iterator().next())) return iRecord.getIdentity(); } final ODocument doc = (ODocument) iRecord.getRecord(); if (preLoadedFieldsArray == null && preLoadedFields != null && preLoadedFields.size() > 0 && preLoadedFields.size() < 5) { // TRANSFORM THE SET IN ARRAY ONLY THE FIRST TIME AND IF FIELDS ARE MORE THAN ONE, OTHERWISE GO WITH THE DEFAULT BEHAVIOR preLoadedFieldsArray = new String[preLoadedFields.size()]; preLoadedFields.toArray(preLoadedFieldsArray); } // UNMARSHALL THE SINGLE FIELD if (preLoadedFieldsArray != null && !doc.deserializeFields(preLoadedFieldsArray)) return null; final Object v = stringValue == null ? doc.rawField(name) : stringValue; if (!collatePreset && doc != null) { OClass schemaClass = doc.getSchemaClass(); if (schemaClass != null) { collate = getCollateForField(schemaClass, name); } } return transformValue(iRecord, iContext, v); }
protected void checkClass() { // FORCE EARLY UNMARSHALLING final ODocument doc = getRecord(); doc.deserializeFields(); final OClass cls = ODocumentInternal.getImmutableSchemaClass(doc); if (cls == null || !cls.isSubClassOf(getBaseClassName())) throw new IllegalArgumentException("The document received is not a " + getElementType() + ". Found class '" + cls + "'"); }
protected void checkClass() { // FORCE EARLY UNMARSHALLING final ODocument doc = getRecord(); doc.deserializeFields(); final OClass cls = doc.getSchemaClass(); if (cls == null || !cls.isSubClassOf(getBaseClassName())) throw new IllegalArgumentException("The document received is not a " + getElementType() + ". Found class '" + cls + "'"); }
for (OTriple<String, Direction, String> connectionField : result) fieldNames[i++] = connectionField.getKey(); doc.deserializeFields(fieldNames);
element.deserializeFields(fieldNames.toArray(new String[] {}));