CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-neo4j--neo4j

Neo4j Community Edition - The world's leading Graph Database with Cypher query language and ACID transactions.

Pending
Overview
Eval results
Files

database-management.mddocs/

Database Management

Core database lifecycle management functionality providing the foundational services for creating, managing, and controlling Neo4j database instances with full multi-database support.

Capabilities

Database Management Service Builder

Primary builder for creating Neo4j database management services with comprehensive configuration options and event listener support.

/**
 * Builder for creating DatabaseManagementService instances with configuration
 * @param databaseDirectory - Path to the database directory
 */
public final class DatabaseManagementServiceBuilder 
    implements Neo4jDatabaseManagementServiceBuilder {
    
    /**
     * Create a new builder for the specified database directory
     * @param databaseDirectory Path where database files will be stored
     */
    public DatabaseManagementServiceBuilder(Path databaseDirectory);
    
    /**
     * Set a configuration setting with type safety
     * @param setting The configuration setting to set
     * @param value The value for the setting
     * @return This builder for method chaining
     */
    public <T> DatabaseManagementServiceBuilder setConfig(Setting<T> setting, T value);
    
    /**
     * Load configuration from a properties file
     * @param path Path to the properties file
     * @return This builder for method chaining
     */
    public DatabaseManagementServiceBuilder loadPropertiesFromFile(Path path);
    
    /**
     * Set configuration from a map
     * @param config Map of settings to values
     * @return This builder for method chaining
     */
    public DatabaseManagementServiceBuilder setConfig(
        Map<Setting<?>, Object> config);
    
    /**
     * Set a custom log provider for user-level logging
     * @param userLogProvider The log provider to use
     * @return This builder for method chaining
     */
    public DatabaseManagementServiceBuilder setUserLogProvider(LogProvider userLogProvider);
    
    /**
     * Add a database event listener
     * @param listener The listener to add
     * @return This builder for method chaining
     */
    public DatabaseManagementServiceBuilder addDatabaseListener(
        DatabaseEventListener listener);
    
    /**
     * Build the database management service
     * @return Configured DatabaseManagementService instance
     */
    public DatabaseManagementService build();
}

Usage Examples:

import org.neo4j.dbms.api.DatabaseManagementService;
import org.neo4j.dbms.api.DatabaseManagementServiceBuilder;
import org.neo4j.configuration.GraphDatabaseSettings;
import java.nio.file.Paths;
import java.time.Duration;

// Basic database service creation
DatabaseManagementService service = new DatabaseManagementServiceBuilder(
    Paths.get("/path/to/database"))
    .build();

// Advanced configuration
DatabaseManagementService service = new DatabaseManagementServiceBuilder(
    Paths.get("/path/to/database"))
    .setConfig(GraphDatabaseSettings.transaction_timeout, Duration.ofMinutes(5))
    .setConfig(GraphDatabaseSettings.data_directory, Paths.get("/custom/data"))
    .loadPropertiesFromFile(Paths.get("/path/to/neo4j.conf"))
    .addDatabaseListener(new MyDatabaseEventListener())
    .build();

Database Management Service

Interface for managing databases and providing access to managed database services with full multi-database support and lifecycle control.

/**
 * Service for managing multiple databases within a Neo4j instance
 */
public interface DatabaseManagementService extends AutoCloseable {
    
    /**
     * Get access to a specific database by name
     * @param databaseName Name of the database (e.g., "neo4j", "system")
     * @return GraphDatabaseService instance for the specified database
     * @throws DatabaseNotFoundException if database doesn't exist
     */
    GraphDatabaseService database(String databaseName);
    
    /**
     * Create a new database with the specified name
     * @param databaseName Name for the new database
     * @throws DatabaseAlreadyExistsException if database already exists
     */
    void createDatabase(String databaseName);
    
    /**
     * Create a new database with specific configuration
     * @param databaseName Name for the new database
     * @param databaseSpecificSettings Database-specific configuration
     * @throws DatabaseAlreadyExistsException if database already exists
     */
    void createDatabase(String databaseName, Configuration databaseSpecificSettings);
    
    /**
     * Delete an existing database
     * @param databaseName Name of the database to drop
     * @throws DatabaseNotFoundException if database doesn't exist
     * @throws DatabaseAliasExistsException if database has aliases that prevent dropping
     */
    void dropDatabase(String databaseName);
    
    /**
     * Start a stopped database
     * @param databaseName Name of the database to start
     */
    void startDatabase(String databaseName);
    
    /**
     * Stop a running database
     * @param databaseName Name of the database to shutdown
     */
    void shutdownDatabase(String databaseName);
    
    /**
     * List all available databases
     * @return List of database names
     */
    List<String> listDatabases();
    
    /**
     * Shutdown the entire database management service
     * This will shutdown all managed databases
     */
    void shutdown();
    
    /**
     * Close the database management service (same as shutdown)
     */
    @Override
    void close();
    
    /**
     * Register a database event listener
     * @param listener Database event listener to register
     */
    void registerDatabaseEventListener(DatabaseEventListener listener);
    
    /**
     * Unregister a database event listener
     * @param listener Database event listener to unregister
     */
    void unregisterDatabaseEventListener(DatabaseEventListener listener);
    
    /**
     * Register a transaction event listener for a specific database
     * @param databaseName Name of the database
     * @param listener Transaction event listener to register
     */
    void registerTransactionEventListener(String databaseName, TransactionEventListener<?> listener);
    
    /**
     * Unregister a transaction event listener for a specific database
     * @param databaseName Name of the database
     * @param listener Transaction event listener to unregister
     */
    void unregisterTransactionEventListener(String databaseName, TransactionEventListener<?> listener);
}

Usage Examples:

// Database lifecycle management
DatabaseManagementService managementService = new DatabaseManagementServiceBuilder(dbPath)
    .build();

// Create and manage multiple databases
managementService.createDatabase("userdata");
managementService.createDatabase("analytics");

// List all databases
List<String> databases = managementService.listDatabases();
System.out.println("Available databases: " + databases);

// Get access to specific databases
GraphDatabaseService mainDb = managementService.database("neo4j");
GraphDatabaseService userData = managementService.database("userdata");

// Stop and start databases
managementService.shutdownDatabase("analytics");
managementService.startDatabase("analytics");

// Cleanup
managementService.shutdown();

Database Event Context

Context information provided to database event listeners containing metadata about database operations.

/**
 * Context information for database lifecycle events
 */
public interface DatabaseEventContext {
    /**
     * Get the name of the database involved in the event
     * @return Database name
     */
    String getDatabaseName();
    
    /**
     * Get additional metadata about the event
     * @return Event metadata map
     */
    Map<String, Object> getEventData();
}

Exception Handling

Common exceptions thrown during database management operations.

/**
 * Thrown when attempting to access a database that doesn't exist
 */
public class DatabaseNotFoundException extends RuntimeException {
    public DatabaseNotFoundException(String message);
}

/**
 * Thrown when attempting to create a database that already exists
 */
public class DatabaseAlreadyExistsException extends RuntimeException {
    public DatabaseAlreadyExistsException(String message);
}

/**
 * Thrown when a database operation fails
 */
public class DatabaseManagementException extends RuntimeException {
    public DatabaseManagementException(String message, Throwable cause);
}

/**
 * Thrown when attempting to drop a database that has aliases
 */
public class DatabaseAliasExistsException extends RuntimeException {
    public DatabaseAliasExistsException(String message);
}

/**
 * Configuration settings for database creation
 */
public interface Configuration {
    /**
     * Get a configuration value
     * @param setting Setting to get value for
     * @return Configuration value
     */
    <T> T get(Setting<T> setting);
    
    /**
     * Create a configuration from a map of settings
     * @param settings Map of settings to values
     * @return Configuration instance
     */
    static Configuration from(Map<Setting<?>, Object> settings) {
        // Implementation
    }
}

Error Handling Example:

try {
    GraphDatabaseService db = managementService.database("nonexistent");
} catch (DatabaseNotFoundException e) {
    System.err.println("Database not found: " + e.getMessage());
    // Handle missing database
}

try {
    managementService.createDatabase("neo4j"); // Default database already exists
} catch (DatabaseAlreadyExistsException e) {
    System.err.println("Database already exists: " + e.getMessage());
    // Handle duplicate database creation
}

Install with Tessl CLI

npx tessl i tessl/maven-org-neo4j--neo4j

docs

configuration.md

database-management.md

events.md

graph-database.md

graph-model.md

index.md

procedures.md

query-execution.md

schema.md

spatial.md

traversal.md

tile.json