Search in sources :

Example 26 with OIndex

use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.

the class LuceneInsertUpdateSingleDocumentTransactionTest method testInsertUpdateTransactionWithIndex.

@Test
public void testInsertUpdateTransactionWithIndex() throws Exception {
    db.close();
    db.open("admin", "admin");
    OSchema schema = db.getMetadata().getSchema();
    schema.reload();
    db.begin();
    ODocument doc = new ODocument("City");
    doc.field("name", "");
    ODocument doc1 = new ODocument("City");
    doc1.field("name", "");
    doc = db.save(doc);
    doc1 = db.save(doc1);
    db.commit();
    db.begin();
    doc = db.load(doc);
    doc1 = db.load(doc1);
    doc.field("name", "Rome");
    doc1.field("name", "Rome");
    db.save(doc);
    db.save(doc1);
    db.commit();
    OIndex idx = schema.getClass("City").getClassIndex("City.name");
    Collection<?> coll = (Collection<?>) idx.get("Rome");
    Assert.assertEquals(coll.size(), 2);
    Assert.assertEquals(idx.getSize(), 2);
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OIndex(com.orientechnologies.orient.core.index.OIndex) Collection(java.util.Collection) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 27 with OIndex

use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.

the class ClassIndexTest method testCreateCompositeEmbeddedMapByValueIndex.

@Test
public void testCreateCompositeEmbeddedMapByValueIndex() {
    final OIndex result = oClass.createIndex("ClassIndexTestCompositeEmbeddedMapByValue", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "fTen", "fEmbeddedMap by value" });
    assertEquals(result.getName(), "ClassIndexTestCompositeEmbeddedMapByValue");
    assertEquals(oClass.getClassIndex("ClassIndexTestCompositeEmbeddedMapByValue").getName(), result.getName());
    assertEquals(database.getMetadata().getIndexManager().getClassIndex("ClassIndexTestClass", "ClassIndexTestCompositeEmbeddedMapByValue").getName(), result.getName());
    final OIndexDefinition indexDefinition = result.getDefinition();
    assertTrue(indexDefinition instanceof OCompositeIndexDefinition);
    assertEquals(indexDefinition.getFields().toArray(), new String[] { "fTen", "fEmbeddedMap" });
    assertEquals(indexDefinition.getTypes(), new OType[] { OType.INTEGER, OType.INTEGER });
    assertEquals(indexDefinition.getParamCount(), 2);
}
Also used : OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 28 with OIndex

use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.

the class ClassIndexTest method testCreateOnePropertyEmbeddedMapIndex.

@Test
public void testCreateOnePropertyEmbeddedMapIndex() {
    final OIndex result = oClass.createIndex("ClassIndexTestPropertyEmbeddedMap", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "fEmbeddedMap" });
    assertEquals(result.getName(), "ClassIndexTestPropertyEmbeddedMap");
    assertEquals(oClass.getClassIndex("ClassIndexTestPropertyEmbeddedMap").getName(), result.getName());
    assertEquals(database.getMetadata().getIndexManager().getClassIndex("ClassIndexTestClass", "ClassIndexTestPropertyEmbeddedMap").getName(), result.getName());
    final OIndexDefinition indexDefinition = result.getDefinition();
    assertTrue(indexDefinition instanceof OPropertyMapIndexDefinition);
    assertEquals(indexDefinition.getFields().get(0), "fEmbeddedMap");
    assertEquals(indexDefinition.getTypes()[0], OType.STRING);
    assertEquals(((OPropertyMapIndexDefinition) indexDefinition).getIndexBy(), OPropertyMapIndexDefinition.INDEX_BY.KEY);
}
Also used : OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OPropertyMapIndexDefinition(com.orientechnologies.orient.core.index.OPropertyMapIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 29 with OIndex

use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.

the class ClassIndexTest method testCreateCompositeEmbeddedListIndex.

@Test
public void testCreateCompositeEmbeddedListIndex() {
    final OIndex result = oClass.createIndex("ClassIndexTestCompositeEmbeddedList", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "fThirteen", "fEmbeddedList" });
    assertEquals(result.getName(), "ClassIndexTestCompositeEmbeddedList");
    assertEquals(oClass.getClassIndex("ClassIndexTestCompositeEmbeddedList").getName(), result.getName());
    assertEquals(database.getMetadata().getIndexManager().getClassIndex("ClassIndexTestClass", "ClassIndexTestCompositeEmbeddedList").getName(), result.getName());
    final OIndexDefinition indexDefinition = result.getDefinition();
    assertTrue(indexDefinition instanceof OCompositeIndexDefinition);
    assertEquals(indexDefinition.getFields().toArray(), new String[] { "fThirteen", "fEmbeddedList" });
    assertEquals(indexDefinition.getTypes(), new OType[] { OType.INTEGER, OType.INTEGER });
    assertEquals(indexDefinition.getParamCount(), 2);
}
Also used : OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 30 with OIndex

use of com.orientechnologies.orient.core.index.OIndex in project orientdb by orientechnologies.

the class ClassIndexTest method testGetIndexesWithoutParent.

@Test
public void testGetIndexesWithoutParent() {
    final OClass inClass = database.getMetadata().getSchema().createClass("ClassIndexInTest");
    inClass.createProperty("fOne", OType.INTEGER);
    final OIndex result = inClass.createIndex("ClassIndexInTestPropertyOne", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "fOne" });
    assertEquals(result.getName(), "ClassIndexInTestPropertyOne");
    assertEquals(inClass.getClassIndex("ClassIndexInTestPropertyOne").getName(), result.getName());
    final Set<OIndex<?>> indexes = inClass.getIndexes();
    final OPropertyIndexDefinition propertyIndexDefinition = new OPropertyIndexDefinition("ClassIndexInTest", "fOne", OType.INTEGER);
    assertEquals(indexes.size(), 1);
    assertTrue(indexes.iterator().next().getDefinition().equals(propertyIndexDefinition));
}
Also used : OPropertyIndexDefinition(com.orientechnologies.orient.core.index.OPropertyIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Aggregations

OIndex (com.orientechnologies.orient.core.index.OIndex)98 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)54 Test (org.testng.annotations.Test)50 OIndexDefinition (com.orientechnologies.orient.core.index.OIndexDefinition)26 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)20 OIndexManager (com.orientechnologies.orient.core.index.OIndexManager)18 OCompositeIndexDefinition (com.orientechnologies.orient.core.index.OCompositeIndexDefinition)16 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)16 Test (org.junit.Test)14 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)12 Collection (java.util.Collection)11 OPropertyIndexDefinition (com.orientechnologies.orient.core.index.OPropertyIndexDefinition)9 OPropertyMapIndexDefinition (com.orientechnologies.orient.core.index.OPropertyMapIndexDefinition)8 OProperty (com.orientechnologies.orient.core.metadata.schema.OProperty)8 HashSet (java.util.HashSet)6 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)5 OIndexManagerProxy (com.orientechnologies.orient.core.index.OIndexManagerProxy)5 OIndexUnique (com.orientechnologies.orient.core.index.OIndexUnique)5 Map (java.util.Map)4 AtomicLong (java.util.concurrent.atomic.AtomicLong)4