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);
}
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);
}
}
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);
}
});
}
};
}
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();
}
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);
}
}
Aggregations