use of com.orientechnologies.orient.core.index.OIndexManager in project orientdb by orientechnologies.
the class OImmutableClass method areIndexed.
@Override
public boolean areIndexed(Collection<String> fields) {
final OIndexManager indexManager = getDatabase().getMetadata().getIndexManager();
final boolean currentClassResult = indexManager.areIndexed(name, fields);
initSuperClasses();
if (currentClassResult)
return true;
for (OImmutableClass superClass : superClasses) {
if (superClass.areIndexed(fields))
return true;
}
return false;
}
use of com.orientechnologies.orient.core.index.OIndexManager in project orientdb by orientechnologies.
the class OTransactionRealAbstract method updateIdentityAfterCommit.
public void updateIdentityAfterCommit(final ORID oldRid, final ORID newRid) {
if (oldRid.equals(newRid))
// NO CHANGE, IGNORE IT
return;
// XXX: Identity update may mutate the index keys, so we have to identify and reinsert potentially affected index keys to keep
// the OTransactionIndexChanges.changesPerKey in a consistent state.
final List<KeyChangesUpdateRecord> keyRecordsToReinsert = new ArrayList<KeyChangesUpdateRecord>();
final OIndexManager indexManager = getDatabase().getMetadata().getIndexManager();
for (Entry<String, OTransactionIndexChanges> entry : indexEntries.entrySet()) {
final OIndex<?> index = indexManager.getIndex(entry.getKey());
if (index == null)
throw new OTransactionException("Cannot find index '" + entry.getValue() + "' while committing transaction");
final Dependency[] fieldRidDependencies = getIndexFieldRidDependencies(index);
if (!isIndexMayDependOnRids(fieldRidDependencies))
continue;
final OTransactionIndexChanges indexChanges = entry.getValue();
for (final Iterator<OTransactionIndexChangesPerKey> iterator = indexChanges.changesPerKey.values().iterator(); iterator.hasNext(); ) {
final OTransactionIndexChangesPerKey keyChanges = iterator.next();
if (isIndexKeyMayDependOnRid(keyChanges.key, oldRid, fieldRidDependencies)) {
keyRecordsToReinsert.add(new KeyChangesUpdateRecord(keyChanges, indexChanges));
iterator.remove();
}
}
}
// Update the identity.
final ORecordOperation rec = getRecordEntry(oldRid);
if (rec != null) {
updatedRids.put(newRid.copy(), oldRid.copy());
if (!rec.getRecord().getIdentity().equals(newRid)) {
ORecordInternal.onBeforeIdentityChanged(rec.getRecord());
final ORecordId recordId = (ORecordId) rec.getRecord().getIdentity();
if (recordId == null) {
ORecordInternal.setIdentity(rec.getRecord(), new ORecordId(newRid));
} else {
recordId.setClusterPosition(newRid.getClusterPosition());
recordId.setClusterId(newRid.getClusterId());
}
ORecordInternal.onAfterIdentityChanged(rec.getRecord());
}
}
for (KeyChangesUpdateRecord record : keyRecordsToReinsert) record.indexChanges.changesPerKey.put(record.keyChanges.key, record.keyChanges);
// Update the indexes.
final List<OTransactionRecordIndexOperation> transactionIndexOperations = recordIndexOperations.get(translateRid(oldRid));
if (transactionIndexOperations != null) {
for (final OTransactionRecordIndexOperation indexOperation : transactionIndexOperations) {
OTransactionIndexChanges indexEntryChanges = indexEntries.get(indexOperation.index);
if (indexEntryChanges == null)
continue;
final OTransactionIndexChangesPerKey keyChanges = indexEntryChanges.changesPerKey.get(indexOperation.key);
if (keyChanges != null)
updateChangesIdentity(oldRid, newRid, keyChanges);
}
}
}
use of com.orientechnologies.orient.core.index.OIndexManager in project orientdb by orientechnologies.
the class IndexManagerTest method testAreIndexedThreePropertiesBrokenClassNameCase.
@Test(dependsOnMethods = { "createCompositeIndexTestWithListener", "createCompositeIndexTestWithoutListener", "testCreateOnePropertyIndexTest" })
public void testAreIndexedThreePropertiesBrokenClassNameCase() {
final OIndexManager indexManager = database.getMetadata().getIndexManager();
final boolean result = indexManager.areIndexed("ClaSSForIndeXManagerTeST", Arrays.asList("fTwo", "fOne", "fThree"));
assertTrue(result);
}
use of com.orientechnologies.orient.core.index.OIndexManager in project orientdb by orientechnologies.
the class ODatabaseCompare method compareIndexes.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void compareIndexes(ODocumentHelper.RIDMapper ridMapper) {
listener.onMessage("\nStarting index comparison:");
boolean ok = true;
final OIndexManager indexManagerOne = makeDbCall(databaseOne, new ODbRelatedCall<OIndexManager>() {
public OIndexManager call(ODatabaseDocumentInternal database) {
return database.getMetadata().getIndexManager();
}
});
final OIndexManager indexManagerTwo = makeDbCall(databaseTwo, new ODbRelatedCall<OIndexManager>() {
public OIndexManager call(ODatabaseDocumentInternal database) {
return database.getMetadata().getIndexManager();
}
});
final Collection<? extends OIndex<?>> indexesOne = makeDbCall(databaseOne, new ODbRelatedCall<Collection<? extends OIndex<?>>>() {
public Collection<? extends OIndex<?>> call(ODatabaseDocumentInternal database) {
return indexManagerOne.getIndexes();
}
});
int indexesSizeOne = makeDbCall(databaseTwo, new ODbRelatedCall<Integer>() {
public Integer call(ODatabaseDocumentInternal database) {
return indexesOne.size();
}
});
int indexesSizeTwo = makeDbCall(databaseTwo, new ODbRelatedCall<Integer>() {
public Integer call(ODatabaseDocumentInternal database) {
return indexManagerTwo.getIndexes().size();
}
});
if (exportImportHashTable != null)
indexesSizeTwo--;
if (indexesSizeOne != indexesSizeTwo) {
ok = false;
listener.onMessage("\n- ERR: Amount of indexes are different.");
listener.onMessage("\n--- DB1: " + indexesSizeOne);
listener.onMessage("\n--- DB2: " + indexesSizeTwo);
listener.onMessage("\n");
++differences;
}
final Iterator<? extends OIndex<?>> iteratorOne = makeDbCall(databaseOne, new ODbRelatedCall<Iterator<? extends OIndex<?>>>() {
public Iterator<? extends OIndex<?>> call(ODatabaseDocumentInternal database) {
return indexesOne.iterator();
}
});
while (makeDbCall(databaseOne, new ODbRelatedCall<Boolean>() {
public Boolean call(ODatabaseDocumentInternal database) {
return iteratorOne.hasNext();
}
})) {
final OIndex indexOne = makeDbCall(databaseOne, new ODbRelatedCall<OIndex<?>>() {
public OIndex<?> call(ODatabaseDocumentInternal database) {
return iteratorOne.next();
}
});
final OIndex<?> indexTwo = makeDbCall(databaseTwo, new ODbRelatedCall<OIndex<?>>() {
public OIndex<?> call(ODatabaseDocumentInternal database) {
return indexManagerTwo.getIndex(indexOne.getName());
}
});
if (indexTwo == null) {
ok = false;
listener.onMessage("\n- ERR: Index " + indexOne.getName() + " is absent in DB2.");
++differences;
continue;
}
if (!indexOne.getType().equals(indexTwo.getType())) {
ok = false;
listener.onMessage("\n- ERR: Index types for index " + indexOne.getName() + " are different.");
listener.onMessage("\n--- DB1: " + indexOne.getType());
listener.onMessage("\n--- DB2: " + indexTwo.getType());
listener.onMessage("\n");
++differences;
continue;
}
if (!indexOne.getClusters().equals(indexTwo.getClusters())) {
ok = false;
listener.onMessage("\n- ERR: Clusters to index for index " + indexOne.getName() + " are different.");
listener.onMessage("\n--- DB1: " + indexOne.getClusters());
listener.onMessage("\n--- DB2: " + indexTwo.getClusters());
listener.onMessage("\n");
++differences;
continue;
}
if (indexOne.getDefinition() == null && indexTwo.getDefinition() != null) {
ok = false;
listener.onMessage("\n- ERR: Index definition for index " + indexOne.getName() + " for DB2 is not null.");
++differences;
continue;
} else if (indexOne.getDefinition() != null && indexTwo.getDefinition() == null) {
ok = false;
listener.onMessage("\n- ERR: Index definition for index " + indexOne.getName() + " for DB2 is null.");
++differences;
continue;
} else if (indexOne.getDefinition() != null && !indexOne.getDefinition().equals(indexTwo.getDefinition())) {
ok = false;
listener.onMessage("\n- ERR: Index definitions for index " + indexOne.getName() + " are different.");
listener.onMessage("\n--- DB1: " + indexOne.getDefinition());
listener.onMessage("\n--- DB2: " + indexTwo.getDefinition());
listener.onMessage("\n");
++differences;
continue;
}
final long indexOneSize = makeDbCall(databaseOne, new ODbRelatedCall<Long>() {
public Long call(ODatabaseDocumentInternal database) {
return indexOne.getSize();
}
});
final long indexTwoSize = makeDbCall(databaseTwo, new ODbRelatedCall<Long>() {
public Long call(ODatabaseDocumentInternal database) {
return indexTwo.getSize();
}
});
if (indexOneSize != indexTwoSize) {
ok = false;
listener.onMessage("\n- ERR: Amount of entries for index " + indexOne.getName() + " are different.");
listener.onMessage("\n--- DB1: " + indexOneSize);
listener.onMessage("\n--- DB2: " + indexTwoSize);
listener.onMessage("\n");
++differences;
}
if (compareIndexMetadata) {
final ODocument metadataOne = indexOne.getMetadata();
final ODocument metadataTwo = indexTwo.getMetadata();
if (metadataOne == null && metadataTwo != null) {
ok = false;
listener.onMessage("\n- ERR: Metadata for index " + indexOne.getName() + " for DB1 is null but for DB2 is not.");
listener.onMessage("\n");
++differences;
} else if (metadataOne != null && metadataTwo == null) {
ok = false;
listener.onMessage("\n- ERR: Metadata for index " + indexOne.getName() + " for DB1 is not null but for DB2 is null.");
listener.onMessage("\n");
++differences;
} else if (metadataOne != null && metadataTwo != null && !ODocumentHelper.hasSameContentOf(metadataOne, databaseOne, metadataTwo, databaseTwo, ridMapper)) {
ok = false;
listener.onMessage("\n- ERR: Metadata for index " + indexOne.getName() + " for DB1 and for DB2 are different.");
makeDbCall(databaseOne, new ODbRelatedCall<Object>() {
@Override
public Object call(ODatabaseDocumentInternal database) {
listener.onMessage("\n--- M1: " + metadataOne);
return null;
}
});
makeDbCall(databaseTwo, new ODbRelatedCall<Object>() {
@Override
public Object call(ODatabaseDocumentInternal database) {
listener.onMessage("\n--- M2: " + metadataTwo);
return null;
}
});
listener.onMessage("\n");
++differences;
}
}
if (((compareEntriesForAutomaticIndexes && !indexOne.getType().equals("DICTIONARY")) || !indexOne.isAutomatic())) {
final OIndexKeyCursor indexKeyCursorOne = makeDbCall(databaseOne, new ODbRelatedCall<OIndexKeyCursor>() {
public OIndexKeyCursor call(ODatabaseDocumentInternal database) {
return indexOne.keyCursor();
}
});
Object key = makeDbCall(databaseOne, new ODbRelatedCall<Object>() {
@Override
public Object call(ODatabaseDocumentInternal database) {
return indexKeyCursorOne.next(-1);
}
});
while (key != null) {
final Object indexKey = key;
Object indexOneValue = makeDbCall(databaseOne, new ODbRelatedCall<Object>() {
public Object call(ODatabaseDocumentInternal database) {
return indexOne.get(indexKey);
}
});
final Object indexTwoValue = makeDbCall(databaseTwo, new ODbRelatedCall<Object>() {
public Object call(ODatabaseDocumentInternal database) {
return indexTwo.get(indexKey);
}
});
if (indexTwoValue == null) {
ok = false;
listener.onMessage("\n- ERR: Entry with key " + key + " is absent in index " + indexOne.getName() + " for DB2.");
++differences;
} else if (indexOneValue instanceof Set && indexTwoValue instanceof Set) {
final Set<Object> indexOneValueSet = (Set<Object>) indexOneValue;
final Set<Object> indexTwoValueSet = (Set<Object>) indexTwoValue;
if (!ODocumentHelper.compareSets(databaseOne, indexOneValueSet, databaseTwo, indexTwoValueSet, ridMapper)) {
ok = false;
reportIndexDiff(indexOne, key, indexOneValue, indexTwoValue);
}
} else if (indexOneValue instanceof ORID && indexTwoValue instanceof ORID) {
if (ridMapper != null && ((ORID) indexOneValue).isPersistent()) {
OIdentifiable identifiable = ridMapper.map((ORID) indexOneValue);
if (identifiable != null)
indexOneValue = identifiable.getIdentity();
}
if (!indexOneValue.equals(indexTwoValue)) {
ok = false;
reportIndexDiff(indexOne, key, indexOneValue, indexTwoValue);
}
} else if (!indexOneValue.equals(indexTwoValue)) {
ok = false;
reportIndexDiff(indexOne, key, indexOneValue, indexTwoValue);
}
key = makeDbCall(databaseOne, new ODbRelatedCall<Object>() {
@Override
public Object call(ODatabaseDocumentInternal database) {
return indexKeyCursorOne.next(-1);
}
});
}
}
}
if (ok)
listener.onMessage("OK");
}
use of com.orientechnologies.orient.core.index.OIndexManager in project orientdb by orientechnologies.
the class IndexManagerTest method testGetClassInvolvedIndexesTwoProperties.
@Test(dependsOnMethods = { "createCompositeIndexTestWithListener", "createCompositeIndexTestWithoutListener", "testCreateOnePropertyIndexTest" })
public void testGetClassInvolvedIndexesTwoProperties() {
final OIndexManager indexManager = database.getMetadata().getIndexManager();
final Set<OIndex<?>> result = indexManager.getClassInvolvedIndexes(CLASS_NAME, Arrays.asList("fTwo", "fOne"));
assertEquals(result.size(), 2);
assertTrue(containsIndex(result, "compositeone"));
assertTrue(containsIndex(result, "compositetwo"));
}
Aggregations