public OSchemaShared load(ODatabaseDocumentInternal database) { rwSpinLock.acquireWriteLock(); try { if (!new ORecordId(database.getStorage().getConfiguration().getSchemaRecordId()).isValid()) throw new OSchemaNotCreatedException("Schema is not created and cannot be loaded"); ((ORecordId) document.getIdentity()).fromString(database.getStorage().getConfiguration().getSchemaRecordId()); reload("*:-1 index:0"); return this; } finally { rwSpinLock.releaseWriteLock(); } }
@Override public String getClusterNameByRid(String rid) { return getClusterNameById(new ORecordId(rid).getClusterId()); }
public ODocument calculateODocument(ProcessEngine processEngine, String taskId) { if(rid!=null) return (ODocument)rid.getRecord(); if(variableName!=null) { Object recording = processEngine.getTaskService().getVariable(taskId, variableName); if(recording!=null) { return new ORecordId(recording.toString()).getRecord(); } } if(schemaClassName!=null) { return new ODocument(schemaClassName); } return null; }
protected ORecordAbstract setIdentity(final int iClusterId, final long iClusterPosition) { if (_recordId == null || _recordId == ORecordId.EMPTY_RECORD_ID) _recordId = new ORecordId(iClusterId, iClusterPosition); else { _recordId.setClusterId(iClusterId); _recordId.setClusterPosition(iClusterPosition); } return this; }
@Override public ODocument getObject(String id, IModel<? extends List<? extends ODocument>> choicesModel) { if(ORecordId.isA(id)) { ORecordId rid = new ORecordId(id); ODocument ret = rid.getRecord(); List<? extends ODocument> choices = choicesModel.getObject(); return choices!=null && choices.contains(ret)?ret:null; } return null; }
throw new ORecordNotFoundException(getIdentity(), "The vertex " + getIdentity() + " has been deleted"); final ORID oldIdentity = getIdentity().copy(); final ORecord oldRecord = oldIdentity.getRecord(); if (oldRecord == null) throw new ORecordNotFoundException(getIdentity(), "The vertex " + getIdentity() + " has been deleted"); final ODocument doc = ((ODocument) getRecord()).copy(); oldRecord.delete(); doc.setClassName(iClassName); doc.setDirty(); ORecordInternal.setIdentity(doc, new ORecordId());
iRecord.clear(); ORecord localRecord = ODatabaseRecordThreadLocal.instance().get().load(new ORecordId(fieldValueAsString)); if (localRecord != null) iRecord = localRecord; iRecord = new ODocument(); ORecordInternal.setIdentity(iRecord, new ORecordId(fieldValueAsString)); else if (fieldName.equals(ODocumentHelper.ATTRIBUTE_VERSION)) ORecordInternal.setVersion(iRecord, Integer.parseInt(fieldValue)); else if (fieldName.equals(ODocumentHelper.ATTRIBUTE_CLASS)) { continue; iRecord.fromStream(OCommonConst.EMPTY_BYTE_ARRAY); else if (iRecord instanceof OBlob) { if (first != null && first instanceof ORecord && !((ORecord) first).getIdentity().isValid()) type = v instanceof Set<?> ? OType.EMBEDDEDSET : OType.EMBEDDEDLIST; doc.field(fieldName, v, type); continue; if (iRecord.getIdentity().isValid()) throw OException.wrapException( throw OException.wrapException(new OSerializationException("Error on unmarshalling JSON content for record: " + iSource), e);
@Ignore //TODO: Uncomment when OrientDB issue will be fixed: https://github.com/orientechnologies/orientdb/issues/8067 @Test public void testLinkToOUser() { ODatabaseDocument db = wicket.getTester().getDatabase(); OSchema schema = db.getMetadata().getSchema(); final OClass classA = schema.createClass("TestLinkToOUser"); classA.createProperty("name", OType.STRING); classA.createProperty("user", OType.LINK).setLinkedClass(schema.getClass("OUser")); ORID userRid = new ORecordId("#5:0"); ODocument doc = new ODocument(classA); wicket.getTester().signIn("writer", "writer"); db = wicket.getTester().getDatabase(); db.begin(); ODocument userDoc = userRid.getRecord(); userDoc.field("roles"); doc.field("Admin"); doc.field("user", userDoc); doc.save(); db.commit(); } }
@Override public List<ILocation> findByParent(String id) { if (id == null || "".equals(id)) return null; initDb(); // execute query OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<>("select @rid as id from Location where parent = ?" + getDefaultOrder(true)); List<ODocument> result = db.command(query).execute(new ORecordId(id)); List<ILocation> list = new ArrayList<>(); // populate set for (ODocument document : result) list.add(lazyLoadInstance(document.field("id", String.class))); return list; }
putInList(to, in, from); } else { ODocument edgeDoc = new ODocument(edgeClass); edgeDoc.fromMap(properties); edgeDoc.field("out", new ORecordId(getClusterId(from), getClusterPosition(from))); edgeDoc.field("in", new ORecordId(getClusterId(to), getClusterPosition(to))); db.save(edgeDoc); ORecordId rid = (ORecordId) edgeDoc.getIdentity(); putInList(from, out, rid);
ORecordId recordId = new ORecordId("#5:0"); ODocumentModel model = new ODocumentModel(recordId); assertModelObjectEquals(recordId.getRecord(), model); recordId = new ORecordId("#5:1"); model.setObject((ODocument)recordId.getRecord()); assertModelObjectEquals(recordId.getRecord(), model); db.begin(); ODocument doc = new ODocument("ClassA"); doc.field("name", "test1"); model = new ODocumentModel(doc); assertEquals("test1", model.getObject().field("name")); interupt(db, model); assertEquals("test1", model.getObject().field("name"));
setClassName(iPropertyValue.toString()); return; } else if (ODocumentHelper.ATTRIBUTE_RID.equals(iPropetyName)) { _recordId.fromString(iPropertyValue.toString()); return; } else if (ODocumentHelper.ATTRIBUTE_VERSION.equals(iPropetyName)) { checkForLoading(); checkForFields();
final List<Object> outIds = out.get(i); final List<Object> inIds = in.get(i); final ODocument doc = new ODocument(vClass); if (outIds == null && inIds == null) { db.save(doc, clusterName).delete(); } else { doc.field(idPropertyName, i); if (outIds != null) { final ORidBag outBag = new ORidBag(); rid = (ORecordId) l; } else { rid = new ORecordId(getClusterId((Long) l), getClusterPosition((Long) l)); doc.field(outField, outBag); rid = (ORecordId) l; } else { rid = new ORecordId(getClusterId((Long) l), getClusterPosition((Long) l)); doc.fromMap(properties); db.save(doc, clusterName);
ODocument oDocument = new ODocument(map); iResult.add(oDocument); return oDocument; ODocument doc = new ODocument().fromMap((Map<String, ? extends Object>) current); ORecordInternal.setIdentity(doc, new ORecordId(-2, cursor--)); current = doc; } else if (current instanceof List) { ODocument doc = new ODocument().field("value", current); ORecordInternal.setIdentity(doc, new ORecordId(-2, cursor--)); current = doc; throw OException.wrapException(new OCommandExecutionException("Error on execution of the GREMLIN script"), e); } finally { OGremlinHelper.global().releaseEngine(engine);
ORecordInternal.setIdentity(doc, new ORecordId(-2, getTemporaryRIDCounter(iContext))); result.add(doc); } else { final List<String> nextFields = unwindFields.subList(1, unwindFields.size()); Object fieldValue = doc.field(firstField); if (fieldValue == null || !(fieldValue instanceof Iterable) || fieldValue instanceof ODocument) { result.addAll(unwind(doc, nextFields, iContext)); Iterator iterator = ((Iterable) fieldValue).iterator(); if (!iterator.hasNext()) { ODocument unwindedDoc = new ODocument(); doc.copyTo(unwindedDoc); unwindedDoc.field(firstField, (Object) null); result.addAll(unwind(unwindedDoc, nextFields, iContext));
/** * helper method to convert entity to document * @param document to be converted * @param entity converted */ protected void populateODocumentWithCreatedModified(ODocument document, SegradaEntity entity) { // only set in new documents if (document.getIdentity().isNew()) { document.field("created", entity.getCreated()) .field("creator", entity.getCreator()==null?null:new ORecordId(entity.getCreator().getId())); } document.field("modified", entity.getModified()) .field("modifier", entity.getModifier() == null ? null : new ORecordId(entity.getModifier().getId())); }
@Override public ILocation convertToEntity(ODocument document) { Location location = new Location(); location.setLongitude(document.field("longitude", Double.class)); location.setLatitude(document.field("latitude", Double.class)); location.setComment(document.field("comment", String.class)); // populate with data populateEntityWithBaseData(document, location); populateEntityWithCreatedModified(document, location); // parent ORecordId parent = document.field("parent", ORecordId.class); if (parent != null) { initDb(); location.setParentId(parent.getIdentity().toString()); location.setParentModel(db.getMetadata().getSchema().getClassByClusterId(parent.getClusterId()).getName()); //TODO: lazy load parent } // add distance, if set in document (added by some query results) if (document.field("$distance") != null) location.setDistance(document.field("$distance", Double.class)); return location; }
private void distributedDropIndex(final String iName) { String dropIndexDDL = "DROP INDEX `" + iName + "`"; //noinspection deprecation getDatabase().command(new OCommandSQL(dropIndexDDL)).execute(); ORecordInternal .setIdentity(delegate.getDocument(), new ORecordId(getDatabase().getStorage().getConfiguration().getIndexMgrRecordId())); reload(); }
@Override public ODocument convertToDocument(ISourceReference entity) { ODocument document = createOrLoadDocument(entity); // populate with data document.field("referenceText", entity.getReferenceText()) .field("source", new ORecordId(entity.getSource().getId())) .field("reference", new ORecordId(entity.getReference().getId())); // populate with data populateODocumentWithCreatedModified(document, (SourceReference) entity); return document; }