Neo4j SDN 4 emulates a sequence object (not a UUID)

Is it possible in Neo4j or SDN4 to create / emulate something similar to a PostgreSQL sequence database object?

I need this streaming safe functionality to be able to ask her about the next, unique long value. I am going to use this value as a surrogate key for my entities.

UPDATED

I do not want to go with UUID, because I have to disclose these identifiers in my URL parameters of the web application, and in the case UUIDmy URLs look terrible. I want to go with equal values Longfor identifiers like StackOverflow, for example:

stackoverflow.com/questions/42228501/neo4j-sdn-4-emulate-sequence-objectnot-uuid
+4
source share
4 answers

The easiest way to use Neo4j is to disable reuse of identifiers and use node Graph ID, for example, a sequencer.

https://neo4j.com/docs/operations-manual/current/reference/configuration-settings/

Table A.83. dbms.ids.reuse.types.override

Description: Specified names of id types (comma separated) that should be reused. Currently only 'node' and 'relationship' types are supported.

Valid values: dbms.ids.reuse.types.override is a list separated by "," where items are one of NODE, RELATIONSHIP

Default value: [RELATIONSHIP, NODE]
0
source

This can be done using custom procedures and functions. As an example:

package sequence;

import org.neo4j.procedure.*;
import java.util.concurrent.atomic.AtomicInteger;

public class Next {
    private static AtomicInteger sequence = new AtomicInteger(0);

    @UserFunction
    public synchronized Number next() {
        return sequence.incrementAndGet();
    }
}

The problem with this example is that when the server restarts, the counter will be set to zero.

Thus, it is necessary to save the last value of the counter. This can be done using the following examples:

https://maxdemarzi.com/2015/03/25/triggers-in-neo4j/

https://github.com/neo4j-contrib/neo4j-apoc-procedures/blob/master/src/main/java/apoc/trigger/Trigger.java

+2
source

. , Neo4j . .

APOC . , .

+1

, , , APOC UUID.

APOC, UUID, apoc.create.uuid. APOC , CALL. , Foo node UUID:

CREATE (f:Foo {uuid: apoc.create.uuid()})
RETURN f;

APOC, apoc.create.uuids(count), UUID. , 5 Foo UUID:

CALL apoc.create.uuids(5) YIELD uuid
CREATE (f:Foo {uuid: uuid})
RETURN f;
+1

Source: https://habr.com/ru/post/1669706/


All Articles