/** * Creates a new Edge persistent class specifying the super class. * * @param iClassName Edge class name * @param iSuperClassName Edge class name to extend * * @return OrientEdgeType instance representing the persistent class */ public OrientEdgeType createEdgeType(final String iClassName, final String iSuperClassName) { makeActive(); return createEdgeType(iClassName, iSuperClassName == null ? getEdgeBaseType() : getEdgeType(iSuperClassName)); }
@SuppressWarnings("unchecked") private void readDatabaseConfiguration() { final ODatabaseDocument databaseDocumentTx = getRawGraph(); final List<OStorageEntryConfiguration> custom = (List<OStorageEntryConfiguration>) databaseDocumentTx.get(ATTRIBUTES.CUSTOM); for (OStorageEntryConfiguration c : custom) { if (c.name.equals("useLightweightEdges")) setUseLightweightEdges(Boolean.parseBoolean(c.value)); else if (c.name.equals("txRequiredForSQLGraphOperations")) // Since v2.2.0 setTxRequiredForSQLGraphOperations(Boolean.parseBoolean(c.value)); else if (c.name.equals("maxRetries")) // Since v2.2.0 setMaxRetries(Integer.parseInt(c.value)); else if (c.name.equals("useClassForEdgeLabel")) setUseClassForEdgeLabel(Boolean.parseBoolean(c.value)); else if (c.name.equals("useClassForVertexLabel")) setUseClassForVertexLabel(Boolean.parseBoolean(c.value)); else if (c.name.equals("useVertexFieldsForEdgeLabels")) setUseVertexFieldsForEdgeLabels(Boolean.parseBoolean(c.value)); else if (c.name.equals("standardElementConstraints")) setStandardElementConstraints(Boolean.parseBoolean(c.value)); } }
/** * Creates a new Vertex persistent class specifying the super class. * * @param iClassName Vertex class name * @param iSuperClassName Vertex class name to extend * * @return OrientVertexType instance representing the persistent class */ public OrientVertexType createVertexType(final String iClassName, final String iSuperClassName) { makeActive(); return createVertexType(iClassName, iSuperClassName == null ? getVertexBaseType() : getVertexType(iSuperClassName)); }
/** * Creates a new Edge persistent class. * * @param iClassName Edge class name * * @return OrientEdgeType instance representing the persistent class */ public OrientEdgeType createEdgeType(final String iClassName) { makeActive(); return createEdgeType(iClassName, (String) null); }
@SuppressWarnings("unchecked") private void config() { final List<OStorageEntryConfiguration> custom = (List<OStorageEntryConfiguration>) getRawGraph() .get(ATTRIBUTES.CUSTOM); for (OStorageEntryConfiguration c : custom) { if (c.name.equals("useLightweightEdges")) setUseLightweightEdges(Boolean.parseBoolean(c.value)); else if (c.name.equals("useClassForEdgeLabel")) setUseClassForEdgeLabel(Boolean.parseBoolean(c.value)); else if (c.name.equals("useClassForVertexLabel")) setUseClassForVertexLabel(Boolean.parseBoolean(c.value)); else if (c.name.equals("useVertexFieldsForEdgeLabels")) setUseVertexFieldsForEdgeLabels(Boolean.parseBoolean(c.value)); } }
/** * Executes commands against the graph. Commands are executed outside * transaction. * * @param iCommand * Command request between SQL, GREMLIN and SCRIPT commands */ public OCommandRequest command(final OCommandRequest iCommand) { return new OrientGraphCommand(this, getRawGraph().command(iCommand)); }
final OrientBaseGraph graph = graphContext.graph; final OrientVertex v = graph.addVertex(null, "_id", resultVertices.current.get()); else if (strategy == STRATEGIES.RANDOM) { do { final int[] totalClusters = graph.getVertexBaseType().getClusterIds(); final int randomCluster = totalClusters[new Random().nextInt(totalClusters.length)]; long totClusterRecords = graph.getRawGraph().countClusterElements(randomCluster); if (totClusterRecords > 0) { final ORecordId randomRid = new ORecordId(randomCluster, new Random().nextInt((int) totClusterRecords)); graphContext.lastVertexToConnect = graph.getVertex(randomRid); break; final int[] totalClusters = graph.getVertexBaseType().getClusterIds(); final int firstCluster = totalClusters[0]; long totClusterRecords = graph.getRawGraph().countClusterElements(firstCluster); if (totClusterRecords > 0) { final ORecordId randomRid = new ORecordId(firstCluster, 0); graphContext.lastVertexToConnect = graph.getVertex(randomRid);
final int maxRetries = graph != null ? graph.getMaxRetries() : 1; for (int retry = 0; retry < maxRetries; ++retry) { try { OIdentifiable from; label = OrientBaseGraph.encodeClassName(label); if (label == null && iClassName != null) label = OrientBaseGraph.encodeClassName(iClassName); if (graph != null && graph.isUseClassForEdgeLabel()) { final OrientEdgeType edgeType = graph.getEdgeType(label); if (edgeType == null) graph.createEdgeType(label); else if (edge == null) { if (settings.isKeepInMemoryReferences()) edge = graph.getEdgeInstance(from.getIdentity(), to.getIdentity(), label); else edge = graph.getEdgeInstance(from, to, label); if (edge == null) { edge = graph.getEdgeInstance(label, fields); edgeRecord = edge.getRecord();
final OSchemaProxy schema = graphDatabase.getRawGraph().getMetadata().getSchema(); cls = schema.getClass(iClassName); if (cls == null) { final OClass superClass = graphDatabase.getRawGraph().getMetadata().getSchema().getClass(iSuperClass); if (superClass == null) throw new OLoaderException("Cannot find super class '" + iSuperClass + "'"); if (graphDatabase.getVertexBaseType().isSuperClassOf(superClass)) { cls = graphDatabase.createVertexType(iClassName, superClass); log(OETLProcessor.LOG_LEVELS.DEBUG, "- OrientDBLoader: created vertex class '%s' extends '%s'", iClassName, iSuperClass); } else { cls = graphDatabase.createEdgeType(iClassName, superClass); log(OETLProcessor.LOG_LEVELS.DEBUG, "- OrientDBLoader: created edge class '%s' extends '%s'", iClassName, iSuperClass); cls = graphDatabase.createVertexType(iClassName); log(OETLProcessor.LOG_LEVELS.DEBUG, "- OrientDBLoader: created vertex class '%s'", iClassName);
@Override public void begin() { ODatabaseDocumentTx documentDatabase = init(); if (documentDatabase == null) { switch (dbType) { case DOCUMENT: documentDatabase = new ODatabaseDocumentTx(dbURL); documentDatabase.open(dbUser, dbPassword); break; case GRAPH: final OrientGraphFactory factory = new OrientGraphFactory(dbURL, dbUser, dbPassword); final OrientBaseGraph graphDatabase = tx ? factory.getTx() : factory.getNoTx(); graphDatabase.setUseLightweightEdges(useLightweightEdges); graphDatabase.setStandardElementConstraints(standardElementConstraints); documentDatabase = graphDatabase.getRawGraph(); pipeline.setGraphDatabase(graphDatabase); break; } pipeline.setDocumentDatabase(documentDatabase); } documentDatabase.declareIntent(new OIntentMassiveInsert()); }
public void dropIndex(final String indexName) { commitAnyActiveTx("drop index"); try { synchronized (contexts) { for (OrientGraphContext ctx : contexts) { ctx.manualIndices.remove(indexName); } } getRawGraph().getMetadata().getIndexManager().dropIndex(indexName); saveIndexConfiguration(); } catch (Exception e) { this.rollback(); throw new RuntimeException(e.getMessage(), e); } }
public OClass createEdgeType(final String iClassName, final String iSuperClassName) { commitAnyActiveTx("create edge type '" + iClassName + "' as subclass of '" + iSuperClassName + "'"); return getRawGraph().getMetadata().getSchema() .createClass(iClassName, getEdgeType(iSuperClassName)); }
@Override public void begin() { final OClass cls = pipeline.getGraphDatabase().getEdgeType(edgeClass); if (cls == null) pipeline.getGraphDatabase().createEdgeType(edgeClass); super.begin(); }
public OClass createVertexType(final String iClassName, final String iSuperClassName) { commitAnyActiveTx("create vertex type '" + iClassName + "' as subclass of '" + iSuperClassName + "'"); return getRawGraph().getMetadata().getSchema() .createClass(iClassName, getVertexType(iSuperClassName)); }
public OClass createVertexType(final String iClassName) { commitAnyActiveTx("create vertex type '" + iClassName + "'"); return getRawGraph().getMetadata().getSchema() .createClass(iClassName, getVertexBaseType()); }
public void runImport(String inputFile, String dbURL) throws IOException, FileNotFoundException { if (inputFile == null) throw new OSystemException("needed an input file as first argument"); if (dbURL == null) throw new OSystemException("needed an database location as second argument"); ODatabaseDocumentInternal db = new ODatabaseDocumentTx(dbURL); ODatabaseHelper.deleteDatabase(db, db.getType()); OrientBaseGraph g = OrientGraphFactory.getNoTxGraphImplFactory().getGraph(dbURL); System.out.println("Importing graph from file '" + inputFile + "' into database: " + g + "..."); final long startTime = System.currentTimeMillis(); OConsoleDatabaseApp console = new OGremlinConsole(new String[] { "import database " + inputFile }) .setCurrentDatabase(g.getRawGraph()); console.run(); System.out.println("Imported in " + (System.currentTimeMillis() - startTime) + "ms. Vertexes: " + g.countVertices()); g.command(new OCommandSQL("alter database TIMEZONE 'GMT'")).execute(); g.command(new OCommandSQL("alter database LOCALECOUNTRY 'UK'")).execute(); g.command(new OCommandSQL("alter database LOCALELANGUAGE 'EN'")).execute(); g.shutdown(); } }
@Override public void declareIntent(final OIntent iIntent) { makeActive(); getRawGraph().declareIntent(iIntent); }
/** * Counts the edges in graph of a particular class. Edge counting works only if useLightweightEdges is false. * * @return Long as number of total edges */ public long countEdges(final String iClassName) { makeActive(); if (isUseLightweightEdges()) throw new UnsupportedOperationException("Graph set to use Lightweight Edges, count against edges is not supported"); return getRawGraph().countClass(iClassName); }
final String iInFieldName, final Object[] fields, final String label) { if (!graph.isUseVertexFieldsForEdgeLabels() && label != null) return false; if (graph.isUseLightweightEdges() && (fields == null || fields.length == 0 || fields[0] == null)) { Object field = iFromVertex.field(iOutFieldName); if (graph.isUseClassForEdgeLabel()) { final OClass cls = graph.getEdgeType(label); if (cls != null) for (OProperty p : cls.properties()) {
@Override public Object call(OrientBaseGraph g) { try { final OIndexManager indexManager = getRawGraph().getMetadata().getIndexManager(); final OIndex index = indexManager.getIndex(indexName); ODocument metadata = index.getConfiguration().field("metadata"); String recordMapIndexName = null; if (metadata != null) { recordMapIndexName = metadata.field(OrientIndex.CONFIG_RECORD_MAP_NAME); } indexManager.dropIndex(indexName); if (recordMapIndexName != null) getRawGraph().getMetadata().getIndexManager().dropIndex(recordMapIndexName); saveIndexConfiguration(); return null; } catch (Exception e) { g.rollback(); throw new RuntimeException(e.getMessage(), e); } } }, "drop index '", indexName, "'");