Search in sources :

Example 41 with OProperty

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

the class DefaultValueTest method testKeepValueSerialization.

@Test
public void testKeepValueSerialization() {
    // create example schema
    OSchema schema = database.getMetadata().getSchema();
    OClass classA = schema.createClass("ClassC");
    OProperty prop = classA.createProperty("name", OType.STRING);
    prop.setDefaultValue("uuid()");
    ODocument doc = new ODocument("ClassC");
    byte[] val = doc.toStream();
    ODocument doc1 = new ODocument();
    doc1.fromStream(val);
    doc1.deserializeFields();
    assertEquals(doc.field("name"), doc1.field("name"));
}
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) Test(org.junit.Test)

Example 42 with OProperty

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

the class DefaultValueTest method testDefaultValueDate.

@Test
public void testDefaultValueDate() {
    OSchema schema = database.getMetadata().getSchema();
    OClass classA = schema.createClass("ClassA");
    OProperty prop = classA.createProperty("date", OType.DATE);
    prop.setDefaultValue(ODateHelper.getDateTimeFormatInstance().format(new Date()));
    OProperty some = classA.createProperty("id", OType.STRING);
    some.setDefaultValue("uuid()");
    ODocument doc = new ODocument(classA);
    ODocument saved = database.save(doc);
    assertNotNull(saved.field("date"));
    assertTrue(saved.field("date") instanceof Date);
    assertNotNull(saved.field("id"));
    OIdentifiable id = database.command(new OCommandSQL("insert into ClassA content {}")).execute();
    ODocument seved1 = database.load(id.getIdentity());
    assertNotNull(seved1.field("date"));
    assertNotNull(seved1.field("id"));
    assertTrue(seved1.field("date") instanceof Date);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) Date(java.util.Date) Test(org.junit.Test)

Example 43 with OProperty

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

the class DefaultValueTest method testDefaultValueUpdateMandatoryReadonlyFromJson.

@Test
public void testDefaultValueUpdateMandatoryReadonlyFromJson() {
    OSchema schema = database.getMetadata().getSchema();
    OClass classA = schema.createClass("ClassA");
    OProperty prop = classA.createProperty("date", OType.DATETIME);
    prop.setMandatory(true);
    prop.setReadonly(true);
    prop.setDefaultValue(ODateHelper.getDateTimeFormatInstance().format(new Date()));
    ODocument doc = new ODocument().fromJSON("{'@class':'ClassA','other':'other'}");
    ODocument saved = database.save(doc);
    assertNotNull(saved.field("date"));
    assertTrue(saved.field("date") instanceof Date);
    assertNotNull(saved.field("other"));
    String val = ODateHelper.getDateTimeFormatInstance().format(doc.field("date"));
    ODocument doc1 = new ODocument().fromJSON("{'@class':'ClassA','date':'" + val + "','other':'other1'}");
    saved.merge(doc1, true, true);
    saved = database.save(saved);
    assertNotNull(saved.field("date"));
    assertEquals(ODateHelper.getDateTimeFormatInstance().format(saved.field("date")), val);
    assertEquals(saved.field("other"), "other1");
}
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) Date(java.util.Date) Test(org.junit.Test)

Example 44 with OProperty

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

the class CollateTest method testCompositeIndexQueryCollateWasChanged.

public void testCompositeIndexQueryCollateWasChanged() {
    final OSchema schema = database.getMetadata().getSchema();
    OClass clazz = schema.createClass("CompositeIndexQueryCollateWasChangedTest");
    OProperty csp = clazz.createProperty("csp", OType.STRING);
    csp.setCollate(ODefaultCollate.NAME);
    clazz.createProperty("cip", OType.STRING);
    clazz.createIndex("collateCompositeIndexCollateWasChanged", OClass.INDEX_TYPE.NOTUNIQUE, "csp", "cip");
    for (int i = 0; i < 10; i++) {
        ODocument document = new ODocument("CompositeIndexQueryCollateWasChangedTest");
        if (i % 2 == 0) {
            document.field("csp", "VAL");
            document.field("cip", "VAL");
        } else {
            document.field("csp", "val");
            document.field("cip", "val");
        }
        document.save();
    }
    String query = "select from CompositeIndexQueryCollateWasChangedTest where csp = 'VAL'";
    List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 5);
    for (ODocument document : result) Assert.assertEquals(document.field("csp"), "VAL");
    ODocument explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("collateCompositeIndexCollateWasChanged"));
    csp = clazz.getProperty("csp");
    csp.setCollate(OCaseInsensitiveCollate.NAME);
    query = "select from CompositeIndexQueryCollateWasChangedTest where csp = 'VaL'";
    result = database.query(new OSQLSynchQuery<ODocument>(query));
    Assert.assertEquals(result.size(), 10);
    for (ODocument document : result) Assert.assertEquals(document.<String>field("csp").toUpperCase(Locale.ENGLISH), "VAL");
    explain = database.command(new OCommandSQL("explain " + query)).execute();
    Assert.assertTrue(explain.<Set<String>>field("involvedIndexes").contains("collateCompositeIndexCollateWasChanged"));
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) Set(java.util.Set) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 45 with OProperty

use of com.orientechnologies.orient.core.metadata.schema.OProperty 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)

Aggregations

OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)121 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)84 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)41 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)32 Test (org.testng.annotations.Test)30 Test (org.junit.Test)28 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)25 OType (com.orientechnologies.orient.core.metadata.schema.OType)15 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)11 FilterCriteriaManager (ru.ydn.wicket.wicketorientdb.utils.query.filter.FilterCriteriaManager)10 IFilterCriteriaManager (ru.ydn.wicket.wicketorientdb.utils.query.filter.IFilterCriteriaManager)10 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)8 OIndex (com.orientechnologies.orient.core.index.OIndex)8 Date (java.util.Date)8 Set (java.util.Set)8 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)7 Map (java.util.Map)7 ODatabaseObject (com.orientechnologies.orient.core.db.object.ODatabaseObject)6 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)6 Collection (java.util.Collection)6