Search in sources :

Example 1 with OIndexManagerProxy

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

the class DropIndexesTypeExtension method beforeRegistration.

@Override
public void beforeRegistration(final OObjectDatabaseTx db, final SchemeDescriptor descriptor, final DropIndexes annotation) {
    for (String index : annotation.value()) {
        final OIndexManagerProxy indexManager = db.getMetadata().getIndexManager();
        if (indexManager.existsIndex(index)) {
            SchemeUtils.dropIndex(db, index);
            logger.info("Index '{}' dropped for type {}", index, descriptor.schemeClass);
        }
    }
}
Also used : OIndexManagerProxy(com.orientechnologies.orient.core.index.OIndexManagerProxy)

Example 2 with OIndexManagerProxy

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

the class OOrientDBLoaderTest method testAddMetadataToIndex.

@Test
public void testAddMetadataToIndex() {
    process("{source: { content: { value: 'name,surname\nJay,Miner' } }, extractor : { csv: {} }, loader: { orientdb: {\n" + "      dbURL: \"memory:OETLBaseTest\",\n" + "      dbUser: \"admin\",\n" + "      dbPassword: \"admin\",\n" + "      dbAutoCreate: true,\n" + "      tx: false,\n" + "      batchCommit: 1000,\n" + "      wal : true,\n" + "      dbType: \"graph\",\n" + "      classes: [\n" + "        {name:\"Person\", extends: \"V\" },\n" + "      ],\n" + "      indexes: [{class:\"V\" , fields:[\"surname:String\"], \"type\":\"NOTUNIQUE\", \"metadata\": { \"ignoreNullValues\" : \"false\"}} ]  } } }");
    final OIndexManagerProxy indexManager = graph.getRawGraph().getMetadata().getIndexManager();
    assertThat(indexManager.existsIndex("V.surname")).isTrue();
    final ODocument indexMetadata = indexManager.getIndex("V.surname").getMetadata();
    assertThat(indexMetadata.containsField("ignoreNullValues")).isTrue();
    assertThat(indexMetadata.<String>field("ignoreNullValues")).isEqualTo("false");
}
Also used : OIndexManagerProxy(com.orientechnologies.orient.core.index.OIndexManagerProxy) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test) OETLBaseTest(com.orientechnologies.orient.etl.OETLBaseTest)

Example 3 with OIndexManagerProxy

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

the class IndexManagerTest method testCreateNullKeyDefinitionIndexTest.

@Test
public void testCreateNullKeyDefinitionIndexTest() {
    final OIndexManagerProxy indexManager = database.getMetadata().getIndexManager();
    final OIndex result = indexManager.createIndex("nullkey", OClass.INDEX_TYPE.UNIQUE.toString(), null, null, null, null);
    assertEquals(result.getName(), "nullkey");
    indexManager.reload();
    assertNull(database.getMetadata().getIndexManager().getClassIndex(CLASS_NAME, "nullkey"));
    assertEquals(database.getMetadata().getIndexManager().getIndex("nullkey").getName(), result.getName());
}
Also used : OIndex(com.orientechnologies.orient.core.index.OIndex) OIndexManagerProxy(com.orientechnologies.orient.core.index.OIndexManagerProxy) Test(org.testng.annotations.Test)

Example 4 with OIndexManagerProxy

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

the class IndexManagerTest method testCreateOnePropertyIndexTest.

@Test
public void testCreateOnePropertyIndexTest() {
    final OIndexManagerProxy indexManager = database.getMetadata().getIndexManager();
    final OIndex result = indexManager.createIndex("propertyone", OClass.INDEX_TYPE.UNIQUE.toString(), new OPropertyIndexDefinition(CLASS_NAME, "fOne", OType.INTEGER), new int[] { database.getClusterIdByName(CLASS_NAME) }, null, null);
    assertEquals(result.getName(), "propertyone");
    indexManager.reload();
    assertEquals(database.getMetadata().getIndexManager().getClassIndex(CLASS_NAME, "propertyone").getName(), result.getName());
}
Also used : OPropertyIndexDefinition(com.orientechnologies.orient.core.index.OPropertyIndexDefinition) OIndex(com.orientechnologies.orient.core.index.OIndex) OIndexManagerProxy(com.orientechnologies.orient.core.index.OIndexManagerProxy) Test(org.testng.annotations.Test)

Example 5 with OIndexManagerProxy

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

the class ODatabaseExport method exportManualIndexes.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void exportManualIndexes() throws IOException {
    listener.onMessage("\nExporting manual indexes content...");
    final OIndexManagerProxy indexManager = database.getMetadata().getIndexManager();
    indexManager.reload();
    final Collection<? extends OIndex<?>> indexes = indexManager.getIndexes();
    ODocument exportEntry = new ODocument();
    int manualIndexes = 0;
    writer.beginCollection(1, true, "manualIndexes");
    for (OIndex<?> index : indexes) {
        if (index.getName().equals(ODatabaseImport.EXPORT_IMPORT_MAP_NAME))
            continue;
        if (!index.isAutomatic()) {
            listener.onMessage("\n- Exporting index " + index.getName() + " ...");
            writer.beginObject(2, true, null);
            writer.writeAttribute(3, true, "name", index.getName());
            List<ODocument> indexContent = database.query(new OSQLSynchQuery<ODocument>("select from index:" + index.getName()));
            writer.beginCollection(3, true, "content");
            int i = 0;
            for (ODocument indexEntry : indexContent) {
                if (i > 0)
                    writer.append(",");
                indexEntry.setLazyLoad(false);
                final OIndexDefinition indexDefinition = index.getDefinition();
                exportEntry.reset();
                exportEntry.setLazyLoad(false);
                if (indexDefinition instanceof ORuntimeKeyIndexDefinition && ((ORuntimeKeyIndexDefinition) indexDefinition).getSerializer() != null) {
                    final OBinarySerializer binarySerializer = ((ORuntimeKeyIndexDefinition) indexDefinition).getSerializer();
                    final int dataSize = binarySerializer.getObjectSize(indexEntry.field("key"));
                    final byte[] binaryContent = new byte[dataSize];
                    binarySerializer.serialize(indexEntry.field("key"), binaryContent, 0);
                    exportEntry.field("binary", true);
                    exportEntry.field("key", binaryContent);
                } else {
                    exportEntry.field("binary", false);
                    exportEntry.field("key", indexEntry.field("key"));
                }
                exportEntry.field("rid", indexEntry.field("rid"));
                i++;
                writer.append(exportEntry.toJSON());
                final long percent = indexContent.size() / 10;
                if (percent > 0 && (i % percent) == 0)
                    listener.onMessage(".");
            }
            writer.endCollection(3, true);
            writer.endObject(2, true);
            listener.onMessage("OK (entries=" + index.getSize() + ")");
            manualIndexes++;
        }
    }
    writer.endCollection(1, true);
    listener.onMessage("\nOK (" + manualIndexes + " manual indexes)");
}
Also used : OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) ORuntimeKeyIndexDefinition(com.orientechnologies.orient.core.index.ORuntimeKeyIndexDefinition) OBinarySerializer(com.orientechnologies.common.serialization.types.OBinarySerializer) OIndexManagerProxy(com.orientechnologies.orient.core.index.OIndexManagerProxy) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OIndexManagerProxy (com.orientechnologies.orient.core.index.OIndexManagerProxy)12 Test (org.testng.annotations.Test)6 OIndex (com.orientechnologies.orient.core.index.OIndex)5 OPropertyIndexDefinition (com.orientechnologies.orient.core.index.OPropertyIndexDefinition)3 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)2 OCompositeIndexDefinition (com.orientechnologies.orient.core.index.OCompositeIndexDefinition)2 OSimpleKeyIndexDefinition (com.orientechnologies.orient.core.index.OSimpleKeyIndexDefinition)2 IOException (java.io.IOException)2 OException (com.orientechnologies.common.exception.OException)1 OProgressListener (com.orientechnologies.common.listener.OProgressListener)1 OBinarySerializer (com.orientechnologies.common.serialization.types.OBinarySerializer)1 OCommandCacheSoftRefs (com.orientechnologies.orient.core.cache.OCommandCacheSoftRefs)1 OStorageEntryConfiguration (com.orientechnologies.orient.core.config.OStorageEntryConfiguration)1 OSecurityAccessException (com.orientechnologies.orient.core.exception.OSecurityAccessException)1 OSecurityException (com.orientechnologies.orient.core.exception.OSecurityException)1 OIndexDefinition (com.orientechnologies.orient.core.index.OIndexDefinition)1 OIndexManager (com.orientechnologies.orient.core.index.OIndexManager)1 OIndexManagerRemote (com.orientechnologies.orient.core.index.OIndexManagerRemote)1 OIndexManagerShared (com.orientechnologies.orient.core.index.OIndexManagerShared)1