Search in sources :

Example 26 with OCompositeIndexDefinition

use of com.orientechnologies.orient.core.index.OCompositeIndexDefinition 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 27 with OCompositeIndexDefinition

use of com.orientechnologies.orient.core.index.OCompositeIndexDefinition 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)

Example 28 with OCompositeIndexDefinition

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

the class SQLDropPropertyIndexTest method testForcePropertyDisabledBrokenCase.

@Test
public void testForcePropertyDisabledBrokenCase() throws Exception {
    database.command(new OCommandSQL("CREATE INDEX DropPropertyIndexCompositeIndex ON DropPropertyIndexTestClass (prop1, prop2) UNIQUE")).execute();
    try {
        database.command(new OCommandSQL("DROP PROPERTY DropPropertyIndextestclaSS.proP1")).execute();
        Assert.fail();
    } catch (OCommandExecutionException e) {
        Assert.assertTrue(e.getMessage().contains("Property used in indexes (" + "DropPropertyIndexCompositeIndex" + "). Please drop these indexes before removing property or use FORCE parameter."));
    }
    database.getMetadata().getIndexManager().reload();
    final OIndex<?> index = database.getMetadata().getSchema().getClass("DropPropertyIndexTestClass").getClassIndex("DropPropertyIndexCompositeIndex");
    Assert.assertNotNull(index);
    final OIndexDefinition indexDefinition = index.getDefinition();
    Assert.assertTrue(indexDefinition instanceof OCompositeIndexDefinition);
    Assert.assertEquals(indexDefinition.getFields(), Arrays.asList("prop1", "prop2"));
    Assert.assertEquals(indexDefinition.getTypes(), new OType[] { EXPECTED_PROP1_TYPE, EXPECTED_PROP2_TYPE });
    Assert.assertEquals(index.getType(), "UNIQUE");
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException)

Example 29 with OCompositeIndexDefinition

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

the class SQLCreateIndexTest method testCreateCompositeIndexWithTypes.

@Test
public void testCreateCompositeIndexWithTypes() throws Exception {
    final String query = new StringBuilder("CREATE INDEX sqlCreateIndexCompositeIndex2 ON sqlCreateIndexTestClass (prop1, prop2) UNIQUE ").append(EXPECTED_PROP1_TYPE).append(", ").append(EXPECTED_PROP2_TYPE).toString();
    database.command(new OCommandSQL(query)).execute();
    database.getMetadata().getIndexManager().reload();
    final OIndex<?> index = database.getMetadata().getSchema().getClass("sqlCreateIndexTestClass").getClassIndex("sqlCreateIndexCompositeIndex2");
    Assert.assertNotNull(index);
    final OIndexDefinition indexDefinition = index.getDefinition();
    Assert.assertTrue(indexDefinition instanceof OCompositeIndexDefinition);
    Assert.assertEquals(indexDefinition.getFields(), Arrays.asList("prop1", "prop2"));
    Assert.assertEquals(indexDefinition.getTypes(), new OType[] { EXPECTED_PROP1_TYPE, EXPECTED_PROP2_TYPE });
    Assert.assertEquals(index.getType(), "UNIQUE");
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) Test(org.testng.annotations.Test)

Aggregations

OCompositeIndexDefinition (com.orientechnologies.orient.core.index.OCompositeIndexDefinition)29 OIndexDefinition (com.orientechnologies.orient.core.index.OIndexDefinition)26 OIndex (com.orientechnologies.orient.core.index.OIndex)16 Test (org.testng.annotations.Test)16 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)11 OIndexCursor (com.orientechnologies.orient.core.index.OIndexCursor)7 OPropertyIndexDefinition (com.orientechnologies.orient.core.index.OPropertyIndexDefinition)7 OIndexDefinitionMultiValue (com.orientechnologies.orient.core.index.OIndexDefinitionMultiValue)6 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)6 HashSet (java.util.HashSet)4 OIndexManager (com.orientechnologies.orient.core.index.OIndexManager)3 OPropertyMapIndexDefinition (com.orientechnologies.orient.core.index.OPropertyMapIndexDefinition)3 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)2 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)2 OIndexCursorCollectionValue (com.orientechnologies.orient.core.index.OIndexCursorCollectionValue)2 OIndexCursorSingleValue (com.orientechnologies.orient.core.index.OIndexCursorSingleValue)2 OIndexManagerProxy (com.orientechnologies.orient.core.index.OIndexManagerProxy)2 OPropertyListIndexDefinition (com.orientechnologies.orient.core.index.OPropertyListIndexDefinition)2 OPropertyRidBagIndexDefinition (com.orientechnologies.orient.core.index.OPropertyRidBagIndexDefinition)2 OProgressListener (com.orientechnologies.common.listener.OProgressListener)1