use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.
the class GenericIndexKeyValidator method worstCaseLength.
private static int worstCaseLength(AnyValue value) {
if (value.isSequenceValue()) {
SequenceValue sequenceValue = (SequenceValue) value;
if (sequenceValue instanceof TextArray) {
TextArray textArray = (TextArray) sequenceValue;
int length = 0;
for (int i = 0; i < textArray.length(); i++) {
length += stringWorstCaseLength(textArray.stringValue(i).length());
}
return length;
}
return sequenceValue.length() * BIGGEST_STATIC_SIZE;
} else {
if (((Value) value).valueGroup().category() == ValueCategory.TEXT) {
// For text, which is very dynamic in its nature do a worst-case off of number of characters in it
return stringWorstCaseLength(((TextValue) value).length());
}
// For all else then use the biggest possible value for a non-dynamic, non-array value a state can occupy
return BIGGEST_STATIC_SIZE;
}
}
use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.
the class ShortStringPropertyEncodeTest method encode.
private void encode(String string) {
PropertyBlock block = new PropertyBlock();
TextValue expectedValue = Values.stringValue(string);
propertyStore.encodeValue(block, KEY_ID, expectedValue, CursorContext.NULL, INSTANCE);
assertEquals(0, block.getValueRecords().size());
Value readValue = block.getType().value(block, propertyStore, CursorContext.NULL);
assertEquals(expectedValue, readValue);
}
use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.
the class TransactionIT method shouldReadYourOwnWrites.
@Test
void shouldReadYourOwnWrites() throws Exception {
var latch = new BinaryLatch();
String bookmarkPrefix = null;
try (var machine = newStateMachineAfterAuth()) {
var recorder = new BoltResponseRecorder();
machine.process(run("CREATE (n:A {prop:'one'})"), nullResponseHandler());
machine.process(pullAll(), recorder);
var bookmark = ((TextValue) recorder.nextResponse().metadata("bookmark")).stringValue();
bookmarkPrefix = bookmark.split(":")[0];
}
var dbVersion = env.lastClosedTxId();
var thread = new Thread(() -> {
try (BoltStateMachine machine = newStateMachineAfterAuth()) {
latch.await();
var recorder = new BoltResponseRecorder();
machine.process(run("MATCH (n:A) SET n.prop = 'two'", EMPTY_MAP), nullResponseHandler());
machine.process(pullAll(), recorder);
} catch (Throwable connectionFatality) {
throw new RuntimeException(connectionFatality);
}
});
thread.start();
var dbVersionAfterWrite = dbVersion + 1;
try (var machine = newStateMachineAfterAuth()) {
var recorder = new BoltResponseRecorder();
latch.release();
var bookmark = bookmarkPrefix + ":" + dbVersionAfterWrite;
machine.process(begin(env.databaseIdRepository(), asMapValue(singletonMap("bookmarks", List.of(bookmark)))), recorder);
machine.process(run("MATCH (n:A) RETURN n.prop"), recorder);
machine.process(pullAll(), recorder);
machine.process(commit(), recorder);
assertThat(recorder.nextResponse()).satisfies(succeeded());
assertThat(recorder.nextResponse()).satisfies(succeeded());
assertThat(recorder.nextResponse()).satisfies(succeededWithRecord("two"));
assertThat(recorder.nextResponse()).satisfies(succeededWithMetadata("bookmark", BOOKMARK_PATTERN));
}
thread.join();
}
use of org.neo4j.values.storable.TextValue in project neo4j by neo4j.
the class IndexEntryTestUtil method generateStringValueResultingInIndexEntrySize.
public static <KEY extends NativeIndexKey<KEY>> TextValue generateStringValueResultingInIndexEntrySize(Layout<KEY, ?> layout, int size) {
TextValue value;
KEY key = layout.newKey();
key.initialize(0);
int stringLength = size;
do {
value = stringValue("A".repeat(stringLength--));
key.initFromValue(0, value, NativeIndexKey.Inclusion.NEUTRAL);
} while (layout.keySize(key) > size);
assertEquals(size, layout.keySize(key));
return value;
}
Aggregations