Java Code Examples for com.orientechnologies.orient.core.metadata.schema.OClass#getClassIndex()

The following examples show how to use com.orientechnologies.orient.core.metadata.schema.OClass#getClassIndex() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrientQuartzSchema.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private static OIndex<?> maybeCreateIndex(final OClass clazz, final String name, final String... props) {
  OIndex<?> index = clazz.getClassIndex(name);
  if (index == null) {
    index = clazz.createIndex(name, UNIQUE, props);
  }
  return index;
}
 
Example 2
Source File: FulltextIndexFieldExtension.java    From guice-persist-orient with MIT License 5 votes vote down vote up
@Override
public void afterRegistration(final ODatabaseObject db, final SchemeDescriptor descriptor,
                              final Field field, final FulltextIndex annotation) {
    final String property = field.getName();
    final String model = descriptor.schemeClass;
    final String name = MoreObjects.firstNonNull(
            Strings.emptyToNull(annotation.name().trim()), model + '.' + property);
    final OClass clazz = db.getMetadata().getSchema().getClass(model);
    final OIndex<?> classIndex = clazz.getClassIndex(name);
    final OClass.INDEX_TYPE type = annotation.useHashIndex()
            ? OClass.INDEX_TYPE.FULLTEXT_HASH_INDEX : OClass.INDEX_TYPE.FULLTEXT;
    if (!descriptor.initialRegistration && classIndex != null) {
        final IndexValidationSupport support = new IndexValidationSupport(classIndex, logger);

        support.checkTypeCompatible(OClass.INDEX_TYPE.FULLTEXT, OClass.INDEX_TYPE.FULLTEXT_HASH_INDEX);
        support.checkFieldsCompatible(property);

        final boolean correct = isIndexCorrect(support, type, annotation);
        if (!correct) {
            support.dropIndex(db);
        } else {
            // index ok
            return;
        }
    }
    final ODocument metadata = createMetadata(annotation);
    clazz.createIndex(name, type.name(), null, metadata, null, new String[]{property});
    logger.info("Fulltext index '{}' ({} [{}]) {} created", name, model, property, type);
}
 
Example 3
Source File: LuceneIndexFieldExtension.java    From guice-persist-orient with MIT License 5 votes vote down vote up
@Override
public void afterRegistration(final ODatabaseObject db, final SchemeDescriptor descriptor,
                              final Field field, final LuceneIndex annotation) {
    db.getMetadata().getIndexManager().reload();
    final String property = field.getName();
    final String model = descriptor.schemeClass;
    final String name = MoreObjects.firstNonNull(
            Strings.emptyToNull(annotation.name().trim()), model + '.' + property);
    final OClass clazz = db.getMetadata().getSchema().getClass(model);
    final OIndex<?> classIndex = clazz.getClassIndex(name);
    final OClass.INDEX_TYPE type = OClass.INDEX_TYPE.FULLTEXT;
    if (!descriptor.initialRegistration && classIndex != null) {
        final IndexValidationSupport support = new IndexValidationSupport(classIndex, logger);
        support.checkTypeCompatible(type);
        support.checkFieldsCompatible(property);

        final boolean correct = support
                .isIndexSigns(classIndex.getConfiguration().field("algorithm"), getAnalyzer(classIndex))
                .matchRequiredSigns(type, OLuceneIndexFactory.LUCENE_ALGORITHM, annotation.value().getName());
        if (!correct) {
            support.dropIndex(db);
        } else {
            // index ok
            return;
        }
    }
    final ODocument metadata = createMetadata(annotation);
    SchemeUtils.command(db, "create index %s on %s (%s) %s engine %s metadata %s",
            name, model, property, type.name(), OLuceneIndexFactory.LUCENE_ALGORITHM, metadata.toJSON());
    logger.info("Lucene fulltext index '{}' ({} [{}]) created", name, model, property);
}
 
Example 4
Source File: IndexFieldExtension.java    From guice-persist-orient with MIT License 5 votes vote down vote up
@Override
public void afterRegistration(final ODatabaseObject db, final SchemeDescriptor descriptor,
                              final Field field, final Index annotation) {
    final String property = field.getName();
    final String model = descriptor.schemeClass;
    final String name = MoreObjects.firstNonNull(
            Strings.emptyToNull(annotation.name().trim()), model + '.' + property);
    final OClass clazz = db.getMetadata().getSchema().getClass(model);
    final OIndex<?> classIndex = clazz.getClassIndex(name);
    final OClass.INDEX_TYPE type = annotation.value();
    if (!descriptor.initialRegistration && classIndex != null) {
        final IndexValidationSupport support = new IndexValidationSupport(classIndex, logger);

        support.checkFieldsCompatible(property);

        final boolean correct = support
                .isIndexSigns(classIndex.getDefinition().isNullValuesIgnored())
                .matchRequiredSigns(type, annotation.ignoreNullValues());
        if (!correct) {
            support.dropIndex(db);
        } else {
            // index ok
            return;
        }
    }
    final ODocument metadata = new ODocument()
            .field("ignoreNullValues", annotation.ignoreNullValues());
    clazz.createIndex(name, type.name(), null, metadata, new String[]{property});
    logger.info("Index '{}' ({} [{}]) {} created", name, model, property, type);
}
 
Example 5
Source File: LuceneIndexTypeExtension.java    From guice-persist-orient with MIT License 5 votes vote down vote up
@Override
public void afterRegistration(final ODatabaseObject db, final SchemeDescriptor descriptor,
                              final CompositeLuceneIndex annotation) {
    db.getMetadata().getIndexManager().reload();
    final String name = Strings.emptyToNull(annotation.name().trim());
    Preconditions.checkArgument(name != null, "Index name required");
    final String model = descriptor.schemeClass;
    final OClass clazz = db.getMetadata().getSchema().getClass(model);
    final OIndex<?> classIndex = clazz.getClassIndex(name);
    final OClass.INDEX_TYPE type = OClass.INDEX_TYPE.FULLTEXT;
    final String[] fields = annotation.fields();
    if (!descriptor.initialRegistration && classIndex != null) {
        final IndexValidationSupport support = new IndexValidationSupport(classIndex, logger);
        support.checkTypeCompatible(type);
        support.checkFieldsCompatible(fields);

        final boolean correct = support
                .isIndexSigns(classIndex.getConfiguration().field("algorithm"), getAnalyzer(classIndex))
                .matchRequiredSigns(type, OLuceneIndexFactory.LUCENE_ALGORITHM, annotation.analyzer().getName());
        if (!correct) {
            support.dropIndex(db);
        } else {
            // index ok
            return;
        }
    }
    final ODocument metadata = createMetadata(annotation);
    SchemeUtils.command(db, "create index %s on %s (%s) %s engine %s metadata %s", name, model,
            Joiner.on(',').join(fields), type.name(), OLuceneIndexFactory.LUCENE_ALGORITHM, metadata.toJSON());
    logger.info("Lucene fulltext index '{}' ({} [{}]) created", name, model, Joiner.on(',').join(fields));
}
 
Example 6
Source File: IndexTypeExtension.java    From guice-persist-orient with MIT License 5 votes vote down vote up
@Override
public void afterRegistration(final ODatabaseObject db, final SchemeDescriptor descriptor,
                              final CompositeIndex annotation) {
    // single field index definition intentionally allowed (no check)
    final String name = Strings.emptyToNull(annotation.name().trim());
    Preconditions.checkArgument(name != null, "Index name required");
    final String model = descriptor.schemeClass;
    final OClass clazz = db.getMetadata().getSchema().getClass(model);
    final OIndex<?> classIndex = clazz.getClassIndex(name);
    final OClass.INDEX_TYPE type = annotation.type();
    final String[] fields = annotation.fields();
    if (!descriptor.initialRegistration && classIndex != null) {
        final IndexValidationSupport support = new IndexValidationSupport(classIndex, logger);

        support.checkFieldsCompatible(fields);

        final boolean correct = support
                .isIndexSigns(classIndex.getDefinition().isNullValuesIgnored())
                .matchRequiredSigns(type, annotation.ignoreNullValues());
        if (!correct) {
            support.dropIndex(db);
        } else {
            // index ok
            return;
        }
    }
    final ODocument metadata = new ODocument()
            .field("ignoreNullValues", annotation.ignoreNullValues());
    clazz.createIndex(name, type.name(), null, metadata, fields);
    logger.info("Index '{}' ({} [{}]) {} created", name, model, Joiner.on(',').join(fields), type);
}