use of org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException in project neo4j by neo4j.
the class PropertyAndNodeIndexedCheck method verifyNodeCorrectlyIndexedUniquely.
private void verifyNodeCorrectlyIndexedUniquely(long nodeId, int propertyKeyId, Object propertyValue, CheckerEngine<NodeRecord, ConsistencyReport.NodeConsistencyReport> engine, IndexRule indexRule, IndexReader reader) {
PrimitiveLongIterator indexedNodeIds = null;
try {
indexedNodeIds = reader.query(IndexQuery.exact(propertyKeyId, propertyValue));
} catch (IndexNotApplicableKernelException e) {
indexedNodeIds = PrimitiveLongCollections.emptyIterator();
}
// For verifying node indexed uniquely in offline CC, if one match found in the first stage match,
// then there is no need to filter the result. The result is a exact match.
// If multiple matches found, we need to filter the result to get exact matches.
indexedNodeIds = filterIfMultipleValuesFound(indexedNodeIds, propertyKeyId, propertyValue);
boolean found = false;
while (indexedNodeIds.hasNext()) {
long indexedNodeId = indexedNodeIds.next();
if (nodeId == indexedNodeId) {
found = true;
} else {
engine.report().uniqueIndexNotUnique(indexRule, propertyValue, indexedNodeId);
}
}
if (!found) {
engine.report().notIndexed(indexRule, propertyValue);
}
}
use of org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException in project neo4j by neo4j.
the class StatementOperationsTestHelper method mockedState.
public static KernelStatement mockedState(final TransactionState txState) {
KernelStatement state = mock(KernelStatement.class);
Locks.Client locks = mock(Locks.Client.class);
try {
IndexReader indexReader = mock(IndexReader.class);
when(indexReader.query(Matchers.isA(IndexQuery.ExactPredicate.class))).thenReturn(PrimitiveLongCollections.emptyIterator());
StorageStatement storageStatement = mock(StorageStatement.class);
when(storageStatement.getIndexReader(Matchers.any())).thenReturn(indexReader);
when(state.getStoreStatement()).thenReturn(storageStatement);
} catch (IndexNotFoundKernelException | IndexNotApplicableKernelException e) {
throw new Error(e);
}
when(state.txState()).thenReturn(txState);
when(state.hasTxStateWithChanges()).thenAnswer(invocation -> txState.hasChanges());
when(state.locks()).thenReturn(new SimpleStatementLocks(locks));
when(state.readOperations()).thenReturn(mock(ReadOperations.class));
return state;
}
use of org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException in project neo4j by neo4j.
the class ConstraintEnforcingEntityOperations method validateNoExistingNodeWithExactValues.
private void validateNoExistingNodeWithExactValues(KernelStatement state, UniquenessConstraintDescriptor constraint, ExactPredicate[] propertyValues, long modifiedNode) throws ConstraintValidationException {
try {
NewIndexDescriptor index = constraint.ownedIndexDescriptor();
assertIndexOnline(state, index);
int labelId = index.schema().getLabelId();
state.locks().optimistic().acquireExclusive(state.lockTracer(), INDEX_ENTRY, indexEntryResourceId(labelId, propertyValues));
long existing = entityReadOperations.nodeGetFromUniqueIndexSeek(state, index, propertyValues);
if (existing != NO_SUCH_NODE && existing != modifiedNode) {
throw new UniquePropertyValueValidationException(constraint, VALIDATION, new IndexEntryConflictException(existing, NO_SUCH_NODE, OrderedPropertyValues.of(propertyValues)));
}
} catch (IndexNotFoundKernelException | IndexBrokenKernelException | IndexNotApplicableKernelException e) {
throw new UnableToValidateConstraintException(constraint, e);
}
}
use of org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException in project neo4j by neo4j.
the class SimpleIndexReader method query.
@Override
public PrimitiveLongIterator query(IndexQuery... predicates) throws IndexNotApplicableKernelException {
IndexQuery predicate = predicates[0];
switch(predicate.type()) {
case exact:
Object[] values = new Object[predicates.length];
for (int i = 0; i < predicates.length; i++) {
assert predicates[i].type() == exact : "Exact followed by another query predicate type is not supported at this moment.";
values[i] = ((IndexQuery.ExactPredicate) predicates[i]).value();
}
return seek(values);
case exists:
for (IndexQuery p : predicates) {
if (p.type() != IndexQueryType.exists) {
throw new IndexNotApplicableKernelException("Exists followed by another query predicate type is not supported.");
}
}
return scan();
case rangeNumeric:
assertNotComposite(predicates);
IndexQuery.NumberRangePredicate np = (IndexQuery.NumberRangePredicate) predicate;
return rangeSeekByNumberInclusive(np.from(), np.to());
case rangeString:
assertNotComposite(predicates);
IndexQuery.StringRangePredicate sp = (IndexQuery.StringRangePredicate) predicate;
return rangeSeekByString(sp.from(), sp.fromInclusive(), sp.to(), sp.toInclusive());
case stringPrefix:
assertNotComposite(predicates);
IndexQuery.StringPrefixPredicate spp = (IndexQuery.StringPrefixPredicate) predicate;
return rangeSeekByPrefix(spp.prefix());
case stringContains:
assertNotComposite(predicates);
IndexQuery.StringContainsPredicate scp = (IndexQuery.StringContainsPredicate) predicate;
return containsString(scp.contains());
case stringSuffix:
assertNotComposite(predicates);
IndexQuery.StringSuffixPredicate ssp = (IndexQuery.StringSuffixPredicate) predicate;
return endsWith(ssp.suffix());
default:
// todo figure out a more specific exception
throw new RuntimeException("Index query not supported: " + Arrays.toString(predicates));
}
}
Aggregations