Search in sources :

Example 16 with OIndex

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

the class OrientJdbcDatabaseMetaData method getIndexInfo.

@Override
public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) throws SQLException {
    database.activateOnCurrentThread();
    OMetadata metadata = database.getMetadata();
    if (!approximate) {
        metadata.getIndexManager().reload();
    }
    final Set<OIndex<?>> classIndexes = metadata.getIndexManager().getClassIndexes(table);
    final Set<OIndex<?>> indexes = new HashSet<OIndex<?>>();
    for (OIndex<?> oIndex : classIndexes) {
        if (!unique || oIndex.getType().equals(INDEX_TYPE.UNIQUE.name()))
            indexes.add(oIndex);
    }
    final List<ODocument> records = new ArrayList<ODocument>();
    for (OIndex<?> idx : indexes) {
        boolean notUniqueIndex = !(idx.getType().equals(INDEX_TYPE.UNIQUE.name()));
        final String fieldNames = idx.getDefinition().getFields().toString();
        ODocument doc = new ODocument().field("TABLE_CAT", catalog).field("TABLE_SCHEM", schema).field("TABLE_NAME", table).field("NON_UNIQUE", notUniqueIndex).field("INDEX_QUALIFIER", (Object) null).field("INDEX_NAME", idx.getName()).field("TYPE", idx.getType()).field("ORDINAL_POSITION", 0).field("COLUMN_NAME", fieldNames.substring(1, fieldNames.length() - 1)).field("ASC_OR_DESC", "ASC");
        records.add(doc);
    }
    return new OrientJdbcResultSet(new OrientJdbcStatement(connection), records, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.HOLD_CURSORS_OVER_COMMIT);
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) OMetadata(com.orientechnologies.orient.core.metadata.OMetadata) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 17 with OIndex

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

the class OLuceneIndexFactory method onDrop.

@Override
public void onDrop(final ODatabaseInternal db) {
    try {
        if (db.isClosed())
            return;
        OLogManager.instance().debug(this, "Dropping Lucene indexes...");
        for (OIndex idx : db.getMetadata().getIndexManager().getIndexes()) {
            if (idx.getInternal() instanceof OLuceneFullTextIndex) {
                OLogManager.instance().debug(this, "- index '%s'", idx.getName());
                idx.delete();
            }
        }
    } catch (Exception e) {
        OLogManager.instance().warn(this, "Error on dropping Lucene indexes", e);
    }
}
Also used : OLuceneFullTextIndex(com.orientechnologies.lucene.index.OLuceneFullTextIndex) OIndex(com.orientechnologies.orient.core.index.OIndex) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException)

Example 18 with OIndex

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

the class RemoteIndexSupportTest method testOneValueIndexInTxLookup.

@Test
public void testOneValueIndexInTxLookup() throws IOException {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx("remote:localhost/test");
    db.open("admin", "admin");
    OClass clazz = db.getMetadata().getSchema().createClass("TestIndex");
    clazz.createProperty("test", OType.STRING).createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
    db.begin();
    ODocument doc = new ODocument("TestIndex");
    doc.field("test", "testKey");
    db.save(doc);
    OIndex<Collection<OIdentifiable>> idx = (OIndex<Collection<OIdentifiable>>) db.getMetadata().getIndexManager().getIndex("TestIndex.test");
    Collection<OIdentifiable> res = idx.get("testKey");
    assertEquals(1, res.size());
    db.close();
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Collection(java.util.Collection) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test)

Example 19 with OIndex

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

the class SQLTruncateRecordTest method truncateRecord.

@Test
public void truncateRecord() {
    if (!database.getMetadata().getSchema().existsClass("Person"))
        database.command(new OCommandSQL("create class Profile")).execute();
    database.command(new OCommandSQL("insert into Profile (sex, salary) values ('female', 2100)")).execute();
    final Long total = database.countClass("Profile");
    final List<ODocument> resultset = database.query(new OSQLSynchQuery<Object>("select from Profile where sex = 'female' and salary = 2100"));
    final Number records = (Number) database.command(new OCommandSQL("truncate record [" + resultset.get(0).getIdentity() + "]")).execute();
    Assert.assertEquals(records.intValue(), 1);
    OClass cls = database.getMetadata().getSchema().getClass("Profile");
    Set<OIndex<?>> indexes = cls.getIndexes();
    for (OIndex<?> index : indexes) {
        index.rebuild();
    }
    Assert.assertEquals(database.countClass("Profile"), total - records.intValue());
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) 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.testng.annotations.Test)

Example 20 with OIndex

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

the class OrientIndex method create.

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<Set<OIdentifiable>>) graph.getRawGraph().getMetadata().getIndexManager().createIndex(indexName, OClass.INDEX_TYPE.NOTUNIQUE.toString(), new OSimpleKeyIndexDefinition(nuFactory.getLastVersion(), iKeyType), null, null, metadata));
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) OSimpleKeyIndexDefinition(com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition) OIndexTxAwareMultiValue(com.orientechnologies.orient.core.index.OIndexTxAwareMultiValue) OIndexTxAwareOneValue(com.orientechnologies.orient.core.index.OIndexTxAwareOneValue) OIndexFactory(com.orientechnologies.orient.core.index.OIndexFactory) Edge(com.tinkerpop.blueprints.Edge) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

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