Ejemplo n.º 1
0
  public void testUpdateEdgeContent() {
    final OSchema schema = database.getMetadata().getSchema();
    OClass vertex = schema.getClass("V");
    OClass edge = schema.getClass("E");

    schema.createClass("UpdateEdgeContentV", vertex);
    schema.createClass("UpdateEdgeContentE", edge);

    final ORID vOneId =
        ((ODocument)
                database.command(new OCommandSQL("create vertex UpdateEdgeContentV")).execute())
            .getIdentity();
    final ORID vTwoId =
        ((ODocument)
                database.command(new OCommandSQL("create vertex UpdateEdgeContentV")).execute())
            .getIdentity();

    database
        .command(new OCommandSQL("create edge UpdateEdgeContentE from " + vOneId + " to " + vTwoId))
        .execute();
    database
        .command(new OCommandSQL("create edge UpdateEdgeContentE from " + vOneId + " to " + vTwoId))
        .execute();
    database
        .command(new OCommandSQL("create edge UpdateEdgeContentE from " + vOneId + " to " + vTwoId))
        .execute();

    List<ODocument> result =
        database.query(
            new OSQLSynchQuery<ODocument>("select outV(), inV() from UpdateEdgeContentE"));

    Assert.assertEquals(result.size(), 3);

    for (ODocument doc : result) {
      Assert.assertEquals(doc.field("outV"), vOneId);
      Assert.assertEquals(doc.field("inV"), vTwoId);
    }

    database
        .command(new OCommandSQL("update UpdateEdgeContentE content {value : 'val'}"))
        .execute();

    result =
        database.query(
            new OSQLSynchQuery<ODocument>("select outV(), inV() from UpdateEdgeContentE"));

    Assert.assertEquals(result.size(), 3);

    for (ODocument doc : result) {
      Assert.assertEquals(doc.field("outV"), vOneId);
      Assert.assertEquals(doc.field("inV"), vTwoId);
    }

    result = database.query(new OSQLSynchQuery<ODocument>("select from UpdateEdgeContentE"));
    Assert.assertEquals(result.size(), 3);
    for (ODocument doc : result) {
      Assert.assertEquals(doc.field("value"), "val");
    }
  }
Ejemplo n.º 2
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;
  }
Ejemplo n.º 3
0
  public void testUpdateVertexContent() {
    final OSchema schema = database.getMetadata().getSchema();
    OClass vertex = schema.getClass("V");
    schema.createClass("UpdateVertexContent", vertex);

    final ORID vOneId =
        ((ODocument)
                database.command(new OCommandSQL("create vertex UpdateVertexContent")).execute())
            .getIdentity();
    final ORID vTwoId =
        ((ODocument)
                database.command(new OCommandSQL("create vertex UpdateVertexContent")).execute())
            .getIdentity();

    database.command(new OCommandSQL("create edge from " + vOneId + " to " + vTwoId)).execute();
    database.command(new OCommandSQL("create edge from " + vOneId + " to " + vTwoId)).execute();
    database.command(new OCommandSQL("create edge from " + vOneId + " to " + vTwoId)).execute();

    List<ODocument> result =
        database.query(
            new OSQLSynchQuery<ODocument>(
                "select sum(outE().size(), inE().size()) from UpdateVertexContent"));

    Assert.assertEquals(result.size(), 2);

    for (ODocument doc : result) {
      Assert.assertEquals(doc.field("sum"), 3);
    }

    database
        .command(
            new OCommandSQL(
                "update UpdateVertexContent content {value : 'val'} where @rid = " + vOneId))
        .execute();
    database
        .command(
            new OCommandSQL(
                "update UpdateVertexContent content {value : 'val'} where @rid =  " + vTwoId))
        .execute();

    result =
        database.query(
            new OSQLSynchQuery<ODocument>(
                "select sum(outE().size(), inE().size()) from UpdateVertexContent"));

    Assert.assertEquals(result.size(), 2);

    for (ODocument doc : result) {
      Assert.assertEquals(doc.field("sum"), 3);
    }

    result = database.query(new OSQLSynchQuery<ODocument>("select from UpdateVertexContent"));
    Assert.assertEquals(result.size(), 2);
    for (ODocument doc : result) {
      Assert.assertEquals(doc.field("value"), "val");
    }
  }
  @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();
  }
Ejemplo n.º 6
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();
  }
  @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();
  }
Ejemplo n.º 8
0
  @Test
  public void insertAvoidingSubQuery() {
    database.open("admin", "admin");

    final OSchema schema = database.getMetadata().getSchema();
    if (schema.getClass("test") == null) schema.createClass("test");

    ODocument doc =
        (ODocument)
            database
                .command(new OCommandSQL("INSERT INTO test(text) VALUES ('(Hello World)')"))
                .execute();

    Assert.assertTrue(doc != null);
    Assert.assertEquals(doc.field("text"), "(Hello World)");

    database.close();
  }
Ejemplo n.º 9
0
  @Test
  public void insertSubQuery() {
    database.open("admin", "admin");

    final OSchema schema = database.getMetadata().getSchema();
    if (schema.getClass("test") == null) schema.createClass("test");

    ODocument doc =
        (ODocument)
            database
                .command(new OCommandSQL("INSERT INTO test SET names = (select name from OUser)"))
                .execute();

    Assert.assertTrue(doc != null);
    Assert.assertNotNull(doc.field("names"));
    Assert.assertTrue(doc.field("names") instanceof Collection);
    Assert.assertEquals(((Collection<?>) doc.field("names")).size(), 3);

    database.close();
  }
  @BeforeClass
  public void beforeClass() throws Exception {
    db = new ODatabaseDocumentTx(DB_STORAGE + ":" + DB_NAME);
    db.create();
    getProfilerInstance().startRecording();

    db.command(new OCommandSQL("CREATE class foo")).execute();
    db.command(new OCommandSQL("CREATE property foo.name STRING")).execute();
    db.command(new OCommandSQL("CREATE property foo.bar INTEGER")).execute();
    db.command(new OCommandSQL("CREATE property foo.address EMBEDDED")).execute();
    db.command(new OCommandSQL("CREATE property foo.comp STRING")).execute();
    db.command(new OCommandSQL("CREATE property foo.osite INTEGER")).execute();

    db.command(new OCommandSQL("CREATE index foo_name on foo (name) NOTUNIQUE")).execute();
    db.command(new OCommandSQL("CREATE index foo_bar on foo (bar) NOTUNIQUE")).execute();
    db.command(new OCommandSQL("CREATE index foo_comp_osite on foo (comp, osite) NOTUNIQUE"))
        .execute();

    db.command(
            new OCommandSQL(
                "insert into foo (name, bar, address) values ('a', 1, {'street':'1st street', 'city':'NY', '@type':'d'})"))
        .execute();
    db.command(new OCommandSQL("insert into foo (name, bar) values ('b', 2)")).execute();
    db.command(new OCommandSQL("insert into foo (name, bar) values ('c', 3)")).execute();

    db.command(new OCommandSQL("insert into foo (comp, osite) values ('a', 1)")).execute();
    db.command(new OCommandSQL("insert into foo (comp, osite) values ('b', 2)")).execute();

    db.command(new OCommandSQL("CREATE class bar")).execute();

    db.command(new OCommandSQL("insert into bar (name, foo) values ('a', 1)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('b', 2)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('c', 3)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('d', 4)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('e', 5)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('f', 1)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('g', 2)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('h', 3)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('i', 4)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('j', 5)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('k', 1)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('l', 2)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('m', 3)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('n', 4)")).execute();
    db.command(new OCommandSQL("insert into bar (name, foo) values ('o', 5)")).execute();

    db.command(new OCommandSQL("CREATE class ridsorttest")).execute();
    db.command(new OCommandSQL("CREATE property ridsorttest.name INTEGER")).execute();
    db.command(new OCommandSQL("CREATE index ridsorttest_name on ridsorttest (name) NOTUNIQUE"))
        .execute();

    db.command(new OCommandSQL("insert into ridsorttest (name) values (1)")).execute();
    db.command(new OCommandSQL("insert into ridsorttest (name) values (5)")).execute();
    db.command(new OCommandSQL("insert into ridsorttest (name) values (3)")).execute();
    db.command(new OCommandSQL("insert into ridsorttest (name) values (4)")).execute();
    db.command(new OCommandSQL("insert into ridsorttest (name) values (1)")).execute();
    db.command(new OCommandSQL("insert into ridsorttest (name) values (8)")).execute();
    db.command(new OCommandSQL("insert into ridsorttest (name) values (6)")).execute();

    db.command(new OCommandSQL("CREATE class unwindtest")).execute();
    db.command(
            new OCommandSQL("insert into unwindtest (name, coll) values ('foo', ['foo1', 'foo2'])"))
        .execute();
    db.command(
            new OCommandSQL("insert into unwindtest (name, coll) values ('bar', ['bar1', 'bar2'])"))
        .execute();

    db.command(new OCommandSQL("CREATE class edge")).execute();

    db.command(new OCommandSQL("CREATE class TestFromInSquare")).execute();
    db.command(
            new OCommandSQL(
                "insert into TestFromInSquare set tags = {' from ':'foo',' to ':'bar'}"))
        .execute();

    db.command(new OCommandSQL("CREATE class TestMultipleClusters")).execute();
    db.command(
            new OCommandSQL("alter class TestMultipleClusters addcluster testmultipleclusters1 "))
        .execute();
    db.command(
            new OCommandSQL("alter class TestMultipleClusters addcluster testmultipleclusters2 "))
        .execute();
    db.command(new OCommandSQL("insert into cluster:testmultipleclusters set name = 'aaa'"))
        .execute();
    db.command(new OCommandSQL("insert into cluster:testmultipleclusters1 set name = 'foo'"))
        .execute();
    db.command(new OCommandSQL("insert into cluster:testmultipleclusters2 set name = 'bar'"))
        .execute();

    db.command(new OCommandSQL("CREATE class TestUrl")).execute();
    db.command(
            new OCommandSQL("insert into TestUrl content { \"url\": \"http://www.google.com\" }"))
        .execute();

    db.command(new OCommandSQL("CREATE class TestParams")).execute();
    db.command(
            new OCommandSQL(
                "insert into TestParams  set name = 'foo', surname ='foo', active = true"))
        .execute();
    db.command(
            new OCommandSQL(
                "insert into TestParams  set name = 'foo', surname ='bar', active = false"))
        .execute();

    db.command(new OCommandSQL("CREATE class TestParamsEmbedded")).execute();
    db.command(
            new OCommandSQL(
                "insert into TestParamsEmbedded set emb = {  \n"
                    + "            \"count\":0,\n"
                    + "            \"testupdate\":\"1441258203385\"\n"
                    + "         }"))
        .execute();
    db.command(
            new OCommandSQL(
                "insert into TestParamsEmbedded set emb = {  \n"
                    + "            \"count\":1,\n"
                    + "            \"testupdate\":\"1441258203385\"\n"
                    + "         }"))
        .execute();

    db.command(new OCommandSQL("CREATE class TestBacktick")).execute();
    db.command(new OCommandSQL("insert into TestBacktick  set foo = 1, bar = 2, `foo-bar` = 10"))
        .execute();

    // /*** from issue #2743
    OSchema schema = db.getMetadata().getSchema();
    if (!schema.existsClass("alphabet")) {
      schema.createClass("alphabet");
    }

    ORecordIteratorClass<ODocument> iter = db.browseClass("alphabet");
    while (iter.hasNext()) {
      iter.next().delete();
    }

    // add 26 entries: { "letter": "A", "number": 0 }, ... { "letter": "Z", "number": 25 }

    String rowModel = "{\"letter\": \"%s\", \"number\": %d}";
    for (int i = 0; i < 26; ++i) {
      String l = String.valueOf((char) ('A' + i));
      String json = String.format(rowModel, l, i);
      ODocument doc = db.newInstance("alphabet");
      doc.fromJSON(json);
      doc.save();
    }

    db.command(new OCommandSQL("create class OCommandExecutorSQLSelectTest_aggregations"))
        .execute();
    db.command(
            new OCommandSQL(
                "insert into OCommandExecutorSQLSelectTest_aggregations set data = [{\"size\": 0}, {\"size\": 0}, {\"size\": 30}, {\"size\": 50}, {\"size\": 50}]"))
        .execute();

    initExpandSkipLimit(db);

    initMassiveOrderSkipLimit(db);
    initDatesSet(db);

    initMatchesWithRegex(db);
    initDistinctLimit(db);
  }
Ejemplo n.º 11
0
  private void configureDocument(
      ORecordAbstract<?> document, ODatabaseRecord db, DefinitionGroup definition) {
    // configure document

    // as of OrientDB 1.0rc8 the database may no longer be set on the
    // document
    // instead the current database can be set using
    // ODatabaseRecordThreadLocal.INSTANCE.set(db);
    //		document.setDatabase(db);
    if (document instanceof ODocument) {
      // reset class name
      ODocument doc = (ODocument) document;
      /*
       * Attention: Two long class names cause problems as file names will
       * be based on them.
       */
      String className = null;
      if (definition != null) {
        className = ONamespaceMap.encode(determineName(definition));
      } else if (doc.containsField(OSerializationHelper.BINARY_WRAPPER_FIELD)
          || doc.containsField(OSerializationHelper.FIELD_SERIALIZATION_TYPE)) {
        className = OSerializationHelper.BINARY_WRAPPER_CLASSNAME;
      }

      if (className != null) {
        OSchema schema = db.getMetadata().getSchema();
        if (!schema.existsClass(className)) {
          // if the class doesn't exist yet, create a physical cluster
          // manually for it
          int cluster = db.addCluster(className, CLUSTER_TYPE.PHYSICAL);
          schema.createClass(className, cluster);
        }
        doc.setClassName(className);
      }

      // configure children
      for (Entry<String, Object> field : doc) {
        List<ODocument> docs = new ArrayList<ODocument>();
        List<ORecordAbstract<?>> recs = new ArrayList<ORecordAbstract<?>>();
        if (field.getValue() instanceof Collection<?>) {
          for (Object value : (Collection<?>) field.getValue()) {
            if (value instanceof ODocument && !getSpecialFieldNames().contains(field.getKey())) {
              docs.add((ODocument) value);
            } else if (value instanceof ORecordAbstract<?>) {
              recs.add((ORecordAbstract<?>) value);
            }
          }
        } else if (field.getValue() instanceof ODocument
            && !getSpecialFieldNames().contains(field.getKey())) {
          docs.add((ODocument) field.getValue());
        } else if (field.getValue() instanceof ORecordAbstract<?>) {
          recs.add((ORecordAbstract<?>) field.getValue());
        }

        if (definition != null) {
          for (ODocument valueDoc : docs) {
            ChildDefinition<?> child = definition.getChild(decodeProperty(field.getKey()));
            DefinitionGroup childGroup;
            if (child.asProperty() != null) {
              childGroup = child.asProperty().getPropertyType();
            } else if (child.asGroup() != null) {
              childGroup = child.asGroup();
            } else {
              throw new IllegalStateException(
                  "Document is associated neither with a property nor a property group.");
            }
            configureDocument(valueDoc, db, childGroup);
          }
        }

        for (ORecordAbstract<?> fieldRec : recs) {
          configureDocument(fieldRec, db, null);
        }
      }
    }
  }
Ejemplo n.º 12
0
  public void testEscaping() {
    final OSchema schema = database.getMetadata().getSchema();
    schema.createClass("FormatEscapingTest");

    final ODocument document = new ODocument("FormatEscapingTest");
    document.save();

    database
        .command(
            new OCommandSQL(
                "UPDATE FormatEscapingTest SET test = format('aaa \\' bbb') WHERE @rid = "
                    + document.getIdentity()))
        .execute();

    document.reload();

    Assert.assertEquals(document.field("test"), "aaa ' bbb");

    database
        .command(
            new OCommandSQL(
                "UPDATE FormatEscapingTest SET test = 'ccc \\' eee', test2 = format('aaa \\' bbb') WHERE @rid = "
                    + document.getIdentity()))
        .execute();

    document.reload();
    Assert.assertEquals(document.field("test"), "ccc ' eee");
    Assert.assertEquals(document.field("test2"), "aaa ' bbb");

    database
        .command(
            new OCommandSQL(
                "UPDATE FormatEscapingTest SET test = 'aaa \\n bbb' WHERE @rid = "
                    + document.getIdentity()))
        .execute();

    document.reload();
    Assert.assertEquals(document.field("test"), "aaa \n bbb");

    database
        .command(
            new OCommandSQL(
                "UPDATE FormatEscapingTest SET test = 'aaa \\r bbb' WHERE @rid = "
                    + document.getIdentity()))
        .execute();

    document.reload();
    Assert.assertEquals(document.field("test"), "aaa \r bbb");

    database
        .command(
            new OCommandSQL(
                "UPDATE FormatEscapingTest SET test = 'aaa \\b bbb' WHERE @rid = "
                    + document.getIdentity()))
        .execute();

    document.reload();
    Assert.assertEquals(document.field("test"), "aaa \b bbb");

    database
        .command(
            new OCommandSQL(
                "UPDATE FormatEscapingTest SET test = 'aaa \\t bbb' WHERE @rid = "
                    + document.getIdentity()))
        .execute();

    document.reload();
    Assert.assertEquals(document.field("test"), "aaa \t bbb");

    database
        .command(
            new OCommandSQL(
                "UPDATE FormatEscapingTest SET test = 'aaa \\f bbb' WHERE @rid = "
                    + document.getIdentity()))
        .execute();

    document.reload();
    Assert.assertEquals(document.field("test"), "aaa \f bbb");
  }