Search in sources :

Example 1 with DatabaseNotFoundException

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

the class HttpTransactionManagerTest method newTransactionManager.

private static HttpTransactionManager newTransactionManager(DatabaseManagementService managementService, MemoryPool memoryPool) {
    JobScheduler jobScheduler = mock(JobScheduler.class);
    AssertableLogProvider logProvider = new AssertableLogProvider(true);
    var defaultDatabase = "neo4j";
    when(managementService.database(any(String.class))).thenAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        String db = (String) args[0];
        if (db.equals(defaultDatabase) || db.equals("system")) {
            return graphWithName(db);
        } else {
            throw new DatabaseNotFoundException("Not found db named " + db);
        }
    });
    return new HttpTransactionManager(managementService, memoryPool, jobScheduler, Clocks.systemClock(), Duration.ofMinutes(1), logProvider);
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) DatabaseNotFoundException(org.neo4j.dbms.api.DatabaseNotFoundException) AssertableLogProvider(org.neo4j.logging.AssertableLogProvider)

Example 2 with DatabaseNotFoundException

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

the class DefaultDatabaseManager method initialiseDefaultDatabase.

@Override
public void initialiseDefaultDatabase() {
    String databaseName = config.get(default_database);
    NamedDatabaseId namedDatabaseId = databaseIdRepository().getByName(databaseName).orElseThrow(() -> new DatabaseNotFoundException("Default database not found: " + databaseName));
    StandaloneDatabaseContext context = createDatabase(namedDatabaseId);
    if (manageDatabasesOnStartAndStop) {
        this.startDatabase(namedDatabaseId, context);
    }
}
Also used : DatabaseNotFoundException(org.neo4j.dbms.api.DatabaseNotFoundException) NamedDatabaseId(org.neo4j.kernel.database.NamedDatabaseId)

Example 3 with DatabaseNotFoundException

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

the class TestFabricDatabaseManagementServiceFactory method createManagementService.

@Override
protected DatabaseManagementService createManagementService(GlobalModule globalModule, LifeSupport globalLife, Log internalLog, DatabaseManager<?> databaseManager) {
    return new DatabaseManagementServiceImpl(databaseManager, globalModule.getGlobalAvailabilityGuard(), globalLife, globalModule.getDatabaseEventListeners(), globalModule.getTransactionEventListeners(), internalLog, globalModule.getGlobalConfig()) {

        @Override
        public GraphDatabaseService database(String name) throws DatabaseNotFoundException {
            BoltFabricDatabaseManagementService fabricBoltDbms = globalModule.getGlobalDependencies().resolveDependency(BoltFabricDatabaseManagementService.class);
            var baseDb = databaseManager.getDatabaseContext(name).orElseThrow(() -> new DatabaseNotFoundException(name)).databaseFacade();
            // Therefore the lookup of Bolt API representation of a database has to be done lazily.
            return new TestFabricGraphDatabaseService(baseDb, config, () -> {
                try {
                    return fabricBoltDbms.getDatabase(name, EmptyMemoryTracker.INSTANCE);
                } catch (UnavailableException e) {
                    throw new RuntimeException(e);
                }
            });
        }
    };
}
Also used : BoltFabricDatabaseManagementService(org.neo4j.fabric.bolt.BoltFabricDatabaseManagementService) DatabaseManagementServiceImpl(org.neo4j.dbms.database.DatabaseManagementServiceImpl) DatabaseNotFoundException(org.neo4j.dbms.api.DatabaseNotFoundException) UnavailableException(org.neo4j.kernel.availability.UnavailableException)

Example 4 with DatabaseNotFoundException

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

the class FabricDatabaseManager method getDatabase.

public GraphDatabaseFacade getDatabase(String databaseNameRaw) throws UnavailableException {
    var databaseContext = databaseIdRepository.getByName(databaseNameRaw).flatMap(databaseManager::getDatabaseContext).orElseThrow(() -> new DatabaseNotFoundException("Database " + databaseNameRaw + " not found"));
    databaseContext.database().getDatabaseAvailabilityGuard().assertDatabaseAvailable();
    return databaseContext.databaseFacade();
}
Also used : DatabaseNotFoundException(org.neo4j.dbms.api.DatabaseNotFoundException)

Example 5 with DatabaseNotFoundException

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

the class SystemDbDatabaseIdRepository method get.

// Run on another thread to avoid running in an enclosing transaction on a different database
private Optional<NamedDatabaseId> get(String propertyKey, String propertyValue) {
    var context = databaseManager.getDatabaseContext(NAMED_SYSTEM_DATABASE_ID).orElseThrow(() -> new DatabaseNotFoundException(GraphDatabaseSettings.SYSTEM_DATABASE_NAME));
    var db = context.databaseFacade();
    try (var tx = db.beginTx()) {
        var node = tx.findNode(DATABASE_LABEL, propertyKey, propertyValue);
        if (node == null) {
            return Optional.empty();
        }
        var databaseName = getPropertyOnNode(node, DATABASE_NAME_PROPERTY, propertyValue);
        var databaseUuid = getPropertyOnNode(node, DATABASE_UUID_PROPERTY, propertyValue);
        return Optional.of(new NamedDatabaseId(databaseName, UUID.fromString(databaseUuid)));
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DatabaseNotFoundException(org.neo4j.dbms.api.DatabaseNotFoundException) CompletionException(java.util.concurrent.CompletionException) DatabaseNotFoundException(org.neo4j.dbms.api.DatabaseNotFoundException)

Aggregations

DatabaseNotFoundException (org.neo4j.dbms.api.DatabaseNotFoundException)7 CompletionException (java.util.concurrent.CompletionException)1 Test (org.junit.jupiter.api.Test)1 BoltIOException (org.neo4j.bolt.messaging.BoltIOException)1 TransactionStateMachineSPIProvider (org.neo4j.bolt.runtime.statemachine.TransactionStateMachineSPIProvider)1 DatabaseManagementException (org.neo4j.dbms.api.DatabaseManagementException)1 DatabaseManagementService (org.neo4j.dbms.api.DatabaseManagementService)1 DatabaseManagementServiceImpl (org.neo4j.dbms.database.DatabaseManagementServiceImpl)1 BoltFabricDatabaseManagementService (org.neo4j.fabric.bolt.BoltFabricDatabaseManagementService)1 UnavailableException (org.neo4j.kernel.availability.UnavailableException)1 Database (org.neo4j.kernel.database.Database)1 NamedDatabaseId (org.neo4j.kernel.database.NamedDatabaseId)1 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)1 JobScheduler (org.neo4j.scheduler.JobScheduler)1