Search in sources :

Example 6 with DatabaseManagementException

use of org.neo4j.dbms.api.DatabaseManagementException in project neo4j by neo4j.

the class DatabaseManagementServiceImpl method systemDatabaseExecute.

private void systemDatabaseExecute(String query, SystemDatabaseExecutionContext beforeCommitHook) {
    try {
        GraphDatabaseAPI database = (GraphDatabaseAPI) database(SYSTEM_DATABASE_NAME);
        try (InternalTransaction transaction = database.beginTransaction(KernelTransaction.Type.EXPLICIT, LoginContext.AUTH_DISABLED)) {
            transaction.execute(query);
            beforeCommitHook.accept(database, transaction);
            transaction.commit();
        }
    } catch (QueryExecutionException | KernelException e) {
        throw new DatabaseManagementException(e);
    }
}
Also used : QueryExecutionException(org.neo4j.graphdb.QueryExecutionException) DatabaseManagementException(org.neo4j.dbms.api.DatabaseManagementException) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) KernelException(org.neo4j.exceptions.KernelException)

Example 7 with DatabaseManagementException

use of org.neo4j.dbms.api.DatabaseManagementException in project neo4j by neo4j.

the class DefaultDatabaseManager method upgradeDatabase.

@Override
public synchronized void upgradeDatabase(NamedDatabaseId namedDatabaseId) throws DatabaseNotFoundException {
    StandaloneDatabaseContext context = getDatabaseContext(namedDatabaseId).orElseThrow(() -> new DatabaseNotFoundException("Database not found: " + namedDatabaseId));
    Database database = context.database();
    log.info("Upgrading '%s'.", namedDatabaseId);
    // Clear any failed state, e.g. due to format being too old on startup.
    context.fail(null);
    try {
        database.upgrade(true);
    } catch (Throwable throwable) {
        String message = "Failed to upgrade " + namedDatabaseId;
        context.fail(throwable);
        throw new DatabaseManagementException(message, throwable);
    }
}
Also used : DatabaseManagementException(org.neo4j.dbms.api.DatabaseManagementException) DatabaseNotFoundException(org.neo4j.dbms.api.DatabaseNotFoundException) Database(org.neo4j.kernel.database.Database)

Aggregations

DatabaseManagementException (org.neo4j.dbms.api.DatabaseManagementException)7 Database (org.neo4j.kernel.database.Database)3 NamedDatabaseId (org.neo4j.kernel.database.NamedDatabaseId)3 Test (org.junit.jupiter.api.Test)2 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)2 DatabaseNotFoundException (org.neo4j.dbms.api.DatabaseNotFoundException)1 KernelException (org.neo4j.exceptions.KernelException)1 QueryExecutionException (org.neo4j.graphdb.QueryExecutionException)1 GlobalModule (org.neo4j.graphdb.factory.module.GlobalModule)1 AbstractEditionModule (org.neo4j.graphdb.factory.module.edition.AbstractEditionModule)1 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)1 RecordStoreVersionCheck (org.neo4j.kernel.impl.storemigration.RecordStoreVersionCheck)1