Java Code Examples for com.tinkerpop.blueprints.impls.orient.OrientBaseGraph

The following examples show how to use com.tinkerpop.blueprints.impls.orient.OrientBaseGraph. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: guice-persist-orient   Source File: RecordConverter.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T> T tryGraphConversion(final ODocument doc, final Class<T> targetType) {
    T res = null;
    final boolean requireVertex = Vertex.class.isAssignableFrom(targetType);
    if (requireVertex || Edge.class.isAssignableFrom(targetType)) {
        final OrientBaseGraph db = injector.getInstance(OrientBaseGraph.class);
        // explicitly check object compatibility to avoid wrong conversions (allowed by orient)
        if (requireVertex && doc.getSchemaClass().isSubClassOf("V")) {
            res = (T) db.getVertex(doc);
        } else if (doc.getSchemaClass().isSubClassOf("E")) {
            res = (T) db.getEdge(doc);
        }
    }
    return res;
}
 
Example 2
Source Project: guice-persist-orient   Source File: OrientGraphProvider.java    License: MIT License 5 votes vote down vote up
@Override
public OrientGraph get() {
    final OrientBaseGraph graph = provider.get();
    Preconditions.checkState(graph instanceof OrientGraph,
            "Transaction started in NOTX mode. You must use OrientGraphNoTx or enable transaction "
                    + "(or use OrientBaseGraph as universal solution for all cases)");
    return (OrientGraph) graph;
}
 
Example 3
Source Project: guice-persist-orient   Source File: OrientGraphNoTxProvider.java    License: MIT License 5 votes vote down vote up
@Override
public OrientGraphNoTx get() {
    final OrientBaseGraph graph = provider.get();
    Preconditions.checkState(graph instanceof OrientGraphNoTx,
            "You must use OrientGraph within transaction or disable transaction "
                    + "(or use OrientBaseGraph as universal solution for all cases)");
    return (OrientGraphNoTx) graph;
}
 
Example 4
Source Project: guice-persist-orient   Source File: GraphPool.java    License: MIT License 5 votes vote down vote up
@Override
public OrientBaseGraph get() {
    if (transaction.get() == null) {
        final ODatabaseDocumentInternal documentDb = (ODatabaseDocumentInternal) documentPool.get();
        final OrientBaseGraph graph = transactionManager.getActiveTransactionType() == OTransaction.TXTYPE.NOTX
                ? new OrientGraphNoTx(documentDb) : new OrientGraph(documentDb);
        transaction.set(graph);
    }
    final OrientBaseGraph db = transaction.get();
    db.getRawGraph().activateOnCurrentThread();
    return db;
}
 
Example 5
Source Project: graphdb-benchmarks   Source File: OrientGraphDatabase.java    License: Apache License 2.0 5 votes vote down vote up
protected void createSchema()
{
    graph.executeOutsideTx(new OCallable<Object, OrientBaseGraph>() {
        @SuppressWarnings({ "unchecked", "rawtypes" })
        @Override
        public Object call(final OrientBaseGraph g)
        {
            OrientVertexType v = g.getVertexBaseType();
            if(!v.existsProperty(NODE_ID)) { // TODO fix schema detection hack later
                v.createProperty(NODE_ID, OType.INTEGER);
                g.createKeyIndex(NODE_ID, Vertex.class, new Parameter("type", "UNIQUE_HASH_INDEX"), new Parameter(
                    "keytype", "INTEGER"));

                v.createEdgeProperty(Direction.OUT, SIMILAR, OType.LINKBAG);
                v.createEdgeProperty(Direction.IN, SIMILAR, OType.LINKBAG);
                OrientEdgeType similar = g.createEdgeType(SIMILAR);
                similar.createProperty("out", OType.LINK, v);
                similar.createProperty("in", OType.LINK, v);
                g.createKeyIndex(COMMUNITY, Vertex.class, new Parameter("type", "NOTUNIQUE_HASH_INDEX"),
                    new Parameter("keytype", "INTEGER"));
                g.createKeyIndex(NODE_COMMUNITY, Vertex.class, new Parameter("type", "NOTUNIQUE_HASH_INDEX"),
                    new Parameter("keytype", "INTEGER"));
            }

            return null;
        }
    });
}
 
Example 6
Source Project: orientdb-etl   Source File: OETLPipeline.java    License: Apache License 2.0 4 votes vote down vote up
public OrientBaseGraph getGraphDatabase() {
  if (graph != null)
    graph.makeActive();
  return graph;
}
 
Example 7
Source Project: orientdb-etl   Source File: OETLPipeline.java    License: Apache License 2.0 4 votes vote down vote up
public OETLPipeline setGraphDatabase(final OrientBaseGraph iGraph) {
  graph = iGraph;
  return this;
}
 
Example 8
Source Project: orientdb-etl   Source File: OOrientDBLoader.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void configure(final OETLProcessor iProcessor, final ODocument iConfiguration, final OCommandContext iContext) {
  super.configure(iProcessor, iConfiguration, iContext);

  if (iConfiguration.containsField("dbURL"))
    dbURL = (String) resolve(iConfiguration.field("dbURL"));
  if (iConfiguration.containsField("dbUser"))
    dbUser = (String) resolve(iConfiguration.field("dbUser"));
  if (iConfiguration.containsField("dbPassword"))
    dbPassword = (String) resolve(iConfiguration.field("dbPassword"));
  if (iConfiguration.containsField("dbType"))
    dbType = DB_TYPE.valueOf(iConfiguration.field("dbType").toString().toUpperCase());
  if (iConfiguration.containsField("tx"))
    tx = (Boolean) iConfiguration.field("tx");
  if (iConfiguration.containsField("wal"))
    wal = (Boolean) iConfiguration.field("wal");
  if (iConfiguration.containsField("txUseLog"))
    txUseLog = (Boolean) iConfiguration.field("txUseLog");
  if (iConfiguration.containsField("batchCommit"))
    batchCommit = (Integer) iConfiguration.field("batchCommit");
  if (iConfiguration.containsField("dbAutoCreate"))
    dbAutoCreate = (Boolean) iConfiguration.field("dbAutoCreate");
  if (iConfiguration.containsField("dbAutoDropIfExists"))
    dbAutoDropIfExists = (Boolean) iConfiguration.field("dbAutoDropIfExists");
  if (iConfiguration.containsField("dbAutoCreateProperties"))
    dbAutoCreateProperties = (Boolean) iConfiguration.field("dbAutoCreateProperties");
  if (iConfiguration.containsField("useLightweightEdges"))
    useLightweightEdges = (Boolean) iConfiguration.field("useLightweightEdges");
  if (iConfiguration.containsField("standardElementConstraints"))
    standardElementConstraints = (Boolean) iConfiguration.field("standardElementConstraints");

  clusterName = iConfiguration.field("cluster");
  className = iConfiguration.field("class");
  indexes = iConfiguration.field("indexes");
  classes = iConfiguration.field("classes");

  if (iConfiguration.containsField("settings")) {
    final ODocument settings = (ODocument) iConfiguration.field("settings");
    settings.setAllowChainedAccess(false);
    for (String s : settings.fieldNames()) {
      final OGlobalConfiguration v = OGlobalConfiguration.findByKey(s);
      if (v != null)
        v.setValue(settings.field(s));
    }
  }

  if (!wal)
    OGlobalConfiguration.USE_WAL.setValue(wal);

  switch (dbType) {
  case DOCUMENT:
    final ODatabaseDocumentTx documentDatabase = new ODatabaseDocumentTx(dbURL);
    if (documentDatabase.exists() && dbAutoDropIfExists) {
      log(OETLProcessor.LOG_LEVELS.INFO, "Dropping existent database '%s'...", dbURL);
      documentDatabase.open(dbUser, dbPassword);
      documentDatabase.drop();
    }

    if (documentDatabase.exists()) {
      log(OETLProcessor.LOG_LEVELS.DEBUG, "Opening database '%s'...", dbURL);
      documentDatabase.open(dbUser, dbPassword);
    } else if (dbAutoCreate) {
      documentDatabase.create();
    } else
      throw new IllegalArgumentException("Database '" + dbURL + "' not exists and 'dbAutoCreate' setting is false");

    documentDatabase.close();
    break;

  case GRAPH:
    final OrientGraphFactory factory = new OrientGraphFactory(dbURL, dbUser, dbPassword);
    if (dbAutoDropIfExists && factory.exists()) {
      log(OETLProcessor.LOG_LEVELS.INFO, "Dropping existent database '%s'...", dbURL);
      factory.drop();
    }

    final OrientBaseGraph graphDatabase = tx ? factory.getTx() : factory.getNoTx();
    graphDatabase.shutdown();
    break;
  }
}
 
Example 9
Source Project: guice-persist-orient   Source File: GraphRepositoryExecutor.java    License: MIT License 4 votes vote down vote up
@Inject
public GraphRepositoryExecutor(final Provider<OrientBaseGraph> provider) {
    this.provider = provider;
}
 
Example 10
Source Project: guice-persist-orient   Source File: GraphPoolBinder.java    License: MIT License 4 votes vote down vote up
public GraphPoolBinder(final OrientModule module, final Method bindPool, final Binder binder) throws Exception {
    binder.bind(OrientGraph.class).toProvider(OrientGraphProvider.class);
    binder.bind(OrientGraphNoTx.class).toProvider(OrientGraphNoTxProvider.class);
    bindPool.invoke(module, OrientBaseGraph.class, GraphPool.class);
}
 
Example 11
Source Project: guice-persist-orient   Source File: GraphExecutorBinder.java    License: MIT License 4 votes vote down vote up
public GraphExecutorBinder(final RepositoryModule module,
                           final Method bindExecutor) throws Exception {
    // explicit dependency on class required to fail
    OrientBaseGraph.class.getName();
    bindExecutor.invoke(module, GraphRepositoryExecutor.class);
}
 
Example 12
Source Project: guice-persist-orient   Source File: EdgesSupportDelegate.java    License: MIT License 4 votes vote down vote up
@Inject
public EdgesSupportDelegate(final Provider<ODatabaseObject> objectDb, final Provider<OrientBaseGraph> graphDb) {
    this.objectDb = objectDb;
    this.graphDb = graphDb;
}
 
Example 13
Source Project: guice-persist-orient   Source File: EdgesSupportDelegate.java    License: MIT License 4 votes vote down vote up
private OrientEdge createEdgeImpl(final Class edgeClass, final Object from, final Object to) {
    final OrientBaseGraph graph = graphDb.get();
    return graph.addEdge("class:" + edgeClass.getSimpleName(),
            getVertex(from),
            getVertex(to), null);
}
 
Example 14
Source Project: guice-persist-orient   Source File: ObjectVertexCrudDelegate.java    License: MIT License 4 votes vote down vote up
@Inject
public ObjectVertexCrudDelegate(final Provider<OrientBaseGraph> graphDb) {
    this.graphDb = graphDb;
}
 
Example 15
Source Project: guice-persist-orient   Source File: OrientGraphProvider.java    License: MIT License 4 votes vote down vote up
@Inject
public OrientGraphProvider(final Provider<OrientBaseGraph> provider) {
    this.provider = provider;
}
 
Example 16
Source Project: guice-persist-orient   Source File: OrientGraphNoTxProvider.java    License: MIT License 4 votes vote down vote up
@Inject
public OrientGraphNoTxProvider(final Provider<OrientBaseGraph> provider) {
    this.provider = provider;
}
 
Example 17
Source Project: light   Source File: LightServer.java    License: Apache License 2.0 4 votes vote down vote up
static public void start() {
    // hosts and server configuration
    Map<String, Object> hostConfigMap = ServiceLocator.getInstance().getJsonMapConfig(ServiceLocator.HOST_CONFIG);
    Map<String, Object> serverConfigMap = ServiceLocator.getInstance().getJsonMapConfig(ServiceLocator.SERVER_CONFIG);

    OrientGraphFactory factory = ServiceLocator.getInstance().getFactory();
    // check if database exists, if not create it and init it.
    if(!factory.exists()) {
        try {
            OrientBaseGraph g = new OrientGraph(ServiceLocator.getInstance().getDbUrl());
            // database is auto created
            g.command(new OCommandSQL("alter database custom useLightweightEdges=true")).execute();
            g.command(new OCommandSQL("alter database DATETIMEFORMAT yyyy-MM-dd'T'HH:mm:ss.SSS")).execute();
            g.command(new OCommandSQL("alter database TIMEZONE UTC")).execute();
            OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(-1);
        } finally {
            // this also closes the OrientGraph instances created by the factory
            // Note that OrientGraphFactory does not implement Closeable
            factory.close();
        }
        InitDatabase.initDb();
        // load rule compileCache here
        AbstractRuleRule.loadCompileCache();
        // replay all the event to create database image.
        // TODO need to rethink replay as orientdb is used instead of Memory Image.
        replayEvent();
    } else {
        // load rule compileCache here
        AbstractRuleRule.loadCompileCache();
    }

    NameVirtualHostHandler virtualHostHandler = new NameVirtualHostHandler();
    Iterator<String> it = hostConfigMap.keySet().iterator();
    while (it.hasNext()) {
        String host = it.next();
        Map<String, String> hostPropMap = (Map<String, String>)hostConfigMap.get(host);
        String base = hostPropMap.get("base");
        String transferMinSize = hostPropMap.get("transferMinSize");
        virtualHostHandler
                .addHost(
                        host,
                        Handlers.predicates(
                            PredicatedHandlersParser.parse("not path-prefix('/images', '/assets', '/api') -> rewrite('/index.html')"
                            //PredicatedHandlersParser.parse("not path-suffix['.js', '.html', '.css'] -> rewrite['/index.html']"
                            //PredicatedHandlersParser.parse("path-prefix['/home', '/page', '/form'] -> rewrite['/index.html']"
                            , LightServer.class.getClassLoader()),
                                new PathHandler(resource(new FileResourceManager(
                                        new File(base), Integer
                                        .valueOf(transferMinSize))))
                                        .addPrefixPath("/api/rs",
                                                new EagerFormParsingHandler().setNext(
                                                        new RestHandler()))
                                        .addPrefixPath("/api/ws",
                                                websocket(new WebSocketHandler()))
                        ));
    }
    String ip = (String)serverConfigMap.get("ip");
    String port = (String)serverConfigMap.get("port");
    server = Undertow
            .builder()
            .addHttpListener(Integer.valueOf(port), ip)
            .setBufferSize(1024 * 16)
            .setServerOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE, false)
            .setHandler(
                    Handlers.header(virtualHostHandler,
                            Headers.SERVER_STRING, "LIGHT"))
            .setWorkerThreads(200).build();
    server.start();

}