Search in sources :

Example 81 with OSchema

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

the class LocalPaginatedStorageUpdateCrashRestoreIT method createSchema.

private void createSchema(ODatabaseDocumentTx dbDocumentTx) {
    ODatabaseRecordThreadLocal.INSTANCE.set(dbDocumentTx);
    OSchema schema = dbDocumentTx.getMetadata().getSchema();
    if (!schema.existsClass("TestClass")) {
        OClass testClass = schema.createClass("TestClass");
        testClass.createProperty("id", OType.LONG);
        testClass.createProperty("timestamp", OType.LONG);
        testClass.createProperty("stringValue", OType.STRING);
        testClass.createIndex("idIndex", OClass.INDEX_TYPE.UNIQUE, "id");
        schema.save();
    }
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass)

Example 82 with OSchema

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

the class LocalPaginatedStorageCreateCrashRestoreIT method createSchema.

private void createSchema(ODatabaseDocumentTx dbDocumentTx) {
    ODatabaseRecordThreadLocal.INSTANCE.set(dbDocumentTx);
    OSchema schema = dbDocumentTx.getMetadata().getSchema();
    if (!schema.existsClass("TestClass")) {
        OClass testClass = schema.createClass("TestClass");
        testClass.createProperty("id", OType.LONG);
        testClass.createProperty("timestamp", OType.LONG);
        testClass.createProperty("stringValue", OType.STRING);
        testClass.createIndex("idIndex", OClass.INDEX_TYPE.UNIQUE, "id");
        schema.save();
    }
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass)

Example 83 with OSchema

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

the class DefaultValuesTrivialTest method testPrepopulation.

@Test
public void testPrepopulation() throws Exception {
    // create example schema
    OSchema schema = database.getMetadata().getSchema();
    OClass classA = schema.createClass("ClassA");
    classA.createProperty("name", OType.STRING).setDefaultValue("default name");
    classA.createProperty("date", OType.DATETIME).setDefaultValue("sysdate()");
    classA.createProperty("active", OType.BOOLEAN).setDefaultValue("true");
    {
        ODocument doc = new ODocument(classA);
        assertEquals("default name", doc.field("name"));
        assertNotNull(doc.field("date"));
        assertEquals(true, doc.field("active"));
    }
    {
        ODocument doc = new ODocument();
        assertNull(doc.field("name"));
        assertNull(doc.field("date"));
        assertNull(doc.field("active"));
        doc.setClassName(classA.getName());
        assertEquals("default name", doc.field("name"));
        assertNotNull(doc.field("date"));
        assertEquals(true, doc.field("active"));
    }
    {
        ODocument doc = new ODocument();
        assertNull(doc.field("name"));
        assertNull(doc.field("date"));
        assertNull(doc.field("active"));
        doc.setClassNameIfExists(classA.getName());
        assertEquals("default name", doc.field("name"));
        assertNotNull(doc.field("date"));
        assertEquals(true, doc.field("active"));
    }
}
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.testng.annotations.Test)

Example 84 with OSchema

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

the class DefaultValuesTrivialTest method testPrepopulationIndexTx.

@Test
public void testPrepopulationIndexTx() throws Exception {
    // create example schema
    OSchema schema = database.getMetadata().getSchema();
    OClass classA = schema.createClass("ClassA");
    OProperty prop = classA.createProperty("name", OType.STRING);
    prop.setDefaultValue("default name");
    OIndex<?> index = prop.createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
    {
        database.begin();
        ODocument doc = new ODocument(classA);
        assertEquals("default name", doc.field("name"));
        database.save(doc);
        assertEquals(1, ((Collection) index.get("default name")).size());
        database.commit();
        assertEquals(1, ((Collection) index.get("default name")).size());
    }
}
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) Collection(java.util.Collection) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 85 with OSchema

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

the class IndexClusterTest method indexAfterRebuildShouldIncludeAllClusters.

@Test
public void indexAfterRebuildShouldIncludeAllClusters() {
    // given
    OSchema schema = database.getMetadata().getSchema();
    String className = "IndexClusterTest";
    OClass oclass = schema.createClass(className);
    oclass.createProperty("key", OType.STRING);
    oclass.createProperty("value", OType.INTEGER);
    oclass.createIndex(className + "index1", OClass.INDEX_TYPE.NOTUNIQUE, "key");
    database.newInstance(className).field("key", "a").field("value", 1).save();
    int clId = database.addCluster(className + "secondCluster");
    oclass.addClusterId(clId);
    database.newInstance(className).field("key", "a").field("value", 2).save(className + "secondCluster");
    // when
    database.command(new OCommandSQL("rebuild index " + className + "index1")).execute();
    assertEquals(database.query(new OSQLSynchQuery<Object>("select from " + className + " where key = 'a'")).size(), 2);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass)

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