commitAnyActiveTx("create key index"); String indexType = OClass.INDEX_TYPE.NOTUNIQUE.name(); OType keyType = OType.STRING; String className = null;
indexType = OClass.INDEX_TYPE.valueOf(word.toString());
OIndexFactory factory = OIndexes.getFactory(indexType.toString(), null); idx = database.getMetadata().getIndexManager().createIndex(indexName, indexType.toString(), new OSimpleKeyIndexDefinition(keyTypes, collatesList, factory.getLastVersion()), null, null, metadataDoc, engine); else if (serializerKeyId != 0) { idx = database.getMetadata().getIndexManager() .createIndex(indexName, indexType.toString(), new ORuntimeKeyIndexDefinition(serializerKeyId, factory.getLastVersion()), null, null, metadataDoc, engine); } else { idx = oClass.createIndex(indexName, indexType.toString(), null, metadataDoc, engine, fields); } else { final List<OType> fieldTypeList; .createIndexDefinition(oClass, Arrays.asList(fields), fieldTypeList, collatesList, indexType.toString(), null); .createIndex(indexName, indexType.name(), idxDef, oClass.getPolymorphicClusterIds(), null, metadataDoc, engine);
@Override public OClass call(final OrientBaseGraph g) { String indexType = OClass.INDEX_TYPE.NOTUNIQUE.name(); OType keyType = OType.STRING; String className = null;
return -1; final OClass.INDEX_TYPE indexType = OClass.INDEX_TYPE.valueOf(index.getType()); final boolean isComposite = isComposite(index); final boolean supportNullValues = supportNullValues(index);
String[] fieldArray = fields.keySet().stream().toArray(String[]::new); OIndex<?> idx = e.createIndex(name, unique ? OClass.INDEX_TYPE.UNIQUE_HASH_INDEX.toString() : OClass.INDEX_TYPE.NOTUNIQUE_HASH_INDEX.toString(), null, new ODocument().fields("ignoreNullValues", true), fieldArray); if (idx == 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); }
clazz.createIndex(name, type.name(), null, metadata, new String[]{property}); logger.info("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)); }
.field("ignoreNullValues", false) .field("mergeKeys", false); type.createIndex(I_BUCKET_GROUP_NAME_VERSION, INDEX_TYPE.UNIQUE.name(), null, metadata, new String[]{P_BUCKET, P_GROUP, P_NAME, P_VERSION}); type.createIndex(I_BUCKET_NAME_VERSION, INDEX_TYPE.NOTUNIQUE.name(), null, metadata, new String[]{P_BUCKET, P_NAME, P_VERSION});
private void create(final String indexName, final Class<? extends Element> indexClass, OType iKeyType) { this.indexClass = indexClass; if (iKeyType == null) iKeyType = OType.STRING; final OIndexFactory factory = OIndexes.getFactory(OClass.INDEX_TYPE.DICTIONARY.toString(), null); this.recordKeyValueIndex = new OIndexTxAwareOneValue(graph.getRawGraph(), (OIndex<OIdentifiable>) graph .getRawGraph() .getMetadata() .getIndexManager() .createIndex("__@recordmap@___" + indexName, OClass.INDEX_TYPE.DICTIONARY.toString(), new OSimpleKeyIndexDefinition(factory.getLastVersion(), OType.LINK, OType.STRING), null, null, null)); final String className; if (Vertex.class.isAssignableFrom(indexClass)) className = VERTEX; else if (Edge.class.isAssignableFrom(indexClass)) className = EDGE; else className = indexClass.getName(); final ODocument metadata = new ODocument(); metadata.field(CONFIG_CLASSNAME, className); metadata.field(CONFIG_RECORD_MAP_NAME, recordKeyValueIndex.getName()); final OIndexFactory nuFactory = OIndexes.getFactory(OClass.INDEX_TYPE.NOTUNIQUE.toString(), null); // CREATE THE MAP this.underlying = new OIndexTxAwareMultiValue(graph.getRawGraph(), (OIndex<Collection<OIdentifiable>>) graph .getRawGraph() .getMetadata() .getIndexManager() .createIndex(indexName, OClass.INDEX_TYPE.NOTUNIQUE.toString(), new OSimpleKeyIndexDefinition(nuFactory.getLastVersion(), iKeyType), null, null, metadata)); }
@Override public void addVertexIndex(String indexName, Class<?> clazzOfVertices, boolean unique, String fieldKey, FieldType fieldType) { if (log.isDebugEnabled()) { log.debug("Adding vertex index for class {" + clazzOfVertices.getName() + "}"); } OrientGraphNoTx noTx = rawNoTx(); try { String name = clazzOfVertices.getSimpleName(); OrientVertexType v = noTx.getVertexType(name); if (v == null) { throw new RuntimeException("Vertex type {" + name + "} is unknown. Can't create index {" + indexName + "}"); } if (v.getProperty(fieldKey) == null) { OType type = toType(fieldType); OType subType = toSubType(fieldType); if (subType != null) { v.createProperty(fieldKey, type, subType); } else { v.createProperty(fieldKey, type); } } if (v.getClassIndex(indexName) == null) { v.createIndex(indexName, unique ? OClass.INDEX_TYPE.UNIQUE_HASH_INDEX.toString() : OClass.INDEX_TYPE.NOTUNIQUE_HASH_INDEX.toString(), null, new ODocument().fields("ignoreNullValues", true), new String[] { fieldKey }); } } finally { noTx.shutdown(); } }
@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); }
private static RecordType getRecordType(OClass oClass) { RecordType type = new RecordType(oClass.getName()); for (OProperty oProperty : oClass.properties()) { OType oType = oProperty.getType(); Class javaType = oType.getDefaultJavaType(); if (oType == OType.LINK) { javaType = RecordId.class; } FieldDefinition field = new FieldDefinition(oProperty.getName(), javaType); field.withNotNull(oProperty.isNotNull()); for (OIndex oIndex : oProperty.getAllIndexes()) { OIndexDefinition def = oIndex.getDefinition(); if (def.isAutomatic() && def.getFields().size() == 1) { boolean unique = oIndex.getType().equalsIgnoreCase(INDEX_TYPE.UNIQUE.name()); field.withIndexed(true).withUnique(unique); } } type.withField(field); } type.withStrict(oClass.isStrictMode()); OClass oSuperClass = oClass.getSuperClass(); if (oSuperClass != null) { type.withSuperType(getRecordType(oSuperClass)); } type.withAbstract(oClass.isAbstract()); return type; }
@Override protected void defineType(final ODatabaseDocumentTx db, final OClass type) { super.defineType(type); type.createProperty(P_COMPONENT, OType.LINK, componentEntityAdapter.getSchemaType()); type.createProperty(P_NAME, OType.STRING) .setMandatory(true) .setNotNull(true); type.createProperty(P_SIZE, OType.LONG); type.createProperty(P_CONTENT_TYPE, OType.STRING); type.createProperty(P_BLOB_REF, OType.STRING); type.createProperty(P_LAST_DOWNLOADED, OType.DATETIME); type.createProperty(P_BLOB_CREATED, OType.DATETIME); type.createProperty(P_BLOB_UPDATED, OType.DATETIME); type.createProperty(P_CREATED_BY, OType.STRING); type.createProperty(P_CREATED_BY_IP, OType.STRING); ODocument metadata = db.newInstance() .field("ignoreNullValues", false) .field("mergeKeys", false); type.createIndex(I_BUCKET_COMPONENT_NAME, INDEX_TYPE.UNIQUE.name(), null, metadata, new String[]{P_BUCKET, P_COMPONENT, P_NAME} ); type.createIndex(I_BUCKET_NAME, INDEX_TYPE.NOTUNIQUE, P_BUCKET, P_NAME); type.createIndex(I_COMPONENT, INDEX_TYPE.NOTUNIQUE, P_COMPONENT); new OIndexBuilder(type, I_NAME_CASEINSENSITIVE, INDEX_TYPE.NOTUNIQUE) .property(P_NAME, OType.STRING) .caseInsensitive() .build(db); }
@Override public ResultSet getPrimaryKeys(final String catalog, final String schema, final String table) throws SQLException { database.activateOnCurrentThread(); final Set<OIndex<?>> classIndexes = database.getMetadata().getIndexManager().getClassIndexes(table); final Set<OIndex<?>> uniqueIndexes = new HashSet<>(); for (OIndex<?> oIndex : classIndexes) { if (oIndex.getType().equals(INDEX_TYPE.UNIQUE.name())) uniqueIndexes.add(oIndex); } final OInternalResultSet resultSet = new OInternalResultSet(); for (OIndex<?> unique : uniqueIndexes) { int keyFiledSeq = 1; for (String keyFieldName : unique.getDefinition().getFields()) { final OResultInternal res = new OResultInternal(); res.setProperty("TABLE_CAT", catalog); res.setProperty("TABLE_SCHEM", catalog); res.setProperty("TABLE_NAME", table); res.setProperty("COLUMN_NAME", keyFieldName); res.setProperty("KEY_SEQ", keyFiledSeq); res.setProperty("PK_NAME", unique.getName()); keyFiledSeq++; resultSet.add(res); } } return new OrientJdbcResultSet(new OrientJdbcStatement(connection), resultSet, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT); }
clazz.createIndex(name, type.name(), null, metadata, fields); logger.info("Index '{}' ({} [{}]) {} created", name, model, Joiner.on(',').join(fields), type);