com.google.inject.persist.jpa.JpaPersistModule Java Examples

The following examples show how to use com.google.inject.persist.jpa.JpaPersistModule. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfigurationModule.java    From J-Kinopoisk2IMDB with Apache License 2.0 6 votes vote down vote up
protected void bindJPAPersistModule() {
    JpaPersistModule jpa = new JpaPersistModule("K2IDB");

    Config dbConfig = config.getConfig("db");

    Properties properties = new Properties();
    properties.put("javax.persistence.jdbc.driver", dbConfig.getString("driver"));
    properties.put("javax.persistence.jdbc.url", dbConfig.getString("url"));
    properties.put("javax.persistence.jdbc.user", dbConfig.getString("user"));
    properties.put("javax.persistence.jdbc.password", dbConfig.getString("password"));

    dbConfig.getObject("additional").entrySet()
            .forEach(e -> properties.put(e.getKey(), (String) e.getValue().unwrapped()));

    jpa.properties(properties);
    install(jpa);
}
 
Example #2
Source File: ResourceTckModule.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void configure() {
  install(new JpaPersistModule("main"));
  H2DBTestServer server = H2DBTestServer.startDefault();
  bind(SchemaInitializer.class)
      .toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
  bind(DBInitializer.class).asEagerSingleton();
  bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));

  bind(new TypeLiteral<TckRepository<FreeResourcesLimitImpl>>() {})
      .toInstance(new JpaTckRepository<>(FreeResourcesLimitImpl.class));
  bind(new TypeLiteral<TckRepository<AccountImpl>>() {})
      .toInstance(new JpaTckRepository<>(AccountImpl.class));

  bind(FreeResourcesLimitDao.class).to(JpaFreeResourcesLimitDao.class);
}
 
Example #3
Source File: OrganizationJpaTckModule.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void configure() {
  install(new JpaPersistModule("main"));
  H2DBTestServer server = H2DBTestServer.startDefault();
  bind(SchemaInitializer.class)
      .toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
  bind(DBInitializer.class).asEagerSingleton();
  bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));

  bind(new TypeLiteral<AbstractPermissionsDomain<MemberImpl>>() {}).to(OrganizationDomain.class);

  bind(new TypeLiteral<TckRepository<OrganizationImpl>>() {})
      .to(JpaOrganizationImplTckRepository.class);
  bind(new TypeLiteral<TckRepository<UserImpl>>() {})
      .toInstance(new JpaTckRepository<>(UserImpl.class));
  bind(new TypeLiteral<TckRepository<MemberImpl>>() {})
      .toInstance(new JpaTckRepository<>(MemberImpl.class));
  bind(new TypeLiteral<TckRepository<OrganizationDistributedResourcesImpl>>() {})
      .toInstance(new JpaTckRepository<>(OrganizationDistributedResourcesImpl.class));

  bind(OrganizationDao.class).to(JpaOrganizationDao.class);
  bind(MemberDao.class).to(JpaMemberDao.class);

  bind(OrganizationDistributedResourcesDao.class)
      .to(JpaOrganizationDistributedResourcesDao.class);
}
 
Example #4
Source File: GlobalDiscoveryEntryPersistedStorePersistedTest.java    From joynr with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {

    Injector injector = Guice.createInjector(new JpaPersistModule("CapabilitiesDirectory"), new AbstractModule() {
        @Override
        protected void configure() {
            bind(String.class).annotatedWith(Names.named(PROPERTY_DISCOVERY_PROVIDER_DEFAULT_EXPIRY_TIME_MS))
                              .toInstance(String.valueOf(DEFAULT_EXPIRY_INTERVAL_MS));
            bind(CapabilitiesProvisioning.class).to(DefaultCapabilitiesProvisioning.class);
            requestStaticInjection(CapabilityUtils.class, RoutingTypesUtil.class);
        }
    });
    service = injector.getInstance(PersistService.class);
    store = injector.getInstance(GlobalDiscoveryEntryPersistedStorePersisted.class);
    entityManager = injector.getInstance(EntityManager.class);
}
 
Example #5
Source File: S3ConnectorFactory.java    From metacat with Apache License 2.0 5 votes vote down vote up
private void init() {
    //JPA module
    final Map<String, Object> props = Maps.newHashMap(configuration);
    props.put("hibernate.connection.datasource",
        DataSourceManager.get().load(catalogShardName, configuration).get(catalogShardName));
    final Module jpaModule = new JpaPersistModule("s3").properties(props);
    final Module s3Module = new S3Module(catalogName, 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);
}
 
Example #6
Source File: AdminUserCreatorTest.java    From codenvy with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void configure() {
  install(new InitModule(PostConstruct.class));
  install(new JpaPersistModule("test"));
  bind(SchemaInitializer.class)
      .toInstance(
          new FlywaySchemaInitializer(inMemoryDefault(), "che-schema", "codenvy-schema"));
  bind(DBInitializer.class).asEagerSingleton();
  bindConstant().annotatedWith(Names.named("codenvy.admin.name")).to(NAME);
  bindConstant().annotatedWith(Names.named("codenvy.admin.initial_password")).to(PASSWORD);
  bindConstant().annotatedWith(Names.named("codenvy.admin.email")).to(EMAIL);
  bind(PermissionsManager.class).toInstance(permissionsManager);
  bind(UserManager.class).toInstance(mock(UserManager.class));
}
 
Example #7
Source File: JpaIntegrationTckModule.java    From codenvy with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void configure() {
  final Map<String, String> properties = new HashMap<>();
  properties.put(TRANSACTION_TYPE, PersistenceUnitTransactionType.RESOURCE_LOCAL.name());

  final String dbUrl = System.getProperty("jdbc.url");
  final String dbUser = System.getProperty("jdbc.user");
  final String dbPassword = System.getProperty("jdbc.password");

  waitConnectionIsEstablished(dbUrl, dbUser, dbPassword);

  properties.put(JDBC_URL, dbUrl);
  properties.put(JDBC_USER, dbUser);
  properties.put(JDBC_PASSWORD, dbPassword);
  properties.put(JDBC_DRIVER, System.getProperty("jdbc.driver"));

  JpaPersistModule main = new JpaPersistModule("main");
  main.properties(properties);
  install(main);
  final PGSimpleDataSource dataSource = new PGSimpleDataSource();
  dataSource.setUser(dbUser);
  dataSource.setPassword(dbPassword);
  dataSource.setUrl(dbUrl);
  bind(SchemaInitializer.class)
      .toInstance(new FlywaySchemaInitializer(dataSource, "che-schema", "codenvy-schema"));
  bind(DBInitializer.class).asEagerSingleton();
  bind(TckResourcesCleaner.class).to(JpaCleaner.class);

  bind(new TypeLiteral<TckRepository<InviteImpl>>() {})
      .toInstance(new JpaTckRepository<>(InviteImpl.class));
  bind(new TypeLiteral<TckRepository<OrganizationImpl>>() {})
      .toInstance(new JpaTckRepository<>(OrganizationImpl.class));
  bind(new TypeLiteral<TckRepository<WorkspaceImpl>>() {})
      .toInstance(new JpaTckRepository<>(WorkspaceImpl.class));

  bind(InviteDao.class).to(JpaInviteDao.class);
}
 
Example #8
Source File: PersistTestModuleBuilder.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void configure() {
  try {
    savePersistenceXml();
  } catch (Exception x) {
    throw new RuntimeException(x.getMessage());
  }
  install(new JpaPersistModule(persistenceUnit));
}
 
Example #9
Source File: CapabilitiesDirectoryLauncher.java    From joynr with Apache License 2.0 5 votes vote down vote up
private static Module getRuntimeModule(Properties joynrConfig) {
    joynrConfig.put("joynr.messaging.mqtt.brokerUri", "tcp://localhost:1883");
    joynrConfig.put(MessagingPropertyKeys.PROPERTY_MESSAGING_PRIMARYGLOBALTRANSPORT, "mqtt");

    Properties userProperties = new Properties();
    userProperties.putAll(System.getenv());
    userProperties.putAll(PropertyLoader.getPropertiesWithPattern(System.getProperties(),
                                                                  "^" + CapabilitiesDirectoryImpl.PROPERTY_PREFIX
                                                                          + ".*$"));
    String gcdGbid = PropertyLoader.getPropertiesWithPattern(userProperties, CapabilitiesDirectoryImpl.GCD_GBID)
                                   .getProperty(CapabilitiesDirectoryImpl.GCD_GBID);
    if (gcdGbid == null || gcdGbid.isEmpty()) {
        gcdGbid = GcdUtilities.loadDefaultGbidsFromDefaultMessagingProperties()[0];
    }
    joynrConfig.put(CapabilitiesDirectoryImpl.GCD_GBID, gcdGbid);

    String validGbidsString = PropertyLoader.getPropertiesWithPattern(userProperties,
                                                                      CapabilitiesDirectoryImpl.VALID_GBIDS)
                                            .getProperty(CapabilitiesDirectoryImpl.VALID_GBIDS);
    if (validGbidsString == null || validGbidsString.isEmpty()) {
        validGbidsString = gcdGbid;
    }
    joynrConfig.put(CapabilitiesDirectoryImpl.VALID_GBIDS, validGbidsString);

    return Modules.override(new JpaPersistModule("CapabilitiesDirectory"), new CCInProcessRuntimeModule())
                  .with(new HivemqMqttClientModule(), new CapabilitiesDirectoryModule());
}
 
Example #10
Source File: JdbcModule.java    From joynr with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {
    install(new JpaPersistModule(BPC_PERSISTENCE_UNIT_NAME));

    bind(BounceProxyDirectory.class).to(BounceProxyDatabase.class);
    bind(ChannelDirectory.class).to(ChannelDatabase.class);
}
 
Example #11
Source File: MultiuserMySqlTckModule.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void configure() {

  final Map<String, String> properties = new HashMap<>();
  properties.put(TRANSACTION_TYPE, PersistenceUnitTransactionType.RESOURCE_LOCAL.name());

  final String dbUrl = System.getProperty("jdbc.url");
  final String dbUser = System.getProperty("jdbc.user");
  final String dbPassword = System.getProperty("jdbc.password");

  waitConnectionIsEstablished(dbUrl, dbUser, dbPassword);

  properties.put(JDBC_URL, dbUrl);
  properties.put(JDBC_USER, dbUser);
  properties.put(JDBC_PASSWORD, dbPassword);
  properties.put(JDBC_DRIVER, System.getProperty("jdbc.driver"));

  JpaPersistModule main = new JpaPersistModule("main");
  main.properties(properties);
  install(main);
  final com.mysql.cj.jdbc.MysqlDataSource dataSource = new com.mysql.cj.jdbc.MysqlDataSource();
  dataSource.setUser(dbUser);
  dataSource.setPassword(dbPassword);
  dataSource.setUrl(dbUrl);
  bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(dataSource, "che-schema"));
  bind(DBInitializer.class).asEagerSingleton();
  bind(TckResourcesCleaner.class).to(JpaCleaner.class);

  // repositories
  // api-account
  bind(new TypeLiteral<TckRepository<AccountImpl>>() {})
      .toInstance(new JpaTckRepository<>(AccountImpl.class));
  // api-user
  bind(new TypeLiteral<TckRepository<UserImpl>>() {}).to(UserJpaTckRepository.class);

  // api-workspace
  bind(new TypeLiteral<TckRepository<WorkspaceImpl>>() {})
      .toInstance(new JpaTckRepository<>(WorkspaceImpl.class));
  bind(new TypeLiteral<TckRepository<WorkerImpl>>() {})
      .toInstance(new JpaTckRepository<>(WorkerImpl.class));

  // api permission
  bind(new TypeLiteral<TckRepository<SystemPermissionsImpl>>() {})
      .toInstance(new JpaTckRepository<>(SystemPermissionsImpl.class));

  bind(new TypeLiteral<PermissionsDao<SystemPermissionsImpl>>() {})
      .to(JpaSystemPermissionsDao.class);

  bind(new TypeLiteral<AbstractPermissionsDomain<WorkerImpl>>() {})
      .to(WorkerDaoTest.TestDomain.class);
  bind(new TypeLiteral<AbstractPermissionsDomain<SystemPermissionsImpl>>() {})
      .to(SystemPermissionsDaoTest.TestDomain.class);

  // api-organization
  bind(new TypeLiteral<TckRepository<OrganizationImpl>>() {})
      .to(JpaOrganizationImplTckRepository.class);
  bind(new TypeLiteral<TckRepository<MemberImpl>>() {})
      .toInstance(new JpaTckRepository<>(MemberImpl.class));
  bind(new TypeLiteral<TckRepository<OrganizationDistributedResourcesImpl>>() {})
      .toInstance(new JpaTckRepository<>(OrganizationDistributedResourcesImpl.class));

  // api-resource
  bind(new TypeLiteral<TckRepository<FreeResourcesLimitImpl>>() {})
      .toInstance(new JpaTckRepository<>(FreeResourcesLimitImpl.class));

  // machine token keys
  bind(new TypeLiteral<TckRepository<SignatureKeyPairImpl>>() {})
      .toInstance(new JpaTckRepository<>(SignatureKeyPairImpl.class));

  // dao
  bind(OrganizationDao.class).to(JpaOrganizationDao.class);
  bind(OrganizationDistributedResourcesDao.class)
      .to(JpaOrganizationDistributedResourcesDao.class);
  bind(FreeResourcesLimitDao.class).to(JpaFreeResourcesLimitDao.class);

  bind(WorkerDao.class).to(JpaWorkerDao.class);
  bind(MemberDao.class).to(JpaMemberDao.class);
  bind(SignatureKeyDao.class).to(JpaSignatureKeyDao.class);
  bind(new TypeLiteral<PermissionsDao<MemberImpl>>() {}).to(JpaMemberDao.class);
  bind(new TypeLiteral<AbstractPermissionsDomain<MemberImpl>>() {}).to(OrganizationDomain.class);

  // SHA-512 ecnryptor is faster than PBKDF2 so it is better for testing
  bind(PasswordEncryptor.class).to(SHA512PasswordEncryptor.class).in(Singleton.class);

  // Creates empty multibinder to avoid error during container starting
  Multibinder.newSetBinder(
      binder(), String.class, Names.named(SystemDomain.SYSTEM_DOMAIN_ACTIONS));
}
 
Example #12
Source File: MultiuserPostgresqlTckModule.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void configure() {
  final Map<String, String> properties = new HashMap<>();
  properties.put(TRANSACTION_TYPE, PersistenceUnitTransactionType.RESOURCE_LOCAL.name());

  final String dbUrl = System.getProperty("jdbc.url");
  final String dbUser = System.getProperty("jdbc.user");
  final String dbPassword = System.getProperty("jdbc.password");

  waitConnectionIsEstablished(dbUrl, dbUser, dbPassword);

  properties.put(JDBC_URL, dbUrl);
  properties.put(JDBC_USER, dbUser);
  properties.put(JDBC_PASSWORD, dbPassword);
  properties.put(JDBC_DRIVER, System.getProperty("jdbc.driver"));

  JpaPersistModule main = new JpaPersistModule("main");
  main.properties(properties);
  install(main);
  final PGSimpleDataSource dataSource = new PGSimpleDataSource();
  dataSource.setUser(dbUser);
  dataSource.setPassword(dbPassword);
  dataSource.setUrl(dbUrl);
  bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(dataSource, "che-schema"));
  bind(DBInitializer.class).asEagerSingleton();
  bind(TckResourcesCleaner.class).to(JpaCleaner.class);

  // repositories
  // api-account
  bind(new TypeLiteral<TckRepository<AccountImpl>>() {})
      .toInstance(new JpaTckRepository<>(AccountImpl.class));
  // api-user
  bind(new TypeLiteral<TckRepository<UserImpl>>() {}).to(UserJpaTckRepository.class);

  // api-workspace
  bind(new TypeLiteral<TckRepository<WorkspaceImpl>>() {})
      .toInstance(new JpaTckRepository<>(WorkspaceImpl.class));
  bind(new TypeLiteral<TckRepository<WorkerImpl>>() {})
      .toInstance(new JpaTckRepository<>(WorkerImpl.class));

  // api permission
  bind(new TypeLiteral<TckRepository<SystemPermissionsImpl>>() {})
      .toInstance(new JpaTckRepository<>(SystemPermissionsImpl.class));

  bind(new TypeLiteral<PermissionsDao<SystemPermissionsImpl>>() {})
      .to(JpaSystemPermissionsDao.class);

  bind(new TypeLiteral<AbstractPermissionsDomain<WorkerImpl>>() {})
      .to(WorkerDaoTest.TestDomain.class);
  bind(new TypeLiteral<AbstractPermissionsDomain<SystemPermissionsImpl>>() {})
      .to(SystemPermissionsDaoTest.TestDomain.class);

  // api-organization
  bind(new TypeLiteral<TckRepository<OrganizationImpl>>() {})
      .to(JpaOrganizationImplTckRepository.class);
  bind(new TypeLiteral<TckRepository<MemberImpl>>() {})
      .toInstance(new JpaTckRepository<>(MemberImpl.class));
  bind(new TypeLiteral<TckRepository<OrganizationDistributedResourcesImpl>>() {})
      .toInstance(new JpaTckRepository<>(OrganizationDistributedResourcesImpl.class));

  // api-resource
  bind(new TypeLiteral<TckRepository<FreeResourcesLimitImpl>>() {})
      .toInstance(new JpaTckRepository<>(FreeResourcesLimitImpl.class));

  // machine token keys
  bind(new TypeLiteral<TckRepository<SignatureKeyPairImpl>>() {})
      .toInstance(new JpaTckRepository<>(SignatureKeyPairImpl.class));

  // dao
  bind(OrganizationDao.class).to(JpaOrganizationDao.class);
  bind(OrganizationDistributedResourcesDao.class)
      .to(JpaOrganizationDistributedResourcesDao.class);
  bind(FreeResourcesLimitDao.class).to(JpaFreeResourcesLimitDao.class);

  bind(WorkerDao.class).to(JpaWorkerDao.class);
  bind(MemberDao.class).to(JpaMemberDao.class);
  bind(SignatureKeyDao.class).to(JpaSignatureKeyDao.class);
  bind(new TypeLiteral<PermissionsDao<MemberImpl>>() {}).to(JpaMemberDao.class);
  bind(new TypeLiteral<AbstractPermissionsDomain<MemberImpl>>() {}).to(OrganizationDomain.class);

  // SHA-512 ecnryptor is faster than PBKDF2 so it is better for testing
  bind(PasswordEncryptor.class).to(SHA512PasswordEncryptor.class).in(Singleton.class);

  // Creates empty multibinder to avoid error during container starting
  Multibinder.newSetBinder(
      binder(), String.class, Names.named(SystemDomain.SYSTEM_DOMAIN_ACTIONS));
}