use of org.neo4j.kernel.api.schema_new.OrderedPropertyValues in project neo4j by neo4j.
the class TxState method getIndexUpdatesForRangeSeekByString.
private ReadableDiffSets<Long> getIndexUpdatesForRangeSeekByString(NewIndexDescriptor descriptor, String lower, boolean includeLower, String upper, boolean includeUpper) {
TreeMap<OrderedPropertyValues, DiffSets<Long>> sortedUpdates = getSortedIndexUpdates(descriptor.schema());
if (sortedUpdates == null) {
return null;
}
OrderedPropertyValues selectedLower;
boolean selectedIncludeLower;
OrderedPropertyValues selectedUpper;
boolean selectedIncludeUpper;
//TODO: Get working with composite indexes
if (lower == null) {
selectedLower = OrderedPropertyValues.ofUndefined(STRING.lowLimit.castValue(String.class));
selectedIncludeLower = STRING.lowLimit.isInclusive;
} else {
selectedLower = OrderedPropertyValues.ofUndefined(lower);
selectedIncludeLower = includeLower;
}
if (upper == null) {
selectedUpper = OrderedPropertyValues.ofUndefined(STRING.highLimit.castValue(Boolean.class).booleanValue());
selectedIncludeUpper = STRING.highLimit.isInclusive;
} else {
selectedUpper = OrderedPropertyValues.ofUndefined(upper);
selectedIncludeUpper = includeUpper;
}
DiffSets<Long> diffs = new DiffSets<>();
Collection<DiffSets<Long>> inRange = sortedUpdates.subMap(selectedLower, selectedIncludeLower, selectedUpper, selectedIncludeUpper).values();
for (DiffSets<Long> diffForSpecificValue : inRange) {
diffs.addAll(diffForSpecificValue.getAdded().iterator());
diffs.removeAll(diffForSpecificValue.getRemoved().iterator());
}
return diffs;
}
use of org.neo4j.kernel.api.schema_new.OrderedPropertyValues in project neo4j by neo4j.
the class TxState method getIndexUpdatesForRangeSeekByPrefix.
private ReadableDiffSets<Long> getIndexUpdatesForRangeSeekByPrefix(NewIndexDescriptor descriptor, String prefix) {
TreeMap<OrderedPropertyValues, DiffSets<Long>> sortedUpdates = getSortedIndexUpdates(descriptor.schema());
if (sortedUpdates == null) {
return null;
}
//TODO: get working with composite indexes
OrderedPropertyValues floor = OrderedPropertyValues.ofUndefined(prefix);
DiffSets<Long> diffs = new DiffSets<>();
for (Map.Entry<OrderedPropertyValues, DiffSets<Long>> entry : sortedUpdates.tailMap(floor).entrySet()) {
OrderedPropertyValues key = entry.getKey();
if (key.getSinglePropertyValue().toString().startsWith(prefix)) {
DiffSets<Long> diffSets = entry.getValue();
diffs.addAll(diffSets.getAdded().iterator());
diffs.removeAll(diffSets.getRemoved().iterator());
} else {
break;
}
}
return diffs;
}
use of org.neo4j.kernel.api.schema_new.OrderedPropertyValues in project neo4j by neo4j.
the class TxState method getIndexUpdatesForRangeSeekByNumber.
private ReadableDiffSets<Long> getIndexUpdatesForRangeSeekByNumber(NewIndexDescriptor descriptor, Number lower, boolean includeLower, Number upper, boolean includeUpper) {
TreeMap<OrderedPropertyValues, DiffSets<Long>> sortedUpdates = getSortedIndexUpdates(descriptor.schema());
if (sortedUpdates == null) {
return null;
}
OrderedPropertyValues selectedLower;
boolean selectedIncludeLower;
OrderedPropertyValues selectedUpper;
boolean selectedIncludeUpper;
//TODO: Get working with composite indexes
if (lower == null) {
selectedLower = OrderedPropertyValues.ofUndefined(NUMBER.lowLimit.castValue(Number.class));
selectedIncludeLower = NUMBER.lowLimit.isInclusive;
} else {
selectedLower = OrderedPropertyValues.ofUndefined(lower);
selectedIncludeLower = includeLower;
}
if (upper == null) {
selectedUpper = OrderedPropertyValues.ofUndefined(NUMBER.highLimit.castValue(Number.class));
selectedIncludeUpper = NUMBER.highLimit.isInclusive;
} else {
selectedUpper = OrderedPropertyValues.ofUndefined(upper);
selectedIncludeUpper = includeUpper;
}
DiffSets<Long> diffs = new DiffSets<>();
Collection<DiffSets<Long>> inRange = sortedUpdates.subMap(selectedLower, selectedIncludeLower, selectedUpper, selectedIncludeUpper).values();
for (DiffSets<Long> diffForSpecificValue : inRange) {
diffs.addAll(diffForSpecificValue.getAdded().iterator());
diffs.removeAll(diffForSpecificValue.getRemoved().iterator());
}
return diffs;
}
use of org.neo4j.kernel.api.schema_new.OrderedPropertyValues in project neo4j by neo4j.
the class TxStateCompositeIndexTest method modifyIndex.
private IndexUpdater modifyIndex(final NewIndexDescriptor descriptor) {
return new IndexUpdater() {
@Override
public void addDefaultStringEntries(long... nodeIds) {
addEntries(getDefaultStringEntries(nodeIds));
}
@Override
public void removeDefaultStringEntries(long... nodeIds) {
removeEntries(getDefaultStringEntries(nodeIds));
}
@Override
public void addDefaultStringProperties(long... nodeIds) {
Collection<Pair<Long, OrderedPropertyValues>> entries = new ArrayList<>(nodeIds.length);
for (long nodeId : nodeIds) {
int[] propertyIds = descriptor.schema().getPropertyIds();
Object[] values = new Object[propertyIds.length];
for (int i = 0; i < propertyIds.length; i++) {
values[i] = nodeId * 1000.0 + propertyIds[i];
}
entries.add(of(nodeId, OrderedPropertyValues.ofUndefined(values)));
}
addEntries(entries);
}
void addEntries(Collection<Pair<Long, OrderedPropertyValues>> nodesWithValues) {
for (Pair<Long, OrderedPropertyValues> entry : nodesWithValues) {
long nodeId = entry.first();
state.indexDoUpdateEntry(descriptor.schema(), nodeId, null, entry.other());
}
}
void removeEntries(Collection<Pair<Long, OrderedPropertyValues>> nodesWithValues) {
for (Pair<Long, OrderedPropertyValues> entry : nodesWithValues) {
long nodeId = entry.first();
state.indexDoUpdateEntry(descriptor.schema(), nodeId, entry.other(), null);
}
}
private Collection<Pair<Long, OrderedPropertyValues>> getDefaultStringEntries(long[] nodeIds) {
Collection<Pair<Long, OrderedPropertyValues>> entries = new ArrayList<>(nodeIds.length);
for (long nodeId : nodeIds) {
int[] propertyIds = descriptor.schema().getPropertyIds();
OrderedPropertyValues values = getDefaultStringPropertyValues(nodeId, propertyIds);
entries.add(of(nodeId, values));
}
return entries;
}
};
}
use of org.neo4j.kernel.api.schema_new.OrderedPropertyValues in project neo4j by neo4j.
the class IndexTxStateUpdater method onPropertyAdd.
// PROPERTY CHANGES
public void onPropertyAdd(KernelStatement state, NodeItem node, DefinedProperty after) throws EntityNotFoundException {
Iterator<NewIndexDescriptor> indexes = getIndexesInvolvingProperty(state, after.propertyKeyId());
nodeIndexMatcher.onMatchingSchema(state, indexes, node, after.propertyKeyId(), index -> {
Validators.INDEX_VALUE_VALIDATOR.validate(after.value());
OrderedPropertyValues values = getOrderedPropertyValues(state, node, after, index.schema().getPropertyIds());
state.txState().indexDoUpdateEntry(index.schema(), node.id(), null, values);
});
}
Aggregations