0
# Neo4j Community Edition
1
2
Neo4j Community Edition is the world's leading Graph Database, providing high-performance graph storage and processing capabilities with the Cypher query language and ACID transactions. It implements the property graph model with nodes and relationships, offering significant performance advantages over traditional relational databases for connected data scenarios.
3
4
## Package Information
5
6
- **Package Name**: neo4j
7
- **Package Type**: maven
8
- **Language**: Java
9
- **Installation**:
10
```xml
11
<dependency>
12
<groupId>org.neo4j</groupId>
13
<artifactId>neo4j</artifactId>
14
<version>5.26.5</version>
15
</dependency>
16
```
17
18
## Core Imports
19
20
```java
21
import org.neo4j.dbms.api.DatabaseManagementService;
22
import org.neo4j.dbms.api.DatabaseManagementServiceBuilder;
23
import org.neo4j.graphdb.GraphDatabaseService;
24
import org.neo4j.graphdb.Transaction;
25
```
26
27
## Basic Usage
28
29
```java
30
import org.neo4j.dbms.api.DatabaseManagementService;
31
import org.neo4j.dbms.api.DatabaseManagementServiceBuilder;
32
import org.neo4j.graphdb.GraphDatabaseService;
33
import org.neo4j.graphdb.Transaction;
34
import org.neo4j.graphdb.Node;
35
import org.neo4j.graphdb.Relationship;
36
import org.neo4j.graphdb.Label;
37
import org.neo4j.graphdb.RelationshipType;
38
import static org.neo4j.graphdb.Label.label;
39
import static org.neo4j.graphdb.RelationshipType.withName;
40
41
// Create database management service
42
DatabaseManagementService managementService = new DatabaseManagementServiceBuilder(databaseDirectory)
43
.build();
44
45
// Get the default database
46
GraphDatabaseService graphDb = managementService.database("neo4j");
47
48
// Create and execute transactions
49
try (Transaction tx = graphDb.beginTx()) {
50
// Create nodes with labels and properties
51
Node alice = tx.createNode(label("Person"));
52
alice.setProperty("name", "Alice");
53
alice.setProperty("age", 30);
54
55
Node bob = tx.createNode(label("Person"));
56
bob.setProperty("name", "Bob");
57
bob.setProperty("age", 25);
58
59
// Create relationships with properties
60
Relationship friendship = alice.createRelationshipTo(bob, withName("FRIENDS"));
61
friendship.setProperty("since", "2020-01-15");
62
63
tx.commit();
64
}
65
66
// Execute Cypher queries
67
try (Transaction tx = graphDb.beginTx()) {
68
String query = "MATCH (p:Person)-[r:FRIENDS]->(f:Person) RETURN p.name, f.name, r.since";
69
tx.execute(query).forEachRemaining(record -> {
70
System.out.println(record.get("p.name") + " is friends with " + record.get("f.name"));
71
});
72
tx.commit();
73
}
74
75
// Shutdown
76
managementService.shutdown();
77
```
78
79
## Architecture
80
81
Neo4j Community Edition is built around several key components:
82
83
- **Database Management Service**: Controls database lifecycle, creation, and management of multiple databases
84
- **Graph Database Service**: Provides access to a specific graph database instance for transactions and queries
85
- **Transaction Management**: ACID-compliant transaction system ensuring data consistency and isolation
86
- **Property Graph Model**: Nodes and relationships with typed properties supporting complex data structures
87
- **Cypher Query Engine**: Declarative graph query language for expressive pattern matching and data manipulation
88
- **Schema Management**: Index and constraint management for query optimization and data integrity
89
- **Event System**: Comprehensive event handling for monitoring database and transaction lifecycle changes
90
91
## Capabilities
92
93
### Database Management
94
95
Core database lifecycle management including creating databases, managing multiple database instances, and controlling database services with full ACID transaction support.
96
97
```java { .api }
98
class DatabaseManagementServiceBuilder {
99
DatabaseManagementServiceBuilder(Path databaseDirectory);
100
<T> DatabaseManagementServiceBuilder setConfig(Setting<T> setting, T value);
101
DatabaseManagementServiceBuilder loadPropertiesFromFile(Path path);
102
DatabaseManagementService build();
103
}
104
105
interface DatabaseManagementService {
106
GraphDatabaseService database(String databaseName);
107
void createDatabase(String databaseName);
108
void dropDatabase(String databaseName);
109
List<String> listDatabases();
110
void shutdown();
111
}
112
```
113
114
[Database Management](./database-management.md)
115
116
### Graph Database Operations
117
118
Core graph database functionality providing transaction management, node and relationship operations, and direct access to the graph data model with property management.
119
120
```java { .api }
121
interface GraphDatabaseService {
122
Transaction beginTx();
123
Transaction beginTx(long timeout, TimeUnit unit);
124
void executeTransactionally(String query);
125
<T> T executeTransactionally(String query, Map<String, Object> parameters,
126
ResultTransformer<T> resultTransformer);
127
boolean isAvailable();
128
}
129
130
interface Transaction extends AutoCloseable {
131
void commit();
132
void rollback();
133
Node createNode();
134
Node createNode(Label... labels);
135
Result execute(String query);
136
Result execute(String query, Map<String, Object> parameters);
137
Schema schema();
138
}
139
```
140
141
[Graph Database Operations](./graph-database.md)
142
143
### Graph Data Model
144
145
Property graph model with nodes, relationships, labels, and properties. Provides the foundational data structures for representing and manipulating connected data.
146
147
```java { .api }
148
interface Node extends Entity {
149
Relationship createRelationshipTo(Node otherNode, RelationshipType type);
150
Iterable<Relationship> getRelationships();
151
Iterable<Relationship> getRelationships(RelationshipType... types);
152
boolean hasLabel(Label label);
153
void addLabel(Label label);
154
void removeLabel(Label label);
155
}
156
157
interface Relationship extends Entity {
158
Node getStartNode();
159
Node getEndNode();
160
Node getOtherNode(Node node);
161
RelationshipType getType();
162
}
163
164
interface Entity {
165
Object getProperty(String key);
166
void setProperty(String key, Object value);
167
boolean hasProperty(String key);
168
void removeProperty(String key);
169
Iterable<String> getPropertyKeys();
170
}
171
```
172
173
[Graph Data Model](./graph-model.md)
174
175
### Query Execution
176
177
Cypher query execution with result handling, parameter binding, and execution plan analysis. Supports both transactional and auto-commit query execution patterns.
178
179
```java { .api }
180
interface Result extends AutoCloseable {
181
boolean hasNext();
182
Map<String, Object> next();
183
void forEachRemaining(Consumer<Map<String, Object>> action);
184
QueryStatistics getQueryStatistics();
185
ExecutionPlanDescription getExecutionPlanDescription();
186
}
187
188
interface ResultTransformer<T> {
189
T apply(Result result) throws Exception;
190
}
191
```
192
193
[Query Execution](./query-execution.md)
194
195
### Schema Management
196
197
Database schema operations including index creation, constraint management, and schema inspection for query optimization and data integrity enforcement.
198
199
```java { .api }
200
interface Schema {
201
IndexCreator indexFor(Label label);
202
ConstraintCreator constraintFor(Label label);
203
Iterable<IndexDefinition> getIndexes();
204
Iterable<ConstraintDefinition> getConstraints();
205
IndexState getIndexState(IndexDefinition index);
206
}
207
208
interface IndexCreator {
209
IndexCreator on(String propertyKey);
210
IndexDefinition create();
211
}
212
213
interface ConstraintCreator {
214
ConstraintCreator assertPropertyIsUnique(String propertyKey);
215
ConstraintDefinition create();
216
}
217
```
218
219
[Schema Management](./schema.md)
220
221
### Stored Procedures and Functions
222
223
Framework for creating custom Cypher-callable procedures and functions with dependency injection, supporting READ, WRITE, SCHEMA, and DBMS execution modes.
224
225
```java { .api }
226
@interface Procedure {
227
String name() default "";
228
Mode mode() default Mode.READ;
229
boolean deprecated() default false;
230
}
231
232
@interface UserFunction {
233
String name() default "";
234
boolean deprecated() default false;
235
}
236
237
@interface Context {
238
}
239
240
enum Mode {
241
READ, WRITE, SCHEMA, DBMS
242
}
243
```
244
245
[Procedures and Functions](./procedures.md)
246
247
### Event Handling
248
249
Comprehensive event system for monitoring database lifecycle, transaction events, and data changes with support for custom event listeners and transaction data inspection.
250
251
```java { .api }
252
interface TransactionEventListener<T> {
253
T beforeCommit(TransactionData data, Transaction transaction) throws Exception;
254
void afterCommit(TransactionData data, T state, Transaction transaction);
255
void afterRollback(TransactionData data, T state, Transaction transaction);
256
}
257
258
interface DatabaseEventListener {
259
void databaseCreate(DatabaseEventContext eventContext);
260
void databaseDrop(DatabaseEventContext eventContext);
261
void databaseStart(DatabaseEventContext eventContext);
262
void databaseShutdown(DatabaseEventContext eventContext);
263
}
264
```
265
266
[Event Handling](./events.md)
267
268
### Configuration
269
270
Type-safe configuration system with validation, default values, and property file loading for customizing database behavior, performance, and security settings.
271
272
```java { .api }
273
interface Setting<T> {
274
String name();
275
T defaultValue();
276
String description();
277
}
278
279
class GraphDatabaseSettings {
280
public static final Setting<Path> data_directory;
281
public static final Setting<Duration> transaction_timeout;
282
public static final Setting<Long> heap_initial_size;
283
// ... many more settings
284
}
285
```
286
287
[Configuration](./configuration.md)
288
289
### Traversal and Path Finding
290
291
Graph traversal framework providing programmatic path finding, relationship filtering, and bidirectional traversal with customizable evaluation criteria and path expansion strategies.
292
293
```java { .api }
294
interface TraversalDescription {
295
TraversalDescription relationships(RelationshipType relationshipType);
296
TraversalDescription depthFirst();
297
TraversalDescription breadthFirst();
298
Traverser traverse(Node startNode);
299
}
300
301
interface Traverser extends Iterable<Path> {
302
Iterable<Node> nodes();
303
Iterable<Relationship> relationships();
304
}
305
306
interface Path {
307
Node startNode();
308
Node endNode();
309
int length();
310
Iterable<Node> nodes();
311
Iterable<Relationship> relationships();
312
}
313
```
314
315
[Traversal](./traversal.md)
316
317
### Spatial Data Types
318
319
Geographic and geometric data support with point representations, coordinate systems, and spatial operations for location-aware graph applications.
320
321
```java { .api }
322
interface Point {
323
CRS getCRS();
324
List<Coordinate> getCoordinates();
325
int getDimension();
326
int getSRID();
327
}
328
329
interface CRS {
330
int getCode();
331
String getType();
332
Map<String, Object> getProperties();
333
}
334
335
interface Coordinate {
336
double getCoordinate();
337
}
338
```
339
340
[Spatial Data Types](./spatial.md)