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);
}
}
}
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");
}
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());
}
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());
}
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)");
}
Aggregations