Search in sources :

Example 6 with OPropertyIndexDefinition

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

the class IndexManagerTest method createCompositeIndexTestWithListener.

@Test
public void createCompositeIndexTestWithListener() {
    final AtomicInteger atomicInteger = new AtomicInteger(0);
    final OProgressListener progressListener = new OProgressListener() {

        @Override
        public void onBegin(final Object iTask, final long iTotal, Object metadata) {
            atomicInteger.incrementAndGet();
        }

        @Override
        public boolean onProgress(final Object iTask, final long iCounter, final float iPercent) {
            return true;
        }

        @Override
        public void onCompletition(final Object iTask, final boolean iSucceed) {
            atomicInteger.incrementAndGet();
        }
    };
    final OIndexManagerProxy indexManager = database.getMetadata().getIndexManager();
    final OIndex result = indexManager.createIndex("compositetwo", OClass.INDEX_TYPE.NOTUNIQUE.toString(), new OCompositeIndexDefinition(CLASS_NAME, Arrays.asList(new OPropertyIndexDefinition(CLASS_NAME, "fOne", OType.INTEGER), new OPropertyIndexDefinition(CLASS_NAME, "fTwo", OType.STRING), new OPropertyIndexDefinition(CLASS_NAME, "fThree", OType.BOOLEAN)), -1), new int[] { database.getClusterIdByName(CLASS_NAME) }, progressListener, null);
    assertEquals(result.getName(), "compositetwo");
    assertEquals(atomicInteger.get(), 2);
    indexManager.reload();
    assertEquals(database.getMetadata().getIndexManager().getClassIndex(CLASS_NAME, "compositetwo").getName(), result.getName());
}
Also used : OProgressListener(com.orientechnologies.common.listener.OProgressListener) OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OPropertyIndexDefinition(com.orientechnologies.orient.core.index.OPropertyIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) OIndexManagerProxy(com.orientechnologies.orient.core.index.OIndexManagerProxy) Test(org.testng.annotations.Test)

Example 7 with OPropertyIndexDefinition

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

the class IndexManagerTest method createCompositeIndexTestWithoutListener.

@Test
public void createCompositeIndexTestWithoutListener() {
    final OIndexManagerProxy indexManager = database.getMetadata().getIndexManager();
    final OIndex result = indexManager.createIndex("compositeone", OClass.INDEX_TYPE.NOTUNIQUE.toString(), new OCompositeIndexDefinition(CLASS_NAME, Arrays.asList(new OPropertyIndexDefinition(CLASS_NAME, "fOne", OType.INTEGER), new OPropertyIndexDefinition(CLASS_NAME, "fTwo", OType.STRING)), -1), new int[] { database.getClusterIdByName(CLASS_NAME) }, null, null);
    assertEquals(result.getName(), "compositeone");
    indexManager.reload();
    assertEquals(database.getMetadata().getIndexManager().getClassIndex(CLASS_NAME, "compositeone").getName(), result.getName());
}
Also used : OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OPropertyIndexDefinition(com.orientechnologies.orient.core.index.OPropertyIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) OIndexManagerProxy(com.orientechnologies.orient.core.index.OIndexManagerProxy) Test(org.testng.annotations.Test)

Example 8 with OPropertyIndexDefinition

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

the class IndexManagerTest method testDropAllClassIndexes.

@Test
public void testDropAllClassIndexes() {
    final OClass oClass = database.getMetadata().getSchema().createClass("indexManagerTestClassTwo");
    oClass.createProperty("fOne", OType.INTEGER);
    final OIndexManager indexManager = database.getMetadata().getIndexManager();
    indexManager.createIndex("twoclassproperty", OClass.INDEX_TYPE.UNIQUE.toString(), new OPropertyIndexDefinition("indexManagerTestClassTwo", "fOne", OType.INTEGER), new int[] { database.getClusterIdByName("indexManagerTestClassTwo") }, null, null);
    assertFalse(indexManager.getClassIndexes("indexManagerTestClassTwo").isEmpty());
    indexManager.dropIndex("twoclassproperty");
    assertTrue(indexManager.getClassIndexes("indexManagerTestClassTwo").isEmpty());
}
Also used : OIndexManager(com.orientechnologies.orient.core.index.OIndexManager) OPropertyIndexDefinition(com.orientechnologies.orient.core.index.OPropertyIndexDefinition) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) Test(org.testng.annotations.Test)

Example 9 with OPropertyIndexDefinition

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

the class IndexManagerTest method testGetClassIndexes.

@Test(dependsOnMethods = { "createCompositeIndexTestWithListener", "createCompositeIndexTestWithoutListener", "testCreateOnePropertyIndexTest" })
public void testGetClassIndexes() {
    final OIndexManager indexManager = database.getMetadata().getIndexManager();
    final Set<OIndex<?>> indexes = indexManager.getClassIndexes(CLASS_NAME);
    final Set<OIndexDefinition> expectedIndexDefinitions = new HashSet<OIndexDefinition>();
    final OCompositeIndexDefinition compositeIndexOne = new OCompositeIndexDefinition(CLASS_NAME);
    compositeIndexOne.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fOne", OType.INTEGER));
    compositeIndexOne.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fTwo", OType.STRING));
    compositeIndexOne.setNullValuesIgnored(false);
    expectedIndexDefinitions.add(compositeIndexOne);
    final OCompositeIndexDefinition compositeIndexTwo = new OCompositeIndexDefinition(CLASS_NAME);
    compositeIndexTwo.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fOne", OType.INTEGER));
    compositeIndexTwo.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fTwo", OType.STRING));
    compositeIndexTwo.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fThree", OType.BOOLEAN));
    compositeIndexTwo.setNullValuesIgnored(false);
    expectedIndexDefinitions.add(compositeIndexTwo);
    final OPropertyIndexDefinition propertyIndex = new OPropertyIndexDefinition(CLASS_NAME, "fOne", OType.INTEGER);
    propertyIndex.setNullValuesIgnored(false);
    expectedIndexDefinitions.add(propertyIndex);
    assertEquals(indexes.size(), 3);
    for (final OIndex index : indexes) {
        assertTrue(expectedIndexDefinitions.contains(index.getDefinition()));
    }
}
Also used : OIndexManager(com.orientechnologies.orient.core.index.OIndexManager) OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OPropertyIndexDefinition(com.orientechnologies.orient.core.index.OPropertyIndexDefinition) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 10 with OPropertyIndexDefinition

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

the class IndexManagerTest method testGetClassIndexesBrokenClassNameCase.

@Test(dependsOnMethods = { "createCompositeIndexTestWithListener", "createCompositeIndexTestWithoutListener", "testCreateOnePropertyIndexTest" })
public void testGetClassIndexesBrokenClassNameCase() {
    final OIndexManager indexManager = database.getMetadata().getIndexManager();
    final Set<OIndex<?>> indexes = indexManager.getClassIndexes("ClassforindeXMaNAgerTeST");
    final Set<OIndexDefinition> expectedIndexDefinitions = new HashSet<OIndexDefinition>();
    final OCompositeIndexDefinition compositeIndexOne = new OCompositeIndexDefinition(CLASS_NAME);
    compositeIndexOne.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fOne", OType.INTEGER));
    compositeIndexOne.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fTwo", OType.STRING));
    compositeIndexOne.setNullValuesIgnored(false);
    expectedIndexDefinitions.add(compositeIndexOne);
    final OCompositeIndexDefinition compositeIndexTwo = new OCompositeIndexDefinition(CLASS_NAME);
    compositeIndexTwo.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fOne", OType.INTEGER));
    compositeIndexTwo.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fTwo", OType.STRING));
    compositeIndexTwo.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fThree", OType.BOOLEAN));
    compositeIndexTwo.setNullValuesIgnored(false);
    expectedIndexDefinitions.add(compositeIndexTwo);
    final OPropertyIndexDefinition propertyIndex = new OPropertyIndexDefinition(CLASS_NAME, "fOne", OType.INTEGER);
    propertyIndex.setNullValuesIgnored(false);
    expectedIndexDefinitions.add(propertyIndex);
    assertEquals(indexes.size(), 3);
    for (final OIndex index : indexes) {
        assertTrue(expectedIndexDefinitions.contains(index.getDefinition()));
    }
}
Also used : OIndexManager(com.orientechnologies.orient.core.index.OIndexManager) OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OPropertyIndexDefinition(com.orientechnologies.orient.core.index.OPropertyIndexDefinition) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Aggregations

OPropertyIndexDefinition (com.orientechnologies.orient.core.index.OPropertyIndexDefinition)13 Test (org.testng.annotations.Test)12 OIndex (com.orientechnologies.orient.core.index.OIndex)9 OCompositeIndexDefinition (com.orientechnologies.orient.core.index.OCompositeIndexDefinition)7 OIndexDefinition (com.orientechnologies.orient.core.index.OIndexDefinition)6 OIndexManager (com.orientechnologies.orient.core.index.OIndexManager)5 HashSet (java.util.HashSet)4 OIndexManagerProxy (com.orientechnologies.orient.core.index.OIndexManagerProxy)3 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)3 OPropertyListIndexDefinition (com.orientechnologies.orient.core.index.OPropertyListIndexDefinition)2 OPropertyMapIndexDefinition (com.orientechnologies.orient.core.index.OPropertyMapIndexDefinition)2 OPropertyRidBagIndexDefinition (com.orientechnologies.orient.core.index.OPropertyRidBagIndexDefinition)2 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)2 OProgressListener (com.orientechnologies.common.listener.OProgressListener)1 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1