Search in sources :

Example 1 with ORuntimeKeyIndexDefinition

use of com.orientechnologies.orient.core.index.ORuntimeKeyIndexDefinition 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)

Example 2 with ORuntimeKeyIndexDefinition

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

the class IndexCustomKeyTest method beforeMethod.

@BeforeMethod
public void beforeMethod() throws Exception {
    super.beforeMethod();
    OIndex<?> index = getIndex();
    if (index == null) {
        OBinarySerializerFactory.getInstance().registerSerializer(new OHash256Serializer(), null);
        database.getMetadata().getIndexManager().createIndex("custom-hash", "UNIQUE", new ORuntimeKeyIndexDefinition(OHash256Serializer.ID, -1), null, null, null);
    }
}
Also used : ORuntimeKeyIndexDefinition(com.orientechnologies.orient.core.index.ORuntimeKeyIndexDefinition) BeforeMethod(org.testng.annotations.BeforeMethod)

Aggregations

ORuntimeKeyIndexDefinition (com.orientechnologies.orient.core.index.ORuntimeKeyIndexDefinition)2 OBinarySerializer (com.orientechnologies.common.serialization.types.OBinarySerializer)1 OIndexDefinition (com.orientechnologies.orient.core.index.OIndexDefinition)1 OIndexManagerProxy (com.orientechnologies.orient.core.index.OIndexManagerProxy)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 BeforeMethod (org.testng.annotations.BeforeMethod)1