Search in sources :

Example 21 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 22 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 23 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)

Example 24 with OSchema

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

the class IndexManagerTest method testGetClassInvolvedIndexesWithNullValues.

@Test
public void testGetClassInvolvedIndexesWithNullValues() {
    String className = "GetClassInvolvedIndexesWithNullValues";
    final OIndexManager indexManager = database.getMetadata().getIndexManager();
    final OSchema schema = database.getMetadata().getSchema();
    final OClass oClass = schema.createClass(className);
    oClass.createProperty("one", OType.STRING);
    oClass.createProperty("two", OType.STRING);
    oClass.createProperty("three", OType.STRING);
    indexManager.createIndex(className + "_indexOne_notunique", OClass.INDEX_TYPE.NOTUNIQUE.toString(), new OPropertyIndexDefinition(className, "one", OType.STRING), oClass.getClusterIds(), null, null);
    indexManager.createIndex(className + "_indexOneTwo_notunique", OClass.INDEX_TYPE.NOTUNIQUE.toString(), new OCompositeIndexDefinition(className, Arrays.asList(new OPropertyIndexDefinition(className, "one", OType.STRING), new OPropertyIndexDefinition(className, "two", OType.STRING)), -1), oClass.getClusterIds(), null, null);
    indexManager.createIndex(className + "_indexOneTwoThree_notunique", OClass.INDEX_TYPE.NOTUNIQUE.toString(), new OCompositeIndexDefinition(className, Arrays.asList(new OPropertyIndexDefinition(className, "one", OType.STRING), new OPropertyIndexDefinition(className, "two", OType.STRING), new OPropertyIndexDefinition(className, "three", OType.STRING)), -1), oClass.getClusterIds(), null, null);
    Set<OIndex<?>> result = indexManager.getClassInvolvedIndexes(className, Arrays.asList("one"));
    assertEquals(result.size(), 3);
    result = indexManager.getClassInvolvedIndexes(className, Arrays.asList("one", "two"));
    assertEquals(result.size(), 2);
    result = indexManager.getClassInvolvedIndexes(className, Arrays.asList("one", "two", "three"));
    assertEquals(result.size(), 1);
    result = indexManager.getClassInvolvedIndexes(className, Arrays.asList("two"));
    assertEquals(result.size(), 0);
    result = indexManager.getClassInvolvedIndexes(className, Arrays.asList("two", "one", "three"));
    assertEquals(result.size(), 1);
}
Also used : OIndexManager(com.orientechnologies.orient.core.index.OIndexManager) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OPropertyIndexDefinition(com.orientechnologies.orient.core.index.OPropertyIndexDefinition) OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) Test(org.testng.annotations.Test)

Example 25 with OSchema

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

the class IndexManagerTest method beforeClass.

@BeforeClass
public void beforeClass() throws Exception {
    super.beforeClass();
    final OSchema schema = database.getMetadata().getSchema();
    final OClass oClass = schema.createClass(CLASS_NAME);
    oClass.createProperty("fOne", OType.INTEGER);
    oClass.createProperty("fTwo", OType.STRING);
    oClass.createProperty("fThree", OType.BOOLEAN);
    oClass.createProperty("fFour", OType.INTEGER);
    oClass.createProperty("fSix", OType.STRING);
    oClass.createProperty("fSeven", OType.STRING);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) BeforeClass(org.testng.annotations.BeforeClass)

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