Search in sources :

Example 6 with TextArray

use of org.neo4j.values.storable.TextArray in project neo4j by neo4j.

the class NodeEntityWrappingNodeValue method labels.

public TextArray labels(NodeCursor nodeCursor) {
    TextArray l = labels;
    if (l == null) {
        try {
            synchronized (this) {
                l = labels;
                if (l == null) {
                    List<String> ls = new ArrayList<>();
                    // No DBHits for Virtual node hacks.
                    var nodeLabels = node instanceof NodeEntity ? ((NodeEntity) node).getLabels(nodeCursor) : node.getLabels();
                    for (Label label : nodeLabels) {
                        ls.add(label.name());
                    }
                    l = labels = Values.stringArray(ls.toArray(new String[0]));
                }
            }
        } catch (NotFoundException | IllegalStateException | StoreFailureException e) {
            throw new ReadAndDeleteTransactionConflictException(NodeEntity.isDeletedInCurrentTransaction(node), e);
        }
    }
    return l;
}
Also used : StoreFailureException(org.neo4j.exceptions.StoreFailureException) ArrayList(java.util.ArrayList) Label(org.neo4j.graphdb.Label) NotFoundException(org.neo4j.graphdb.NotFoundException) TextArray(org.neo4j.values.storable.TextArray) NodeEntity(org.neo4j.kernel.impl.core.NodeEntity)

Example 7 with TextArray

use of org.neo4j.values.storable.TextArray in project neo4j by neo4j.

the class NodeEntityWrappingNodeValue method writeTo.

@Override
public <E extends Exception> void writeTo(AnyValueWriter<E> writer) throws E {
    if (writer.entityMode() == REFERENCE) {
        writer.writeNodeReference(id());
    } else {
        TextArray l;
        MapValue p;
        try {
            l = labels();
            p = properties();
        } catch (ReadAndDeleteTransactionConflictException e) {
            if (!e.wasDeletedInThisTransaction()) {
                throw e;
            }
            // If it isn't a transient error then the node was deleted in the current transaction and we should write an 'empty' node.
            l = Values.stringArray();
            p = VirtualValues.EMPTY_MAP;
        }
        if (id() < 0) {
            writer.writeVirtualNodeHack(node);
        }
        writer.writeNode(node.getId(), l, p);
    }
}
Also used : MapValue(org.neo4j.values.virtual.MapValue) TextArray(org.neo4j.values.storable.TextArray)

Example 8 with TextArray

use of org.neo4j.values.storable.TextArray in project neo4j by neo4j.

the class TransportUnauthenticatedConnectionErrorIT method createHelloWithOversizeDeclaredList.

byte[] createHelloWithOversizeDeclaredList(Neo4jPack neo4jPack) throws IOException {
    PackedOutputArray output = new PackedOutputArray();
    Neo4jPack.Packer packer = neo4jPack.newPacker(output);
    packer.packStructHeader(2, HelloMessage.SIGNATURE);
    packer.packMapHeader(1);
    packer.pack("x");
    // list claims to be huge when it isn't
    packer.packListHeader(Integer.MAX_VALUE);
    TextArray labels = ALICE.labels();
    for (int i = 0; i < labels.length(); i++) {
        String labelName = labels.stringValue(i);
        packer.pack(labelName);
    }
    return output.bytes();
}
Also used : PackedOutputArray(org.neo4j.bolt.packstream.PackedOutputArray) Neo4jPack(org.neo4j.bolt.packstream.Neo4jPack) TextArray(org.neo4j.values.storable.TextArray)

Example 9 with TextArray

use of org.neo4j.values.storable.TextArray in project neo4j by neo4j.

the class LuceneIndexValueValidatorTest method tooLongArrayIsNotAllowed.

@Test
void tooLongArrayIsNotAllowed() {
    IllegalArgumentException iae = assertThrows(IllegalArgumentException.class, () -> {
        TextArray largeArray = Values.stringArray(randomAlphabetic(MAX_TERM_LENGTH), randomAlphabetic(MAX_TERM_LENGTH));
        VALIDATOR.validate(ENTITY_ID, largeArray);
    });
    assertThat(iae.getMessage()).contains("Property value is too large to index");
}
Also used : TextArray(org.neo4j.values.storable.TextArray) Test(org.junit.jupiter.api.Test)

Example 10 with TextArray

use of org.neo4j.values.storable.TextArray in project neo4j by neo4j.

the class Neo4jPackV1Test method shouldBeAbleToPackAndUnpackList.

@Test
void shouldBeAbleToPackAndUnpackList() throws IOException {
    // Given
    PackedOutputArray output = new PackedOutputArray();
    Neo4jPack.Packer packer = neo4jPack.newPacker(output);
    packer.packListHeader(ALICE.labels().length());
    List<String> expected = new ArrayList<>();
    TextArray labels = ALICE.labels();
    for (int i = 0; i < labels.length(); i++) {
        String labelName = labels.stringValue(i);
        packer.pack(labelName);
        expected.add(labelName);
    }
    AnyValue unpacked = unpacked(output.bytes());
    // Then
    assertThat(unpacked).isInstanceOf(ListValue.class);
    ListValue unpackedList = (ListValue) unpacked;
    assertThat(unpackedList).isEqualTo(ValueUtils.asListValue(expected));
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) ArrayList(java.util.ArrayList) AnyValue(org.neo4j.values.AnyValue) TextArray(org.neo4j.values.storable.TextArray) Test(org.junit.jupiter.api.Test)

Aggregations

TextArray (org.neo4j.values.storable.TextArray)11 Test (org.junit.jupiter.api.Test)5 ArrayList (java.util.ArrayList)3 AnyValue (org.neo4j.values.AnyValue)3 StoreFailureException (org.neo4j.exceptions.StoreFailureException)2 Label (org.neo4j.graphdb.Label)2 NotFoundException (org.neo4j.graphdb.NotFoundException)2 MapValue (org.neo4j.values.virtual.MapValue)2 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Collectors.joining (java.util.stream.Collectors.joining)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Matcher (org.hamcrest.Matcher)1 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)1 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)1 IsEqual.equalTo (org.hamcrest.core.IsEqual.equalTo)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1