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