use of org.neo4j.kernel.api.schema_new.IndexQuery.ExactPredicate in project neo4j by neo4j.
the class IndexQueryTest method assertExactPredicate.
private void assertExactPredicate(Object value) {
ExactPredicate p = IndexQuery.exact(propId, value);
assertTrue(p.test(value));
assertFalseForOtherThings(p);
}
use of org.neo4j.kernel.api.schema_new.IndexQuery.ExactPredicate in project neo4j by neo4j.
the class IndexQueryTest method testExact_ComparingBigDoublesAndLongs.
@Test
public void testExact_ComparingBigDoublesAndLongs() {
ExactPredicate p = IndexQuery.exact(propId, 9007199254740993L);
Assert.assertFalse(p.test(9007199254740992D));
}
use of org.neo4j.kernel.api.schema_new.IndexQuery.ExactPredicate in project neo4j by neo4j.
the class ConstraintEnforcingEntityOperations method nodeAddLabel.
@Override
public boolean nodeAddLabel(KernelStatement state, long nodeId, int labelId) throws EntityNotFoundException, ConstraintValidationException {
try (Cursor<NodeItem> cursor = nodeCursorById(state, nodeId)) {
NodeItem node = cursor.get();
Iterator<ConstraintDescriptor> constraints = schemaReadOperations.constraintsGetForLabel(state, labelId);
while (constraints.hasNext()) {
ConstraintDescriptor constraint = constraints.next();
if (constraint.type() == UNIQUE) {
UniquenessConstraintDescriptor uniqueConstraint = (UniquenessConstraintDescriptor) constraint;
ExactPredicate[] propertyValues = getAllPropertyValues(state, uniqueConstraint.schema(), node);
if (propertyValues != null) {
validateNoExistingNodeWithExactValues(state, uniqueConstraint, propertyValues, node.id());
}
}
}
}
return entityWriteOperations.nodeAddLabel(state, nodeId, labelId);
}
use of org.neo4j.kernel.api.schema_new.IndexQuery.ExactPredicate in project neo4j by neo4j.
the class ConstraintEnforcingEntityOperations method getAllPropertyValues.
/**
* Fetch the property values for all properties in schema for a given node. Return these as an exact predicate
* array.
*
* The changedProperty is used to override the store/txState value of the property. This is used when we intend
* to change a property, and that to verify that the post-change values do not validate some constraint.
*/
private ExactPredicate[] getAllPropertyValues(KernelStatement state, SchemaDescriptor schema, NodeItem node, DefinedProperty changedProperty) {
int[] schemaPropertyIds = schema.getPropertyIds();
ExactPredicate[] values = new ExactPredicate[schemaPropertyIds.length];
int nMatched = 0;
Cursor<PropertyItem> nodePropertyCursor = nodeGetProperties(state, node);
int changedPropId = changedProperty.propertyKeyId();
while (nodePropertyCursor.next()) {
PropertyItem property = nodePropertyCursor.get();
int nodePropertyId = property.propertyKeyId();
int k = ArrayUtils.indexOf(schemaPropertyIds, nodePropertyId);
if (k >= 0) {
if (nodePropertyId != changedPropId) {
values[k] = IndexQuery.exact(nodePropertyId, property.value());
}
nMatched++;
}
}
if (changedPropId != NO_SUCH_PROPERTY_KEY) {
int k = ArrayUtils.indexOf(schemaPropertyIds, changedPropId);
if (k >= 0) {
values[k] = IndexQuery.exact(changedPropId, changedProperty.value());
nMatched++;
}
}
if (nMatched < values.length) {
return null;
}
return values;
}
Aggregations