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"));
}
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);
}
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");
}
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"));
}
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());
}
}
Aggregations