Exemplo n.º 1
0
  public static OClass create(OSchema schema) {
    // Create Book table
    OClass oClass = schema.createClass("Comment");

    // comment STRING
    OProperty prop = oClass.createProperty("comment", OType.STRING);
    prop.setNotNull(true);
    // submittedDate DATETIME
    prop = oClass.createProperty("submittedDate", OType.DATETIME);
    prop.setNotNull(true);
    // eMailAddress STRING 0 60
    prop = oClass.createProperty("eMailAddress", OType.STRING);
    prop.setMin("0");
    prop.setMax("60");
    // userId STRING 6 20
    prop = oClass.createProperty("userId", OType.STRING);
    prop.setMin("6");
    prop.setMax("20");

    // Idexes
    // submittedDate_idx NOTUNIQUE submittedDate
    oClass.createIndex("submittedDate_idx", INDEX_TYPE.NOTUNIQUE, "submittedDate");

    return oClass;
  }
 @Override
 protected void defineType(final OClass type) {
   type.createProperty(P_APIKEY, OType.STRING).setMandatory(true).setNotNull(true);
   type.createProperty(P_PRIMARY_PRINCIPAL, OType.STRING).setMandatory(true).setNotNull(true);
   type.createProperty(P_PRINCIPALS, OType.BINARY).setMandatory(true).setNotNull(true);
   type.createIndex(I_APIKEY, INDEX_TYPE.UNIQUE, P_APIKEY);
   type.createIndex(I_PRIMARY_PRINCIPAL, INDEX_TYPE.UNIQUE, P_PRIMARY_PRINCIPAL);
 }
Exemplo n.º 3
0
  @SuppressWarnings("unchecked")
  @Test
  public void test1() {

    db =
        new ODatabaseDocumentTx(
            "local:C:/work/dev/orientechnologies/orientdb/temp/danny/library/library");

    try {
      db.create();

      master = db.getMetadata().getSchema().createClass("Master");
      master.createProperty("type", OType.STRING);
      master.createProperty("master", OType.LONG);

      dependents = db.getMetadata().getSchema().createClass("Dependents");
      dependents.createProperty("type", OType.STRING);
      dependents.createProperty("dependents", OType.EMBEDDEDLIST, master);

      db.close();

      db.open("admin", "admin");
      dependents = db.getMetadata().getSchema().getClass("Dependents");
      master = db.getMetadata().getSchema().getClass("Master");

      // CREATE NEW DOC
      new ODocument(db, "Dependents")
          .field(
              "dependents",
              new ODocument[] {
                new ODocument(db, "Master")
                    .field("mastertype", "Title")
                    .field("master", 4151788013272153098L)
              })
          .save();
      db.close();

      db.open("admin", "admin");

      // LOAD IT AND CHECK THE LONG VALUE
      for (ODocument doc : db.browseClass("Dependents")) {
        System.out.println(doc);
        for (ODocument emb : (Iterable<ODocument>) doc.field("dependents"))
          Assert.assertEquals(emb.field("master"), 4151788013272153098L);
      }
      db.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 4
0
 public static void create() {
   OClass account =
       database
           .getMetadata()
           .getSchema()
           .createClass(
               "Account",
               database.getStorage().addCluster("account", OStorage.CLUSTER_TYPE.PHYSICAL));
   account.createProperty("id", OType.LONG);
   account.createProperty("val1", OType.DOUBLE);
   account.createProperty("val2", OType.DOUBLE);
   account.createProperty("val3", OType.FLOAT);
   account.createProperty("val4", OType.SHORT);
   account.createProperty("val5", OType.STRING);
   account.createProperty("name", OType.STRING);
 }
  @BeforeClass
  @Override
  public void init() {
    super.init();
    OSchema schema = databaseDocumentTx.getMetadata().getSchema();
    OClass v = schema.getClass("V");
    OClass oClass = schema.createClass("Place");
    oClass.setSuperClass(v);
    oClass.createProperty("location", OType.EMBEDDED, schema.getClass("OMultiLineString"));
    oClass.createProperty("name", OType.STRING);

    databaseDocumentTx
        .command(
            new OCommandSQL("CREATE INDEX Place.location ON Place(location) SPATIAL ENGINE LUCENE"))
        .execute();
  }
  @Override
  public void initClazz(ODatabaseDocumentTx db) {

    OSchemaProxy schema = db.getMetadata().getSchema();
    OClass shape = superClass(db);
    OClass polygon = schema.createAbstractClass(getName(), shape);
    polygon.createProperty("geometries", OType.EMBEDDEDLIST, shape);
  }
Exemplo n.º 7
0
  @BeforeClass
  public void setupSchema() {
    final OClass linkMapIndexTestClass =
        database.getMetadata().getSchema().createClass("LinkMapIndexTestClass");
    linkMapIndexTestClass.createProperty("linkMap", OType.LINKMAP);

    linkMapIndexTestClass.createIndex("mapIndexTestKey", OClass.INDEX_TYPE.NOTUNIQUE, "linkMap");
    linkMapIndexTestClass.createIndex(
        "mapIndexTestValue", OClass.INDEX_TYPE.NOTUNIQUE, "linkMap by value");

    database.getMetadata().getSchema().save();
  }
  @Before
  public void init() {
    initDB();
    OSchema schema = databaseDocumentTx.getMetadata().getSchema();

    if (schema.getClass("City") == null) {
      OClass oClass = schema.createClass("City");
      oClass.createProperty("name", OType.STRING);
    }
    databaseDocumentTx
        .command(new OCommandSQL("create index City.name on City (name) FULLTEXT ENGINE LUCENE"))
        .execute();
  }
  @Before
  public void init() {
    initDB();
    OSchema schema = databaseDocumentTx.getMetadata().getSchema();
    OClass v = schema.getClass("V");
    OClass song = schema.createClass("City");
    song.setSuperClass(v);
    song.createProperty("name", OType.STRING);

    databaseDocumentTx
        .command(new OCommandSQL("create index City.name on City (name) FULLTEXT ENGINE LUCENE"))
        .execute();
  }
Exemplo n.º 10
0
  @BeforeClass
  public void beforeClass() {
    database = new ODatabaseDocumentTx(url);

    if (database.isClosed()) database.open("admin", "admin");

    final OSchema schema = database.getMetadata().getSchema();
    final OClass oClass = schema.createClass("SQLDropIndexTestClass");
    oClass.createProperty("prop1", EXPECTED_PROP1_TYPE);
    oClass.createProperty("prop2", EXPECTED_PROP2_TYPE);

    schema.save();
  }
Exemplo n.º 11
0
  public void testAutoConversionOfEmbeddededListWithLinkedClass() {
    OClass c = database.getMetadata().getSchema().getOrCreateClass("TestConvert");
    if (!c.existsProperty("embeddedListWithLinkedClass"))
      c.createProperty(
          "embeddedListWithLinkedClass",
          OType.EMBEDDEDLIST,
          database.getMetadata().getSchema().getOrCreateClass("TestConvertLinkedClass"));

    ODocument doc =
        database
            .command(
                new OCommandSQL(
                    "INSERT INTO TestConvert SET name = 'embeddedListWithLinkedClass', embeddedListWithLinkedClass = [{'line1':'123 Fake Street'}]"))
            .execute();

    database
        .command(
            new OCommandSQL(
                "UPDATE "
                    + doc.getIdentity()
                    + " ADD embeddedListWithLinkedClass = [{'line1':'123 Fake Street'}]"))
        .execute();

    doc.reload();

    Assert.assertTrue(doc.field("embeddedListWithLinkedClass") instanceof List);
    Assert.assertEquals(((Collection) doc.field("embeddedListWithLinkedClass")).size(), 2);

    database
        .command(
            new OCommandSQL(
                "UPDATE "
                    + doc.getIdentity()
                    + " ADD embeddedListWithLinkedClass = {'line1':'123 Fake Street'}"))
        .execute();

    doc.reload();

    Assert.assertTrue(doc.field("embeddedListWithLinkedClass") instanceof List);
    Assert.assertEquals(((Collection) doc.field("embeddedListWithLinkedClass")).size(), 3);

    List addr = doc.field("embeddedListWithLinkedClass");
    for (Object o : addr) {
      Assert.assertTrue(o instanceof ODocument);
      Assert.assertEquals(((ODocument) o).getClassName(), "TestConvertLinkedClass");
    }
  }
Exemplo n.º 12
0
  protected void open() {
    log.debug("try to open database");

    this.graphFactory =
        new OrientGraphFactory(this.databaseUrl, this.username, this.password).setupPool(10, 10);

    OSchema schema = this.graphFactory.getDatabase().getMetadata().getSchema();

    OClass oClass = schema.getClass("V");

    if (!oClass.areIndexed("mailadress")) {
      oClass.createProperty("mailadress", OType.STRING).setNotNull(true);
      oClass.createIndex("mailadressIndex", OClass.INDEX_TYPE.UNIQUE, "mailadress");
    }

    log.debug("Succesfully opened database");
  }
Exemplo n.º 13
0
  @SuppressWarnings("unchecked")
  @Test
  public void createLinkInTx() {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(url);
    db.open("admin", "admin");

    OClass profile =
        db.getMetadata()
            .getSchema()
            .createClass("MyProfile", db.addCluster("myprofile", OStorage.CLUSTER_TYPE.PHYSICAL));
    OClass edge =
        db.getMetadata()
            .getSchema()
            .createClass("MyEdge", db.addCluster("myedge", OStorage.CLUSTER_TYPE.PHYSICAL));
    profile
        .createProperty("name", OType.STRING)
        .setMin("3")
        .setMax("30")
        .createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
    profile.createProperty("surname", OType.STRING).setMin("3").setMax("30");
    profile.createProperty("in", OType.LINKSET, edge);
    profile.createProperty("out", OType.LINKSET, edge);
    edge.createProperty("in", OType.LINK, profile);
    edge.createProperty("out", OType.LINK, profile);

    db.begin();

    ODocument kim = new ODocument("MyProfile").field("name", "Kim").field("surname", "Bauer");
    ODocument teri = new ODocument("MyProfile").field("name", "Teri").field("surname", "Bauer");
    ODocument jack = new ODocument("MyProfile").field("name", "Jack").field("surname", "Bauer");

    ODocument myedge = new ODocument("MyEdge").field("in", kim).field("out", jack);
    myedge.save();
    ((HashSet<ODocument>) kim.field("out", new HashSet<ORID>()).field("out")).add(myedge);
    ((HashSet<ODocument>) jack.field("in", new HashSet<ORID>()).field("in")).add(myedge);

    jack.save();
    kim.save();
    teri.save();

    db.commit();

    db.close();

    db.open("admin", "admin");
    List<ODocument> result =
        db.command(new OSQLSynchQuery<ODocument>("select from MyProfile ")).execute();

    Assert.assertTrue(result.size() != 0);

    db.close();
  }
Exemplo n.º 14
0
  @Test
  public void queryCountWithConditions() {
    OClass indexed = database.getMetadata().getSchema().getOrCreateClass("Indexed");
    indexed.createProperty("key", OType.STRING);
    indexed.createIndex("keyed", OClass.INDEX_TYPE.NOTUNIQUE, "key");
    database.<ODocument>newInstance("Indexed").field("key", "one").save();
    database.<ODocument>newInstance("Indexed").field("key", "two").save();

    List<ODocument> result =
        database
            .command(
                new OSQLSynchQuery<ODocument>(
                    "select count(*) as total from Indexed where key > 'one'"))
            .execute();

    Assert.assertTrue(result.size() == 1);
    for (ODocument d : result) {
      Assert.assertNotNull(d.field("total"));
      Assert.assertTrue(((Number) d.field("total")).longValue() > 0);
    }
  }
Exemplo n.º 15
0
  @BeforeMethod
  public void beforeMethod() throws Exception {
    super.beforeMethod();

    hashFunction.setValueSerializer(new OIntegerSerializer());

    if (database.getMetadata().getSchema().existsClass("AutoShardingTest"))
      database.getMetadata().getSchema().dropClass("AutoShardingTest");

    cls = database.getMetadata().getSchema().createClass("AutoShardingTest");
    cls.createProperty("id", OType.INTEGER);

    idx =
        cls.createIndex(
            "testAutoSharding",
            OClass.INDEX_TYPE.NOTUNIQUE.toString(),
            (OProgressListener) null,
            (ODocument) null,
            "AUTOSHARDING",
            new String[] {"id"});

    clusterIds = cls.getClusterIds();
  }
Exemplo n.º 16
0
 @Override
 public void create() {
   final ODatabaseDocument db = ODatabaseRecordThreadLocal.INSTANCE.get();
   if (db.getMetadata().getSchema().existsClass(OScheduledEvent.CLASS_NAME)) return;
   final OClass f = db.getMetadata().getSchema().createClass(OScheduledEvent.CLASS_NAME);
   f.createProperty(OScheduledEvent.PROP_NAME, OType.STRING, (OType) null, true)
       .setMandatory(true)
       .setNotNull(true);
   f.createProperty(OScheduledEvent.PROP_RULE, OType.STRING, (OType) null, true)
       .setMandatory(true)
       .setNotNull(true);
   f.createProperty(OScheduledEvent.PROP_ARGUMENTS, OType.EMBEDDEDMAP, (OType) null, true);
   f.createProperty(OScheduledEvent.PROP_STATUS, OType.STRING, (OType) null, true);
   f.createProperty(
           OScheduledEvent.PROP_FUNC,
           OType.LINK,
           db.getMetadata().getSchema().getClass(OFunction.CLASS_NAME),
           true)
       .setMandatory(true)
       .setNotNull(true);
   f.createProperty(OScheduledEvent.PROP_STARTTIME, OType.DATETIME, (OType) null, true);
 }
Exemplo n.º 17
0
  public void TransactionRollbackConstistencyTest() {
    System.out.println(
        "**************************TransactionRollbackConsistencyTest***************************************");
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(url);
    db.open("admin", "admin");
    OClass vertexClass = db.getMetadata().getSchema().createClass("TRVertex");
    OClass edgeClass = db.getMetadata().getSchema().createClass("TREdge");
    vertexClass.createProperty("in", OType.LINKSET, edgeClass);
    vertexClass.createProperty("out", OType.LINKSET, edgeClass);
    edgeClass.createProperty("in", OType.LINK, vertexClass);
    edgeClass.createProperty("out", OType.LINK, vertexClass);

    OClass personClass = db.getMetadata().getSchema().createClass("TRPerson", vertexClass);
    personClass.createProperty("name", OType.STRING).createIndex(OClass.INDEX_TYPE.UNIQUE);
    personClass.createProperty("surname", OType.STRING).createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
    personClass.createProperty("version", OType.INTEGER);

    db.getMetadata().getSchema().save();
    db.close();

    final int cnt = 4;

    db.open("admin", "admin");
    db.begin();
    Vector inserted = new Vector();

    for (int i = 0; i < cnt; i++) {
      ODocument person = new ODocument("TRPerson");
      person.field("name", Character.toString((char) ('A' + i)));
      person.field("surname", Character.toString((char) ('A' + (i % 3))));
      person.field("myversion", 0);
      person.field("in", new HashSet<ODocument>());
      person.field("out", new HashSet<ODocument>());

      if (i >= 1) {
        ODocument edge = new ODocument("TREdge");
        edge.field("in", person.getIdentity());
        edge.field("out", inserted.elementAt(i - 1));
        ((HashSet<ODocument>) person.field("out")).add(edge);
        ((HashSet<ODocument>) ((ODocument) inserted.elementAt(i - 1)).field("in")).add(edge);
        edge.save();
      }
      inserted.add(person);
      person.save();
    }
    db.commit();

    final List<ODocument> result1 = db.command(new OCommandSQL("select from TRPerson")).execute();
    Assert.assertNotNull(result1);
    Assert.assertEquals(result1.size(), cnt);
    System.out.println("Before transaction commit");
    for (ODocument d : result1) System.out.println(d);

    try {
      db.begin();
      Vector inserted2 = new Vector();

      for (int i = 0; i < cnt; i++) {
        ODocument person = new ODocument("TRPerson");
        person.field("name", Character.toString((char) ('a' + i)));
        person.field("surname", Character.toString((char) ('a' + (i % 3))));
        person.field("myversion", 0);
        person.field("in", new HashSet<ODocument>());
        person.field("out", new HashSet<ODocument>());

        if (i >= 1) {
          ODocument edge = new ODocument("TREdge");
          edge.field("in", person.getIdentity());
          edge.field("out", inserted2.elementAt(i - 1));
          ((HashSet<ODocument>) person.field("out")).add(edge);
          ((HashSet<ODocument>) ((ODocument) inserted2.elementAt(i - 1)).field("in")).add(edge);
          edge.save();
        }
        inserted2.add(person);
        person.save();
      }

      for (int i = 0; i < cnt; i++) {
        if (i != cnt - 1) {
          ((ODocument) inserted.elementAt(i)).field("myversion", 2);
          ((ODocument) inserted.elementAt(i)).save();
        }
      }

      ((ODocument) inserted.elementAt(cnt - 1)).delete();
      ((ODocument) inserted.elementAt(cnt - 2)).getRecordVersion().reset();
      ((ODocument) inserted.elementAt(cnt - 2)).save();
      db.commit();
      Assert.assertTrue(false);
    } catch (OConcurrentModificationException e) {
      Assert.assertTrue(true);
      db.rollback();
    }

    final List<ODocument> result2 = db.command(new OCommandSQL("select from TRPerson")).execute();
    Assert.assertNotNull(result2);
    System.out.println("After transaction commit failure/rollback");
    for (ODocument d : result2) System.out.println(d);
    Assert.assertEquals(result2.size(), cnt);

    db.close();
    System.out.println(
        "**************************TransactionRollbackConstistencyTest***************************************");
  }
Exemplo n.º 18
0
  @Test
  public void testTransactionPopulateDelete() {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(url);
    db.open("admin", "admin");

    if (!db.getMetadata().getSchema().existsClass("MyFruit")) {
      OClass fruitClass = db.getMetadata().getSchema().createClass("MyFruit");
      fruitClass.createProperty("name", OType.STRING);
      fruitClass.createProperty("color", OType.STRING);
      fruitClass.createProperty("flavor", OType.STRING);

      db.getMetadata()
          .getSchema()
          .getClass("MyFruit")
          .getProperty("name")
          .createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
      db.getMetadata()
          .getSchema()
          .getClass("MyFruit")
          .getProperty("color")
          .createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
      db.getMetadata()
          .getSchema()
          .getClass("MyFruit")
          .getProperty("flavor")
          .createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
    }
    db.close();

    db = new ODatabaseDocumentTx(url);
    db.open("admin", "admin");
    int chunkSize = 500;
    for (int initialValue = 0; initialValue < 10; initialValue++) {
      System.out.println("initialValue = " + initialValue);
      Assert.assertEquals(db.countClusterElements("MyFruit"), 0);

      // do insert
      Vector<ODocument> v = new Vector<ODocument>();
      db.begin();
      for (int i = initialValue * chunkSize; i < (initialValue * chunkSize) + chunkSize; i++) {
        ODocument d =
            new ODocument("MyFruit")
                .field("name", "" + i)
                .field("color", "FOO")
                .field("flavor", "BAR" + i);
        d.save();
        v.addElement(d);
      }
      System.out.println("populate commit");
      db.commit();

      // do delete
      db.begin();
      System.out.println("vector size = " + v.size());
      for (int i = 0; i < v.size(); i++) {
        db.delete(v.elementAt(i));
      }
      System.out.println("delete commit");
      db.commit();

      Assert.assertEquals(db.countClusterElements("MyFruit"), 0);
    }

    db.close();
  }
Exemplo n.º 19
0
  private void initializeExceptionRecordTable(String databaseUrl) {
    ODatabaseDocumentTx database = new ODatabaseDocumentTx(databaseUrl).create();
    OClass exceptionRecordClass = database.getMetadata().getSchema().createClass("ExceptionRecord");
    OClass exceptionVersionClass =
        database.getMetadata().getSchema().createClass("ExceptionRecordVersion");
    try {

      exceptionRecordClass.createProperty("id", OType.STRING);
      exceptionRecordClass.createProperty("status", OType.STRING);
      exceptionRecordClass.createProperty("approved", OType.BOOLEAN);
      exceptionRecordClass.createProperty("recordType", OType.STRING);
      exceptionRecordClass.createProperty("groupNonException", OType.BOOLEAN);
      exceptionRecordClass.createProperty("comment", OType.STRING);
      exceptionRecordClass.createProperty("jobId", OType.STRING);
      exceptionRecordClass.createProperty("dataflowName", OType.STRING);
      exceptionRecordClass.createProperty("username", OType.STRING);
      exceptionRecordClass.createProperty("timestamp", OType.LONG);
      exceptionRecordClass.createProperty("stageLabel", OType.STRING);
      exceptionRecordClass.createProperty("groupColumn", OType.STRING);
      exceptionRecordClass.createProperty("lastModifiedBy", OType.STRING);
      exceptionRecordClass.createProperty("lastModified", OType.LONG);
      exceptionRecordClass.createProperty("data", OType.STRING);

      exceptionVersionClass.createProperty("key-exceptionId", OType.STRING);
      exceptionVersionClass.createProperty("key-version", OType.STRING);
      exceptionVersionClass.createProperty("jobId", OType.STRING);
      exceptionVersionClass.createProperty("dataflowName", OType.STRING);

      exceptionRecordClass.createIndex("ExceptionRecord_pk", INDEX_TYPE.UNIQUE, "id");
      exceptionRecordClass.createIndex(
          "ExceptionRecord_idx",
          INDEX_TYPE.NOTUNIQUE,
          "status",
          "approved",
          "recordType",
          "groupNonException",
          "comment",
          "jobId",
          "dataflowName",
          "username",
          "timestamp",
          "stageLabel",
          "groupColumn",
          "lastModifiedBy",
          "lastModified");

      exceptionVersionClass.createIndex(
          "ExceptionVersion_Index",
          INDEX_TYPE.NOTUNIQUE,
          "key-exceptionId",
          "key-version",
          "jobId",
          "dataflowname");
    } finally {
      database.close();
    }
  }
 @Override
 protected OProperty createInstance(OProperty proxy) {
   OSchema schema = OrientDbWebSession.get().getDatabase().getMetadata().getSchema();
   OClass oClass = schema.getClass(className);
   return oClass.createProperty(proxy.getName(), proxy.getType());
 }