@Override
  protected void onAfterDatabaseCreation(final OrientBaseGraph graph) {
    System.out.println("Creating graph schema...");

    // CREATE BASIC SCHEMA
    OrientVertexType personClass = graph.createVertexType("Person");
    personClass.createProperty("id", OType.STRING);
    personClass.createProperty("name", OType.STRING);
    personClass.createProperty("birthday", OType.DATE);
    personClass.createProperty("children", OType.STRING);

    OrientVertexType person = graph.getVertexType("Person");
    person.createIndex("Person.name", OClass.INDEX_TYPE.UNIQUE, "name");

    OrientVertexType customer = graph.createVertexType("Customer", person);
    customer.createProperty("totalSold", OType.DECIMAL);

    OrientVertexType provider = graph.createVertexType("Provider", person);
    provider.createProperty("totalPurchased", OType.DECIMAL);

    factory = new OrientGraphFactory(graph.getRawGraph().getURL(), "admin", "admin", false);
    factory.setStandardElementConstraints(false);

    v = createVertex(graph, 0, 0, 0).getIdentity();
  }
Esempio n. 2
0
 /** Destroys the helper by cleaning all the in memory objects. */
 public void destroy() {
   if (graphPool != null) {
     for (OrientBaseGraph graph : graphPool.getResources()) {
       graph.shutdown();
     }
     graphPool.close();
   }
 }
  public void createDom(String domainName) {

    Vertex v = getRoot(domainName);

    if (v == null) {
      v = graph.addVertex(GDomConfig.global().getRootClass(), (String) null);
      v.setProperty("tag", domainName);
      graph.commit();
    }
  }
  protected void dbClient1() {
    // OGlobalConfiguration.LOG_CONSOLE_LEVEL.setValue("FINEST");

    OrientBaseGraph graph = new OrientGraph(getLocalURL());
    OrientVertex vertex1 = graph.addVertex("vertextype", (String) null);
    graph.commit();
    graph.shutdown();

    vertex1Id = vertex1.getIdentity();

    exec("client1");
  }
  protected void exec(final String iClient) {
    counter.countDown();

    try {
      counter.await();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    OrientBaseGraph graph = new OrientGraph(getLocalURL());

    OrientVertex vertex1 = graph.getVertex(vertex1Id);

    try {
      int i = 0;
      for (; i < TOTAL; ++i) {

        for (int retry = 0; retry < 20; ++retry) {
          try {
            OrientVertex vertex2 = graph.addVertex("vertextype", (String) null);
            vertex1.addEdge("edgetype", vertex2);
            graph.commit();

            System.out.println(
                iClient + " - successfully committed version: " + vertex1.getRecord().getVersion());
          } catch (ONeedRetryException e) {
            System.out.println(
                iClient
                    + " - caught conflict, reloading vertex. v="
                    + vertex1.getRecord().getVersion());
            vertex1.reload();
          }
        }
      }

      // STATISTICALLY HERE AT LEAST ON CONFLICT HAS BEEN RECEIVED
      vertex1.reload();

      Assert.assertTrue(vertex1.getRecord().getVersion() > TOTAL * 2 + 1);
      Assert.assertEquals(TOTAL, i);

    } catch (Throwable e) {
      if (exceptionInThread == null) exceptionInThread = e;

    } finally {
      System.out.println("Shutting down");
      graph.shutdown();

      sleep(1000);
    }
  }
  protected OrientVertex createVertex(OrientBaseGraph graph, int serverId, int threadId, int i) {
    final String uniqueId = serverId + "-" + threadId + "-" + i;

    final Object result =
        graph
            .command(
                new OCommandSQL(
                    "create vertex Provider content {'id': '"
                        + UUID.randomUUID().toString()
                        + "', 'name': 'Billy"
                        + uniqueId
                        + "', 'surname': 'Mayes"
                        + uniqueId
                        + "', 'birthday': '"
                        + ODatabaseRecordThreadLocal.INSTANCE
                            .get()
                            .getStorage()
                            .getConfiguration()
                            .getDateFormatInstance()
                            .format(new Date())
                        + "', 'children': '"
                        + uniqueId
                        + "', 'saved': 0}"))
            .execute();
    return (OrientVertex) result;
  }
  public List<String> listPublicDomains() {

    String q = "select from Space where role is not null";

    List<ODocument> docs = graph.getRawGraph().query(new OSQLSynchQuery<ODocument>(q));

    return new GenericNodeCollection<String>(docs, new NameAttributeProvider());
  }
 public String getRoleProperty(String roleName, String key, String def) {
   OSecurity security = graph.getRawGraph().getMetadata().getSecurity();
   ORole role = security.getRole(roleName);
   if (role == null) return def;
   String ret = role.getDocument().field("properties." + key);
   if (ret == null) ret = def;
   return ret;
 }
 public List<ODocument> query(String query) {
   try {
     List<ODocument> docs = graph.getRawGraph().query(new OSQLSynchQuery<ODocument>(query));
     return docs;
   } catch (Exception ex) {
     ex.printStackTrace();
     return new ArrayList<ODocument>();
   }
 }
 private Vertex getRoot(String cls) {
   try {
     List<ODocument> list =
         graph
             .getRawGraph()
             .query(
                 new OSQLSynchQuery<ODocument>(
                     "SELECT FROM "
                         + GDomConfig.global().getRootClass()
                         + " WHERE tag='"
                         + cls
                         + "'"));
     if (list == null) return null;
     if (!(list.size() > 0)) return null;
     return graph.getVertex(list.get(0).getIdentity());
   } catch (Exception ex) {
     return null;
   }
 }
 public List<String> listRoles() {
   List<ODocument> list =
       graph
           .getRawGraph()
           .query(new OSQLSynchQuery<ODocument>("SELECT FROM orole WHERE type='template'"));
   return new GenericNodeCollection<String>(
       list,
       new AttributeProvider<String>() {
         @Override
         public String getValue(ODocument doc) {
           return doc.field("name");
         }
       });
 }
  public List<String> listUsers(String from, String max, String pattern) {

    String q = "SELECT FROM ouser";
    if (pattern != null) if (!"".equals(pattern)) q += " WHERE name like '" + pattern + "'";
    q += " SKIP " + from;
    q += " LIMIT " + max;
    List<ODocument> list = graph.getRawGraph().query(new OSQLSynchQuery<ODocument>(q));
    return new GenericNodeCollection<String>(
        list,
        new AttributeProvider<String>() {
          @Override
          public String getValue(ODocument doc) {
            return doc.field("name");
          }
        });
  }
 public void createRole(String roleName) {
   OSecurity security = graph.getRawGraph().getMetadata().getSecurity();
   if (security.getRole(roleName) == null) {
     ORole role = security.createRole(roleName, ALLOW_MODES.ALLOW_ALL_BUT);
     //			role.addRule(ORule.ResourceGeneric.DATABASE, null, ORole.PERMISSION_ALL);
     //			role.addRule(ORule.ResourceGeneric.SCHEMA, null, ORole.PERMISSION_ALL);
     //			role.addRule(ORule.ResourceGeneric.CLUSTER, OMetadataDefault.CLUSTER_INTERNAL_NAME,
     // ORole.PERMISSION_ALL);
     //			role.addRule(ORule.ResourceGeneric.CLUSTER, "orole", ORole.PERMISSION_ALL);
     //			role.addRule(ORule.ResourceGeneric.CLUSTER, "ouser", ORole.PERMISSION_ALL);
     //			role.addRule(ORule.ResourceGeneric.CLUSTER, null, ORole.PERMISSION_ALL);
     //			role.addRule(ORule.ResourceGeneric.COMMAND, null, ORole.PERMISSION_ALL);
     //			role.addRule(ORule.ResourceGeneric.RECORD_HOOK, null, ORole.PERMISSION_ALL);
     //			role.addRule(ORule.ResourceGeneric.FUNCTION, null, ORole.PERMISSION_ALL);
     role.getDocument().field("type", "template");
     role.save();
   }
 }
  public List<String> listDomains(String username) {

    Set<? extends OSecurityRole> roles = graph.getRawGraph().getUser().getRoles();
    for (OSecurityRole role : roles) {
      if (role.hasRule(ResourceGeneric.BYPASS_RESTRICTED, null)) {
        return new GenericNodeCollection<String>(
            query("select from " + GDomConfig.global().getRootClass()),
            new NameAttributeProvider());
      }
    }

    String q =
        "select from ( select expand(domain) from (select from orole where @this in (select expand(roles) from ouser where name = '"
            + username
            + "')))";

    List<ODocument> list = query(q);

    return new GenericNodeCollection<String>(list, new NameAttributeProvider());
  }
 @Override
 protected void onAfterDatabaseCreation(OrientBaseGraph db) {
   db.command(new OCommandSQL("CREATE CLASS Item extends V")).execute();
   db.command(new OCommandSQL("CREATE PROPERTY Item.name STRING")).execute();
   db.command(new OCommandSQL("CREATE PROPERTY Item.map EMBEDDEDMAP")).execute();
 }
 public void setRoleProperty(String roleName, String key, String value) {
   OSecurity security = graph.getRawGraph().getMetadata().getSecurity();
   ORole role = security.getRole(roleName);
   if (role == null) return;
   role.getDocument().field("properties." + key, value);
 }
 public void execute(String cmd) {
   graph.getRawGraph().command(new OCommandSQL(cmd)).execute();
 }