Search in sources :

Example 1 with OSchema

use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.

the class ODocumentTest method testRemovingReadonlyField.

@Test
public void testRemovingReadonlyField() {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + ODocumentTest.class.getSimpleName());
    db.create();
    try {
        OSchema schema = db.getMetadata().getSchema();
        OClass classA = schema.createClass("TestRemovingField2");
        classA.createProperty("name", OType.STRING);
        OProperty property = classA.createProperty("property", OType.STRING);
        property.setReadonly(true);
        ODocument doc = new ODocument(classA);
        doc.field("name", "My Name");
        doc.field("property", "value1");
        doc.save();
        doc.field("name", "My Name 2");
        doc.field("property", "value2");
        // we decided undo everything
        doc.undo();
        // change something
        doc.field("name", "My Name 3");
        doc.save();
        doc.field("name", "My Name 4");
        doc.field("property", "value4");
        // we decided undo readonly field
        doc.undo("property");
        doc.save();
    } finally {
        db.drop();
    }
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Test(org.testng.annotations.Test)

Example 2 with OSchema

use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.

the class OCommandExecutorSQLSelectTest method beforeClass.

@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 clusters 1")).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 unwindtest2")).execute();
    db.command(new OCommandSQL("insert into unwindtest2 (name, coll) values ('foo', [])")).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", 1, null);
    }
    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);
    initLinkListSequence(db);
    initMaxLongNumber(db);
    initFilterAndOrderByTest(db);
    initComplexFilterInSquareBrackets(db);
    initCollateOnLinked(db);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with OSchema

use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.

the class NestedInsertTest method testLinkedNested.

@Test
public void testLinkedNested() {
    OSchema schm = db.getMetadata().getSchema();
    OClass cl = schm.createClass("myClass");
    OClass linked = schm.createClass("Linked");
    cl.createProperty("some", OType.LINK, linked);
    final ODocument res = db.command(new OCommandSQL("insert into myClass set some ={\"@type\":\"d\",\"@class\":\"Linked\",\"name\":\"a name\"} return @this")).execute();
    final ODocument ln = res.field("some");
    Assert.assertNotNull(ln);
    Assert.assertTrue(ln.getIdentity().isPersistent());
    Assert.assertEquals(ln.fields(), 1);
    Assert.assertEquals(ln.field("name"), "a name");
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 4 with OSchema

use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.

the class OCommandExecutorSQLCreateClassTest method init.

@BeforeClass
public static void init() throws Exception {
    db = new ODatabaseDocumentTx("memory:" + OCommandExecutorSQLCreateClassTest.class.getSimpleName());
    if (db.exists()) {
        db.open("admin", "admin");
        db.drop();
    }
    db.create();
    final OSchema schema = db.getMetadata().getSchema();
    schema.createClass("User", schema.getClass("V"));
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)

Example 5 with OSchema

use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.

the class OBonsaiTreeRepair method repairDatabaseRidbags.

public void repairDatabaseRidbags(ODatabaseDocument db, OCommandOutputListener outputListener) {
    message(outputListener, "Repair of ridbags is started ...\n");
    final OMetadata metadata = db.getMetadata();
    final OSchema schema = metadata.getSchema();
    final OClass edgeClass = schema.getClass(OrientEdgeType.CLASS_NAME);
    if (edgeClass != null) {
        final HashMap<String, Set<ORID>> processedVertexes = new HashMap<String, Set<ORID>>();
        final long countEdges = db.countClass(edgeClass.getName());
        message(outputListener, countEdges + " will be processed.");
        long counter = 0;
        for (ODocument edge : db.browseClass(edgeClass.getName())) {
            try {
                final String label;
                if (edge.field(OrientElement.LABEL_FIELD_NAME) != null) {
                    label = edge.field(OrientElement.LABEL_FIELD_NAME);
                } else if (!edge.getClassName().equals(edgeClass.getName())) {
                    label = edge.getClassName();
                } else {
                    counter++;
                    continue;
                }
                final ODocument inVertex = edge.<OIdentifiable>field(OrientBaseGraph.CONNECTION_IN).getRecord();
                final ODocument outVertex = edge.<OIdentifiable>field(OrientBaseGraph.CONNECTION_OUT).getRecord();
                final String inVertexName = OrientVertex.getConnectionFieldName(Direction.IN, label, true);
                final String outVertexName = OrientVertex.getConnectionFieldName(Direction.OUT, label, true);
                Set<ORID> inVertexes = processedVertexes.get(inVertexName);
                if (inVertexes == null) {
                    inVertexes = new HashSet<ORID>();
                    processedVertexes.put(inVertexName, inVertexes);
                }
                Set<ORID> outVertexes = processedVertexes.get(outVertexName);
                if (outVertexes == null) {
                    outVertexes = new HashSet<ORID>();
                    processedVertexes.put(outVertexName, outVertexes);
                }
                if (inVertex.field(inVertexName) instanceof ORidBag) {
                    if (inVertexes.add(inVertex.getIdentity())) {
                        inVertex.field(inVertexName, new ORidBag());
                    }
                    final ORidBag inRidBag = inVertex.field(inVertexName);
                    inRidBag.add(edge.getIdentity());
                    inVertex.save();
                }
                if (outVertex.field(outVertexName) instanceof ORidBag) {
                    if (outVertexes.add(outVertex.getIdentity())) {
                        outVertex.field(outVertexName, new ORidBag());
                    }
                    final ORidBag outRidBag = outVertex.field(outVertexName);
                    outRidBag.add(edge.getIdentity());
                    outVertex.save();
                }
                counter++;
                if (counter > 0 && counter % 1000 == 0)
                    message(outputListener, counter + " edges were processed out of " + countEdges + " \n.");
            } catch (Exception e) {
                e.printStackTrace();
                message(outputListener, "Error during processing of edge with id " + edge.getIdentity() + "\n");
            }
        }
        message(outputListener, "Processed " + counter + " from " + countEdges + ".");
    }
    message(outputListener, "repair of ridbags is completed\n");
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OMetadata(com.orientechnologies.orient.core.metadata.OMetadata) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)203 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)165 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)122 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)54 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)46 Test (org.testng.annotations.Test)35 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)31 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)23 Test (org.junit.Test)19 Before (org.junit.Before)16 ORID (com.orientechnologies.orient.core.id.ORID)15 OIndex (com.orientechnologies.orient.core.index.OIndex)15 Collection (java.util.Collection)15 Set (java.util.Set)15 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)9 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)9 BeforeClass (org.testng.annotations.BeforeClass)9 OStorage (com.orientechnologies.orient.core.storage.OStorage)6 ArrayList (java.util.ArrayList)5 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)4