Search in sources :

Example 1 with OIndex

use of com.orientechnologies.orient.core.index.OIndex in project guice-persist-orient by xvik.

the class FulltextIndexFieldExtension method isIndexCorrect.

private boolean isIndexCorrect(final IndexValidationSupport support, final OClass.INDEX_TYPE type, final FulltextIndex annotation) {
    final OIndex classIndex = support.getIndex();
    final ODocument metadata = classIndex.getConfiguration();
    final Iterable<String> field = metadata.field(STOP_WORDS);
    return support.isIndexSigns(metadata.field(INDEX_RADIX), metadata.field(IGNORE_CHARS), metadata.field(SEPARATOR_CHARS), metadata.field(MIN_WORD_LENGTH), Sets.newHashSet(field)).matchRequiredSigns(type, annotation.indexRadix(), annotation.ignoreChars(), annotation.separatorChars(), annotation.minWordLength(), Sets.newHashSet(annotation.stopWords()));
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 2 with OIndex

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

the class TestModels method testOIndexDataProvider.

@Test
public void testOIndexDataProvider() {
    OSchema schema = wicket.getTester().getSchema();
    OClass oClass = schema.getClass("OUser");
    OIndexesDataProvider provider = new OIndexesDataProvider(oClass, true);
    provider.setSort("name", SortOrder.ASCENDING);
    Iterator<? extends OIndex<?>> it = provider.iterator(0, -1);
    List<OIndex<?>> allIndexes = new ArrayList<OIndex<?>>(oClass.getIndexes());
    while (it.hasNext()) {
        OIndex<?> oIndex = it.next();
        assertTrue(allIndexes.remove(provider.model(oIndex).getObject()));
    }
    assertTrue(allIndexes.size() == 0);
    provider.detach();
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OIndexesDataProvider(ru.ydn.wicket.wicketorientdb.model.OIndexesDataProvider) OIndex(com.orientechnologies.orient.core.index.OIndex) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with OIndex

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

the class TestPrototypers method testOIndexPrototyper.

@Test
public void testOIndexPrototyper() throws Exception {
    OClass newClass = wicket.getTester().getSchema().createClass("NewClass");
    OProperty property = newClass.createProperty("name", OType.STRING);
    OIndex<?> newIndex = OIndexPrototyper.newPrototype("NewClass", Arrays.asList("name"));
    assertTrue(property.getAllIndexes().size() == 0);
    PropertyResolver.setValue("type", newIndex, "notunique", null);
    assertNotNull(newIndex.getDefinition());
    assertTrue(newIndex.getDefinition().getFields().contains("name"));
    assertTrue(newIndex instanceof IPrototype);
    OIndex<?> realizedNewIndex = ((IPrototype<OIndex<?>>) newIndex).realizePrototype();
    assertEquals(1, property.getAllIndexes().size());
    assertEquals(1, newClass.getIndexes().size());
    property = newClass.createProperty("description", OType.STRING);
    newIndex = OIndexPrototyper.newPrototype("NewClass", Arrays.asList("description"));
    PropertyResolver.setValue("type", newIndex, "notunique", null);
    assertEquals(0, property.getAllIndexes().size());
    PropertyResolver.setValue("algorithm", newIndex, ODefaultIndexFactory.SBTREE_ALGORITHM, null);
    ODocument metadata = new ODocument();
    metadata.field("test", "test123", OType.STRING);
    PropertyResolver.setValue("metadata", newIndex, metadata, null);
    realizedNewIndex = ((IPrototype<OIndex<?>>) newIndex).realizePrototype();
    assertEquals(1, property.getAllIndexes().size());
    assertEquals(2, newClass.getIndexes().size());
    assertEquals("test123", realizedNewIndex.getMetadata().field("test"));
    wicket.getTester().getSchema().dropClass(newClass.getName());
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) 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.junit.Test)

Example 4 with OIndex

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

the class OCommandExecutorSQLDropProperty method relatedIndexes.

private List<OIndex<?>> relatedIndexes(final String fieldName) {
    final List<OIndex<?>> result = new ArrayList<OIndex<?>>();
    final ODatabaseDocument database = getDatabase();
    for (final OIndex<?> oIndex : database.getMetadata().getIndexManager().getClassIndexes(className)) {
        if (OCollections.indexOf(oIndex.getDefinition().getFields(), fieldName, new OCaseInsentiveComparator()) > -1) {
            result.add(oIndex);
        }
    }
    return result;
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ArrayList(java.util.ArrayList) OCaseInsentiveComparator(com.orientechnologies.common.comparator.OCaseInsentiveComparator)

Example 5 with OIndex

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

the class OCommandExecutorSQLDropProperty method execute.

/**
 * Execute the CREATE PROPERTY.
 */
public Object execute(final Map<Object, Object> iArgs) {
    if (fieldName == null)
        throw new OCommandExecutionException("Cannot execute the command because it has not yet been parsed");
    final ODatabaseDocument database = getDatabase();
    final OClassImpl sourceClass = (OClassImpl) database.getMetadata().getSchema().getClass(className);
    if (sourceClass == null)
        throw new OCommandExecutionException("Source class '" + className + "' not found");
    if (ifExists && !sourceClass.existsProperty(fieldName)) {
        return null;
    }
    final List<OIndex<?>> indexes = relatedIndexes(fieldName);
    if (!indexes.isEmpty()) {
        if (force) {
            dropRelatedIndexes(indexes);
        } else {
            final StringBuilder indexNames = new StringBuilder();
            boolean first = true;
            for (final OIndex<?> index : sourceClass.getClassInvolvedIndexes(fieldName)) {
                if (!first) {
                    indexNames.append(", ");
                } else {
                    first = false;
                }
                indexNames.append(index.getName());
            }
            throw new OCommandExecutionException("Property used in indexes (" + indexNames.toString() + "). Please drop these indexes before removing property or use FORCE parameter.");
        }
    }
    // REMOVE THE PROPERTY
    sourceClass.dropProperty(fieldName);
    return null;
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OClassImpl(com.orientechnologies.orient.core.metadata.schema.OClassImpl)

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