Search in sources :

Example 31 with OIndex

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

the class ClassIndexTest method testCreateOnePropertyLinkMapByKeyIndex.

@Test
public void testCreateOnePropertyLinkMapByKeyIndex() {
    final OIndex result = oClass.createIndex("ClassIndexTestPropertyLinkedMapByKey", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "fLinkMap by key" });
    assertEquals(result.getName(), "ClassIndexTestPropertyLinkedMapByKey");
    assertEquals(oClass.getClassIndex("ClassIndexTestPropertyLinkedMapByKey").getName(), result.getName());
    assertEquals(database.getMetadata().getIndexManager().getClassIndex("ClassIndexTestClass", "ClassIndexTestPropertyLinkedMapByKey").getName(), result.getName());
    final OIndexDefinition indexDefinition = result.getDefinition();
    assertTrue(indexDefinition instanceof OPropertyMapIndexDefinition);
    assertEquals(indexDefinition.getFields().get(0), "fLinkMap");
    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 32 with OIndex

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

the class ClassIndexTest method testCreateCompositeLinkMapByValueIndex.

@Test
public void testCreateCompositeLinkMapByValueIndex() {
    final OIndex result = oClass.createIndex("ClassIndexTestCompositeLinkMapByValue", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "fEleven", "fLinkMap by value" });
    assertEquals(result.getName(), "ClassIndexTestCompositeLinkMapByValue");
    assertEquals(oClass.getClassIndex("ClassIndexTestCompositeLinkMapByValue").getName(), result.getName());
    assertEquals(database.getMetadata().getIndexManager().getClassIndex("ClassIndexTestClass", "ClassIndexTestCompositeLinkMapByValue").getName(), result.getName());
    final OIndexDefinition indexDefinition = result.getDefinition();
    assertTrue(indexDefinition instanceof OCompositeIndexDefinition);
    assertEquals(indexDefinition.getFields().toArray(), new String[] { "fEleven", "fLinkMap" });
    assertEquals(indexDefinition.getTypes(), new OType[] { OType.INTEGER, OType.LINK });
    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 33 with OIndex

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

the class ClassIndexTest method createCompositeIndexTestWithoutListener.

@Test
public void createCompositeIndexTestWithoutListener() {
    final OIndex result = oClass.createIndex("ClassIndexTestCompositeOne", OClass.INDEX_TYPE.UNIQUE.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { "fOne", "fTwo" });
    assertEquals(result.getName(), "ClassIndexTestCompositeOne");
    assertEquals(oClass.getClassIndex("ClassIndexTestCompositeOne").getName(), result.getName());
    assertEquals(database.getMetadata().getIndexManager().getClassIndex("ClassIndexTestClass", "ClassIndexTestCompositeOne").getName(), result.getName());
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 34 with OIndex

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

the class ClassIndexTest method testGetIndexes.

@Test(dependsOnMethods = { "createCompositeIndexTestWithListener", "createCompositeIndexTestWithoutListener", "testCreateOnePropertyIndexTest", "createParentPropertyIndex", "testCreateOnePropertyEmbeddedMapIndex", "testCreateOnePropertyByKeyEmbeddedMapIndex", "testCreateOnePropertyByValueEmbeddedMapIndex", "testCreateOnePropertyLinkedMapIndex", "testCreateOnePropertyLinkMapByKeyIndex", "testCreateOnePropertyLinkMapByValueIndex", "testCreateCompositeEmbeddedMapIndex", "testCreateCompositeEmbeddedMapByKeyIndex", "testCreateCompositeEmbeddedMapByValueIndex", "testCreateCompositeLinkMapByValueIndex", "testCreateCompositeEmbeddedSetIndex", "testCreateCompositeEmbeddedListIndex", "testCreateCompositeLinkListIndex", "testCreateCompositeRidBagIndex" })
public void testGetIndexes() {
    final Set<OIndex<?>> indexes = oClass.getIndexes();
    final Set<OIndexDefinition> expectedIndexDefinitions = new HashSet<OIndexDefinition>();
    final OCompositeIndexDefinition compositeIndexOne = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexOne.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fOne", OType.INTEGER));
    compositeIndexOne.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fTwo", OType.STRING));
    expectedIndexDefinitions.add(compositeIndexOne);
    final OCompositeIndexDefinition compositeIndexTwo = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexTwo.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fOne", OType.INTEGER));
    compositeIndexTwo.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fTwo", OType.STRING));
    compositeIndexTwo.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fThree", OType.BOOLEAN));
    expectedIndexDefinitions.add(compositeIndexTwo);
    final OCompositeIndexDefinition compositeIndexThree = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexThree.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fEight", OType.INTEGER));
    compositeIndexThree.addIndex(new OPropertyMapIndexDefinition("ClassIndexTestClass", "fEmbeddedMap", OType.STRING, OPropertyMapIndexDefinition.INDEX_BY.KEY));
    expectedIndexDefinitions.add(compositeIndexThree);
    final OCompositeIndexDefinition compositeIndexFour = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexFour.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fTen", OType.INTEGER));
    compositeIndexFour.addIndex(new OPropertyMapIndexDefinition("ClassIndexTestClass", "fEmbeddedMap", OType.INTEGER, OPropertyMapIndexDefinition.INDEX_BY.VALUE));
    expectedIndexDefinitions.add(compositeIndexFour);
    final OCompositeIndexDefinition compositeIndexFive = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexFive.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fEleven", OType.INTEGER));
    compositeIndexFive.addIndex(new OPropertyMapIndexDefinition("ClassIndexTestClass", "fLinkMap", OType.LINK, OPropertyMapIndexDefinition.INDEX_BY.VALUE));
    expectedIndexDefinitions.add(compositeIndexFive);
    final OCompositeIndexDefinition compositeIndexSix = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexSix.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fTwelve", OType.INTEGER));
    compositeIndexSix.addIndex(new OPropertyListIndexDefinition("ClassIndexTestClass", "fEmbeddedSet", OType.INTEGER));
    expectedIndexDefinitions.add(compositeIndexSix);
    final OCompositeIndexDefinition compositeIndexSeven = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexSeven.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fThirteen", OType.INTEGER));
    compositeIndexSeven.addIndex(new OPropertyListIndexDefinition("ClassIndexTestClass", "fEmbeddedList", OType.INTEGER));
    expectedIndexDefinitions.add(compositeIndexSeven);
    final OCompositeIndexDefinition compositeIndexEight = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexEight.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fFourteen", OType.INTEGER));
    compositeIndexEight.addIndex(new OPropertyListIndexDefinition("ClassIndexTestClass", "fEmbeddedList", OType.LINK));
    expectedIndexDefinitions.add(compositeIndexEight);
    final OCompositeIndexDefinition compositeIndexNine = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexNine.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fFifteen", OType.INTEGER));
    compositeIndexNine.addIndex(new OPropertyMapIndexDefinition("ClassIndexTestClass", "fEmbeddedMap", OType.STRING, OPropertyMapIndexDefinition.INDEX_BY.KEY));
    expectedIndexDefinitions.add(compositeIndexNine);
    final OCompositeIndexDefinition compositeIndexTen = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexTen.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fFourteen", OType.INTEGER));
    compositeIndexTen.addIndex(new OPropertyListIndexDefinition("ClassIndexTestClass", "fLinkList", OType.LINK));
    expectedIndexDefinitions.add(compositeIndexTen);
    final OCompositeIndexDefinition compositeIndexEleven = new OCompositeIndexDefinition("ClassIndexTestClass");
    compositeIndexEleven.addIndex(new OPropertyIndexDefinition("ClassIndexTestClass", "fFourteen", OType.INTEGER));
    compositeIndexEleven.addIndex(new OPropertyRidBagIndexDefinition("ClassIndexTestClass", "fRidBag"));
    expectedIndexDefinitions.add(compositeIndexEleven);
    final OPropertyIndexDefinition propertyIndex = new OPropertyIndexDefinition("ClassIndexTestClass", "fOne", OType.INTEGER);
    expectedIndexDefinitions.add(propertyIndex);
    final OPropertyIndexDefinition parentPropertyIndex = new OPropertyIndexDefinition("ClassIndexTestSuperClass", "fNine", OType.INTEGER);
    expectedIndexDefinitions.add(parentPropertyIndex);
    final OPropertyMapIndexDefinition propertyMapIndexDefinition = new OPropertyMapIndexDefinition("ClassIndexTestClass", "fEmbeddedMap", OType.STRING, OPropertyMapIndexDefinition.INDEX_BY.KEY);
    expectedIndexDefinitions.add(propertyMapIndexDefinition);
    final OPropertyMapIndexDefinition propertyMapByValueIndexDefinition = new OPropertyMapIndexDefinition("ClassIndexTestClass", "fEmbeddedMap", OType.INTEGER, OPropertyMapIndexDefinition.INDEX_BY.VALUE);
    expectedIndexDefinitions.add(propertyMapByValueIndexDefinition);
    final OPropertyMapIndexDefinition propertyLinkMapByKeyIndexDefinition = new OPropertyMapIndexDefinition("ClassIndexTestClass", "fLinkMap", OType.STRING, OPropertyMapIndexDefinition.INDEX_BY.KEY);
    expectedIndexDefinitions.add(propertyLinkMapByKeyIndexDefinition);
    final OPropertyMapIndexDefinition propertyLinkMapByValueIndexDefinition = new OPropertyMapIndexDefinition("ClassIndexTestClass", "fLinkMap", OType.LINK, OPropertyMapIndexDefinition.INDEX_BY.VALUE);
    expectedIndexDefinitions.add(propertyLinkMapByValueIndexDefinition);
    assertEquals(indexes.size(), 18);
    for (final OIndex index : indexes) {
        assertTrue(expectedIndexDefinitions.contains(index.getDefinition()));
    }
}
Also used : OPropertyRidBagIndexDefinition(com.orientechnologies.orient.core.index.OPropertyRidBagIndexDefinition) OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OPropertyIndexDefinition(com.orientechnologies.orient.core.index.OPropertyIndexDefinition) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OPropertyMapIndexDefinition(com.orientechnologies.orient.core.index.OPropertyMapIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) OPropertyListIndexDefinition(com.orientechnologies.orient.core.index.OPropertyListIndexDefinition) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 35 with OIndex

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

the class OConsoleDatabaseApp method infoProperty.

@ConsoleCommand(description = "Display a class property", onlineHelp = "Console-Command-Info-Property")
public void infoProperty(@ConsoleParameter(name = "property-name", description = "The name of the property as <class>.<property>") final String iPropertyName) {
    checkForDatabase();
    if (iPropertyName.indexOf('.') == -1)
        throw new OSystemException("Property name is in the format <class>.<property>");
    final String[] parts = iPropertyName.split("\\.");
    final OClass cls = currentDatabase.getMetadata().getImmutableSchemaSnapshot().getClass(parts[0]);
    if (cls == null) {
        message("\n! Class '" + parts[0] + "' does not exist in the database '" + currentDatabaseName + "'");
        return;
    }
    final OProperty prop = cls.getProperty(parts[1]);
    if (prop == null) {
        message("\n! Property '" + parts[1] + "' does not exist in class '" + parts[0] + "'");
        return;
    }
    message("\nPROPERTY '" + prop.getFullName() + "'\n");
    message("\nType.................: " + prop.getType());
    message("\nMandatory............: " + prop.isMandatory());
    message("\nNot null.............: " + prop.isNotNull());
    message("\nRead only............: " + prop.isReadonly());
    message("\nDefault value........: " + prop.getDefaultValue());
    message("\nMinimum value........: " + prop.getMin());
    message("\nMaximum value........: " + prop.getMax());
    message("\nREGEXP...............: " + prop.getRegexp());
    message("\nCollate..............: " + prop.getCollate());
    message("\nLinked class.........: " + prop.getLinkedClass());
    message("\nLinked type..........: " + prop.getLinkedType());
    if (prop.getCustomKeys().size() > 0) {
        message("\n\nCUSTOM ATTRIBUTES");
        final List<ODocument> resultSet = new ArrayList<ODocument>();
        for (final String k : prop.getCustomKeys()) {
            try {
                final ODocument row = new ODocument();
                resultSet.add(row);
                row.field("NAME", k);
                row.field("VALUE", prop.getCustom(k));
            } catch (Exception ignored) {
            }
        }
        final OTableFormatter formatter = new OTableFormatter(this);
        formatter.writeRecords(resultSet, -1);
    }
    final Collection<OIndex<?>> indexes = prop.getAllIndexes();
    if (!indexes.isEmpty()) {
        message("\n\nINDEXES (" + indexes.size() + " altogether)");
        final List<ODocument> resultSet = new ArrayList<ODocument>();
        for (final OIndex<?> index : indexes) {
            final ODocument row = new ODocument();
            resultSet.add(row);
            row.field("NAME", index.getName());
            final OIndexDefinition indexDefinition = index.getDefinition();
            if (indexDefinition != null) {
                final List<String> fields = indexDefinition.getFields();
                row.field("PROPERTIES", fields);
            }
        }
        final OTableFormatter formatter = new OTableFormatter(this);
        formatter.writeRecords(resultSet, -1);
    }
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) OSystemException(com.orientechnologies.common.exception.OSystemException) OSystemException(com.orientechnologies.common.exception.OSystemException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) ORetryQueryException(com.orientechnologies.orient.core.exception.ORetryQueryException) OIOException(com.orientechnologies.common.io.OIOException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) ConsoleCommand(com.orientechnologies.common.console.annotation.ConsoleCommand)

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