getValueRelationships();
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/NodeCollectionLoader.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections;
21 |
22 | import java.lang.reflect.Constructor;
23 |
24 | import org.neo4j.graphdb.Node;
25 |
26 | /**
27 | * Load a node collection from the graph database.
28 | */
29 | public class NodeCollectionLoader
30 | {
31 | /**
32 | * Load a node collection from the graph database given the base node of the collection.
33 | *
34 | * To load a collection from
35 | * the database the node must have a { @link NodeCollection#NODE_COLLECTION_CLASS } property with the full class
36 | * name of the { @link NodeCollection } class represented by the datastructure in the graph.
37 | *
38 | * The { @link NodeCollection } referenced by this node must have a constructor that takes the base node in order
39 | * to be loaded.
40 | *
41 | * @param baseNode the base node of the { @link NodeCollection }
42 | * @return the { @link NodeCollection }
43 | */
44 | @SuppressWarnings({"unchecked"})
45 | public static NodeCollection load( Node baseNode ) {
46 | String className = (String) baseNode.getProperty( NodeCollection.GRAPH_COLLECTION_CLASS, null );
47 | if ( className != null ) {
48 | try {
49 | Class extends NodeCollection> nodeCollectionClass =
50 | (Class extends NodeCollection>) Class.forName( className );
51 | Constructor extends NodeCollection> constructor = nodeCollectionClass.getConstructor( Node.class );
52 | return constructor.newInstance( baseNode );
53 | }
54 | catch ( Exception e )
55 | {
56 | throw new RuntimeException( "Unable to load node collection", e );
57 | }
58 | }
59 | return null;
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/BijectiveConnectionMode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | /**
23 | * Defines the {@link ConnectionMode} that is both a
24 | * {@link LeftRestrictedConnectionMode} and a
25 | * {@link RightRestrictedConnectionMode}.
26 | *
27 | * When a {@link Connnector} has a BijectiveConnectionMode, only one Vertex may
28 | * connect to that Connector, and that Vertex may only connect to one Connector
29 | * with the same {@link ConnectorType} on an {@link Edge} with a particular
30 | * {@link EdgeType}
31 | *
32 | */
33 | public interface BijectiveConnectionMode extends LeftRestrictedConnectionMode,
34 | RightRestrictedConnectionMode {
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/BinaryEdge.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | import org.neo4j.graphdb.Relationship;
23 |
24 | /**
25 | * A specialized version of an {@link Edge}, where the number of
26 | * {@link Connectors} is two, and where those Connectors have a
27 | * {@link SurjectiveConnectionMode}. BinaryEdges is a wrapper
28 | * {@link Relationship} in the standard Neo4j API.
29 | *
30 | */
31 | public interface BinaryEdge extends Edge {
32 |
33 | /**
34 | * @return the Vertex connected to the EndConnector.
35 | */
36 | public Vertex getEndVertex();
37 |
38 | /**
39 | * @param vertex
40 | * @return the StartVertex if the vertex argument is the EndVertex or the
41 | * EndVertex if the vertex argument is the StartVertex
42 | */
43 | public Vertex getOtherVertex(Vertex vertex);
44 |
45 | /**
46 | * @return the Vertex connected to the StartConnector.
47 | */
48 | public Vertex getStartVertex();
49 |
50 | /**
51 | * @return the Neo4j Relationship wrapped by this BinaryEdge
52 | */
53 | public org.neo4j.graphdb.Relationship getRelationship();
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/BinaryEdgeType.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | import org.neo4j.graphdb.Direction;
23 | import org.neo4j.graphdb.RelationshipType;
24 |
25 | /**
26 | * A wrapper around {@link RelationshipType} in the standard Neo4j API.
27 | *
28 | * BinaryEdgeType is a specialized version of a generalized {@link Edge}.
29 | */
30 | public interface BinaryEdgeType extends EdgeType {
31 |
32 | /**
33 | * @return the {@link RelationshipType} wrapped by this BinaryEdgeType
34 | */
35 | public RelationshipType getRelationshipType();
36 |
37 | /**
38 | * @param startVertex
39 | * @param endVertex
40 | * @return a {@link BinaryEdge} created from startVertex to EndVertex with
41 | * this BinaryEdgeType
42 | */
43 | public BinaryEdge createEdge(Vertex startVertex, Vertex endVertex);
44 |
45 | /**
46 | * @param vertex
47 | * @return the {@link BinaryEdge}s connected to vertex with this
48 | * BinaryEdgeType
49 | */
50 | public Iterable getEdges(Vertex vertex);
51 |
52 | /**
53 | * @param vertex
54 | * @param dir
55 | * @return the {@link BinaryEdge}s connected to vertex with this
56 | * BinaryEdgeType and the given {@link Direction}
57 | */
58 | public Iterable getEdges(Vertex vertex, Direction dir);
59 |
60 | /**
61 | * @param vertex
62 | * @return true if the vertex is connected to a {@link BinaryEdge} with this
63 | * BinaryEdgeType
64 | */
65 | public boolean hasEdge(Vertex vertex);
66 |
67 | /**
68 | * @param vertex
69 | * @param dir
70 | * @return true if the vertex is connected to a {@link BinaryEdge} with this
71 | * BinaryEdgeType and the given direction.
72 | */
73 | public boolean hasEdge(Vertex vertex, Direction dir);
74 |
75 | /**
76 | * @param vertex
77 | * @param dir
78 | * @return the single BinaryEdge connected to vertex with this
79 | * BinaryEdgeType and the given direction. Null is returned if no
80 | * BinaryEdge is connected. If more than one BinaryEdge is found, an
81 | * exception will be raised.
82 | */
83 | public BinaryEdge getSingleBinaryEdge(Vertex vertex, Direction dir);
84 |
85 | /**
86 | * @return the StartConnector associated with this BinaryEdge
87 | */
88 | public ConnectorType getStartConnectorType();
89 |
90 | /**
91 | * @return the EndConnector associated with this BinaryEdge
92 | */
93 | public ConnectorType getEndConnectorType();
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/Connection.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public class Connection {
23 |
24 | private final Connector connector;
25 | private final Vertex vertex;
26 |
27 | public Connection(Connector connector, Vertex vertex) {
28 | super();
29 | this.connector = connector;
30 | this.vertex = vertex;
31 | }
32 |
33 | public Connector getConnector() {
34 | return connector;
35 | }
36 |
37 | public Edge getEdge() {
38 | return connector.getEdge();
39 | }
40 |
41 | public Vertex getVertex() {
42 | return vertex;
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/ConnectionMode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | import org.neo4j.collections.graphdb.impl.ConnectionModeImpl.Bijective;
23 | import org.neo4j.collections.graphdb.impl.ConnectionModeImpl.Injective;
24 | import org.neo4j.collections.graphdb.impl.ConnectionModeImpl.Surjective;
25 | import org.neo4j.collections.graphdb.impl.ConnectionModeImpl.Unrestricted;
26 |
27 |
28 | /**
29 | * Defines the mode of a {@link Connection}.
30 | * A connection is defined as going from a {@link Vertex} to an {@link Edge}.
31 | * The left hand side (the Vertex side) can either be restricted,
32 | * ie. allowing only one Vertex to connect to an Edge with a {@link Connector}
33 | * having a {@link LeftRestrictedConnectionMode}, or it can be unrestricted,
34 | * ie. allowing an unlimited number of Vertices to connect to an Edge
35 | * with a Connector having a {@link LeftUnrestrictedConnectionMode}.
36 | * The right hand side (the Edge side) can also either be restricted,
37 | * ie. allowing a Vertex to only connect to one edge with a particular
38 | * {@EdgeType} on a Connector having a {@link RightRestrictedConnectionMode}.
39 | * The right hand side can be unrestricted too, ie. allowing a Vertex
40 | * to connect to any number of EdgeTypes on a Connectior having a
41 | * {@link RightRestrictedConnectionMode}.
42 | * The four restrictions lead to four basic ConnectionModes:
43 | *
44 | * - {@link UnrestrictedConnectionMode}: having both a RightUnrestrictedConnectionMode and a LeftUnrestrictedConnectionMode
45 | * - {@link InjectiveConnectionMode}: having a RightUnrestrictedConnectionMode and a LeftRestrictedConnectionMode
46 | * - {@link SurjectiveConnectionMode}: having a RightRestrictedConnectionMode and a LeftUnrestrictedConnectionMode
47 | * - {@link BijectiveConnectionMode}: having a RightRestrictedConnectionMode and a LeftRestrictedConnectionMode
48 | *
49 | * A {@link ConnectorType} can only be created with one of these four ConnectionModes.
50 | *
51 | */
52 | public interface ConnectionMode {
53 |
54 | /**
55 | * @return the name of the ConnectionMode
56 | */
57 | public String getName();
58 |
59 | /**
60 | * Access method for UnrestricedConnectionMode object
61 | */
62 | public static UnrestrictedConnectionMode UNRESTRICTED = new Unrestricted();
63 |
64 | /**
65 | * Access method for InjectiveConnectionMode object
66 | */
67 | public static InjectiveConnectionMode INJECTIVE = new Injective();
68 |
69 | /**
70 | * Access method for SurjectiveConnectionMode object
71 | */
72 | public static SurjectiveConnectionMode SURJECTIVE = new Surjective();
73 |
74 | /**
75 | * Access method for BijectiveConnectionMode object
76 | */
77 | public static BijectiveConnectionMode BIJECTIVE = new Bijective();
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/Connector.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | import java.util.Iterator;
23 |
24 | public class Connector {
25 |
26 | Connector outer = this;
27 |
28 | private final ConnectorType connectorType;
29 | private final Edge edge;
30 |
31 | @SuppressWarnings("unchecked")
32 | public static Connector> getInstance(ConnectorType> connectorType, Edge edge){
33 | if(connectorType.getConnectionMode().getName().equals(ConnectionMode.UNRESTRICTED.getName())){
34 | return new Connector((ConnectorType) connectorType, edge);
35 | }else if(connectorType.getConnectionMode().getName().equals(ConnectionMode.INJECTIVE.getName())){
36 | return new Connector((ConnectorType) connectorType, edge);
37 | }else if(connectorType.getConnectionMode().getName().equals(ConnectionMode.SURJECTIVE.getName())){
38 | return new Connector((ConnectorType) connectorType, edge);
39 | }else if(connectorType.getConnectionMode().getName().equals(ConnectionMode.BIJECTIVE.getName())){
40 | return new Connector((ConnectorType) connectorType, edge);
41 | }else{
42 | throw new RuntimeException("Unsupported ConnectionMode "+connectorType.getConnectionMode().getName()+"found");
43 | }
44 | }
45 |
46 | public Connector(ConnectorType connectorType, Edge edge) {
47 | this.connectorType = connectorType;
48 | this.edge = edge;
49 | }
50 |
51 | public Edge getEdge(){
52 | return edge;
53 | }
54 |
55 | public ConnectorType getConnectorType(){
56 | return connectorType;
57 | }
58 |
59 | public String getName(){
60 | return connectorType.getName();
61 | }
62 |
63 | public Iterable getVertices(){
64 | return edge.getVertices(connectorType);
65 | }
66 |
67 |
68 | public Iterable> getConnections(){
69 | return new Iterable>(){
70 |
71 | @Override
72 | public Iterator> iterator() {
73 | return new Iterator>(){
74 |
75 | Iterator vertices = getVertices().iterator();
76 |
77 | @Override
78 | public boolean hasNext() {
79 | return vertices.hasNext();
80 | }
81 |
82 | @Override
83 | public Connection next() {
84 | return new Connection(outer, vertices.next());
85 | }
86 |
87 | @Override
88 | public void remove() {
89 | }
90 |
91 | };
92 | }
93 |
94 | };
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/ConnectorDescription.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | import java.util.ArrayList;
23 |
24 | public class ConnectorDescription{
25 |
26 | private final ConnectorType> connectorType;
27 | private final Iterable vertices;
28 |
29 | public ConnectorDescription(ConnectorType> connectorType, Iterable elements) {
30 | this.connectorType = connectorType;
31 | this.vertices = elements;
32 | }
33 |
34 | public ConnectorDescription(ConnectorType> connector, Vertex... elements) {
35 | ArrayList vertices = new ArrayList();
36 | for(Vertex vertex: elements){
37 | vertices.add(vertex);
38 | }
39 | this.connectorType = connector;
40 | this.vertices = vertices;
41 | }
42 |
43 | public Iterable getVertices(){
44 | return vertices;
45 | }
46 |
47 | public ConnectorType> getConnectorType(){
48 | return connectorType;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/ConnectorType.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public interface ConnectorType extends Vertex{
23 | public String getName();
24 |
25 | public ConnectionMode getConnectionMode();
26 |
27 | public EdgeType getEdgeType();
28 |
29 | public VertexType getDomain();
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/ConnectorTypeDescription.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public class ConnectorTypeDescription {
23 |
24 | private final String name;
25 | private final ConnectionMode connectionMode;
26 | private final VertexType domain;
27 |
28 | public ConnectorTypeDescription(String name, ConnectionMode connectionMode, VertexType domain) {
29 | this.name = name;
30 | this.connectionMode = connectionMode;
31 | this.domain = domain;
32 | }
33 |
34 | public ConnectorTypeDescription(String name, ConnectionMode connectionMode) {
35 | this.name = name;
36 | this.connectionMode = connectionMode;
37 | this.domain = null;
38 | }
39 |
40 | public String getName() {
41 | return name;
42 | }
43 |
44 | public ConnectionMode getConnectionMode() {
45 | return connectionMode;
46 | }
47 |
48 | public VertexType getDomain() {
49 | return domain;
50 | }
51 |
52 |
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/DatabaseService.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | import org.neo4j.collections.graphdb.PropertyType.ComparablePropertyType;
23 | import org.neo4j.graphdb.GraphDatabaseService;
24 | import org.neo4j.graphdb.Node;
25 | import org.neo4j.graphdb.RelationshipType;
26 |
27 | public interface DatabaseService extends GraphDatabaseService{
28 |
29 | public Vertex createVertex();
30 |
31 | public Edge createEdge(EdgeType relType, ConnectorDescription... edgeElements);
32 |
33 | public Iterable getAllVertices();
34 |
35 | public Vertex getVertex(Node node);
36 |
37 | public VertexType getRootType();
38 |
39 | public BinaryEdge getBinaryEdgeById(long arg0);
40 |
41 | public BinaryEdgeType getBinaryEdgeType(RelationshipType relType);
42 |
43 | public BinaryEdgeType getBinaryEdgeType(RelationshipType relType, VertexType domain, VertexType range);
44 |
45 | public EdgeType createEdgeType(String name, ConnectorTypeDescription... connectorTypeDescriptions);
46 |
47 | public Iterable getEdgeTypes();
48 |
49 | public PropertyType getBooleanPropertyType(String name);
50 |
51 | public PropertyType getBooleanArrayPropertyType(String name);
52 |
53 | public PropertyType.ComparablePropertyType getBytePropertyType(String name);
54 |
55 | public PropertyType getByteArrayPropertyType(String name);
56 |
57 | public PropertyType.ComparablePropertyType getDoublePropertyType(String name);
58 |
59 | public PropertyType getDoubleArrayPropertyType(String name);
60 |
61 | public PropertyType.ComparablePropertyType getFloatPropertyType(String name);
62 |
63 | public PropertyType getFloatArrayPropertyType(String name);
64 |
65 | public PropertyType.ComparablePropertyType getLongPropertyType(String name);
66 |
67 | public PropertyType getLongArrayPropertyType(String name);
68 |
69 | public PropertyType.ComparablePropertyType getShortPropertyType(String name);
70 |
71 | public PropertyType getShortArrayPropertyType(String name);
72 |
73 | public PropertyType.ComparablePropertyType getStringPropertyType(String name);
74 |
75 | public PropertyType getStringArrayPropertyType(String name);
76 |
77 | public SortableBinaryEdgeType getSortableRelationshipType(String name, ComparablePropertyType propertyType);
78 |
79 | public org.neo4j.graphdb.GraphDatabaseService getGraphDatabaseService();
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/Edge.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 |
23 | public interface Edge extends Vertex{
24 |
25 | public void delete();
26 |
27 | public EdgeType getType();
28 |
29 | public boolean isType(EdgeType relType);
30 |
31 | public Iterable> getConnectors();
32 |
33 | public Iterable> getConnectors(ConnectorType>... connectorType);
34 |
35 | public Connector getConnector(ConnectorType connectorType);
36 |
37 | public Iterable getVertices(ConnectorType connectorType);
38 |
39 | public Iterable> getConnections(ConnectorType connectorType);
40 |
41 | public Vertex getVertex(ConnectorType connectorType);
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/EdgeType.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | import java.util.Set;
23 |
24 | public interface EdgeType extends VertexType{
25 |
26 | public Iterable getEdges(Vertex vertex, ConnectorType>... connectorTypes);
27 |
28 | public boolean hasEdge(Vertex vertex, ConnectorType>... connectorTypes);
29 |
30 | public ConnectorType> getConnectorType(String name);
31 |
32 | public Set> getConnectorTypes();
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/InjectiveConnectionMode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public interface InjectiveConnectionMode extends LeftUnrestrictedConnectionMode, RightRestrictedConnectionMode{
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/LeftRestricedEdgeElement.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | import java.util.ArrayList;
23 |
24 | public class LeftRestricedEdgeElement extends ConnectorDescription{
25 |
26 | private static Iterable toElements(Vertex vertex){
27 | ArrayList elements = new ArrayList();
28 | elements.add(vertex);
29 | return elements;
30 | }
31 |
32 | private final Vertex element;
33 |
34 | public LeftRestricedEdgeElement(ConnectorType connector,
35 | Vertex element) {
36 | super(connector, toElements(element));
37 | this.element = element;
38 | }
39 |
40 | public Vertex getElement(){
41 | return element;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/LeftRestrictedConnectionMode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public interface LeftRestrictedConnectionMode extends ConnectionMode {
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/LeftUnrestrictedConnectionMode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public interface LeftUnrestrictedConnectionMode extends ConnectionMode {
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/NullaryEdge.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public interface NullaryEdge extends Edge{
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/NullaryEdgeType.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public interface NullaryEdgeType extends EdgeType {
23 |
24 | public ConnectorType getConnectorType();
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/Property.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public interface Property extends UnaryEdge{
23 |
24 | public T getValue();
25 |
26 | public PropertyType getPropertyType();
27 |
28 | public Vertex getVertex();
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/PropertyComparator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | import org.neo4j.graphdb.Node;
23 |
24 | public interface PropertyComparator {
25 |
26 | public int compare(T value, Node node);
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/ReferenceNodes.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | /**
21 | ' * Copyright (c) 2002-2011 "Neo Technology,"
22 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
23 | *
24 | * This file is part of Neo4j.
25 | *
26 | * Neo4j is free software: you can redistribute it and/or modify
27 | * it under the terms of the GNU Affero General Public License as
28 | * published by the Free Software Foundation, either version 3 of the
29 | * License, or (at your option) any later version.
30 | *
31 | * This program is distributed in the hope that it will be useful,
32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 | * GNU Affero General Public License for more details.
35 | *
36 | * You should have received a copy of the GNU Affero General Public License
37 | * along with this program. If not, see .
38 | */
39 | package org.neo4j.collections.graphdb;
40 |
41 | import org.neo4j.cypher.javacompat.ExecutionEngine;
42 | import org.neo4j.cypher.javacompat.ExecutionResult;
43 | import org.neo4j.graphdb.GraphDatabaseService;
44 | import org.neo4j.graphdb.Node;
45 | import org.neo4j.helpers.collection.IteratorUtil;
46 |
47 | import static org.neo4j.helpers.collection.MapUtil.map;
48 |
49 | public class ReferenceNodes {
50 |
51 | private static ExecutionEngine engine;
52 | private static GraphDatabaseService dbRef;
53 |
54 | public static Node getReferenceNode(GraphDatabaseService db) {
55 | return getReferenceNode(db, "rtree");
56 | }
57 |
58 | public static Node getReferenceNode(GraphDatabaseService db, String name) {
59 | if (engine == null || db != dbRef) {
60 | engine = new ExecutionEngine(db);
61 | ReferenceNodes.dbRef = db;
62 | }
63 | ExecutionResult result = engine.execute("MERGE (ref:ReferenceNode {name:{name}}) RETURN ref", map("name", name));
64 | return IteratorUtil.single(result.columnAs("ref"));
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/RightRestrictedConnectionMode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public interface RightRestrictedConnectionMode extends ConnectionMode {
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/RightUnrestrictedConnectionMode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public interface RightUnrestrictedConnectionMode extends ConnectionMode {
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/SortableBinaryEdge.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public interface SortableBinaryEdge extends BinaryEdge{
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/SortableBinaryEdgeType.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public interface SortableBinaryEdgeType extends BinaryEdgeType{
23 |
24 | PropertyType.ComparablePropertyType getPropertyType();
25 |
26 | public SortableBinaryEdge createEdge(Vertex startVertex, Vertex endVertex);
27 | }
28 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/SurjectiveConnectionMode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public interface SurjectiveConnectionMode extends LeftRestrictedConnectionMode, RightUnrestrictedConnectionMode{
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/Traversal.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public interface Traversal extends Iterable{
23 |
24 | TraversalPath getPath();
25 |
26 | Iterable getContainedPaths();
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/TraversalDescription.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | import org.neo4j.collections.graphdb.traversal.BranchSelector;
23 | import org.neo4j.collections.graphdb.traversal.Evaluator;
24 | import org.neo4j.graphdb.Direction;
25 |
26 | public interface TraversalDescription extends Iterable{
27 |
28 | TraversalDescription set(Evaluator evaluator);
29 | TraversalDescription set(BranchSelector selector);
30 | TraversalDescription add(BinaryEdgeType edgeType);
31 | TraversalDescription add(BinaryEdgeType edgeType, Direction dir);
32 | TraversalDescription add(Connector> connector);
33 | TraversalDescription add(TraversalDescription description);
34 | TraversalDescription insert(TraversalDescription description, int position);
35 | Traversal traverse(Traversal traversal);
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/TraversalPath.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public interface TraversalPath extends Iterable>{
23 |
24 | Connection> getFirstElement();
25 | Connection> getLastElement();
26 |
27 | int length();
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/UnaryEdge.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public interface UnaryEdge extends Edge{
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/UnrestrictedConnectionMode.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public interface UnrestrictedConnectionMode extends LeftUnrestrictedConnectionMode, RightUnrestrictedConnectionMode{
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/VertexType.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb;
21 |
22 | public interface VertexType extends Vertex{
23 |
24 | public String getName();
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/impl/ConnectionModeImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.impl;
21 |
22 | import org.neo4j.collections.graphdb.BijectiveConnectionMode;
23 | import org.neo4j.collections.graphdb.ConnectionMode;
24 | import org.neo4j.collections.graphdb.InjectiveConnectionMode;
25 | import org.neo4j.collections.graphdb.SurjectiveConnectionMode;
26 | import org.neo4j.collections.graphdb.UnrestrictedConnectionMode;
27 |
28 | public abstract class ConnectionModeImpl implements ConnectionMode{
29 |
30 |
31 | private ConnectionModeImpl(){
32 | }
33 |
34 | public static class Unrestricted extends ConnectionModeImpl implements UnrestrictedConnectionMode{
35 | public Unrestricted(){
36 | super();
37 | }
38 | public String getName(){
39 | return "Unrestricted";
40 | }
41 |
42 | }
43 |
44 | public static class Injective extends ConnectionModeImpl implements InjectiveConnectionMode{
45 | public Injective(){
46 | super();
47 | }
48 |
49 | public String getName(){
50 | return "Injective";
51 | }
52 | }
53 |
54 | public static class Surjective extends ConnectionModeImpl implements SurjectiveConnectionMode{
55 | public Surjective(){
56 | super();
57 | }
58 |
59 | public String getName(){
60 | return "Surjective";
61 | }
62 |
63 | }
64 |
65 | public static class Bijective extends ConnectionModeImpl implements BijectiveConnectionMode{
66 | public Bijective(){
67 | super();
68 | }
69 |
70 | public String getName(){
71 | return "Bijective";
72 | }
73 |
74 | }
75 |
76 | }
77 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/impl/ConnectorTypeImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.impl;
21 |
22 | import org.neo4j.collections.graphdb.ConnectionMode;
23 | import org.neo4j.collections.graphdb.ConnectorType;
24 | import org.neo4j.collections.graphdb.DatabaseService;
25 | import org.neo4j.collections.graphdb.EdgeType;
26 | import org.neo4j.collections.graphdb.VertexType;
27 | import org.neo4j.graphdb.Direction;
28 | import org.neo4j.graphdb.DynamicRelationshipType;
29 | import org.neo4j.graphdb.Node;
30 | import org.neo4j.graphdb.Relationship;
31 | import org.neo4j.graphdb.RelationshipType;
32 |
33 | public class ConnectorTypeImpl extends VertexImpl implements ConnectorType{
34 |
35 | public final static String CONNECTOR_TYPE_NAME = "org.neo4j.collections.graphdb.connector_type_name";
36 | public final static String CONNECTOR_MODE = "org.neo4j.collections.graphdb.connector_mode";
37 |
38 | public enum RelTypes implements RelationshipType{
39 | ORG_NEO4J_COLLECTIONS_GRAPHDB_CONNECTOR_TYPE, ORG_NEO4J_COLLECTIONS_GRAPHDB_CONNECTOR_DOMAIN
40 | }
41 |
42 | public ConnectorTypeImpl(DatabaseService db, Long id) {
43 | super(db, id);
44 | }
45 |
46 | private static ConnectorType create(DatabaseService db, String name, Node edgeTypeNode, U connectionMode, VertexType domain){
47 | Node n = db.createNode();
48 | edgeTypeNode.createRelationshipTo(n, RelTypes.ORG_NEO4J_COLLECTIONS_GRAPHDB_CONNECTOR_TYPE);
49 | n.setProperty(CONNECTOR_TYPE_NAME, name);
50 | n.setProperty(CONNECTOR_MODE, connectionMode.getName());
51 | if(domain == null){
52 | n.createRelationshipTo(db.getRootType().getNode(), RelTypes.ORG_NEO4J_COLLECTIONS_GRAPHDB_CONNECTOR_DOMAIN);
53 | }else{
54 | n.createRelationshipTo(domain.getNode(), RelTypes.ORG_NEO4J_COLLECTIONS_GRAPHDB_CONNECTOR_DOMAIN);
55 | }
56 | return new ConnectorTypeImpl(db, n.getId());
57 | }
58 |
59 | public static ConnectorType getOrCreateInstance(DatabaseService db, String name, Node edgeTypeNode, U connectionMode) {
60 | return getOrCreateInstance(db, name, edgeTypeNode, connectionMode, db.getRootType());
61 | }
62 |
63 | public static ConnectorType getOrCreateInstance(DatabaseService db, String name, Node edgeTypeNode, U connectionMode, VertexType domain) {
64 | if(edgeTypeNode.hasRelationship(RelTypes.ORG_NEO4J_COLLECTIONS_GRAPHDB_CONNECTOR_TYPE, Direction.OUTGOING)){
65 | for(Relationship rel: edgeTypeNode.getRelationships(RelTypes.ORG_NEO4J_COLLECTIONS_GRAPHDB_CONNECTOR_TYPE, Direction.OUTGOING)){
66 | if(rel.getEndNode().getProperty(CONNECTOR_TYPE_NAME).equals(name))
67 | return new ConnectorTypeImpl(db, rel.getEndNode().getId());
68 | }
69 | return create(db, name, edgeTypeNode, connectionMode, domain);
70 | }else{
71 | return create(db, name, edgeTypeNode, connectionMode, domain);
72 | }
73 | }
74 |
75 | @Override
76 | public String getName() {
77 | return (String)getNode().getProperty(CONNECTOR_TYPE_NAME);
78 | }
79 |
80 | public static ConnectionMode getConnectionMode(String name){
81 | if(name.equals(ConnectionMode.UNRESTRICTED.getName())){
82 | return ConnectionMode.UNRESTRICTED;
83 | }
84 | if(name.equals(ConnectionMode.INJECTIVE.getName())){
85 | return ConnectionMode.INJECTIVE;
86 | }
87 | if(name.equals(ConnectionMode.SURJECTIVE.getName())){
88 | return ConnectionMode.SURJECTIVE;
89 | }
90 | if(name.equals(ConnectionMode.BIJECTIVE.getName())){
91 | return ConnectionMode.BIJECTIVE;
92 | }else{
93 | throw new RuntimeException("Unknown connection mode "+name);
94 | }
95 | }
96 |
97 | @Override
98 | public ConnectionMode getConnectionMode() {
99 | String connectionModeName = (String)getNode().getProperty(CONNECTOR_MODE);
100 | return getConnectionMode(connectionModeName);
101 | }
102 |
103 | @Override
104 | public EdgeType getEdgeType() {
105 | return (EdgeType)db.getVertex(getNode().getSingleRelationship(DynamicRelationshipType.withName(getName()), Direction.INCOMING).getStartNode());
106 | }
107 |
108 | @Override
109 | public VertexType getDomain() {
110 | return (VertexType)db.getVertex(getNode().getSingleRelationship(RelTypes.ORG_NEO4J_COLLECTIONS_GRAPHDB_CONNECTOR_DOMAIN, Direction.OUTGOING).getEndNode());
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/impl/EdgeTypeImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.impl;
21 |
22 | import java.util.HashSet;
23 | import java.util.Set;
24 |
25 | import org.neo4j.collections.graphdb.ConnectionMode;
26 | import org.neo4j.collections.graphdb.ConnectorType;
27 | import org.neo4j.collections.graphdb.ConnectorTypeDescription;
28 | import org.neo4j.collections.graphdb.DatabaseService;
29 | import org.neo4j.collections.graphdb.Edge;
30 | import org.neo4j.collections.graphdb.EdgeType;
31 | import org.neo4j.collections.graphdb.Vertex;
32 | import org.neo4j.graphdb.Direction;
33 | import org.neo4j.graphdb.Node;
34 | import org.neo4j.graphdb.Relationship;
35 |
36 | public class EdgeTypeImpl extends VertexTypeImpl implements EdgeType {
37 |
38 | public EdgeTypeImpl(DatabaseService db, Long id){
39 | super(db, id);
40 | }
41 |
42 | private static Class> getImplementationClass(){
43 | try{
44 | return Class.forName("org.neo4j.collections.graphdb.impl.EdgeTypeImpl");
45 | }catch(ClassNotFoundException cce){
46 | throw new RuntimeException(cce);
47 | }
48 | }
49 |
50 | public static class EdgeTypeNodeDescriptor extends TypeNodeDescriptor{
51 |
52 | private final ConnectorTypeDescription[] connectorTypeDescriptions;
53 |
54 | public EdgeTypeNodeDescriptor(DatabaseService db, String name,
55 | Class> claz, ConnectorTypeDescription... connectorTypeDescriptions) {
56 | super(db, name, claz);
57 | this.connectorTypeDescriptions = connectorTypeDescriptions;
58 | }
59 |
60 | @Override
61 | public void initialize(Node n){
62 | super.initialize(n);
63 | for(ConnectorTypeDescription connectorTypeDescription: connectorTypeDescriptions){
64 | ConnectorTypeImpl.getOrCreateInstance(db, connectorTypeDescription.getName(), n, connectorTypeDescription.getConnectionMode(), connectorTypeDescription.getDomain());
65 | }
66 | }
67 | }
68 |
69 | public static EdgeTypeImpl getOrCreateInstance(DatabaseService db, String name, ConnectorTypeDescription... connectorTypeDescriptions){
70 | VertexTypeImpl vertexType = new VertexTypeImpl(db, getOrCreateByDescriptor(new EdgeTypeNodeDescriptor(db, name, getImplementationClass(), connectorTypeDescriptions)).getId());
71 | return new EdgeTypeImpl(db, vertexType.getNode().getId());
72 | }
73 |
74 | @Override
75 | public ConnectorType> getConnectorType(String name) {
76 | for(Relationship rel: getNode().getRelationships(ConnectorTypeImpl.RelTypes.ORG_NEO4J_COLLECTIONS_GRAPHDB_CONNECTOR_TYPE, Direction.OUTGOING)){
77 | if(rel.getEndNode().hasProperty(ConnectorTypeImpl.CONNECTOR_TYPE_NAME)){
78 | if(rel.getEndNode().getProperty(ConnectorTypeImpl.CONNECTOR_TYPE_NAME).equals(name)){
79 | String connectionModeName = (String)rel.getEndNode().getProperty(ConnectorTypeImpl.CONNECTOR_MODE);
80 | return ConnectorTypeImpl.getOrCreateInstance(getDb(), name, this.getNode(), ConnectorTypeImpl.getConnectionMode(connectionModeName));
81 | }
82 | }
83 | }
84 | return null;
85 | }
86 |
87 | public Iterable getEdges(Vertex vertex, ConnectorType>... connectorTypes) {
88 | Set> connectorTypes1 = new HashSet>();
89 | Set> connectorTypes2 = getConnectorTypes();
90 | for (ConnectorType> connectorType : connectorTypes) {
91 | for (ConnectorType> connectorType2 : connectorTypes2) {
92 | if (connectorType.getName().equals(connectorType2.getName())) {
93 | connectorTypes1.add(connectorType2);
94 | }
95 | }
96 | }
97 | return new ConnectorTypeIterable(this, connectorTypes1, vertex);
98 | }
99 |
100 | @Override
101 | public Set> getConnectorTypes() {
102 | Set> connectorTypes = new HashSet>();
103 | for(Relationship rel: getNode().getRelationships(ConnectorTypeImpl.RelTypes.ORG_NEO4J_COLLECTIONS_GRAPHDB_CONNECTOR_TYPE, Direction.OUTGOING)){
104 | String connectorName = (String)rel.getEndNode().getProperty(ConnectorTypeImpl.CONNECTOR_TYPE_NAME);
105 | ConnectionMode connectionMode = ConnectorTypeImpl.getConnectionMode((String) rel.getEndNode().getProperty(ConnectorTypeImpl.CONNECTOR_MODE));
106 | connectorTypes.add(ConnectorTypeImpl.getOrCreateInstance(getDb(), connectorName, this.getNode(), connectionMode));
107 | }
108 | return connectorTypes;
109 | }
110 |
111 | public boolean hasEdge(Vertex vertex, ConnectorType>... connectorTypes){
112 | return getEdges(vertex, connectorTypes).iterator().hasNext();
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/impl/EmbeddedGraphDatabase.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.impl;
21 |
22 | import org.neo4j.graphdb.factory.GraphDatabaseBuilder;
23 | import org.neo4j.graphdb.factory.GraphDatabaseFactory;
24 |
25 | import java.util.Map;
26 |
27 | public class EmbeddedGraphDatabase extends GraphDatabaseImpl{
28 |
29 | public EmbeddedGraphDatabase(String storeDir){
30 | super(new GraphDatabaseFactory().newEmbeddedDatabase(storeDir));
31 | }
32 |
33 | public EmbeddedGraphDatabase(String storeDir, Map params){
34 | super(new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir).setConfig(params).newGraphDatabase());
35 | }
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/impl/NodeIterable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.impl;
21 |
22 | import java.util.Iterator;
23 |
24 | import org.neo4j.collections.graphdb.Vertex;
25 | import org.neo4j.graphdb.Node;
26 |
27 | class NodeIterable implements Iterable{
28 |
29 | private Iterable nodes;
30 |
31 | NodeIterable(Iterable nodes){
32 | this.nodes = nodes;
33 | }
34 |
35 | @Override
36 | public Iterator iterator() {
37 | return new NodeIterator(nodes.iterator());
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/impl/NodeIterator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.impl;
21 |
22 | import java.util.Iterator;
23 |
24 | import org.neo4j.collections.graphdb.Vertex;
25 | import org.neo4j.graphdb.Node;
26 |
27 | class NodeIterator implements Iterator{
28 |
29 | private final Iterator nodes;
30 |
31 | NodeIterator(Iterator nodes){
32 | this.nodes = nodes;
33 | }
34 |
35 | @Override
36 | public boolean hasNext() {
37 | return nodes.hasNext();
38 | }
39 |
40 | @Override
41 | public Vertex next() {
42 | Node node = nodes.next();
43 | return new VertexImpl(new GraphDatabaseImpl(node.getGraphDatabase()), node.getId());
44 | }
45 |
46 | @Override
47 | public void remove() {
48 | nodes.remove();
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/impl/NullaryEdgeImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.impl;
21 |
22 | import java.util.ArrayList;
23 |
24 | import org.neo4j.collections.graphdb.Connection;
25 | import org.neo4j.collections.graphdb.ConnectionMode;
26 | import org.neo4j.collections.graphdb.Connector;
27 | import org.neo4j.collections.graphdb.ConnectorType;
28 | import org.neo4j.collections.graphdb.DatabaseService;
29 | import org.neo4j.collections.graphdb.EdgeType;
30 | import org.neo4j.collections.graphdb.LeftRestrictedConnectionMode;
31 | import org.neo4j.collections.graphdb.NullaryEdge;
32 | import org.neo4j.collections.graphdb.Vertex;
33 |
34 | public class NullaryEdgeImpl extends VertexImpl implements NullaryEdge{
35 |
36 |
37 | public NullaryEdgeImpl(DatabaseService db, Long id) {
38 | super(db, id);
39 | }
40 |
41 | @Override
42 | public void delete() {
43 | getNode().delete();
44 | }
45 |
46 | @Override
47 | public EdgeType getType() {
48 | return NullaryEdgeTypeImpl.getOrCreateInstance(getDb());
49 | }
50 |
51 | @Override
52 | public boolean isType(EdgeType relType) {
53 | return relType.getName().equals(getType().getName());
54 | }
55 |
56 | @Override
57 | public Iterable> getConnectors() {
58 | ArrayList> connectors = new ArrayList>();
59 | connectors.add(Connector.getInstance(ConnectorTypeImpl.getOrCreateInstance(db, NullaryEdgeTypeImpl.NULLARYCONNECTORNAME, getType().getNode(), ConnectionMode.BIJECTIVE), this));
60 | return connectors;
61 | }
62 |
63 | @Override
64 | public Iterable> getConnectors(
65 | ConnectorType>... connectorTypes) {
66 | ArrayList> connectors = new ArrayList>();
67 | for(ConnectorType> connectorType: connectorTypes){
68 | if(connectorType.getName().equals(NullaryEdgeTypeImpl.NULLARYCONNECTORNAME)){
69 | connectors.add(Connector.getInstance(ConnectorTypeImpl.getOrCreateInstance(db, NullaryEdgeTypeImpl.NULLARYCONNECTORNAME, getType().getNode(), ConnectionMode.BIJECTIVE), this));
70 | }
71 | }
72 | return connectors;
73 | }
74 |
75 | @Override
76 | public Iterable getVertices(
77 | ConnectorType connectorType) {
78 | // TODO Auto-generated method stub
79 | return null;
80 | }
81 |
82 | @Override
83 | public Vertex getVertex(
84 | ConnectorType connectorType) {
85 | // TODO Auto-generated method stub
86 | return null;
87 | }
88 |
89 | @Override
90 | public Connector getConnector(
91 | ConnectorType connectorType) {
92 | // TODO Auto-generated method stub
93 | return null;
94 | }
95 |
96 | @Override
97 | public Iterable> getConnections(
98 | ConnectorType connectorType) {
99 | // TODO Auto-generated method stub
100 | return null;
101 | }
102 |
103 | }
104 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/impl/NullaryEdgeTypeImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.impl;
21 |
22 | import java.util.HashSet;
23 | import java.util.Set;
24 |
25 | import org.neo4j.collections.graphdb.BijectiveConnectionMode;
26 | import org.neo4j.collections.graphdb.ConnectionMode;
27 | import org.neo4j.collections.graphdb.ConnectorType;
28 | import org.neo4j.collections.graphdb.DatabaseService;
29 | import org.neo4j.collections.graphdb.NullaryEdgeType;
30 |
31 | public class NullaryEdgeTypeImpl extends EdgeTypeImpl implements NullaryEdgeType{
32 |
33 | public final static String NULLARYCONNECTORNAME = "NullaryConnector";
34 |
35 | public NullaryEdgeTypeImpl(DatabaseService db, Long id) {
36 | super(db, id);
37 | }
38 |
39 | protected static Class> getImplementationClass(){
40 | try{
41 | return Class.forName("org.neo4j.collections.graphdb.impl.NullaryEdgeTypeImpl");
42 | }catch(ClassNotFoundException cce){
43 | throw new RuntimeException(cce);
44 | }
45 | }
46 |
47 | public static NullaryEdgeTypeImpl getOrCreateInstance(DatabaseService db){
48 | VertexTypeImpl vertexType = new VertexTypeImpl(db, getOrCreateByDescriptor(new TypeNodeDescriptor(db, "NullaryEdgeType", getImplementationClass())).getId());
49 | return new NullaryEdgeTypeImpl(db, vertexType.getNode().getId());
50 | }
51 |
52 | @Override
53 | public Set> getConnectorTypes() {
54 | Set> connectorTypes = new HashSet>();
55 | connectorTypes.add(getConnectorType());
56 | return connectorTypes;
57 | }
58 |
59 | @Override
60 | public ConnectorType getConnectorType() {
61 | return ConnectorTypeImpl.getOrCreateInstance(getDb(), NULLARYCONNECTORNAME, getNode(), ConnectionMode.BIJECTIVE);
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/impl/PropertyImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.impl;
21 |
22 | import java.util.ArrayList;
23 |
24 | import org.neo4j.collections.graphdb.BinaryEdge;
25 | import org.neo4j.collections.graphdb.ConnectionMode;
26 | import org.neo4j.collections.graphdb.Connector;
27 | import org.neo4j.collections.graphdb.ConnectorType;
28 | import org.neo4j.collections.graphdb.DatabaseService;
29 | import org.neo4j.collections.graphdb.EdgeType;
30 | import org.neo4j.collections.graphdb.LeftRestrictedConnectionMode;
31 | import org.neo4j.collections.graphdb.Property;
32 | import org.neo4j.collections.graphdb.PropertyType;
33 | import org.neo4j.collections.graphdb.Vertex;
34 | import org.neo4j.collections.graphdb.VertexType;
35 | import org.neo4j.graphdb.Node;
36 |
37 | public class PropertyImpl extends EdgeImpl implements Property{
38 |
39 | public final static String PROPERTYCONTAINER_ID = "org.neo4j.collections.graphdb.propertycontainer_id";
40 | public final static String PROPERTYCONTAINER_TYPE = "org.neo4j.collections.graphdb.propertycontainer_type";
41 | public final static String PROPERTY_NAME = "org.neo4j.collections.graphdb.property_name";
42 |
43 | public enum PropertyContainerType{
44 | NODE, RELATIONSHIP
45 | }
46 |
47 | private final Vertex vertex;
48 | private final PropertyType propertyType;
49 | private Node node;
50 |
51 | public PropertyImpl(DatabaseService db, Vertex vertex, PropertyType propertyType){
52 | super(db, 0l);
53 | this.vertex = vertex;
54 | this.propertyType = propertyType;
55 | }
56 |
57 | public long getId(){
58 | return getNode().getId();
59 | }
60 |
61 | @Override
62 | public T getValue() {
63 | return vertex.getPropertyValue(propertyType);
64 | }
65 |
66 | @Override
67 | public PropertyType getPropertyType() {
68 | return propertyType;
69 | }
70 |
71 | @Override
72 | public org.neo4j.graphdb.PropertyContainer getPropertyContainer() {
73 | return getNode();
74 | }
75 |
76 | @Override
77 | public Iterable> getPropertyTypes() {
78 | return null;
79 | }
80 |
81 | @Override
82 | public Node getNode() {
83 | if(node != null){
84 | return node;
85 | }else{
86 | if(vertex.getPropertyContainer().hasProperty(propertyType.getName()+".node_id")){
87 | return getDb().getGraphDatabaseService().getNodeById((Long)vertex.getPropertyContainer().getProperty(propertyType.getName()+".node_id"));
88 | }else{
89 | Node n = db.createNode();
90 | n.setProperty(PROPERTYCONTAINER_ID, vertex.getNode().getId());
91 | n.setProperty(PROPERTY_NAME, propertyType.getName());
92 | if(vertex instanceof BinaryEdge){
93 | n.setProperty(PROPERTYCONTAINER_TYPE, PropertyContainerType.RELATIONSHIP.name());
94 | }else{
95 | n.setProperty(PROPERTYCONTAINER_TYPE, PropertyContainerType.NODE.name());
96 | }
97 | vertex.getPropertyContainer().setProperty(propertyType.getName()+".node_id", n.getId());
98 | return n;
99 | }
100 | }
101 | }
102 |
103 | @Override
104 | public Vertex getVertex() {
105 | return new VertexImpl(db, getNode().getId());
106 | }
107 |
108 | @Override
109 | public void delete() {
110 | node.removeProperty(getType().getName());
111 | }
112 |
113 | @Override
114 | protected VertexType getSpecialVertexType(){
115 | return getType();
116 | }
117 |
118 | @Override
119 | public PropertyType getType() {
120 | return this.propertyType;
121 | }
122 |
123 | @Override
124 | public boolean isType(EdgeType relType) {
125 | return this.propertyType.getNode().getId() == relType.getNode().getId();
126 | }
127 |
128 | @Override
129 | public Iterable> getConnectors() {
130 | ArrayList> connectors = new ArrayList>();
131 | connectors.add(Connector.getInstance(getType().getPropertyConnectorType(), this));
132 | return connectors;
133 | }
134 |
135 | @Override
136 | public Vertex getVertex(ConnectorType connectorType) {
137 | if(connectorType.getName().equals(PropertyType.PROPERTYCONNECTORNAME)){
138 | return getVertex();
139 | }else{
140 | return null;
141 | }
142 | }
143 |
144 | @Override
145 | public Iterable> getConnectors(ConnectorType>... connectorTypes) {
146 | ArrayList> connectors = new ArrayList>();
147 | for(ConnectorType> connectorType: connectorTypes){
148 | if(connectorType.getName().equals(PropertyType.PROPERTYCONNECTORNAME)){
149 | connectors.add(Connector.getInstance(ConnectorTypeImpl.getOrCreateInstance(db, NullaryEdgeTypeImpl.NULLARYCONNECTORNAME, getType().getNode(), ConnectionMode.BIJECTIVE), this));
150 | }
151 | }
152 | return connectors;
153 | }
154 |
155 | @Override
156 | public Iterable getVertices(ConnectorType connectorType) {
157 | ArrayList vertices = new ArrayList();
158 | vertices.add(getVertex());
159 | return vertices;
160 | }
161 |
162 |
163 | }
164 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/impl/RelationshipIterable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.impl;
21 |
22 | import java.util.Iterator;
23 |
24 | import org.neo4j.collections.graphdb.BinaryEdge;
25 | import org.neo4j.graphdb.Relationship;
26 |
27 | class RelationshipIterable implements Iterable{
28 |
29 | private Iterable rels;
30 |
31 | RelationshipIterable(Iterable rels){
32 | this.rels = rels;
33 | }
34 |
35 | @Override
36 | public Iterator iterator() {
37 | return new RelationshipIterator(rels.iterator());
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/impl/RelationshipIterator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.impl;
21 |
22 | import java.util.Iterator;
23 |
24 | import org.neo4j.collections.graphdb.BinaryEdge;
25 | import org.neo4j.graphdb.Relationship;
26 |
27 | class RelationshipIterator implements Iterator{
28 |
29 | private final Iterator rels;
30 |
31 | RelationshipIterator(Iterator rels){
32 | this.rels = rels;
33 | }
34 |
35 | @Override
36 | public boolean hasNext() {
37 | return rels.hasNext();
38 | }
39 |
40 | @Override
41 | public BinaryEdge next() {
42 | Relationship rel = rels.next();
43 | return new BinaryEdgeImpl(new GraphDatabaseImpl(rel.getGraphDatabase()),rel.getId());
44 | }
45 |
46 | @Override
47 | public void remove() {
48 | rels.remove();
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/impl/RelationshipTypeIterable.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.impl;
21 |
22 | import java.util.Iterator;
23 |
24 | import org.neo4j.collections.graphdb.DatabaseService;
25 | import org.neo4j.collections.graphdb.EdgeType;
26 |
27 | class RelationshipTypeIterable implements Iterable{
28 |
29 | private Iterable rels;
30 | private final DatabaseService graphDb;
31 |
32 | RelationshipTypeIterable(Iterable rels, DatabaseService graphDb){
33 | this.rels = rels;
34 | this.graphDb = graphDb;
35 | }
36 |
37 | @Override
38 | public Iterator iterator() {
39 | return new RelationshipTypeIterator(rels.iterator(), graphDb);
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/impl/RelationshipTypeIterator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.impl;
21 |
22 | import java.util.Iterator;
23 |
24 | import org.neo4j.collections.graphdb.DatabaseService;
25 | import org.neo4j.collections.graphdb.EdgeType;
26 |
27 | class RelationshipTypeIterator implements Iterator{
28 |
29 | private final Iterator relTypes;
30 | private final DatabaseService graphDb;
31 |
32 | RelationshipTypeIterator(Iterator relTypes, DatabaseService graphDb){
33 | this.relTypes = relTypes;
34 | this.graphDb = graphDb;
35 | }
36 |
37 | @Override
38 | public boolean hasNext() {
39 | return relTypes.hasNext();
40 | }
41 |
42 | @Override
43 | public EdgeType next() {
44 | return BinaryEdgeTypeImpl.getOrCreateInstance(graphDb, relTypes.next());
45 | }
46 |
47 | @Override
48 | public void remove() {
49 | relTypes.remove();
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/impl/SortableBinaryEdgeImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.impl;
21 |
22 | import org.neo4j.collections.graphdb.BinaryEdgeType;
23 | import org.neo4j.collections.graphdb.DatabaseService;
24 | import org.neo4j.collections.graphdb.EdgeType;
25 | import org.neo4j.collections.graphdb.SortableBinaryEdge;
26 | import org.neo4j.collections.graphdb.Vertex;
27 | import org.neo4j.collections.graphdb.VertexType;
28 | import org.neo4j.collections.indexedrelationship.IndexedRelationship;
29 | import org.neo4j.graphdb.DynamicRelationshipType;
30 | import org.neo4j.graphdb.Node;
31 |
32 | public class SortableBinaryEdgeImpl extends BinaryEdgeImpl implements SortableBinaryEdge{
33 |
34 | SortableBinaryEdgeImpl(DatabaseService db, Long id, IndexedRelationship relIdx) {
35 | super(db, id);
36 | this.relIdx = relIdx;
37 | }
38 |
39 | private IndexedRelationship relIdx;
40 |
41 |
42 | public IndexedRelationship getRelIdx(){
43 | return relIdx;
44 | }
45 |
46 | public Node getRootNode(){
47 | return relIdx.getIndexedNode();
48 | }
49 |
50 |
51 | @Override
52 | public Vertex getEndVertex() {
53 | return getDb().getVertex(getRelationship().getEndNode());
54 | }
55 |
56 | @Override
57 | public Vertex getOtherVertex(Vertex element) {
58 | return getDb().getVertex(getRelationship().getOtherNode(element.getNode()));
59 | }
60 |
61 | @Override
62 | public Vertex getStartVertex() {
63 | return getDb().getVertex(getRootNode());
64 | }
65 |
66 | @Override
67 | public void delete() {
68 | getRelIdx().removeRelationshipTo(getEndVertex().getNode());
69 | }
70 |
71 | @Override
72 | protected VertexType getSpecialVertexType(){
73 | return getType();
74 | }
75 |
76 | @Override
77 | public BinaryEdgeType getType() {
78 | return SortableBinaryEdgeTypeImpl.getOrCreateInstance(getDb(), getRelationship().getType());
79 | }
80 |
81 | @Override
82 | public boolean isType(EdgeType relType) {
83 | return getRelationship().isType(DynamicRelationshipType.withName(relType.getName()));
84 | }
85 |
86 | @Override
87 | public org.neo4j.graphdb.PropertyContainer getPropertyContainer() {
88 | return getNode();
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/impl/SortableBinaryEdgeTypeImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.impl;
21 |
22 | import org.neo4j.collections.graphdb.DatabaseService;
23 | import org.neo4j.collections.graphdb.PropertyType;
24 | import org.neo4j.collections.graphdb.PropertyType.ComparablePropertyType;
25 | import org.neo4j.collections.graphdb.SortableBinaryEdge;
26 | import org.neo4j.collections.graphdb.SortableBinaryEdgeType;
27 | import org.neo4j.collections.graphdb.Vertex;
28 | import org.neo4j.collections.indexedrelationship.IndexedRelationship;
29 | import org.neo4j.collections.sortedtree.PropertySortedTree;
30 | import org.neo4j.graphdb.Direction;
31 | import org.neo4j.graphdb.DynamicRelationshipType;
32 | import org.neo4j.graphdb.Node;
33 | import org.neo4j.graphdb.Relationship;
34 | import org.neo4j.graphdb.RelationshipType;
35 |
36 | public class SortableBinaryEdgeTypeImpl extends BinaryEdgeTypeImpl implements SortableBinaryEdgeType{
37 |
38 | public static String PROPERTY_TYPE = "org.neo4j.collections.graphdb.property_type";
39 |
40 | public SortableBinaryEdgeTypeImpl(DatabaseService db, Long id) {
41 | super(db, id);
42 | }
43 |
44 | protected static Class> getImplementationClass(){
45 | try{
46 | return Class.forName("org.neo4j.collections.graphdb.impl.SortableBinaryEdgeTypeImpl");
47 | }catch(ClassNotFoundException cce){
48 | throw new RuntimeException(cce);
49 | }
50 | }
51 |
52 | public static class SortableTypeNodeDescriptor extends TypeNodeDescriptor{
53 |
54 | public final ComparablePropertyType propertyType;
55 |
56 | SortableTypeNodeDescriptor(DatabaseService db, String name,
57 | Class> claz, ComparablePropertyType propertyType) {
58 | super(db, name, claz);
59 | this.propertyType = propertyType;
60 | }
61 |
62 | @Override
63 | public void initialize(Node n){
64 | super.initialize(n);
65 | n.setProperty(PROPERTY_TYPE, propertyType.getName());
66 | }
67 | }
68 |
69 | public static SortableBinaryEdgeType getOrCreateInstance(DatabaseService db,
70 | RelationshipType relType, PropertyType.ComparablePropertyType propertyType) {
71 | VertexTypeImpl vertexType = new VertexTypeImpl(db, getOrCreateByDescriptor(new SortableTypeNodeDescriptor(db, relType.name(), getImplementationClass(), propertyType)).getId());
72 | return new SortableBinaryEdgeTypeImpl(db, vertexType.getNode().getId());
73 | }
74 |
75 | @SuppressWarnings("unchecked")
76 | @Override
77 | public ComparablePropertyType getPropertyType() {
78 | return (ComparablePropertyType) getByName(getDb(), (String)getNode().getProperty(PROPERTY_TYPE));
79 | }
80 |
81 | @Override
82 | public SortableBinaryEdge createEdge(Vertex startVertex, Vertex endVertex) {
83 | IndexedRelationship idxRel = new IndexedRelationship( startVertex.getNode(),
84 | DynamicRelationshipType.withName(this.getName()), Direction.OUTGOING );
85 | if ( !idxRel.exists() )
86 | {
87 | PropertySortedTree propertySortedTree = new PropertySortedTree( getDb().getGraphDatabaseService(),
88 | getPropertyType(), true, getName() );
89 | idxRel.create( propertySortedTree );
90 | }
91 | Relationship rel = idxRel.createRelationshipTo(endVertex.getNode());
92 | return new SortableBinaryEdgeImpl(db, rel.getId(), idxRel);
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/impl/VertexTypeImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.impl;
21 |
22 | import org.neo4j.collections.graphdb.DatabaseService;
23 | import org.neo4j.collections.graphdb.ReferenceNodes;
24 | import org.neo4j.collections.graphdb.VertexType;
25 | import org.neo4j.graphdb.Direction;
26 | import org.neo4j.graphdb.DynamicRelationshipType;
27 | import org.neo4j.graphdb.Node;
28 | import org.neo4j.graphdb.RelationshipType;
29 |
30 | public class VertexTypeImpl extends VertexImpl implements VertexType {
31 |
32 | public enum RelTypes implements RelationshipType {
33 | ORG_NEO4J_COLLECTIONS_GRAPHDB_TYPE_SUBREF, ORG_NEO4J_COLLECTIONS_GRAPHDB_TYPE
34 | }
35 |
36 | public static class TypeNodeDescriptor {
37 |
38 | public final DatabaseService db;
39 |
40 | public final String name;
41 | public final Class> claz;
42 |
43 | public TypeNodeDescriptor(DatabaseService db, String name, Class> claz) {
44 | this.db = db;
45 | this.name = name;
46 | this.claz = claz;
47 | }
48 |
49 | public void initialize(Node n) {
50 | if (name.startsWith("org.neo4j.collections.graphdb")
51 | || name.startsWith("ORG_NEO4J_COLLECTIONS_GRAPHDB")) {
52 | throw new RuntimeException(
53 | "Type names should never start with org.neo4j.collections.graphdb or with ORG_NEO4J_COLLECTIONS_GRAPHDB");
54 | }
55 | n.setProperty(TYPE_NAME, name);
56 | n.setProperty(CLASS_NAME, claz.getName());
57 | }
58 | }
59 |
60 | public static String TYPE_NAME = "org.neo4j.collections.graphdb.TYPE_NAME";
61 |
62 | public static String CLASS_NAME = "org.neo4j.collections.graphdb.CLASS_NAME";
63 |
64 | public static VertexType getByName(DatabaseService db, String name) {
65 | return (VertexType) db.getVertex(getNodeByName(db, name));
66 | }
67 |
68 | private static Class> getImplementationClass() {
69 | try {
70 | return Class
71 | .forName("org.neo4j.collections.graphdb.impl.VertexTypeImpl");
72 | } catch (ClassNotFoundException cce) {
73 | throw new RuntimeException(cce);
74 | }
75 | }
76 |
77 | private static Node getNodeByName(DatabaseService db, String name) {
78 | Node typeSubRef = getOrCreateTypeSubRef(db);
79 | RelationshipType relType = DynamicRelationshipType.withName(name);
80 | if (typeSubRef.hasRelationship(relType, Direction.OUTGOING)) {
81 | return typeSubRef
82 | .getSingleRelationship(relType, Direction.OUTGOING)
83 | .getEndNode();
84 | } else {
85 | return null;
86 | }
87 | }
88 |
89 | public static Node getOrCreateByDescriptor(TypeNodeDescriptor tnd) {
90 | Node typeSubRef = getOrCreateTypeSubRef(tnd.db);
91 | RelationshipType relType = DynamicRelationshipType.withName(tnd.name);
92 | Node foundNode = getNodeByName(tnd.db, tnd.name);
93 | if (foundNode != null) {
94 | if (tnd.claz.getName().equals(foundNode.getProperty(CLASS_NAME))) {
95 | return foundNode;
96 | } else {
97 | throw new RuntimeException(
98 | "A type already exists with than name");
99 | }
100 |
101 | } else {
102 | Node newNode = tnd.db.createNode();
103 | tnd.initialize(newNode);
104 | typeSubRef.createRelationshipTo(newNode, relType);
105 | return newNode;
106 | }
107 | }
108 |
109 | public static VertexTypeImpl getOrCreateInstance(DatabaseService db,
110 | String name) {
111 | return new VertexTypeImpl(db, getOrCreateByDescriptor(
112 | new TypeNodeDescriptor(db, name, getImplementationClass()))
113 | .getId());
114 | }
115 |
116 | private static Node getOrCreateTypeSubRef(DatabaseService db) {
117 | Node refNode = ReferenceNodes.getReferenceNode(db);
118 | RelationshipType relType = RelTypes.ORG_NEO4J_COLLECTIONS_GRAPHDB_TYPE_SUBREF;
119 | if (refNode.hasRelationship(relType, Direction.OUTGOING)) {
120 | return refNode.getSingleRelationship(relType, Direction.OUTGOING)
121 | .getEndNode();
122 | } else {
123 | Node n = db.createNode();
124 | refNode.createRelationshipTo(n, relType);
125 | return n;
126 | }
127 | }
128 |
129 | public VertexTypeImpl(DatabaseService db, Long id) {
130 | super(db, id);
131 | }
132 |
133 | @Override
134 | public String getName() {
135 | return (String) getNode().getProperty(TYPE_NAME);
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/traversal/BranchSelector.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.traversal;
21 |
22 | import org.neo4j.collections.graphdb.Traversal;
23 | import org.neo4j.collections.graphdb.TraversalPath;
24 |
25 | public interface BranchSelector {
26 |
27 | Traversal next(TraversalPath path);
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/traversal/Evaluator.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.traversal;
21 |
22 | import org.neo4j.collections.graphdb.TraversalPath;
23 | import org.neo4j.graphdb.traversal.Evaluation;
24 |
25 | public interface Evaluator {
26 |
27 | Evaluation evaluate(TraversalPath path);
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/traversal/impl/TraversalDescriptionImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.traversal.impl;
21 |
22 | import java.util.ArrayList;
23 | import java.util.Iterator;
24 | import java.util.List;
25 |
26 | import org.neo4j.collections.graphdb.BinaryEdgeType;
27 | import org.neo4j.collections.graphdb.Connector;
28 | import org.neo4j.collections.graphdb.Traversal;
29 | import org.neo4j.collections.graphdb.TraversalDescription;
30 | import org.neo4j.collections.graphdb.traversal.BranchSelector;
31 | import org.neo4j.collections.graphdb.traversal.Evaluator;
32 | import org.neo4j.graphdb.Direction;
33 |
34 | public class TraversalDescriptionImpl implements TraversalDescription{
35 |
36 |
37 | final Evaluator evaluator;
38 | final BranchSelector selector;
39 | final Connector> connector;
40 | final List descriptions;
41 |
42 |
43 |
44 | public TraversalDescriptionImpl(Evaluator evaluator,
45 | BranchSelector selector, Connector> connector,
46 | List descriptions) {
47 | super();
48 | this.evaluator = evaluator;
49 | this.selector = selector;
50 | this.connector = connector;
51 | this.descriptions = descriptions;
52 | }
53 |
54 | @Override
55 | public Iterator iterator() {
56 | return descriptions.iterator();
57 | }
58 |
59 | @Override
60 | public TraversalDescription set(Evaluator evaluator) {
61 | return new TraversalDescriptionImpl(evaluator, selector, connector, descriptions);
62 | }
63 |
64 | @Override
65 | public TraversalDescription set(BranchSelector selector) {
66 | return new TraversalDescriptionImpl(evaluator, selector, connector, descriptions); }
67 |
68 | @Override
69 | public TraversalDescription add(BinaryEdgeType edgeType) {
70 | // TODO Auto-generated method stub
71 | return null;
72 | }
73 |
74 | @Override
75 | public TraversalDescription add(BinaryEdgeType edgeType, Direction dir) {
76 | // TODO Auto-generated method stub
77 | return null;
78 | }
79 |
80 | @Override
81 | public TraversalDescription add(Connector> connector) {
82 | return new TraversalDescriptionImpl(evaluator, selector, connector, descriptions); }
83 |
84 | @Override
85 | public TraversalDescription add(TraversalDescription description) {
86 | List descriptions = new ArrayList();
87 | descriptions.addAll(this.descriptions);
88 | descriptions.add(description);
89 | return new TraversalDescriptionImpl(evaluator, selector, connector, descriptions);
90 | }
91 |
92 | @Override
93 | public TraversalDescription insert(TraversalDescription description,
94 | int position) {
95 | List descriptions = new ArrayList();
96 | descriptions.addAll(this.descriptions);
97 | descriptions.add(position, description);
98 | return new TraversalDescriptionImpl(evaluator, selector, connector, descriptions);
99 | }
100 |
101 | @Override
102 | public Traversal traverse(Traversal traversal) {
103 | return new TraversalImpl(traversal, this);
104 | }
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/traversal/impl/TraversalImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.traversal.impl;
21 |
22 | import java.util.Iterator;
23 | import java.util.NoSuchElementException;
24 |
25 | import org.neo4j.collections.graphdb.Traversal;
26 | import org.neo4j.collections.graphdb.TraversalDescription;
27 | import org.neo4j.collections.graphdb.TraversalPath;
28 |
29 | public class TraversalImpl implements Traversal{
30 |
31 | private final Traversal traversal;
32 | private final TraversalDescriptionImpl description;
33 |
34 | public TraversalImpl(Traversal traversal, TraversalDescriptionImpl description) {
35 | this.traversal = traversal;
36 | this.description = description;
37 | }
38 |
39 | private class PathIterator implements Iterator{
40 |
41 | DescriptionIterator iter = new DescriptionIterator();
42 |
43 | @Override
44 | public boolean hasNext() {
45 | return iter.hasNext();
46 | }
47 |
48 | @Override
49 | public TraversalPath next() {
50 | return concatenatePaths(getPath(), iter.next().getPath());
51 | }
52 |
53 | @Override
54 | public void remove() {
55 | }
56 |
57 | }
58 |
59 | private class DescriptionIterator implements Iterator{
60 |
61 | final Iterator iter = description.descriptions.iterator();
62 |
63 | Boolean hasNext = null;
64 |
65 | @Override
66 | public boolean hasNext() {
67 | if(hasNext == null){
68 | hasNext = iter.hasNext();
69 |
70 | }
71 | return hasNext;
72 | }
73 |
74 | @Override
75 | public Traversal next() {
76 | if(hasNext == null){
77 | throw new NoSuchElementException();
78 | }else{
79 | if(hasNext()){
80 | return iter.next().traverse(traversal);
81 | }else{
82 | throw new NoSuchElementException();
83 | }
84 | }
85 | }
86 |
87 | @Override
88 | public void remove() {
89 | }
90 |
91 | }
92 |
93 | @Override
94 | public Iterator iterator() {
95 | return new DescriptionIterator();
96 | }
97 |
98 | @Override
99 | public TraversalPath getPath() {
100 | // TODO Auto-generated method stub
101 | return null;
102 | }
103 |
104 | @Override
105 | public Iterable getContainedPaths() {
106 |
107 | return new Iterable(){
108 |
109 | @Override
110 | public Iterator iterator() {
111 | return new PathIterator();
112 | }
113 |
114 | };
115 | }
116 |
117 | private TraversalPath concatenatePaths(TraversalPath path1, TraversalPath path2){
118 | //TODO
119 | return null;
120 | }
121 |
122 | }
123 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/graphdb/traversal/impl/TraversalPathImpl.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.graphdb.traversal.impl;
21 |
22 | import java.util.Iterator;
23 | import java.util.LinkedList;
24 |
25 | import org.neo4j.collections.graphdb.Connection;
26 | import org.neo4j.collections.graphdb.TraversalPath;
27 |
28 | public class TraversalPathImpl implements TraversalPath{
29 |
30 | private LinkedList> connections;
31 |
32 | @Override
33 | public Iterator> iterator() {
34 | return connections.iterator();
35 | }
36 |
37 | @Override
38 | public Connection> getFirstElement() {
39 | return connections.getFirst();
40 | }
41 |
42 | @Override
43 | public Connection> getLastElement() {
44 | return connections.getLast();
45 | }
46 |
47 | @Override
48 | public int length() {
49 | return connections.size();
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/indexprovider/NodeIndexHits.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.indexprovider;
21 |
22 | import java.util.List;
23 |
24 | import org.neo4j.graphdb.Node;
25 | import org.neo4j.index.impl.lucene.AbstractIndexHits;
26 |
27 | public class NodeIndexHits extends AbstractIndexHits
28 | {
29 | private final int size;
30 | private final List hits;
31 | private int index;
32 |
33 | public NodeIndexHits( List hits )
34 | {
35 | this.size = hits.size();
36 | this.hits = hits;
37 | }
38 |
39 | @Override
40 | protected Node fetchNextOrNull()
41 | {
42 | int i = index++;
43 | return i < size() ? hits.get( i ) : null;
44 | }
45 |
46 | public int size()
47 | {
48 | return this.size;
49 | }
50 |
51 | public float currentScore()
52 | {
53 | return 0;
54 | }
55 | }
56 |
57 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/indexprovider/TimelineIndexImplementation.java:
--------------------------------------------------------------------------------
1 | package org.neo4j.collections.indexprovider;
2 |
3 | import org.neo4j.graphdb.GraphDatabaseService;
4 | import org.neo4j.graphdb.Node;
5 | import org.neo4j.graphdb.index.Index;
6 | import org.neo4j.graphdb.index.IndexImplementation;
7 | import org.neo4j.graphdb.index.RelationshipIndex;
8 | import org.neo4j.index.impl.lucene.LuceneDataSource;
9 |
10 | import java.util.HashMap;
11 | import java.util.Map;
12 |
13 | /**
14 | * @author mh
15 | * @since 25.11.13
16 | */
17 | class TimelineIndexImplementation implements IndexImplementation
18 | {
19 |
20 | private GraphDatabaseService db;
21 | private Map indexes = new HashMap();
22 |
23 | public TimelineIndexImplementation(GraphDatabaseService db)
24 | {
25 |
26 | this.db = db;
27 | }
28 |
29 | @Override
30 | public String getDataSourceName()
31 | {
32 | return LuceneDataSource.DEFAULT_NAME;
33 | }
34 |
35 | @Override
36 | public Index nodeIndex( String indexName,
37 | Map config )
38 | {
39 | TimelineNodeIndex index = indexes.get( indexName );
40 | if ( index == null )
41 | {
42 | index = new TimelineNodeIndex( indexName, db,
43 | config );
44 | indexes.put( indexName, index );
45 | }
46 | return index;
47 | }
48 |
49 | @Override
50 | public RelationshipIndex relationshipIndex( String indexName,
51 | Map config )
52 | {
53 | throw new UnsupportedOperationException(
54 | "timeline relationship indexing is not supported at the moment. Please use the node index." );
55 | }
56 |
57 | @Override
58 | public Map fillInDefaults( Map config )
59 | {
60 | return config;
61 | }
62 |
63 | @Override
64 | public boolean configMatches( Map config1,
65 | Map config2 )
66 | {
67 | return config1.equals(config2);
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/indexprovider/TimelineIndexKernelExtensionFactory.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.indexprovider;
21 |
22 | import org.neo4j.graphdb.GraphDatabaseService;
23 | import org.neo4j.graphdb.index.IndexProviders;
24 | import org.neo4j.kernel.extension.KernelExtensionFactory;
25 | import org.neo4j.kernel.lifecycle.Lifecycle;
26 |
27 | public class TimelineIndexKernelExtensionFactory extends KernelExtensionFactory {
28 |
29 | public TimelineIndexKernelExtensionFactory() {
30 | super(TimelineNodeIndex.SERVICE_NAME);
31 | }
32 |
33 | @Override
34 | public Lifecycle newKernelExtension(Depencies depencies) throws Throwable {
35 | return new TimelineIndexKerneExtension(depencies.getGraphDatabaseService(), depencies.getIndexProviders());
36 | }
37 |
38 | public static interface Depencies {
39 | IndexProviders getIndexProviders();
40 |
41 | GraphDatabaseService getGraphDatabaseService();
42 |
43 | }
44 |
45 | public static class TimelineIndexKerneExtension implements Lifecycle {
46 | private final GraphDatabaseService graphDatabaseService;
47 | private final IndexProviders indexProviders;
48 |
49 | public TimelineIndexKerneExtension(GraphDatabaseService graphDatabaseService, IndexProviders indexProviders) {
50 | this.graphDatabaseService = graphDatabaseService;
51 | this.indexProviders = indexProviders;
52 | }
53 |
54 | @Override
55 | public void init() throws Throwable {
56 | }
57 |
58 | @Override
59 | public void start() throws Throwable {
60 | TimelineIndexImplementation indexImplementation = new TimelineIndexImplementation(graphDatabaseService);
61 | indexProviders.registerIndexProvider(TimelineNodeIndex.SERVICE_NAME, indexImplementation);
62 | }
63 |
64 | @Override
65 | public void stop() throws Throwable {
66 | indexProviders.unregisterIndexProvider(TimelineNodeIndex.SERVICE_NAME);
67 | }
68 |
69 | @Override
70 | public void shutdown() throws Throwable {
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/indexprovider/TimelineNodeIndex.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.indexprovider;
21 |
22 | import java.util.ArrayList;
23 | import java.util.Collections;
24 | import java.util.List;
25 | import java.util.Map;
26 |
27 | import org.neo4j.collections.graphdb.ReferenceNodes;
28 | import org.neo4j.collections.timeline.Timeline;
29 | import org.neo4j.graphdb.GraphDatabaseService;
30 | import org.neo4j.graphdb.Node;
31 | import org.neo4j.graphdb.index.Index;
32 | import org.neo4j.graphdb.index.IndexHits;
33 | import org.neo4j.graphdb.index.IndexManager;
34 | import org.neo4j.helpers.collection.MapUtil;
35 |
36 | public class TimelineNodeIndex implements Index
37 | {
38 |
39 |
40 | public static final String TIMESTAMP = "timestamp";
41 | public static final String START_NODE_ID = "start_node_id";
42 | public static final String SERVICE_NAME = "graph-collections-timeline";
43 | public static final Map CONFIG = Collections.unmodifiableMap(MapUtil.stringMap(
44 | IndexManager.PROVIDER, SERVICE_NAME));
45 | private Timeline timeline;
46 | private final String indexName;
47 |
48 | public TimelineNodeIndex( String indexName, GraphDatabaseService db,
49 | Map config )
50 | {
51 | this.indexName = indexName;
52 | // Transaction tx = db.beginTx();
53 | Node underlyingNode = getOrCreateStartNode(db, config);
54 | timeline = new Timeline( indexName, underlyingNode, false, db );
55 | // tx.success();
56 | // tx.finish();
57 | }
58 |
59 | private Node getOrCreateStartNode(GraphDatabaseService db, Map config) {
60 | if (underlyingNodeWasProvided(config)) {
61 | return db.getNodeById(Long.parseLong(config.get(START_NODE_ID)));
62 | }
63 | return ReferenceNodes.getReferenceNode(db);
64 | }
65 |
66 | private boolean underlyingNodeWasProvided(Map config) {
67 | return config.containsKey(START_NODE_ID);
68 | }
69 |
70 | public Timeline getTimeline() {
71 | return timeline;
72 | }
73 |
74 | @Override
75 | public boolean isWriteable()
76 | {
77 | return true;
78 | }
79 |
80 | @Override
81 | public String getName()
82 | {
83 | // TODO Auto-generated method stub
84 | return indexName;
85 | }
86 |
87 | @Override
88 | public Class getEntityType()
89 | {
90 | return Node.class;
91 | }
92 |
93 | @Override
94 | public IndexHits get( String key, Object value )
95 | {
96 | return new NodeIndexHits( toList(timeline.getNodes( (Long) value )) );
97 | }
98 |
99 | private List toList( Iterable nodes )
100 | {
101 | List results = new ArrayList();
102 | for(Node node : nodes) {
103 | results.add( node );
104 | }
105 | return results;
106 | }
107 |
108 | @Override
109 | public IndexHits query( String key, Object queryOrQueryObject )
110 | {
111 | return null;
112 | }
113 |
114 | @Override
115 | public IndexHits query( Object queryString )
116 | {
117 | String query = (String)queryString;
118 | Long from = Long.parseLong( query.substring( 1, query.indexOf( "TO" ) ).trim());
119 | Long to = Long.parseLong( query.substring( query.indexOf( "TO" )+2,query.indexOf( "]" ) ).trim());
120 | return new NodeIndexHits( toList(timeline.getAllNodesBetween( from, to )));
121 | }
122 |
123 | @Override
124 | public void add( Node entity, String key, Object value )
125 | {
126 | if(key.equals( TIMESTAMP ))
127 | {
128 | timeline.addNode( entity, (Long) value );
129 | } else
130 | {
131 | throw new RuntimeException( "need a timestamp key and a LONG value" );
132 | }
133 | }
134 |
135 | @Override
136 | public void remove( Node entity, String key, Object value )
137 | {
138 | timeline.removeNode( entity );
139 |
140 | }
141 |
142 | @Override
143 | public void remove( Node entity, String key )
144 | {
145 | this.remove( entity );
146 |
147 | }
148 |
149 | @Override
150 | public void remove( Node entity )
151 | {
152 | timeline.removeNode( entity );
153 |
154 | }
155 |
156 | @Override
157 | public void delete()
158 | {
159 | timeline.delete();
160 | }
161 |
162 | @Override
163 | public GraphDatabaseService getGraphDatabase()
164 | {
165 | return timeline.getUnderlyingNode().getGraphDatabase();
166 | }
167 |
168 | @Override
169 | public Node putIfAbsent( Node entity, String key, Object value )
170 | {
171 | return entity;
172 | }
173 | }
174 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/radixtree/RadixTree.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.radixtree;
21 |
22 | import java.util.List;
23 |
24 | import org.neo4j.graphdb.Node;
25 |
26 |
27 | public interface RadixTree {
28 |
29 | List get(String key);
30 |
31 | void insert(String key, Node node);
32 |
33 |
34 | Node getUnique(String key);
35 |
36 | boolean insertUnique(String key, Node node);
37 |
38 |
39 | int remove(String key, boolean deleteIndexedNodes);
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/radixtree/RadixTreeRelationshipTypes.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.radixtree;
21 |
22 | import org.neo4j.graphdb.RelationshipType;
23 |
24 |
25 | public enum RadixTreeRelationshipTypes implements RelationshipType {
26 |
27 | RADIXTREE_ROOT,
28 | RADIXTREE_TREE,
29 | RADIXTREE_LEAF
30 |
31 | }
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/rtree/EnvelopeDecoder.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.rtree;
21 |
22 | import org.neo4j.graphdb.PropertyContainer;
23 |
24 |
25 | public interface EnvelopeDecoder {
26 |
27 | Envelope decodeEnvelope(PropertyContainer container);
28 |
29 | }
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/rtree/EnvelopeDecoderFromDoubleArray.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.rtree;
21 |
22 | import org.neo4j.graphdb.PropertyContainer;
23 |
24 |
25 | /**
26 | *
27 | * The property must contain an array of double: xmin, ymin, xmax, ymax.
28 | */
29 | public class EnvelopeDecoderFromDoubleArray implements EnvelopeDecoder {
30 |
31 | public EnvelopeDecoderFromDoubleArray(String propertyName) {
32 | this.propertyName = propertyName;
33 | }
34 |
35 | @Override
36 | public Envelope decodeEnvelope(PropertyContainer container) {
37 | Object propValue = container.getProperty(propertyName);
38 |
39 | if (propValue instanceof Double[]) {
40 | Double[] bbox = (Double[]) propValue;
41 | return new Envelope(bbox[0], bbox[2], bbox[1], bbox[3]);
42 | } else if (propValue instanceof double[]) {
43 | double[] bbox = (double[]) propValue;
44 | return new Envelope(bbox[0], bbox[2], bbox[1], bbox[3]);
45 | } else {
46 | // invalid content
47 | return new Envelope();
48 | }
49 | }
50 |
51 | private String propertyName;
52 | }
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/rtree/Listener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.rtree;
21 |
22 |
23 | /**
24 | * Classes that implement this interface will be notified of units of work done,
25 | * and can therefor be used for progress bars or console logging or similar activities.
26 | */
27 | public interface Listener {
28 |
29 | void begin(int unitsOfWork);
30 |
31 | void worked(int workedSinceLastNotification);
32 |
33 | void done();
34 |
35 | }
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/rtree/NullListener.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.rtree;
21 |
22 |
23 | /**
24 | * This listener ignores all notifications of progress. It is useful when progress is not necessary.
25 | */
26 | public class NullListener implements Listener {
27 |
28 | // Public methods
29 |
30 | @Override
31 | public void begin(int unitsOfWork) {
32 | }
33 |
34 | @Override
35 | public void worked(int workedSinceLastNotification) {
36 | }
37 |
38 | @Override
39 | public void done() {
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/rtree/RTreeRelationshipTypes.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.rtree;
21 |
22 | import org.neo4j.graphdb.RelationshipType;
23 |
24 |
25 | public enum RTreeRelationshipTypes implements RelationshipType {
26 |
27 | RTREE_METADATA,
28 | RTREE_ROOT,
29 | RTREE_CHILD,
30 | RTREE_REFERENCE
31 |
32 | }
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/rtree/SpatialIndexReader.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.rtree;
21 |
22 | import org.neo4j.collections.rtree.filter.SearchFilter;
23 | import org.neo4j.collections.rtree.filter.SearchResults;
24 | import org.neo4j.graphdb.Node;
25 |
26 |
27 | public interface SpatialIndexReader {
28 |
29 | EnvelopeDecoder getEnvelopeDecoder();
30 |
31 | boolean isEmpty();
32 |
33 | int count();
34 |
35 | Envelope getBoundingBox();
36 |
37 | boolean isNodeIndexed(Long nodeId);
38 |
39 | Iterable getAllIndexedNodes();
40 |
41 | SearchResults searchIndex(SearchFilter filter);
42 | }
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/rtree/SpatialIndexRecordCounter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.rtree;
21 |
22 | import org.neo4j.graphdb.Node;
23 |
24 |
25 | public class SpatialIndexRecordCounter implements SpatialIndexVisitor {
26 |
27 | @Override
28 | public boolean needsToVisit(Envelope indexNodeEnvelope) {
29 | return true;
30 | }
31 |
32 | @Override
33 | public void onIndexReference(Node geomNode) {
34 | count++;
35 | }
36 |
37 | public int getResult() {
38 | return count;
39 | }
40 |
41 |
42 | private int count = 0;
43 | }
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/rtree/SpatialIndexVisitor.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.rtree;
21 |
22 | import org.neo4j.graphdb.Node;
23 |
24 |
25 | public interface SpatialIndexVisitor {
26 |
27 | boolean needsToVisit(Envelope indexNodeEnvelope);
28 |
29 | void onIndexReference(Node geomNode);
30 |
31 | }
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/rtree/SpatialIndexWriter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.rtree;
21 |
22 | import org.neo4j.graphdb.Node;
23 |
24 |
25 | public interface SpatialIndexWriter extends SpatialIndexReader {
26 |
27 | void add(Node geomNode);
28 |
29 | void remove(long geomNodeId, boolean deleteGeomNode);
30 |
31 | void removeAll(boolean deleteGeomNodes, Listener monitor);
32 |
33 | void clear(Listener monitor);
34 |
35 | }
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/rtree/filter/AbstractSearchEnvelopeIntersection.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.rtree.filter;
21 |
22 | import org.neo4j.collections.rtree.Envelope;
23 | import org.neo4j.collections.rtree.EnvelopeDecoder;
24 | import org.neo4j.graphdb.Node;
25 |
26 | public abstract class AbstractSearchEnvelopeIntersection implements SearchFilter {
27 |
28 | protected EnvelopeDecoder decoder;
29 | protected Envelope referenceEnvelope;
30 |
31 | public AbstractSearchEnvelopeIntersection(EnvelopeDecoder decoder, Envelope referenceEnvelope) {
32 | this.decoder = decoder;
33 | this.referenceEnvelope = referenceEnvelope;
34 | }
35 |
36 | @Override
37 | public boolean needsToVisit(Envelope indexNodeEnvelope) {
38 | return indexNodeEnvelope.intersects(referenceEnvelope);
39 | }
40 |
41 | @Override
42 | public final boolean geometryMatches(Node geomNode) {
43 | Envelope geomEnvelope = decoder.decodeEnvelope(geomNode);
44 | if (geomEnvelope.intersects(referenceEnvelope)) {
45 | return onEnvelopeIntersection(geomNode, geomEnvelope);
46 | }
47 |
48 | return false;
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return "SearchEnvelopeIntersection[" + referenceEnvelope + "]";
54 | }
55 |
56 | protected abstract boolean onEnvelopeIntersection(Node geomNode, Envelope geomEnvelope);
57 | }
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/rtree/filter/SearchAll.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.rtree.filter;
21 |
22 | import org.neo4j.collections.rtree.Envelope;
23 | import org.neo4j.graphdb.Node;
24 |
25 | public class SearchAll implements SearchFilter {
26 |
27 | @Override
28 | public boolean needsToVisit(Envelope indexNodeEnvelope) {
29 | return true;
30 | }
31 |
32 | @Override
33 | public boolean geometryMatches(Node geomNode) {
34 | return true;
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/rtree/filter/SearchCoveredByEnvelope.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.rtree.filter;
21 |
22 | import org.neo4j.collections.rtree.Envelope;
23 | import org.neo4j.collections.rtree.EnvelopeDecoder;
24 | import org.neo4j.graphdb.Node;
25 |
26 | /**
27 | * Find Envelopes covered by the given Envelope
28 | */
29 | public class SearchCoveredByEnvelope extends AbstractSearchEnvelopeIntersection {
30 |
31 | public SearchCoveredByEnvelope(EnvelopeDecoder decoder, Envelope referenceEnvelope) {
32 | super(decoder, referenceEnvelope);
33 | }
34 |
35 | @Override
36 | protected boolean onEnvelopeIntersection(Node geomNode, Envelope geomEnvelope) {
37 | // check if every point of this Envelope is a point of the Reference Envelope
38 | return referenceEnvelope.contains(geomEnvelope);
39 | }
40 |
41 | }
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/rtree/filter/SearchEqualEnvelopes.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.rtree.filter;
21 |
22 | import org.neo4j.collections.rtree.Envelope;
23 | import org.neo4j.collections.rtree.EnvelopeDecoder;
24 | import org.neo4j.graphdb.Node;
25 |
26 | public class SearchEqualEnvelopes extends AbstractSearchEnvelopeIntersection {
27 |
28 | public SearchEqualEnvelopes(EnvelopeDecoder decoder, Envelope referenceEnvelope) {
29 | super(decoder, referenceEnvelope);
30 | }
31 |
32 | @Override
33 | protected boolean onEnvelopeIntersection(Node geomNode, Envelope geomEnvelope) {
34 | return referenceEnvelope.contains(geomEnvelope) && geomEnvelope.contains(referenceEnvelope);
35 | }
36 |
37 | }
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/rtree/filter/SearchFilter.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.rtree.filter;
21 |
22 | import org.neo4j.collections.rtree.Envelope;
23 | import org.neo4j.graphdb.Node;
24 |
25 | public interface SearchFilter {
26 |
27 | boolean needsToVisit(Envelope envelope);
28 |
29 | boolean geometryMatches(Node geomNode);
30 |
31 | }
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/rtree/filter/SearchResults.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.rtree.filter;
21 |
22 | import java.util.Iterator;
23 |
24 | import org.neo4j.graphdb.Node;
25 |
26 | public class SearchResults implements Iterable {
27 | private Iterable traverser;
28 | private int count = -1;
29 |
30 | public SearchResults(Iterable traverser) {
31 | this.traverser = traverser;
32 | }
33 |
34 | @Override
35 | public Iterator iterator() {
36 | return traverser.iterator();
37 | }
38 |
39 | public int count() {
40 | if (count < 0) {
41 | count = 0;
42 | for (@SuppressWarnings("unused")
43 | Node node : this) {
44 | count++;
45 | }
46 | }
47 | return count;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/sortedtree/PropertySortedTree.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.sortedtree;
21 |
22 | import org.neo4j.collections.graphdb.PropertyType.ComparablePropertyType;
23 | import org.neo4j.graphdb.GraphDatabaseService;
24 | import org.neo4j.graphdb.Node;
25 |
26 | public class PropertySortedTree extends SortedTree{
27 |
28 | final ComparablePropertyType propertyType;
29 |
30 | /**
31 | * @param val the value to check if it's in the tree.
32 | * @return {@code true} if this list contains the node, otherwise
33 | * {@code false}.
34 | */
35 | public boolean containsValue(T val) {
36 | return containsValue(val, propertyType);
37 | }
38 |
39 | public Iterable getWithValue(T val){
40 | return getWithValue(val, propertyType);
41 | }
42 |
43 | public PropertySortedTree( GraphDatabaseService graphDb, ComparablePropertyType propertyType,
44 | boolean isUniqueIndex, String treeName ) {
45 | super(graphDb, propertyType, isUniqueIndex, treeName);
46 | this.propertyType = propertyType;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/sortedtree/TempRelationship.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.sortedtree;
21 |
22 | import java.util.HashMap;
23 |
24 | import org.neo4j.graphdb.Node;
25 | import org.neo4j.graphdb.Relationship;
26 |
27 | class TempRelationship{
28 | final Node endNode;
29 | final HashMap props;
30 |
31 | TempRelationship(Relationship rel){
32 | endNode = rel.getEndNode();
33 | props = new HashMap();
34 | for(String key: rel.getPropertyKeys()){
35 | props.put(key, rel.getProperty(key));
36 | }
37 | }
38 |
39 | Node getEndNode(){
40 | return endNode;
41 | }
42 |
43 | HashMap getProperties(){
44 | return props;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/collections/timeline/package-info.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | /**
21 | * A utility for indexing nodes ordered by a timestamp. You add each
22 | * node with a timestamp and then can then ask the timeline to return all nodes
23 | * within a specific period of time with optional start/end timestamps (exclusive).
24 | */
25 | package org.neo4j.collections.timeline;
26 |
27 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/kernel/impl/transaction/Locker.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.kernel.impl.transaction;
21 |
22 | import org.neo4j.graphdb.GraphDatabaseService;
23 | import org.neo4j.graphdb.PropertyContainer;
24 |
25 | import java.lang.reflect.InvocationTargetException;
26 |
27 | public abstract class Locker {
28 | public static Locker getInstance(GraphDatabaseService graphDatabaseService) {
29 | return new Neo4j19Locker(graphDatabaseService);
30 | }
31 |
32 | private static Locker newLockerInstance(String subClass, GraphDatabaseService graphDatabaseService) {
33 | try {
34 | return (Locker)Class.forName("org.neo4j.kernel.impl.transaction." + subClass).getConstructor(GraphDatabaseService.class).newInstance(graphDatabaseService);
35 | } catch (Exception e) {
36 | throw new RuntimeException("Error creating Locker "+subClass,e);
37 | }
38 | }
39 |
40 | public abstract void acquireLock(LockType lockType, PropertyContainer element);
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/org/neo4j/kernel/impl/transaction/Neo4j19Locker.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.kernel.impl.transaction;
21 |
22 | import org.neo4j.graphdb.GraphDatabaseService;
23 | import org.neo4j.graphdb.PropertyContainer;
24 | import org.neo4j.kernel.GraphDatabaseAPI;
25 | import org.neo4j.kernel.impl.core.TransactionState;
26 |
27 | import javax.transaction.SystemException;
28 | import javax.transaction.TransactionManager;
29 |
30 | class Neo4j19Locker extends Locker {
31 |
32 | private final TransactionManager txManager;
33 |
34 | public Neo4j19Locker(GraphDatabaseService graphDatabaseService) {
35 | if (!(graphDatabaseService instanceof GraphDatabaseAPI)) throw new RuntimeException("Error accessing transaction management, not a GraphDatabaseAPI " + graphDatabaseService);
36 | GraphDatabaseAPI graphDatabaseAPI = (GraphDatabaseAPI) graphDatabaseService;
37 | txManager = graphDatabaseAPI.getDependencyResolver().resolveDependency(TransactionManager.class);
38 | }
39 |
40 | @Override
41 | public void acquireLock(LockType lockType, PropertyContainer element) {
42 | TransactionImpl tx = getCurrentTransaction();
43 | if (tx==null) return; // no lock taken without external tx
44 | TransactionState state = tx.getState();
45 | switch (lockType) {
46 | case READ:
47 | state.acquireReadLock(element);
48 | break;
49 | case WRITE:
50 | state.acquireWriteLock(element);
51 | break;
52 | default: throw new IllegalStateException("Unknown lock type "+lockType);
53 | }
54 | }
55 | private TransactionImpl getCurrentTransaction() {
56 | try {
57 | return (TransactionImpl) txManager.getTransaction();
58 | } catch (SystemException e) {
59 | throw new RuntimeException("Error accessing current transaction", e);
60 | }
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/services/org.neo4j.graphdb.index.IndexProvider:
--------------------------------------------------------------------------------
1 | org.neo4j.collections.indexprovider.TimelineIndexProvider
--------------------------------------------------------------------------------
/src/main/resources/META-INF/services/org.neo4j.kernel.extension.KernelExtensionFactory:
--------------------------------------------------------------------------------
1 | org.neo4j.collections.indexprovider.TimelineIndexKernelExtensionFactory
2 |
--------------------------------------------------------------------------------
/src/test/java/org/neo4j/collections/indexedrelationship/TestSortedTreeRelationshipProperties.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.indexedrelationship;
21 |
22 | import static junit.framework.Assert.assertEquals;
23 |
24 | import org.junit.Test;
25 | import org.neo4j.collections.Neo4jTestCase;
26 | import org.neo4j.collections.sortedtree.SortedTree;
27 | import org.neo4j.graphdb.Direction;
28 | import org.neo4j.graphdb.Node;
29 | import org.neo4j.graphdb.Relationship;
30 |
31 | public class TestSortedTreeRelationshipProperties extends Neo4jTestCase
32 | {
33 | @Test
34 | public void testIndexRelationshipAttributes()
35 | {
36 | Node indexedNode = graphDb().createNode();
37 | SortedTree st = new SortedTree( graphDb(), new TestSortedTreeIndexedRelationship.IdComparator(), true,
38 | TestSortedTreeIndexedRelationship.RelTypes.INDEXED_RELATIONSHIP.name() );
39 | IndexedRelationship ir = new IndexedRelationship( indexedNode,
40 | TestSortedTreeIndexedRelationship.RelTypes.INDEXED_RELATIONSHIP, Direction.OUTGOING, st );
41 |
42 | Node node1 = graphDb().createNode();
43 | node1.setProperty( "name", "node 1" );
44 | Node node2 = graphDb().createNode();
45 | node2.setProperty( "name", "node 2" );
46 |
47 | Relationship relationship1 = ir.createRelationshipTo( node1 );
48 | relationship1.setProperty( "rel property", "relationship 1" );
49 | Relationship relationship2 = ir.createRelationshipTo( node2 );
50 | relationship2.setProperty( "rel property", "relationship 2" );
51 |
52 | IndexedRelationshipExpander expander = new IndexedRelationshipExpander( graphDb(), Direction.OUTGOING,
53 | TestSortedTreeIndexedRelationship.RelTypes.INDEXED_RELATIONSHIP );
54 |
55 | int count = 0;
56 | for ( Relationship rel : expander.expand( indexedNode ) )
57 | {
58 | if ( rel.getEndNode().equals( node1 ) )
59 | {
60 | assertEquals( "relationship 1", rel.getProperty( "rel property" ) );
61 | }
62 |
63 | if ( rel.getEndNode().equals( node2 ) )
64 | {
65 | assertEquals( "relationship 2", rel.getProperty( "rel property" ) );
66 | }
67 |
68 | count++;
69 | }
70 |
71 | assertEquals( 2, count );
72 | }
73 |
74 | @Test
75 | public void testIndexRelationshipAttributesFromDestination()
76 | {
77 | Node indexedNode = graphDb().createNode();
78 | SortedTree st1 = new SortedTree( graphDb(), new TestSortedTreeIndexedRelationship.IdComparator(), true,
79 | TestSortedTreeIndexedRelationship.RelTypes.INDEXED_RELATIONSHIP.name() );
80 | IndexedRelationship ir = new IndexedRelationship( indexedNode,
81 | TestSortedTreeIndexedRelationship.RelTypes.INDEXED_RELATIONSHIP, Direction.OUTGOING, st1 );
82 |
83 | Node indexedNode2 = graphDb().createNode();
84 | SortedTree st2 = new SortedTree( graphDb(), new TestSortedTreeIndexedRelationship.IdComparator(), true,
85 | TestSortedTreeIndexedRelationship.RelTypes.INDEXED_RELATIONSHIP.name() );
86 | IndexedRelationship ir2 = new IndexedRelationship( indexedNode2,
87 | TestSortedTreeIndexedRelationship.RelTypes.INDEXED_RELATIONSHIP, Direction.OUTGOING, st2 );
88 |
89 | Node destination = graphDb().createNode();
90 | destination.setProperty( "name", "node 1" );
91 |
92 | Relationship relationship1 = ir.createRelationshipTo( destination );
93 | relationship1.setProperty( "rel property", "relationship 1" );
94 | Relationship relationship2 = ir2.createRelationshipTo( destination );
95 | relationship2.setProperty( "rel property", "relationship 2" );
96 |
97 | IndexedRelationshipExpander expander = new IndexedRelationshipExpander( graphDb(), Direction.INCOMING,
98 | TestSortedTreeIndexedRelationship.RelTypes.INDEXED_RELATIONSHIP );
99 |
100 | int count = 0;
101 | for ( Relationship rel : expander.expand( destination ) )
102 | {
103 | if ( rel.getStartNode().equals( indexedNode ) )
104 | {
105 | assertEquals( rel.getProperty( "rel property" ), "relationship 1" );
106 | }
107 |
108 | if ( rel.getStartNode().equals( indexedNode2 ) )
109 | {
110 | assertEquals( rel.getProperty( "rel property" ), "relationship 2" );
111 | }
112 |
113 | count++;
114 | }
115 |
116 | assertEquals( 2, count );
117 | }
118 | }
--------------------------------------------------------------------------------
/src/test/java/org/neo4j/collections/indexedrelationship/TestUnrolledLinkedListRelationshipProperties.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | package org.neo4j.collections.indexedrelationship;
21 |
22 | import static junit.framework.Assert.assertEquals;
23 |
24 | import org.junit.Test;
25 | import org.neo4j.collections.Neo4jTestCase;
26 | import org.neo4j.collections.list.UnrolledLinkedList;
27 | import org.neo4j.graphdb.Direction;
28 | import org.neo4j.graphdb.Node;
29 | import org.neo4j.graphdb.Relationship;
30 | import org.neo4j.graphdb.RelationshipType;
31 |
32 | public class TestUnrolledLinkedListRelationshipProperties extends Neo4jTestCase
33 | {
34 | public static class IdComparator implements java.util.Comparator
35 | {
36 | public int compare( Node n1, Node n2 )
37 | {
38 | return ((Long) n1.getId()).compareTo( n2.getId() );
39 | }
40 | }
41 |
42 | public static enum RelTypes implements RelationshipType
43 | {
44 | INDEXED_RELATIONSHIP
45 | }
46 |
47 | @Test
48 | public void testIndexRelationshipAttributes()
49 | {
50 | Node indexedNode = graphDb().createNode();
51 | UnrolledLinkedList ull = new UnrolledLinkedList( graphDb(), new IdComparator(), 4 );
52 | IndexedRelationship ir = new IndexedRelationship( indexedNode, RelTypes.INDEXED_RELATIONSHIP,
53 | Direction.OUTGOING, ull );
54 |
55 | Node node1 = graphDb().createNode();
56 | node1.setProperty( "name", "node 1" );
57 | Node node2 = graphDb().createNode();
58 | node2.setProperty( "name", "node 2" );
59 |
60 | Relationship relationship1 = ir.createRelationshipTo( node1 );
61 | relationship1.setProperty( "rel property", "relationship 1" );
62 | Relationship relationship2 = ir.createRelationshipTo( node2 );
63 | relationship2.setProperty( "rel property", "relationship 2" );
64 |
65 | IndexedRelationshipExpander expander = new IndexedRelationshipExpander( graphDb(), Direction.OUTGOING,
66 | RelTypes.INDEXED_RELATIONSHIP );
67 |
68 | int count = 0;
69 | for ( Relationship rel : expander.expand( indexedNode ) )
70 | {
71 | if ( rel.getEndNode().equals( node1 ) )
72 | {
73 | assertEquals( "relationship 1", rel.getProperty( "rel property" ) );
74 | }
75 |
76 | if ( rel.getEndNode().equals( node2 ) )
77 | {
78 | assertEquals( "relationship 2", rel.getProperty( "rel property" ) );
79 | }
80 |
81 | count++;
82 | }
83 |
84 | assertEquals( 2, count );
85 | }
86 |
87 | @Test
88 | public void testIndexRelationshipAttributesFromDestination()
89 | {
90 | Node indexedNode = graphDb().createNode();
91 | UnrolledLinkedList ull1 = new UnrolledLinkedList( graphDb(), new IdComparator(), 4 );
92 | IndexedRelationship ir = new IndexedRelationship( indexedNode, RelTypes.INDEXED_RELATIONSHIP,
93 | Direction.OUTGOING, ull1 );
94 |
95 | Node indexedNode2 = graphDb().createNode();
96 | UnrolledLinkedList ull2 = new UnrolledLinkedList( graphDb(), new IdComparator(), 4 );
97 | IndexedRelationship ir2 = new IndexedRelationship( indexedNode2, RelTypes.INDEXED_RELATIONSHIP,
98 | Direction.OUTGOING, ull2 );
99 |
100 | Node destination = graphDb().createNode();
101 | destination.setProperty( "name", "node 1" );
102 |
103 | Relationship relationship1 = ir.createRelationshipTo( destination );
104 | relationship1.setProperty( "rel property", "relationship 1" );
105 | Relationship relationship2 = ir2.createRelationshipTo( destination );
106 | relationship2.setProperty( "rel property", "relationship 2" );
107 |
108 | IndexedRelationshipExpander expander = new IndexedRelationshipExpander( graphDb(), Direction.INCOMING,
109 | RelTypes.INDEXED_RELATIONSHIP );
110 |
111 | int count = 0;
112 | for ( Relationship rel : expander.expand( destination ) )
113 | {
114 | if ( rel.getStartNode().equals( indexedNode ) )
115 | {
116 | assertEquals( rel.getProperty( "rel property" ), "relationship 1" );
117 | }
118 |
119 | if ( rel.getStartNode().equals( indexedNode2 ) )
120 | {
121 | assertEquals( rel.getProperty( "rel property" ), "relationship 2" );
122 | }
123 |
124 | count++;
125 | }
126 |
127 | assertEquals( 2, count );
128 | }
129 | }
--------------------------------------------------------------------------------
/src/test/java/org/neo4j/collections/indexprovider/TimelineIndexProviderTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2002-2013 "Neo Technology,"
3 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
4 | *
5 | * This file is part of Neo4j.
6 | *
7 | * Neo4j is free software: you can redistribute it and/or modify
8 | * it under the terms of the GNU General Public License as published by
9 | * the Free Software Foundation, either version 3 of the License, or
10 | * (at your option) any later version.
11 | *
12 | * This program is distributed in the hope that it will be useful,
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | * GNU General Public License for more details.
16 | *
17 | * You should have received a copy of the GNU General Public License
18 | * along with this program. If not, see .
19 | */
20 | /**
21 | ' * Copyright (c) 2002-2011 "Neo Technology,"
22 | * Network Engine for Objects in Lund AB [http://neotechnology.com]
23 | *
24 | * This file is part of Neo4j.
25 | *
26 | * Neo4j is free software: you can redistribute it and/or modify
27 | * it under the terms of the GNU Affero General Public License as
28 | * published by the Free Software Foundation, either version 3 of the
29 | * License, or (at your option) any later version.
30 | *
31 | * This program is distributed in the hope that it will be useful,
32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 | * GNU Affero General Public License for more details.
35 | *
36 | * You should have received a copy of the GNU Affero General Public License
37 | * along with this program. If not, see .
38 | */
39 | package org.neo4j.collections.indexprovider;
40 |
41 | import org.junit.Before;
42 | import org.junit.Test;
43 | import org.neo4j.collections.graphdb.ReferenceNodes;
44 | import org.neo4j.collections.timeline.Timeline;
45 | import org.neo4j.cypher.javacompat.ExecutionEngine;
46 | import org.neo4j.cypher.javacompat.ExecutionResult;
47 | import org.neo4j.graphdb.Node;
48 | import org.neo4j.graphdb.Transaction;
49 | import org.neo4j.graphdb.index.Index;
50 | import org.neo4j.graphdb.index.IndexHits;
51 | import org.neo4j.graphdb.index.IndexManager;
52 | import org.neo4j.test.ImpermanentGraphDatabase;
53 | import org.neo4j.visualization.graphviz.GraphvizWriter;
54 | import org.neo4j.walk.Walker;
55 |
56 | import java.util.HashMap;
57 | import java.util.Map;
58 |
59 | import static org.junit.Assert.assertEquals;
60 | import static org.junit.Assert.assertNotNull;
61 |
62 | public class TimelineIndexProviderTest {
63 |
64 | private ImpermanentGraphDatabase db;
65 |
66 | @Before
67 | public void setup() throws Exception {
68 | db = new ImpermanentGraphDatabase();
69 | db.cleanContent();
70 | }
71 |
72 | @Test
73 | public void testLoadIndex() {
74 | db.beginTx();
75 | Map config = TimelineNodeIndex.CONFIG;
76 | IndexManager indexMan = db.index();
77 | Index index = indexMan.forNodes("timeline1", config);
78 | assertNotNull(index);
79 |
80 | }
81 |
82 | @Test
83 | public void testLoadIndexWithRootNode() {
84 | db.beginTx();
85 | Map config = new HashMap(TimelineNodeIndex.CONFIG);
86 | final Node startNode = ReferenceNodes.getReferenceNode(db);
87 | config.put(TimelineNodeIndex.START_NODE_ID, String.valueOf(startNode.getId()));
88 | IndexManager indexMan = db.index();
89 | Index index = indexMan.forNodes("timeline1", config);
90 | final Timeline timeline = ((TimelineNodeIndex) index).getTimeline();
91 | assertEquals(startNode, timeline.getUnderlyingNode());
92 | assertNotNull(index);
93 |
94 | }
95 |
96 | @Test
97 | public void testAddToIndex() throws Exception {
98 | Transaction tx = db.beginTx();
99 | Map config = TimelineNodeIndex.CONFIG;
100 | IndexManager indexMan = db.index();
101 | Index index = indexMan.forNodes("timeline1", config);
102 | assertNotNull(index);
103 | Node n1 = db.createNode();
104 | n1.setProperty("time", 123);
105 | index.add(n1, "timestamp", 123L);
106 | Node n2 = db.createNode();
107 | n2.setProperty("time", 123);
108 | index.add(n2, "timestamp", 123L);
109 | Node n3 = db.createNode();
110 | n3.setProperty("time", 124);
111 | index.add(n3, "timestamp", 124L);
112 | tx.success();
113 | tx.finish();
114 |
115 | tx = db.beginTx();
116 | GraphvizWriter writer = new GraphvizWriter();
117 | writer.emit(System.out, Walker.fullGraph(db));
118 | IndexHits