public static void rawField(final ODocument oDocument, final String iFieldName, final Object iFieldValue, final OType iFieldType) { oDocument.rawField(iFieldName, iFieldValue, iFieldType); }
public static OIdentifiable getConnection(final ODocument iEdgeRecord, final Direction iDirection) { return iEdgeRecord .rawField(iDirection == Direction.OUT ? OrientBaseGraph.CONNECTION_OUT : OrientBaseGraph.CONNECTION_IN); }
public static OIdentifiable getConnection(final ODocument iEdgeRecord, final Direction iDirection) { return iEdgeRecord.rawField(iDirection == Direction.OUT ? OrientBaseGraph.CONNECTION_OUT : OrientBaseGraph.CONNECTION_IN); }
public static OIdentifiable getConnection(final ODocument iEdgeRecord, final Direction iDirection) { return iEdgeRecord.rawField(iDirection == Direction.OUT ? OrientGraphUtils.CONNECTION_OUT : OrientGraphUtils.CONNECTION_IN); }
/** * Does one last round of comparison between the (hopefully) deconflicted records. * * @since 3.14 */ protected ConflictState compare(final ODocument storedRecord, final ODocument changeRecord) { for (Entry<String, Object> property : storedRecord) { Object changeValue = changeRecord.rawField(property.getKey()); if (!Objects.equals(property.getValue(), changeValue)) { log.trace("Conflict detected in {}: {} vs {}", property.getKey(), property.getValue(), changeValue); return DENY; } } return IGNORE; // identical content, update can be ignored or allowed } }
private void detachRidbags(ORecord oldRecord) { ODocument oldDoc = (ODocument) oldRecord; for (String field : oldDoc.fieldNames()) { if (field.equalsIgnoreCase("out") || field.equalsIgnoreCase("in") || field.startsWith("out_") || field.startsWith("in_") || field.startsWith("OUT_") || field.startsWith("IN_")) { Object val = oldDoc.rawField(field); if (val instanceof ORidBag) { oldDoc.removeField(field); } } } }
@Override public List<String> getAllFiltered(String type) { try (ODatabaseDocumentTx db = docDb()) { List<ODocument> r = db.query(new OSQLSynchQuery<>(String.format("select value from Filter where type=\"%s\"", type))); return r.stream().map(o -> (String) o.rawField("value")).collect(Collectors.toList()); } }
protected Map<Object, Object> deserializeQueryParameters(final byte[] paramBuffer, ORecordSerializer serializer) { if (paramBuffer == null || paramBuffer.length == 0) return Collections.emptyMap(); final ODocument param = new ODocument(); serializer.fromStream(paramBuffer, param, null); param.setFieldType("params", OType.EMBEDDEDMAP); final Map<String, Object> params = param.rawField("params"); final Map<Object, Object> result = new HashMap<Object, Object>(); for (Entry<String, Object> p : params.entrySet()) { if (Character.isDigit(p.getKey().charAt(0))) result.put(Integer.parseInt(p.getKey()), p.getValue()); else result.put(p.getKey(), p.getValue()); } return result; }
/** * Resolves differences in cache tokens: "invalidated" always wins, non-null tokens win over null tokens. */ private static ConflictState resolveCacheToken(final ODocument storedRecord, final ODocument changeRecord) { Object storedToken = storedRecord.rawField(CACHE_TOKEN_ATTRIBUTE); Object changeToken = changeRecord.rawField(CACHE_TOKEN_ATTRIBUTE); if (Objects.equals(storedToken, changeToken)) { return IGNORE; } else if (storedToken == null || CACHE_TOKEN_INVALIDATED.equals(changeToken)) { storedRecord.field(CACHE_TOKEN_ATTRIBUTE, changeToken); return ALLOW; } else if (changeToken == null || CACHE_TOKEN_INVALIDATED.equals(storedToken)) { changeRecord.field(CACHE_TOKEN_ATTRIBUTE, storedToken); return MERGE; } return DENY; }
/** * Resolves differences in the given optional field by picking non-null values over null values. */ public static ConflictState pickNonNull(final ODocument storedRecord, final ODocument changeRecord, final String fieldName) { Object storedValue = storedRecord.rawField(fieldName); Object changeValue = changeRecord.rawField(fieldName); if (Objects.equals(storedValue, changeValue)) { return IGNORE; } else if (storedValue == null) { storedRecord.field(fieldName, changeValue); return ALLOW; } else if (changeValue == null) { changeRecord.field(fieldName, storedValue); return MERGE; } return DENY; }
/** * 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; }
@Override public ConflictState deconflict(final ODocument storedRecord, final ODocument changeRecord) { Object storedMaven = storedRecord.rawField(MAVEN_ATTRIBUTES); Object changeMaven = changeRecord.rawField(MAVEN_ATTRIBUTES); if (storedMaven != null && changeMaven != null) { // packaging is only added when the pom asset is fetched/deployed return pickNonNull(storedRecord, changeRecord, PACKAGING_ATTRIBUTE); } else if (changeMaven != null) { storedRecord.field(MAVEN_ATTRIBUTES, changeMaven); return ALLOW; } else if (storedMaven != null) { changeRecord.field(MAVEN_ATTRIBUTES, storedMaven); return MERGE; } return IGNORE; } }
public ORID getRoleRID(final String iRoleName) { if (iRoleName == null) return null; final List<ODocument> result = getDatabase().<OCommandRequest>command( new OSQLSynchQuery<ODocument>("select rid from index:ORole.name where key = ? limit 1")).execute(iRoleName); if (result != null && !result.isEmpty()) return result.get(0).rawField("rid"); return null; }
private void copyRidBags(ORecord oldRecord, ODocument newDoc) { ODocument oldDoc = (ODocument) oldRecord; for (String field : oldDoc.fieldNames()) { if (field.equalsIgnoreCase("out") || field.equalsIgnoreCase("in") || field.startsWith("out_") || field.startsWith("in_") || field.startsWith("OUT_") || field.startsWith("IN_")) { Object val = oldDoc.rawField(field); if (val instanceof ORidBag) { ORidBag bag = (ORidBag) val; if (!bag.isEmbedded()) { ORidBag newBag = new ORidBag(); Iterator<OIdentifiable> rawIter = bag.rawIterator(); while (rawIter.hasNext()) { newBag.add(rawIter.next()); } newDoc.field(field, newBag); } } } } }
public ORID getUserRID(final String iUserName) { List<ODocument> result = getDatabase().<OCommandRequest>command( new OSQLSynchQuery<ODocument>("select rid from index:OUser.name where key = ? limit 1")).execute(iUserName); if (result != null && !result.isEmpty()) return result.get(0).rawField("rid"); return null; }
/** * Resolves minor book-keeping differences in cache information. */ public static ConflictState resolveCache(final ODocument storedRecord, final ODocument changeRecord) { Object storedCache = storedRecord.rawField(CACHE_ATTRIBUTES); Object changeCache = changeRecord.rawField(CACHE_ATTRIBUTES); if (storedCache != null && changeCache != null) { return resolveCacheToken(storedRecord, changeRecord) .andThen(() -> pickLatest(storedRecord, changeRecord, LAST_VERIFIED_ATTRIBUTE)); } else if (changeCache != null) { storedRecord.field(CACHE_ATTRIBUTES, changeCache); return ALLOW; } else if (storedCache != null) { changeRecord.field(CACHE_ATTRIBUTES, storedCache); return MERGE; } return IGNORE; }
public OIdentifiable getOutVertex() { if (vOut != null) // LIGHTWEIGHT EDGE return vOut; graph.setCurrentGraphInThreadLocal(); final ODocument doc = getRecord(); if (doc == null) return null; if (graph.isKeepInMemoryReferences()) // AVOID LAZY RESOLVING+SETTING OF RECORD return doc.rawField(OrientBaseGraph.CONNECTION_OUT); else return doc.field(OrientBaseGraph.CONNECTION_OUT); }
public OIdentifiable getInVertex() { if (vIn != null) // LIGHTWEIGHT EDGE return vIn; graph.setCurrentGraphInThreadLocal(); final ODocument doc = getRecord(); if (doc == null) return null; if (graph.isKeepInMemoryReferences()) // AVOID LAZY RESOLVING+SETTING OF RECORD return doc.rawField(OrientBaseGraph.CONNECTION_IN); else return doc.field(OrientBaseGraph.CONNECTION_IN); }
/** * (Blueprints Extension) Returns the incoming vertex in form of record. */ public OIdentifiable getInVertex() { if (vIn != null) // LIGHTWEIGHT EDGE return vIn; setCurrentGraphInThreadLocal(); final ODocument doc = getRecord(); if (doc == null) return null; if (settings != null && settings.isKeepInMemoryReferences()) // AVOID LAZY RESOLVING+SETTING OF RECORD return doc.rawField(OrientBaseGraph.CONNECTION_IN); else return doc.field(OrientBaseGraph.CONNECTION_IN); }
/** * (Blueprints Extension) Returns the outgoing vertex in form of record. */ public OIdentifiable getOutVertex() { if (vOut != null) // LIGHTWEIGHT EDGE return vOut; setCurrentGraphInThreadLocal(); final ODocument doc = getRecord(); if (doc == null) return null; if (settings != null && settings.isKeepInMemoryReferences()) // AVOID LAZY RESOLVING+SETTING OF RECORD return doc.rawField(OrientBaseGraph.CONNECTION_OUT); else return doc.field(OrientBaseGraph.CONNECTION_OUT); }