Search in sources :

Example 1 with ExactPredicate

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);
}
Also used : ExactPredicate(org.neo4j.kernel.api.schema_new.IndexQuery.ExactPredicate)

Example 2 with ExactPredicate

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));
}
Also used : ExactPredicate(org.neo4j.kernel.api.schema_new.IndexQuery.ExactPredicate) Test(org.junit.Test)

Example 3 with ExactPredicate

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);
}
Also used : NodeItem(org.neo4j.storageengine.api.NodeItem) ConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) NodeExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.NodeExistenceConstraintDescriptor) RelExistenceConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.RelExistenceConstraintDescriptor) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) ExactPredicate(org.neo4j.kernel.api.schema_new.IndexQuery.ExactPredicate)

Example 4 with ExactPredicate

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;
}
Also used : PropertyItem(org.neo4j.storageengine.api.PropertyItem) ExactPredicate(org.neo4j.kernel.api.schema_new.IndexQuery.ExactPredicate)

Aggregations

ExactPredicate (org.neo4j.kernel.api.schema_new.IndexQuery.ExactPredicate)4 Test (org.junit.Test)1 ConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.ConstraintDescriptor)1 NodeExistenceConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.NodeExistenceConstraintDescriptor)1 RelExistenceConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.RelExistenceConstraintDescriptor)1 UniquenessConstraintDescriptor (org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor)1 NodeItem (org.neo4j.storageengine.api.NodeItem)1 PropertyItem (org.neo4j.storageengine.api.PropertyItem)1