Search in sources :

Example 1 with DatabaseAdapter

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;
}
Also used : TracingDatabaseAdapter(org.projectnessie.versioned.persist.adapter.spi.TracingDatabaseAdapter) VersionStoreType(org.projectnessie.quarkus.config.VersionStoreConfig.VersionStoreType) TableCommitMetaStoreWorker(org.projectnessie.server.store.TableCommitMetaStoreWorker) Literal(org.projectnessie.quarkus.providers.StoreType.Literal) TracingDatabaseAdapter(org.projectnessie.versioned.persist.adapter.spi.TracingDatabaseAdapter) DatabaseAdapter(org.projectnessie.versioned.persist.adapter.DatabaseAdapter) Produces(javax.enterprise.inject.Produces) Singleton(javax.inject.Singleton) Startup(io.quarkus.runtime.Startup)

Example 2 with 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";
}
Also used : PersistVersionStore(org.projectnessie.versioned.persist.store.PersistVersionStore) MediaType(javax.ws.rs.core.MediaType) CommitMessage(org.projectnessie.versioned.testworker.CommitMessage) BackendLimitExceededException(org.projectnessie.versioned.BackendLimitExceededException) BaseContent(org.projectnessie.versioned.testworker.BaseContent) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) BackendLimitExceededException(org.projectnessie.versioned.BackendLimitExceededException) ConstraintDefinitionException(javax.validation.ConstraintDefinitionException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) ConstraintDeclarationException(javax.validation.ConstraintDeclarationException) GroupDefinitionException(javax.validation.GroupDefinitionException) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) DatabaseAdapter(org.projectnessie.versioned.persist.adapter.DatabaseAdapter) ReferenceInfo(org.projectnessie.versioned.ReferenceInfo) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) GET(javax.ws.rs.GET)

Example 3 with DatabaseAdapter

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;
}
Also used : TracingDatabaseAdapter(org.projectnessie.versioned.persist.adapter.spi.TracingDatabaseAdapter) TracingVersionStore(org.projectnessie.versioned.TracingVersionStore) TracingDatabaseAdapter(org.projectnessie.versioned.persist.adapter.spi.TracingDatabaseAdapter) DatabaseAdapter(org.projectnessie.versioned.persist.adapter.DatabaseAdapter) VersionStore(org.projectnessie.versioned.VersionStore) PersistVersionStore(org.projectnessie.versioned.persist.store.PersistVersionStore) TracingVersionStore(org.projectnessie.versioned.TracingVersionStore)

Aggregations

DatabaseAdapter (org.projectnessie.versioned.persist.adapter.DatabaseAdapter)3 TracingDatabaseAdapter (org.projectnessie.versioned.persist.adapter.spi.TracingDatabaseAdapter)2 PersistVersionStore (org.projectnessie.versioned.persist.store.PersistVersionStore)2 Startup (io.quarkus.runtime.Startup)1 Produces (javax.enterprise.inject.Produces)1 Singleton (javax.inject.Singleton)1 ConstraintDeclarationException (javax.validation.ConstraintDeclarationException)1 ConstraintDefinitionException (javax.validation.ConstraintDefinitionException)1 GroupDefinitionException (javax.validation.GroupDefinitionException)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 MediaType (javax.ws.rs.core.MediaType)1 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)1 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)1 VersionStoreType (org.projectnessie.quarkus.config.VersionStoreConfig.VersionStoreType)1 Literal (org.projectnessie.quarkus.providers.StoreType.Literal)1 TableCommitMetaStoreWorker (org.projectnessie.server.store.TableCommitMetaStoreWorker)1 BackendLimitExceededException (org.projectnessie.versioned.BackendLimitExceededException)1 ReferenceInfo (org.projectnessie.versioned.ReferenceInfo)1