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