com.tinkerpop.blueprints.impls.orient.OrientGraphFactory Java Examples

The following examples show how to use com.tinkerpop.blueprints.impls.orient.OrientGraphFactory. 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 File: GraphTest.java    From light with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    String sql = "select from Comment where in_HasComment[0] = #35:22";

    OrientGraphFactory factory = new OrientGraphFactory("plocal:/home/steve/lightdb").setupPool(1,10);
    //OrientGraphFactory factory = new OrientGraphFactory("plocal:/Users/HUS5/lightdb").setupPool(1,10);
    OrientGraph graph = factory.getTx();
    try {
        //System.out.println(graph.getVertex("#11:0").getRecord().toJSON("rid, fetchPlan:*:-1"));

        //String result = graph.getVertex("#37:0").getRecord().toJSON("rid,fetchPlan:[*]in_Create:-2 out_HasComment:5");
        //String result = graph.getVertex("#35:22").getRecord().toJSON("rid,version,fetchPlan:out_HasComment:-1 out_HasComment.out_HasComment:-1 out_HasComment.in_Create:0");
        //String result = graph.getVertex("#35:22").getRecord().toJSON("rid,in_Create.userId, fetchPlan:out_HasComment:5");
        //System.out.println(result);
        OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(sql);
        List<ODocument> list = graph.getRawGraph().command(query).execute();
        String json = OJSONWriter.listToJSON(list, "rid,fetchPlan:[*]in_HasComment:-2 [*]out_ReportSpam:-2 [*]out_UpVote:-2 [*]out_DownVote:-2 in_Create[]:0 [*]out_Create:-2 [*]out_Update:-2 [*]out_HasComment:-1");
        System.out.println(json);
        //System.out.println(getBfnTree("forum", "example"));
    } finally {
        graph.shutdown();
    }
}
 
Example #2
Source File: ServiceLocator.java    From light with Apache License 2.0 5 votes vote down vote up
public OrientGraphFactory getFactory() {
    if(factory == null) {
        factory = new OrientGraphFactory(getDbUrl()).setupPool(1,100);
        OGlobalConfiguration.RID_BAG_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(-1);
    }
    return factory;
}
 
Example #3
Source File: OrientGraphDatabase.java    From graphdb-benchmarks with Apache License 2.0 5 votes vote down vote up
private OrientGraph getGraph(final File dbPath)
{
    OrientGraph g;
    OrientGraphFactory graphFactory = new OrientGraphFactory("plocal:" + dbPath.getAbsolutePath());
    g = graphFactory.getTx();
    g.setUseLightweightEdges(this.useLightWeightEdges);
    return g;
}
 
Example #4
Source File: OrientDBConnector.java    From bjoern with GNU General Public License v3.0 4 votes vote down vote up
public void connect(String databaseName)
{
	graphFactory = new OrientGraphFactory(
			"plocal:" + System.getProperty("ORIENTDB_HOME") + "/databases/" + databaseName)
			.setupPool(1, MAX_POOL_SIZE);
}
 
Example #5
Source File: OOrientDBLoader.java    From orientdb-etl with 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 #6
Source File: LightServer.java    From light with 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();

}