Database Reference
In-Depth Information
Managing schema with Java API
In this section, you will learn about the various ways of performing CRUD operations over
indexes provided by schema using the Java API.
The following Java code creates the index on the Movie Label:
GraphDatabaseService graphDb = new GraphDatabaseFactory()
.newEmbeddedDatabase(DBLocation);
// Get the Schema from the Graph DB Service
Schema schema = graphDb.schema();
// Create Index on the provided Label and property
IndexDefinition indexDefinition =
schema.indexFor(DynamicLabel.label("Movie")).on("Title").create();
The following Java code fetches all indexes from the Neo4j database and prints them on
the console:
GraphDatabaseService graphDb = new GraphDatabaseFactory()
.newEmbeddedDatabase(DBLocation);
// Get the Schema from the Graph DB Service
Schema schema = graphDb.schema();
// Iterate through all Indexes and Print the Labels and
Properties
for (IndexDefinition inDef : schema.getIndexes()) {
System.out.println("Label = " + inDef.getLabel().name() +
", Property Keys = " + inDef.getPropertyKeys());
}
The following Java code deletes all the indexes on the Movie label:
GraphDatabaseService graphDb = new GraphDatabaseFactory()
.newEmbeddedDatabase(DBLocation);
// Get the Schema from the Graph DB Service
Schema schema = graphDb.schema();
// Iterate through all Indexes on a Label Movies and delete
them
for (IndexDefinition inDef :
schema.getIndexes(DynamicLabel.label("Movie"))) {
Search WWH ::




Custom Search