use of com.orientechnologies.orient.core.index.OIndexDefinition 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)");
}
use of com.orientechnologies.orient.core.index.OIndexDefinition in project orientdb by orientechnologies.
the class IndexManagerTest method testGetClassIndexes.
@Test(dependsOnMethods = { "createCompositeIndexTestWithListener", "createCompositeIndexTestWithoutListener", "testCreateOnePropertyIndexTest" })
public void testGetClassIndexes() {
final OIndexManager indexManager = database.getMetadata().getIndexManager();
final Set<OIndex<?>> indexes = indexManager.getClassIndexes(CLASS_NAME);
final Set<OIndexDefinition> expectedIndexDefinitions = new HashSet<OIndexDefinition>();
final OCompositeIndexDefinition compositeIndexOne = new OCompositeIndexDefinition(CLASS_NAME);
compositeIndexOne.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fOne", OType.INTEGER));
compositeIndexOne.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fTwo", OType.STRING));
compositeIndexOne.setNullValuesIgnored(false);
expectedIndexDefinitions.add(compositeIndexOne);
final OCompositeIndexDefinition compositeIndexTwo = new OCompositeIndexDefinition(CLASS_NAME);
compositeIndexTwo.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fOne", OType.INTEGER));
compositeIndexTwo.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fTwo", OType.STRING));
compositeIndexTwo.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fThree", OType.BOOLEAN));
compositeIndexTwo.setNullValuesIgnored(false);
expectedIndexDefinitions.add(compositeIndexTwo);
final OPropertyIndexDefinition propertyIndex = new OPropertyIndexDefinition(CLASS_NAME, "fOne", OType.INTEGER);
propertyIndex.setNullValuesIgnored(false);
expectedIndexDefinitions.add(propertyIndex);
assertEquals(indexes.size(), 3);
for (final OIndex index : indexes) {
assertTrue(expectedIndexDefinitions.contains(index.getDefinition()));
}
}
use of com.orientechnologies.orient.core.index.OIndexDefinition in project orientdb by orientechnologies.
the class IndexManagerTest method testGetClassIndexesBrokenClassNameCase.
@Test(dependsOnMethods = { "createCompositeIndexTestWithListener", "createCompositeIndexTestWithoutListener", "testCreateOnePropertyIndexTest" })
public void testGetClassIndexesBrokenClassNameCase() {
final OIndexManager indexManager = database.getMetadata().getIndexManager();
final Set<OIndex<?>> indexes = indexManager.getClassIndexes("ClassforindeXMaNAgerTeST");
final Set<OIndexDefinition> expectedIndexDefinitions = new HashSet<OIndexDefinition>();
final OCompositeIndexDefinition compositeIndexOne = new OCompositeIndexDefinition(CLASS_NAME);
compositeIndexOne.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fOne", OType.INTEGER));
compositeIndexOne.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fTwo", OType.STRING));
compositeIndexOne.setNullValuesIgnored(false);
expectedIndexDefinitions.add(compositeIndexOne);
final OCompositeIndexDefinition compositeIndexTwo = new OCompositeIndexDefinition(CLASS_NAME);
compositeIndexTwo.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fOne", OType.INTEGER));
compositeIndexTwo.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fTwo", OType.STRING));
compositeIndexTwo.addIndex(new OPropertyIndexDefinition(CLASS_NAME, "fThree", OType.BOOLEAN));
compositeIndexTwo.setNullValuesIgnored(false);
expectedIndexDefinitions.add(compositeIndexTwo);
final OPropertyIndexDefinition propertyIndex = new OPropertyIndexDefinition(CLASS_NAME, "fOne", OType.INTEGER);
propertyIndex.setNullValuesIgnored(false);
expectedIndexDefinitions.add(propertyIndex);
assertEquals(indexes.size(), 3);
for (final OIndex index : indexes) {
assertTrue(expectedIndexDefinitions.contains(index.getDefinition()));
}
}
use of com.orientechnologies.orient.core.index.OIndexDefinition in project orientdb by orientechnologies.
the class SQLDropPropertyIndexTest method testForcePropertyDisabledBrokenCase.
@Test
public void testForcePropertyDisabledBrokenCase() throws Exception {
database.command(new OCommandSQL("CREATE INDEX DropPropertyIndexCompositeIndex ON DropPropertyIndexTestClass (prop1, prop2) UNIQUE")).execute();
try {
database.command(new OCommandSQL("DROP PROPERTY DropPropertyIndextestclaSS.proP1")).execute();
Assert.fail();
} catch (OCommandExecutionException e) {
Assert.assertTrue(e.getMessage().contains("Property used in indexes (" + "DropPropertyIndexCompositeIndex" + "). Please drop these indexes before removing property or use FORCE parameter."));
}
database.getMetadata().getIndexManager().reload();
final OIndex<?> index = database.getMetadata().getSchema().getClass("DropPropertyIndexTestClass").getClassIndex("DropPropertyIndexCompositeIndex");
Assert.assertNotNull(index);
final OIndexDefinition indexDefinition = index.getDefinition();
Assert.assertTrue(indexDefinition instanceof OCompositeIndexDefinition);
Assert.assertEquals(indexDefinition.getFields(), Arrays.asList("prop1", "prop2"));
Assert.assertEquals(indexDefinition.getTypes(), new OType[] { EXPECTED_PROP1_TYPE, EXPECTED_PROP2_TYPE });
Assert.assertEquals(index.getType(), "UNIQUE");
}
use of com.orientechnologies.orient.core.index.OIndexDefinition in project orientdb by orientechnologies.
the class PropertyIndexTest method testCreateUniqueIndex.
@Test
public void testCreateUniqueIndex() {
final OSchema schema = database.getMetadata().getSchema();
final OClass oClass = schema.getClass("PropertyIndexTestClass");
final OProperty propOne = oClass.getProperty("prop1");
propOne.createIndex(OClass.INDEX_TYPE.UNIQUE, new ODocument().field("ignoreNullValues", true));
final Collection<OIndex<?>> indexes = propOne.getIndexes();
OIndexDefinition indexDefinition = null;
for (final OIndex<?> index : indexes) {
if (index.getName().equals("PropertyIndexTestClass.prop1")) {
indexDefinition = index.getDefinition();
break;
}
}
Assert.assertNotNull(indexDefinition);
Assert.assertEquals(indexDefinition.getParamCount(), 1);
Assert.assertEquals(indexDefinition.getFields().size(), 1);
Assert.assertTrue(indexDefinition.getFields().contains("prop1"));
Assert.assertEquals(indexDefinition.getTypes().length, 1);
Assert.assertEquals(indexDefinition.getTypes()[0], OType.STRING);
schema.save();
}
Aggregations