Refine search
/** * (Blueprints Extension) Returns the Vertex's label. By default OrientDB binds the Blueprints Label concept to Vertex Class. To * disable this feature execute this at database level <code>alter database custom useClassForVertexLabel=false </code> */ @Override public String getLabel() { setCurrentGraphInThreadLocal(); if (settings.isUseClassForVertexLabel()) { final String clsName = getRecord().getClassName(); if (!OrientVertexType.CLASS_NAME.equals(clsName)) // RETURN THE CLASS NAME return clsName; } return getRecord().field(OrientElement.LABEL_FIELD_NAME); }
public static boolean hasEdgeToClass(OrientGraph graph, OrientVertex vertex, String edgeName) throws Exception { boolean result = false; if(vertex.countEdges(Direction.IN, edgeName) > 0) { result = true; } return result; } }
private void removeEdges(OrientGraph tx, OrientVertex vertex) { OrientVertex destination = tx.getVertex(documentModel.getObject().getIdentity()); Iterable<Edge> edges = vertex.getEdges(destination, Direction.BOTH); for(Edge edge : edges) { tx.removeEdge(edge); } }
public OrientVertex addVertex(final String iClassName, final String iClusterName) { this.autoStartTransaction(); final OrientVertex vertex = new OrientVertex(this, iClassName); // SAVE IT if (iClusterName != null) vertex.save(iClusterName); else vertex.save(); return vertex; }
@Override public void initCommunityProperty() { int communityCounter = 0; for (Vertex v : graph.getVertices()) { ((OrientVertex) v).setProperties(NODE_COMMUNITY, communityCounter, COMMUNITY, communityCounter); ((OrientVertex) v).save(); communityCounter++; } }
protected void manageNeedRetryException(OBaseWorkLoadContext context, ONeedRetryException e) { if (((OWorkLoadContext) context).lastVertexToConnect.getIdentity().isPersistent()) ((OWorkLoadContext) context).lastVertexToConnect.reload(); }
final OrientBaseGraph graph = getGraph(); if (checkDeletedInTx()) graph.throwRecordNotFoundException(getIdentity(), "The vertex " + getIdentity() + " has been deleted"); final ORID oldIdentity = getIdentity().copy(); graph.throwRecordNotFoundException(getIdentity(), "The vertex " + getIdentity() + " has been deleted"); final ODocument doc = ((ODocument) rawElement.getRecord()).copy(); final Iterable<Edge> outEdges = getEdges(Direction.OUT); final Iterable<Edge> inEdges = getEdges(Direction.IN); copyRidBags(oldRecord, doc); oldRecord.delete(); doc.setClassName(iClassName); .getConnectionFieldName(Direction.IN, oe.getLabel(), graph.isUseVertexFieldsForEdgeLabels()); replaceLinks(inV.getRecord(), inFieldName, oldIdentity, newIdentity); } else { .getConnectionFieldName(Direction.OUT, oe.getLabel(), graph.isUseVertexFieldsForEdgeLabels()); replaceLinks(outV.getRecord(), outFieldName, oldIdentity, newIdentity); } else {
OrientEdge addEdgeInternal(final OrientVertex currentVertex, String label, final OrientVertex inVertex, final String iClassName, final String iClusterName, final Object... fields) { if (currentVertex.checkDeletedInTx()) throw new ORecordNotFoundException(currentVertex.getIdentity(), "The vertex " + currentVertex.getIdentity() + " has been deleted"); if (inVertex.checkDeletedInTx()) throw new ORecordNotFoundException(inVertex.getIdentity(), "The vertex " + inVertex.getIdentity() + " has been deleted"); final ODocument outDocument = currentVertex.getRecord(); if (outDocument == null) throw new IllegalArgumentException("source vertex is invalid (rid=" + currentVertex.getIdentity() + ")"); ODocument inDocument = inVertex.getRecord(); if (inDocument == null) throw new IllegalArgumentException("destination vertex is invalid (rid=" + inVertex.getIdentity() + ")"); final String outFieldName = currentVertex.getConnectionFieldName(Direction.OUT, label, settings.isUseVertexFieldsForEdgeLabels()); final String inFieldName = currentVertex.getConnectionFieldName(Direction.IN, label, settings.isUseVertexFieldsForEdgeLabels()); if (currentVertex.canCreateDynamicEdge(outDocument, inDocument, outFieldName, inFieldName, fields, label)) { currentVertex.createLink(this, outDocument, to, outFieldName); currentVertex.createLink(this, inDocument, from, inFieldName);
cls = getOrCreateClass(className, null); else cls = doc.getSchemaClass(); for (String f : doc.fieldNames()) { final String newName = transformFieldName(f); final String fName = newName != null ? newName : f; OProperty p = cls.getProperty(fName); if (p == null) { final Object fValue = doc.field(f); createProperty(cls, fName, fValue); if (newName != null) { final String fName = newName != null ? newName : f; OProperty p = cls.getProperty(fName); if (p == null) { final Object fValue = element.getProperty(f); v.save(clusterName); else v.save();
continue; final ORID oldVertex = fromVertex.getIdentity().copy(); final ORID newVertex = fromVertex.moveTo(className, clusterName); newVertexDoc.merge(merge, true, false); newVertexDoc.save(); result.add(new ODocument().setTrackingChanges(false).field("old", oldVertex, OType.LINK) .field("new", newVertex, OType.LINK));
String pmRID = ""; OrientGraph graphTwo = new OrientGraph(URL, USER, USER); try { ODocument pokemon = new ODocument("Pokemon"); pokemon.field("name", "Pikachu"); Map<String,ODocument> foo = new HashMap(); foo.put("pikachu", pokemon); OrientVertex v = graphTwo.addVertex("class:PokemonMaster", "name", "Sacha", "age", "42", "pokemons", foo); graphTwo.commit(); pmRID = v.getIdentity().toString(); } catch (Exception e) { // ... } finally { graphTwo.shutdown(); }
final String[] lookupParts = lookup.split("\\."); final OrientVertex linkedV = pipeline.getGraphDatabase().addTemporaryVertex(lookupParts[0]); linkedV.setProperty(lookupParts[1], joinCurrentValue); for (String f : targetVertexFields.fieldNames()) linkedV.setProperty(f, resolve(targetVertexFields.field(f))); linkedV.save(); log(OETLProcessor.LOG_LEVELS.DEBUG, "created new vertex=%s", linkedV.getRecord()); result = linkedV.getIdentity(); } else { throw new OConfigurationException("Cannot create linked document because target class is unknown. Use 'lookup' field"); edge = (OrientEdge) vertex.addEdge(edgeClass, targetVertex); else edge = (OrientEdge) targetVertex.addEdge(edgeClass, vertex); for (String f : edgeFields.fieldNames()) edge.setProperty(f, resolve(edgeFields.field(f)));
public String getLabel() { graph.setCurrentGraphInThreadLocal(); if (graph.isUseClassForVertexLabel()) { final String clsName = getRecord().getClassName(); if (!CLASS_NAME.equals(clsName)) // RETURN THE CLASS NAME return clsName; } return getRecord().field(OrientElement.LABEL_FIELD_NAME); }
entry = ((OIdentifiable) entry).getRecord(); OClass schemaClass = ((ODocument) entry).getSchemaClass(); if (schemaClass != null && schemaClass.isVertexType()) vertices.add(graph.getVertex(entry)); else if (schemaClass != null && schemaClass.isEdgeType()) { OrientEdge edge = graph.getEdge(entry); rsEdges.add(edge); json.beginObject(); json.writeAttribute("@rid", vertex.getIdentity()); json.writeAttribute("@class", vertex.getRecord().getClassName()); for (String field : vertex.getPropertyKeys()) { final Object v = vertex.getProperty(field); if (v != null) json.writeAttribute(field, v); for (Edge e : vertex.getEdges(Direction.BOTH)) { OrientEdge edge = (OrientEdge) e; if (edgeRids.contains(((OrientEdge) e).getIdentity())) {
@Override public OrientEdge createWrapper(final Object iObject) { if (iObject instanceof OrientEdge) return (OrientEdge) iObject; final OIdentifiable rec = (OIdentifiable) iObject; final ODocument value = rec.getRecord(); if (value == null || value.getSchemaClass() == null) return null; final OrientEdge edge; if (value.getSchemaClass().isSubClassOf(OrientVertex.CLASS_NAME)) { // DIRECT VERTEX, CREATE DUMMY EDGE if (connection.getKey() == Direction.OUT) edge = new OrientEdge(this.vertex.graph, this.vertex.getIdentity(), rec.getIdentity(), connection.getValue()); else edge = new OrientEdge(this.vertex.graph, rec.getIdentity(), this.vertex.getIdentity(), connection.getValue()); } else if (value.getSchemaClass().isSubClassOf(OrientEdge.CLASS_NAME)) { // EDGE edge = new OrientEdge(this.vertex.graph, rec.getIdentity()); } else throw new IllegalStateException("Invalid content found between connections:" + value); if (this.vertex.graph.isUseVertexFieldsForEdgeLabels() || edge.isLabeled(labels)) return edge; return null; }
/** * Returns a string representation of the vertex. */ public String toString() { setCurrentGraphInThreadLocal(); final ODocument record = getRecord(); if (record == null) return "<invalid record " + rawElement.getIdentity() + ">"; final String clsName = record.getClassName(); if (OrientVertexType.CLASS_NAME.equals(clsName)) return StringFactory.vertexString(this); return StringFactory.V + "(" + clsName + ")" + StringFactory.L_BRACKET + getId() + StringFactory.R_BRACKET; }
final ODocument doc = getRecord(); List<OTriple<String, Direction, String>> result = new ArrayList<>(); for (String fieldName : doc.fieldNames()) { final OPair<Direction, String> connection = getConnection(iDirection, fieldName, iClassNames); if (connection != null) result.add(new OTriple<String, Direction, String>(fieldName, connection.getKey(), connection.getValue())); OSchema schema = getGraph().getRawGraph().getMetadata().getSchema(); OClass clazz = schema.getClass(className); if (clazz != null) { Collection<OClass> subClasses = clazz.getAllSubclasses(); for (OClass subClass : subClasses) { allClassNames.add(subClass.getName()); for (OTriple<String, Direction, String> connectionField : result) fieldNames[i++] = connectionField.getKey(); doc.deserializeFields(fieldNames);
protected CacheObject getPageById(OrientGraph graph, String pageId) { CacheObject co = null; Map<String, Object> pageMap = ServiceLocator.getInstance().getMemoryImage("pageMap"); ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>)pageMap.get("cache"); if(cache == null) { cache = new ConcurrentLinkedHashMap.Builder<Object, Object>() .maximumWeightedCapacity(1000) .build(); pageMap.put("cache", cache); } else { co = (CacheObject)cache.get(pageId); } if(co == null) { OrientVertex page = (OrientVertex)graph.getVertexByKey("Page.pageId", pageId); if(page != null) { String json = page.getRecord().toJSON(); co = new CacheObject(page.getProperty("@version").toString(), json); cache.put(pageId, co); } } return co; }
final ORecord record = rec.getRecord(); if (record == null) { sourceVertex != null ? sourceVertex.getIdentity() : null, targetVertex != null ? targetVertex.getIdentity() : null, record.getDatabase().getURL()); return null; final ODocument value = rec.getRecord(); ODatabaseDocument db = value.getDatabaseIfDefined(); if (db == null) { return null; edge = this.sourceVertex.getGraph().getEdgeInstance( this.sourceVertex.getIdentity(), rec.getIdentity(), connection.getValue()); else edge = this.sourceVertex.getGraph().getEdgeInstance( rec.getIdentity(), this.sourceVertex.getIdentity(), connection.getValue()); } else if (immutableSchema.isEdgeType()) { edge = new OrientEdge(this.sourceVertex.getGraph(), rec.getIdentity(), connection.getValue()); } else throw new IllegalStateException("Invalid content found while iterating edges, value '" + value + "' is not an edge");