use of org.neo4j.values.storable.Value in project neo4j by neo4j.
the class LuceneFulltextIndexTest method completeConfigurationMustInjectMissingConfigurations.
@Test
void completeConfigurationMustInjectMissingConfigurations() throws Exception {
int label;
int propertyKey;
try (Transaction tx = db.beginTx()) {
createNodeIndexableByPropertyValue(tx, LABEL, "bla");
tx.commit();
}
try (KernelTransactionImplementation tx = getKernelTransaction()) {
label = tx.tokenRead().nodeLabel(LABEL.name());
propertyKey = tx.tokenRead().propertyKey(PROP);
tx.success();
}
IndexConfig indexConfig = IndexConfig.with(EVENTUALLY_CONSISTENT, Values.booleanValue(true));
FulltextSchemaDescriptor schema = SchemaDescriptor.fulltext(NODE, new int[] { label }, new int[] { propertyKey });
IndexProviderDescriptor providerDescriptor = indexProvider.getProviderDescriptor();
IndexDescriptor descriptor = indexProvider.completeConfiguration(IndexPrototype.forSchema(schema, providerDescriptor).withName("index_1").withIndexConfig(indexConfig).materialise(1));
assertThat((Value) descriptor.getIndexConfig().get(ANALYZER)).isEqualTo(Values.stringValue("standard-no-stop-words"));
assertThat((Value) descriptor.getIndexConfig().get(EVENTUALLY_CONSISTENT)).isEqualTo(Values.booleanValue(true));
assertThat(asList(descriptor.getCapability().behaviours())).containsExactlyInAnyOrder(IndexBehaviour.EVENTUALLY_CONSISTENT, IndexBehaviour.SKIP_AND_LIMIT);
}
use of org.neo4j.values.storable.Value in project neo4j by neo4j.
the class EntityValueIndexCursorTestBase method assertFoundEntitiesAndValue.
private void assertFoundEntitiesAndValue(ENTITY_VALUE_INDEX_CURSOR cursor, int expectedCount, MutableLongSet uniqueIds, IndexValueCapability expectValue, boolean indexProvidesValues) {
uniqueIds.clear();
for (int i = 0; i < expectedCount; i++) {
assertTrue(cursor.next(), "at least " + expectedCount + " entities, was " + uniqueIds.size());
long reference = entityParams.entityReference(cursor);
assertTrue(uniqueIds.add(reference), "all entities are unique");
// Assert has value capability
if (IndexValueCapability.YES.equals(expectValue)) {
assertTrue(cursor.hasValue(), "Value capability said index would have value for " + expectValue + ", but didn't");
}
// Assert has correct value
if (indexProvidesValues) {
assertTrue(cursor.hasValue(), "Index did not provide values");
Value storedValue = entityParams.getPropertyValueFromStore(tx, cursors, reference);
assertThat(cursor.propertyValue(0)).as("has correct value").isEqualTo(storedValue);
}
}
assertFalse(cursor.next(), "no more than " + expectedCount + " entities");
}
use of org.neo4j.values.storable.Value in project neo4j by neo4j.
the class Operations method nodeSetProperty.
@Override
public Value nodeSetProperty(long node, int propertyKey, Value value) throws EntityNotFoundException, ConstraintValidationException {
assert value != NO_VALUE;
acquireExclusiveNodeLock(node);
ktx.assertOpen();
singleNode(node);
long[] labels = acquireSharedNodeLabelLocks();
Value existingValue = readNodeProperty(propertyKey);
int[] existingPropertyKeyIds = null;
boolean hasRelatedSchema = storageReader.hasRelatedSchema(labels, propertyKey, NODE);
if (hasRelatedSchema) {
existingPropertyKeyIds = loadSortedNodePropertyKeyList();
}
if (existingValue == NO_VALUE) {
ktx.securityAuthorizationHandler().assertAllowsSetProperty(ktx.securityContext(), this::resolvePropertyKey, Labels.from(labels), propertyKey);
checkUniquenessConstraints(node, propertyKey, value, labels, existingPropertyKeyIds);
// no existing value, we just add it
ktx.txState().nodeDoAddProperty(node, propertyKey, value);
if (hasRelatedSchema) {
updater.onPropertyAdd(nodeCursor, propertyCursor, labels, propertyKey, existingPropertyKeyIds, value);
}
} else if (propertyHasChanged(value, existingValue)) {
ktx.securityAuthorizationHandler().assertAllowsSetProperty(ktx.securityContext(), this::resolvePropertyKey, Labels.from(labels), propertyKey);
checkUniquenessConstraints(node, propertyKey, value, labels, existingPropertyKeyIds);
// the value has changed to a new value
ktx.txState().nodeDoChangeProperty(node, propertyKey, value);
if (hasRelatedSchema) {
updater.onPropertyChange(nodeCursor, propertyCursor, labels, propertyKey, existingPropertyKeyIds, existingValue, value);
}
}
return existingValue;
}
use of org.neo4j.values.storable.Value in project neo4j by neo4j.
the class Operations method readNodeProperty.
private Value readNodeProperty(int propertyKey) {
nodeCursor.properties(propertyCursor);
// Find out if the property had a value
Value existingValue = NO_VALUE;
while (propertyCursor.next()) {
if (propertyCursor.propertyKey() == propertyKey) {
existingValue = propertyCursor.propertyValue();
break;
}
}
return existingValue;
}
use of org.neo4j.values.storable.Value in project neo4j by neo4j.
the class TxStateIndexChanges method indexUpdatesWithValuesScanAndFilter.
private static AddedWithValuesAndRemoved indexUpdatesWithValuesScanAndFilter(ReadableTransactionState txState, IndexDescriptor descriptor, PropertyIndexQuery filter, IndexOrder indexOrder) {
Map<ValueTuple, ? extends LongDiffSets> updates = getUpdates(txState, descriptor, indexOrder);
if (updates == null) {
return EMPTY_ADDED_AND_REMOVED_WITH_VALUES;
}
MutableList<EntityWithPropertyValues> added = Lists.mutable.empty();
MutableLongSet removed = LongSets.mutable.empty();
for (Map.Entry<ValueTuple, ? extends LongDiffSets> entry : updates.entrySet()) {
ValueTuple key = entry.getKey();
if (filter == null || filter.acceptsValue(key.valueAt(0))) {
Value[] values = key.getValues();
LongDiffSets diffSet = entry.getValue();
diffSet.getAdded().each(nodeId -> added.add(new EntityWithPropertyValues(nodeId, values)));
removed.addAll(diffSet.getRemoved());
}
}
return new AddedWithValuesAndRemoved(indexOrder == IndexOrder.DESCENDING ? added.asReversed() : added, removed);
}
Aggregations