use of org.projectnessie.versioned.persist.adapter.DatabaseAdapter in project nessie by projectnessie.
the class DatabaseAdapterProvider method produceDatabaseAdapter.
@Produces
@Singleton
@Startup
public DatabaseAdapter produceDatabaseAdapter() {
VersionStoreType versionStoreType = storeConfig.getVersionStoreType();
LOGGER.info("Using {} Version store", versionStoreType);
TableCommitMetaStoreWorker storeWorker = new TableCommitMetaStoreWorker();
DatabaseAdapter databaseAdapter = databaseAdapterBuilder.select(new Literal(versionStoreType)).get().newDatabaseAdapter(new GenericContentVariantSupplier<>(storeWorker));
databaseAdapter.initializeRepo(serverConfig.getDefaultBranch());
if (storeConfig.isTracingEnabled()) {
databaseAdapter = new TracingDatabaseAdapter(databaseAdapter);
}
return databaseAdapter;
}
use of org.projectnessie.versioned.persist.adapter.DatabaseAdapter in project nessie by projectnessie.
the class ErrorTestService method unhandledExceptionInTvsStore.
/**
* Throws an exception depending on the parameter.
*
* @return nothing
* @see TestNessieError#unhandledRuntimeExceptionInStore()
* @see TestNessieError#backendThrottledExceptionInStore()
*/
@Path("unhandledExceptionInTvsStore/{exception}")
@GET
@Consumes(MediaType.APPLICATION_JSON)
public String unhandledExceptionInTvsStore(@PathParam("exception") String exception) throws ReferenceNotFoundException {
Exception ex;
switch(exception) {
case "runtime":
ex = new RuntimeException("Store.getValues-throwing");
break;
case "throttle":
ex = new BackendLimitExceededException("Store.getValues-throttled");
break;
default:
throw new IllegalArgumentException("test code error");
}
DatabaseAdapter databaseAdapter = Mockito.mock(DatabaseAdapter.class);
Mockito.when(databaseAdapter.namedRefs(Mockito.any())).thenThrow(ex);
PersistVersionStore<BaseContent, CommitMessage, BaseContent.Type> tvs = new PersistVersionStore<>(databaseAdapter, SimpleStoreWorker.INSTANCE);
try (Stream<ReferenceInfo<CommitMessage>> refs = tvs.getNamedRefs(GetNamedRefsParams.DEFAULT)) {
refs.forEach(ref -> {
});
}
return "we should not get here";
}
use of org.projectnessie.versioned.persist.adapter.DatabaseAdapter in project nessie by projectnessie.
the class DatabaseAdapterExtension method resolve.
private Object resolve(NessieDbAdapter nessieDbAdapter, AnnotatedElement annotatedElement, Class<?> type, ExtensionContext context, ParameterContext parameterContext, boolean canReinit, Consumer<DatabaseAdapter> newAdapter) {
StoreWorker<?, ?, ?> storeWorker = createStoreWorker(nessieDbAdapter);
DatabaseAdapter databaseAdapter = createAdapterResource(nessieDbAdapter, context, parameterContext, storeWorker);
if (nessieDbAdapter.withTracing()) {
databaseAdapter = new TracingDatabaseAdapter(databaseAdapter);
}
if (canReinit && nessieDbAdapter.initializeRepo()) {
reinit(databaseAdapter);
}
Object assign;
if (type.isAssignableFrom(DatabaseAdapter.class)) {
assign = databaseAdapter;
} else if (type.isAssignableFrom(VersionStore.class)) {
VersionStore<?, ?, ?> store = createStore(databaseAdapter, storeWorker);
if (nessieDbAdapter.withTracing()) {
store = new TracingVersionStore<>(store);
}
assign = store;
} else {
throw new IllegalStateException("Cannot assign to " + annotatedElement);
}
newAdapter.accept(databaseAdapter);
return assign;
}
Aggregations