Search in sources :

Example 56 with OSchema

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

the class ClassIndexManagerTest method testMapDelete.

public void testMapDelete() {
    final OSchema schema = database.getMetadata().getSchema();
    final OClass oClass = schema.getClass("classIndexManagerTestClass");
    final OIndex<?> propFiveIndexKey = oClass.getClassIndex("classIndexManagerTestIndexByKey");
    final OIndex<?> propFiveIndexValue = oClass.getClassIndex("classIndexManagerTestIndexByValue");
    Assert.assertEquals(propFiveIndexKey.getSize(), 0);
    final ODocument doc = new ODocument("classIndexManagerTestClass");
    final Map<String, String> mapProperty = new HashMap<String, String>();
    mapProperty.put("key1", "value1");
    mapProperty.put("key2", "value2");
    doc.field("prop5", mapProperty);
    doc.save();
    Assert.assertEquals(propFiveIndexKey.getSize(), 2);
    Assert.assertNotNull(propFiveIndexKey.get("key1"));
    Assert.assertNotNull(propFiveIndexKey.get("key2"));
    Map<String, String> trackedMap = doc.field("prop5");
    trackedMap.put("key3", "value3");
    trackedMap.put("key4", "value4");
    trackedMap.remove("key1");
    trackedMap.put("key1", "value5");
    trackedMap.remove("key2");
    trackedMap.put("key6", "value6");
    trackedMap.put("key7", "value6");
    trackedMap.put("key8", "value6");
    trackedMap.put("key4", "value7");
    trackedMap.remove("key8");
    doc.save();
    Assert.assertEquals(propFiveIndexKey.getSize(), 5);
    Assert.assertNotNull(propFiveIndexKey.get("key1"));
    Assert.assertNotNull(propFiveIndexKey.get("key3"));
    Assert.assertNotNull(propFiveIndexKey.get("key4"));
    Assert.assertNotNull(propFiveIndexKey.get("key6"));
    Assert.assertNotNull(propFiveIndexKey.get("key7"));
    Assert.assertEquals(propFiveIndexValue.getSize(), 4);
    Assert.assertNotNull(propFiveIndexValue.get("value5"));
    Assert.assertNotNull(propFiveIndexValue.get("value3"));
    Assert.assertNotNull(propFiveIndexValue.get("value7"));
    Assert.assertNotNull(propFiveIndexValue.get("value6"));
    trackedMap = doc.field("prop5");
    trackedMap.remove("key1");
    trackedMap.remove("key3");
    trackedMap.remove("key4");
    trackedMap.put("key6", "value10");
    trackedMap.put("key11", "value11");
    doc.delete();
    Assert.assertEquals(propFiveIndexKey.getSize(), 0);
    Assert.assertEquals(propFiveIndexValue.getSize(), 0);
}
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)

Example 57 with OSchema

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

the class SQLCreateVertexTest method testCreateVertexByContent.

public void testCreateVertexByContent() {
    OrientGraph graph = new OrientGraph(database, false);
    graph.shutdown();
    database.open("admin", "admin");
    OSchema schema = database.getMetadata().getSchema();
    if (!schema.existsClass("CreateVertexByContent")) {
        OClass vClass = schema.createClass("CreateVertexByContent", schema.getClass("V"));
        vClass.createProperty("message", OType.STRING);
    }
    database.command(new OCommandSQL("create vertex CreateVertexByContent content { \"message\": \"(:\"}")).execute();
    database.command(new OCommandSQL("create vertex CreateVertexByContent content { \"message\": \"\\\"‎ה, כן?...‎\\\"\"}")).execute();
    List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select from CreateVertexByContent"));
    Assert.assertEquals(result.size(), 2);
    List<String> messages = new ArrayList<String>();
    messages.add("\"‎ה, כן?...‎\"");
    messages.add("(:");
    List<String> resultMessages = new ArrayList<String>();
    for (ODocument document : result) {
        resultMessages.add(document.<String>field("message"));
    }
//issue #1787, works fine locally, not on CI
//    Assert.assertEqualsNoOrder(messages.toArray(), resultMessages.toArray(),
//    "arrays are different: "+toString(messages)+" - "+toString(resultMessages) );
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ArrayList(java.util.ArrayList) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 58 with OSchema

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

the class PropertyIndexTest method testGetAllIndexes.

@Test(dependsOnMethods = "createAdditionalSchemas")
public void testGetAllIndexes() {
    final OSchema schema = database.getMetadata().getSchema();
    final OClass oClass = schema.getClass("PropertyIndexTestClass");
    final OProperty propOne = oClass.getProperty("prop1");
    final Collection<OIndex<?>> indexes = propOne.getAllIndexes();
    Assert.assertEquals(indexes.size(), 5);
    Assert.assertNotNull(containsIndex(indexes, "PropertyIndexTestClass.prop1"));
    Assert.assertNotNull(containsIndex(indexes, "propOne0"));
    Assert.assertNotNull(containsIndex(indexes, "propOne1"));
    Assert.assertNotNull(containsIndex(indexes, "propOne2"));
    Assert.assertNotNull(containsIndex(indexes, "propOne4"));
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OIndex(com.orientechnologies.orient.core.index.OIndex) OClass(com.orientechnologies.orient.core.metadata.schema.OClass)

Example 59 with OSchema

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

the class PropertyIndexTest method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    super.beforeClass();
    final OSchema schema = database.getMetadata().getSchema();
    final OClass oClass = schema.createClass("PropertyIndexTestClass");
    oClass.createProperty("prop0", OType.LINK);
    oClass.createProperty("prop1", OType.STRING);
    oClass.createProperty("prop2", OType.INTEGER);
    oClass.createProperty("prop3", OType.BOOLEAN);
    oClass.createProperty("prop4", OType.INTEGER);
    oClass.createProperty("prop5", OType.STRING);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass)

Example 60 with OSchema

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

the class PolymorphicQueryTest method beforeMethod.

@BeforeMethod
public void beforeMethod() throws Exception {
    super.beforeMethod();
    final OSchema schema = database.getMetadata().getSchema();
    schema.reload();
    database.command(new OCommandSQL("delete from IndexInSubclassesTestBase")).execute();
    database.command(new OCommandSQL("delete from IndexInSubclassesTestChild1")).execute();
    database.command(new OCommandSQL("delete from IndexInSubclassesTestChild2")).execute();
    database.command(new OCommandSQL("delete from IndexInSubclassesTestBaseFail")).execute();
    database.command(new OCommandSQL("delete from IndexInSubclassesTestChild1Fail")).execute();
    database.command(new OCommandSQL("delete from IndexInSubclassesTestChild2Fail")).execute();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema)

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