@Override public OIndex<?> getClassIndex(final String iName) { return delegate.getClassIndex(iName); }
private static Set<? extends Comparable<?>> keySet(final OClass documentClass, final String indexName){ final OIndex<?> index = documentClass.getClassIndex(indexName); final OIndexKeyCursor cursor = index.keyCursor(); Object key; final Set<Comparable<?>> result = new HashSet<>(15); while ((key = cursor.next(5)) instanceof OCompositeKey) { final OCompositeKey compositeKey = (OCompositeKey) key; compositeKey.getKeys().stream() .filter(k -> k instanceof Comparable<?>) .map(k -> (Comparable<?>) k) .findFirst() .ifPresent(result::add); } return result; }
/** * Create {@link OIndex} on a set of fields if required * @param name name of an index * @param type type of an index * @param fields fields to create index on * @return this helper */ public OSchemaHelper oIndex(String name, INDEX_TYPE type, String... fields) { checkOClass(); lastIndex = lastClass.getClassIndex(name); if(lastIndex==null) { lastIndex = lastClass.createIndex(name, type, fields); } else { //We can't do something to change type and fields if required } return this; }
private <V> V getRecord(final Comparable<?> indexKey, final Function<? super OIdentifiable, ? extends V> transform) { final OClass documentClass = getDocumentClass(); final OIdentifiable recordId = DBUtils.supplyWithDatabase(database, () -> (OIdentifiable) documentClass.getClassIndex(indexName).get(PersistentFieldDefinition.getCompositeKey(indexKey))); return recordId == null ? null : transform.apply(recordId); }
/** * Create {@link OIndex} on a set of fields if required * @param name name of an index * @param type type of an index * @param fields fields to create index on * @return this helper */ public OSchemaHelper oIndex(String name, INDEX_TYPE type, String... fields) { checkOClass(); lastIndex = lastClass.getClassIndex(name); if(lastIndex==null) { lastIndex = lastClass.createIndex(name, type, fields); } else { //We can't do something to change type and fields if required } return this; }
@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); }
@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)); }
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();
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) {
@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); }
@Test public void testConverters() throws Exception { OSchema schema = wicket.getTester().getSchema(); testConverter(OClassClassNameConverter.INSTANCE, schema.getClass("OUser"), "OUser"); testConverter(OPropertyFullNameConverter.INSTANCE, schema.getClass("Ouser").getProperty("name"), "OUser.name"); testConverter(OIndexNameConverter.INSTANCE, schema.getClass("Ouser").getClassIndex("OUser.name"), "OUser.name"); ORID orid = new ORecordId("#5:0"); //Admin ORID ODocument document = orid.getRecord(); testConverter(ODocumentORIDConverter.INSTANCE, document, orid); }