Search in sources :

Example 1 with JpaPersistModule

use of com.google.inject.persist.jpa.JpaPersistModule in project che by eclipse.

the class JpaTckModule method configure.

@Override
protected void configure() {
    install(new JpaPersistModule("main"));
    bind(DBInitializer.class).asEagerSingleton();
    bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(H2TestHelper.inMemoryDefault(), "che-schema"));
    bind(TckResourcesCleaner.class).to(H2JpaCleaner.class);
    bind(new TypeLiteral<TckRepository<RecipeImpl>>() {
    }).toInstance(new JpaTckRepository<>(RecipeImpl.class));
    bind(new TypeLiteral<TckRepository<SnapshotImpl>>() {
    }).toInstance(new JpaTckRepository<>(SnapshotImpl.class));
    bind(new TypeLiteral<TckRepository<Workspace>>() {
    }).toInstance(new TestWorkspacesTckRepository());
    bind(new TypeLiteral<TckRepository<AccountImpl>>() {
    }).toInstance(new JpaTckRepository<>(AccountImpl.class));
    bind(RecipeDao.class).to(JpaRecipeDao.class);
    bind(SnapshotDao.class).to(JpaSnapshotDao.class);
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) SnapshotImpl(org.eclipse.che.api.machine.server.model.impl.SnapshotImpl) AccountImpl(org.eclipse.che.account.spi.AccountImpl) JpaPersistModule(com.google.inject.persist.jpa.JpaPersistModule) SchemaInitializer(org.eclipse.che.core.db.schema.SchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) SnapshotDao(org.eclipse.che.api.machine.server.spi.SnapshotDao) TypeLiteral(com.google.inject.TypeLiteral) DBInitializer(org.eclipse.che.core.db.DBInitializer) RecipeDao(org.eclipse.che.api.machine.server.spi.RecipeDao) RecipeImpl(org.eclipse.che.api.machine.server.recipe.RecipeImpl) Workspace(org.eclipse.che.api.core.model.workspace.Workspace)

Example 2 with JpaPersistModule

use of com.google.inject.persist.jpa.JpaPersistModule in project roboguice by roboguice.

the class EdslTest method testModuleConfigUsingJpa.

public void testModuleConfigUsingJpa() throws Exception {
    Logger.getLogger(getClass().getName()).info("Starting EDSL test.");
    Guice.createInjector(Stage.PRODUCTION, new AbstractModule() {

        @Override
        protected void configure() {
            install(new JpaPersistModule("myunit"));
            binder().requireExplicitBindings();
        }
    });
    Logger.getLogger(getClass().getName()).info("Completed EDSL test.");
}
Also used : JpaPersistModule(com.google.inject.persist.jpa.JpaPersistModule) AbstractModule(com.google.inject.AbstractModule)

Example 3 with JpaPersistModule

use of com.google.inject.persist.jpa.JpaPersistModule in project metacat by Netflix.

the class S3ConnectorFactory method init.

private void init() {
    //JPA module
    final Map<String, Object> props = Maps.newHashMap(configuration);
    props.put("hibernate.connection.datasource", DataSourceManager.get().load(name, configuration).get(name));
    final Module jpaModule = new JpaPersistModule("s3").properties(props);
    final Module s3Module = new S3Module(name, configuration, infoConverter);
    final Injector injector = Guice.createInjector(jpaModule, s3Module);
    persistService = injector.getInstance(PersistService.class);
    persistService.start();
    this.databaseService = injector.getInstance(ConnectorDatabaseService.class);
    this.tableService = injector.getInstance(ConnectorTableService.class);
    this.partitionService = injector.getInstance(ConnectorPartitionService.class);
}
Also used : ConnectorDatabaseService(com.netflix.metacat.common.server.connectors.ConnectorDatabaseService) ConnectorTableService(com.netflix.metacat.common.server.connectors.ConnectorTableService) Injector(com.google.inject.Injector) ConnectorPartitionService(com.netflix.metacat.common.server.connectors.ConnectorPartitionService) PersistService(com.google.inject.persist.PersistService) Module(com.google.inject.Module) JpaPersistModule(com.google.inject.persist.jpa.JpaPersistModule) JpaPersistModule(com.google.inject.persist.jpa.JpaPersistModule)

Example 4 with JpaPersistModule

use of com.google.inject.persist.jpa.JpaPersistModule in project guice by google.

the class EdslTest method testModuleConfigUsingJpa.

public void testModuleConfigUsingJpa() throws Exception {
    Logger.getLogger(getClass().getName()).info("Starting EDSL test.");
    Guice.createInjector(Stage.PRODUCTION, new AbstractModule() {

        @Override
        protected void configure() {
            install(new JpaPersistModule("myunit"));
            binder().requireExplicitBindings();
        }
    });
    Logger.getLogger(getClass().getName()).info("Completed EDSL test.");
}
Also used : JpaPersistModule(com.google.inject.persist.jpa.JpaPersistModule) AbstractModule(com.google.inject.AbstractModule)

Example 5 with JpaPersistModule

use of com.google.inject.persist.jpa.JpaPersistModule in project ninja by ninjaframework.

the class JpaModule method configure.

@Override
protected void configure() {
    ///////////////////////////////////////////////////////////////
    // only start up Jpa when it is configured in application.conf
    ///////////////////////////////////////////////////////////////
    String persistenceUnitName = ninjaProperties.get(NinjaConstant.PERSISTENCE_UNIT_NAME);
    if (persistenceUnitName != null) {
        // Get the connection credentials from application.conf
        String connectionUrl = ninjaProperties.get(NinjaConstant.DB_CONNECTION_URL);
        String connectionUsername = ninjaProperties.get(NinjaConstant.DB_CONNECTION_USERNAME);
        String connectionPassword = ninjaProperties.get(NinjaConstant.DB_CONNECTION_PASSWORD);
        Properties jpaProperties = new Properties();
        // via system properties:
        if (connectionUrl != null) {
            jpaProperties.put("hibernate.connection.url", connectionUrl);
        }
        if (connectionUsername != null) {
            jpaProperties.put("hibernate.connection.username", connectionUsername);
        }
        if (connectionPassword != null) {
            jpaProperties.put("hibernate.connection.password", connectionPassword);
        }
        // Now - it may be the case the neither connection.url, connection.username nor
        // connection.password is set. But this may be okay e.g. when using JDNI to
        // configure your datasources...
        install(new JpaPersistModule(persistenceUnitName).properties(jpaProperties));
        UnitOfWorkInterceptor unitOfWorkInterceptor = new UnitOfWorkInterceptor();
        requestInjection(unitOfWorkInterceptor);
        // class-level @UnitOfWork
        bindInterceptor(annotatedWith(UnitOfWork.class), any(), unitOfWorkInterceptor);
        // method-level @UnitOfWork
        bindInterceptor(any(), annotatedWith(UnitOfWork.class), unitOfWorkInterceptor);
        bind(JpaInitializer.class).asEagerSingleton();
    }
}
Also used : Properties(java.util.Properties) NinjaProperties(ninja.utils.NinjaProperties) JpaPersistModule(com.google.inject.persist.jpa.JpaPersistModule)

Aggregations

JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)5 AbstractModule (com.google.inject.AbstractModule)2 Injector (com.google.inject.Injector)1 Module (com.google.inject.Module)1 TypeLiteral (com.google.inject.TypeLiteral)1 PersistService (com.google.inject.persist.PersistService)1 ConnectorDatabaseService (com.netflix.metacat.common.server.connectors.ConnectorDatabaseService)1 ConnectorPartitionService (com.netflix.metacat.common.server.connectors.ConnectorPartitionService)1 ConnectorTableService (com.netflix.metacat.common.server.connectors.ConnectorTableService)1 Properties (java.util.Properties)1 NinjaProperties (ninja.utils.NinjaProperties)1 AccountImpl (org.eclipse.che.account.spi.AccountImpl)1 Workspace (org.eclipse.che.api.core.model.workspace.Workspace)1 SnapshotImpl (org.eclipse.che.api.machine.server.model.impl.SnapshotImpl)1 RecipeImpl (org.eclipse.che.api.machine.server.recipe.RecipeImpl)1 RecipeDao (org.eclipse.che.api.machine.server.spi.RecipeDao)1 SnapshotDao (org.eclipse.che.api.machine.server.spi.SnapshotDao)1 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)1 DBInitializer (org.eclipse.che.core.db.DBInitializer)1 SchemaInitializer (org.eclipse.che.core.db.schema.SchemaInitializer)1