org.h2.Driver Java Examples

The following examples show how to use org.h2.Driver. 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: SshTckModule.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void configure() {
  H2DBTestServer server = H2DBTestServer.startDefault();
  install(
      new PersistTestModuleBuilder()
          .setDriver(Driver.class)
          .runningOn(server)
          .addEntityClasses(SshPairImpl.class, UserImpl.class, AccountImpl.class)
          .setExceptionHandler(H2ExceptionHandler.class)
          .build());
  bind(DBInitializer.class).asEagerSingleton();
  bind(SchemaInitializer.class)
      .toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
  bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));

  bind(SshDao.class).to(JpaSshDao.class);
  bind(new TypeLiteral<TckRepository<SshPairImpl>>() {})
      .toInstance(new JpaTckRepository<>(SshPairImpl.class));
  bind(new TypeLiteral<TckRepository<UserImpl>>() {})
      .toInstance(new JpaTckRepository<>(UserImpl.class));
}
 
Example #2
Source File: AccountJpaTckModule.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void configure() {
  H2DBTestServer server = H2DBTestServer.startDefault();
  install(
      new PersistTestModuleBuilder()
          .setDriver(Driver.class)
          .runningOn(server)
          .addEntityClass(AccountImpl.class)
          .setExceptionHandler(H2ExceptionHandler.class)
          .build());
  bind(DBInitializer.class).asEagerSingleton();
  bind(SchemaInitializer.class)
      .toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
  bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));

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

  bind(AccountDao.class).to(JpaAccountDao.class);
}
 
Example #3
Source File: HibernateSessionExtension.java    From judgels with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
        throws ParameterResolutionException {

    Configuration config = new Configuration();

    Class<?> declaringClass = parameterContext.getDeclaringExecutable().getDeclaringClass();
    WithHibernateSession annotation = getAnnotation(declaringClass);
    for (Class<?> modelClass : annotation.models()) {
        config.addAnnotatedClass(modelClass);
    }

    config.setProperty(DIALECT, H2Dialect.class.getName());
    config.setProperty(DRIVER, Driver.class.getName());
    config.setProperty(URL, "jdbc:h2:mem:./" + UUID.randomUUID().toString());
    config.setProperty(HBM2DDL_AUTO, "create");
    config.setProperty(CURRENT_SESSION_CONTEXT_CLASS, "managed");
    config.setProperty(GENERATE_STATISTICS, "false");

    SessionFactory sessionFactory = config.buildSessionFactory();
    openSession(sessionFactory, extensionContext);
    return sessionFactory;
}
 
Example #4
Source File: PersistenceService.java    From state-machine with Apache License 2.0 5 votes vote down vote up
private static DataSource createDataSource() {
	log.info("creating data source");
	try {
		// create a new file based db in target on every startup
		File file = File.createTempFile("test", "db", new File("target"));
		return DataSourceBuilder //
				.create() //
				.url("jdbc:h2:file:" + file.getAbsolutePath()) //
				.driverClassName(Driver.class.getName()) //
				.build();
	} catch (IOException e) {
		throw new RuntimeException(e);
	}

}
 
Example #5
Source File: TestBasicManagedDataSource.java    From commons-dbcp with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateXaDataSourceNewInstance() throws SQLException, XAException {
    try (final BasicManagedDataSource basicManagedDataSource = new BasicManagedDataSource()) {
        basicManagedDataSource.setXADataSource(JdbcDataSource.class.getCanonicalName());
        basicManagedDataSource.setDriverClassName(Driver.class.getName());
        basicManagedDataSource.setTransactionManager(new TransactionManagerImpl());
        assertNotNull(basicManagedDataSource.createConnectionFactory());
    }
}
 
Example #6
Source File: JdbcJavaRDDFT.java    From deep-spark with Apache License 2.0 5 votes vote down vote up
@BeforeSuite
public void init() throws Exception {
    DriverManager.registerDriver(new Driver());
    connCell = DriverManager.getConnection("jdbc:h2:~/" + NAMESPACE_CELL + ";DATABASE_TO_UPPER=FALSE", "sa", "");
    createTables(connCell, NAMESPACE_CELL, INPUT_TABLE, OUTPUT_CELLS_TABLE);
    deleteData(connCell, NAMESPACE_CELL, INPUT_TABLE, OUTPUT_CELLS_TABLE);
    connEntity = DriverManager.getConnection("jdbc:h2:~/" + NAMESPACE_ENTITY + ";DATABASE_TO_UPPER=FALSE", "sa", "");
    createTables(connEntity, NAMESPACE_ENTITY, INPUT_TABLE, OUTPUT_ENTITY_TABLE);
    deleteData(connEntity, NAMESPACE_ENTITY, INPUT_TABLE, OUTPUT_ENTITY_TABLE);

}
 
Example #7
Source File: JpaTckModule.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void configure() {
  H2DBTestServer server = H2DBTestServer.startDefault();
  install(
      new PersistTestModuleBuilder()
          .setDriver(Driver.class)
          .runningOn(server)
          .addEntityClasses(
              UserImpl.class, ProfileImpl.class, PreferenceEntity.class, AccountImpl.class)
          .setExceptionHandler(H2ExceptionHandler.class)
          .build());
  bind(DBInitializer.class).asEagerSingleton();
  bind(SchemaInitializer.class)
      .toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
  bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server.getDataSource()));

  bind(new TypeLiteral<TckRepository<UserImpl>>() {}).to(UserJpaTckRepository.class);
  bind(new TypeLiteral<TckRepository<ProfileImpl>>() {})
      .toInstance(new JpaTckRepository<>(ProfileImpl.class));
  bind(new TypeLiteral<TckRepository<Pair<String, Map<String, String>>>>() {})
      .to(PreferenceJpaTckRepository.class);

  bind(UserDao.class).to(JpaUserDao.class);
  bind(ProfileDao.class).to(JpaProfileDao.class);
  bind(PreferenceDao.class).to(JpaPreferenceDao.class);
  // SHA-512 encryptor is faster than PBKDF2 so it is better for testing
  bind(PasswordEncryptor.class).to(SHA512PasswordEncryptor.class).in(Singleton.class);
}
 
Example #8
Source File: SystemPermissionsTckModule.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void configure() {
  H2DBTestServer server = H2DBTestServer.startDefault();
  install(
      new PersistTestModuleBuilder()
          .setDriver(Driver.class)
          .runningOn(server)
          .addEntityClasses(
              UserImpl.class,
              AccountImpl.class,
              AbstractPermissions.class,
              SystemPermissionsImpl.class)
          .setExceptionHandler(H2ExceptionHandler.class)
          .build());
  bind(DBInitializer.class).asEagerSingleton();
  bind(SchemaInitializer.class)
      .toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
  bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));
  // Creates empty multibinder to avoid error during container starting
  Multibinder.newSetBinder(
      binder(), String.class, Names.named(SystemDomain.SYSTEM_DOMAIN_ACTIONS));

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

  bind(new TypeLiteral<TckRepository<SystemPermissionsImpl>>() {})
      .toInstance(new JpaTckRepository<>(SystemPermissionsImpl.class));
  bind(new TypeLiteral<TckRepository<UserImpl>>() {})
      .toInstance(new JpaTckRepository<>(UserImpl.class));
}
 
Example #9
Source File: InviteJpaTckModule.java    From codenvy with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void configure() {
  H2DBTestServer server = H2DBTestServer.startDefault();
  install(
      new PersistTestModuleBuilder()
          .setDriver(Driver.class)
          .runningOn(server)
          .addEntityClasses(
              OrganizationImpl.class,
              AccountImpl.class,
              WorkspaceImpl.class,
              WorkspaceConfigImpl.class,
              ProjectConfigImpl.class,
              EnvironmentImpl.class,
              ExtendedMachineImpl.class,
              CommandImpl.class,
              SourceStorageImpl.class,
              ServerConf2Impl.class,
              SnapshotImpl.class,
              InviteImpl.class)
          .addEntityClass(
              "org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl$Attribute")
          .setExceptionHandler(H2ExceptionHandler.class)
          .build());
  bind(DBInitializer.class).asEagerSingleton();
  bind(SchemaInitializer.class)
      .toInstance(
          new FlywaySchemaInitializer(server.getDataSource(), "che-schema", "codenvy-schema"));
  bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));

  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 #10
Source File: JPADao.java    From openwebbeans-meecrowave with Apache License 2.0 5 votes vote down vote up
@Produces
@ApplicationScoped
public DataSource dataSource() {
    final BasicDataSource source = new BasicDataSource();
    source.setDriver(new Driver());
    source.setUrl("jdbc:h2:mem:jpaextensiontest");
    return source;
}
 
Example #11
Source File: JPAExceptionLostTest.java    From openwebbeans-meecrowave with Apache License 2.0 5 votes vote down vote up
@Produces
@ApplicationScoped
public DataSource dataSource() {
    final BasicDataSource source = new BasicDataSource();
    source.setDriver(new Driver());
    source.setUrl("jdbc:h2:mem:jpaextensiontest");
    return source;
}
 
Example #12
Source File: YamlShardingDataSourceTest.java    From sharding-jdbc-1.5.1 with Apache License 2.0 5 votes vote down vote up
private DataSource createDataSource() {
    BasicDataSource result = new BasicDataSource();
    result.setDriverClassName(Driver.class.getName());
    result.setUrl("jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;MODE=MYSQL");
    result.setUsername("sa");
    result.setPassword("");
    return result;
}
 
Example #13
Source File: TestJpaConfiguration.java    From jwala with Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource getDataSource() {
    return new SimpleDriverDataSource(new Driver(),
            "jdbc:h2:mem:test-services;DB_CLOSE_DELAY=-1;LOCK_MODE=0",
            "sa",
            "");
}
 
Example #14
Source File: TestingDatabase.java    From presto with Apache License 2.0 5 votes vote down vote up
public TestingDatabase()
        throws SQLException
{
    String connectionUrl = "jdbc:h2:mem:test" + System.nanoTime() + ThreadLocalRandom.current().nextLong();
    jdbcClient = new TestingH2JdbcClient(
            new BaseJdbcConfig(),
            new DriverConnectionFactory(new Driver(), connectionUrl, new Properties(), new EmptyCredentialProvider()));

    connection = DriverManager.getConnection(connectionUrl);
    connection.createStatement().execute("CREATE SCHEMA example");

    connection.createStatement().execute("CREATE TABLE example.numbers(text varchar primary key, text_short varchar(32), value bigint)");
    connection.createStatement().execute("INSERT INTO example.numbers(text, text_short, value) VALUES " +
            "('one', 'one', 1)," +
            "('two', 'two', 2)," +
            "('three', 'three', 3)," +
            "('ten', 'ten', 10)," +
            "('eleven', 'eleven', 11)," +
            "('twelve', 'twelve', 12)" +
            "");
    connection.createStatement().execute("CREATE TABLE example.view_source(id varchar primary key)");
    connection.createStatement().execute("CREATE VIEW example.view AS SELECT id FROM example.view_source");
    connection.createStatement().execute("CREATE SCHEMA tpch");
    connection.createStatement().execute("CREATE TABLE tpch.orders(orderkey bigint primary key, custkey bigint)");
    connection.createStatement().execute("CREATE TABLE tpch.lineitem(orderkey bigint primary key, partkey bigint)");

    connection.createStatement().execute("CREATE SCHEMA exa_ple");
    connection.createStatement().execute("CREATE TABLE exa_ple.num_ers(te_t varchar primary key, \"VA%UE\" bigint)");
    connection.createStatement().execute("CREATE TABLE exa_ple.table_with_float_col(col1 bigint, col2 double, col3 float, col4 real)");

    connection.commit();
}
 
Example #15
Source File: TestExportUsingProcedure.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 5 votes vote down vote up
/**
 * This gets called during {@link #setUp()} to check the non-HSQLDB database
 * is valid. We'll therefore set the connection manager here...
 */
@Override
protected SqoopOptions getSqoopOptions(Configuration conf) {
  SqoopOptions ret = new SqoopOptions(conf);
  if (ret.getConnManagerClassName() == null) {
    ret.setConnManagerClassName(GenericJdbcManager.class.getName());
  }
  if (ret.getDriverClassName() == null) {
    ret.setDriverClassName(Driver.class.getName());
  }
  return ret;
}
 
Example #16
Source File: TestExportUsingProcedure.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 5 votes vote down vote up
@Override
protected String[] getCodeGenArgv(String... extraArgs) {
  String[] myExtraArgs = newStrArray(extraArgs, "--"
      + ExportTool.CONN_MANAGER_CLASS_NAME,
      GenericJdbcManager.class.getName(), "--" + ExportTool.DRIVER_ARG,
      Driver.class.getName());
  return super.getCodeGenArgv(myExtraArgs);
}
 
Example #17
Source File: TestExportUsingProcedure.java    From aliyun-maxcompute-data-collectors with Apache License 2.0 5 votes vote down vote up
@Override
protected String[] getArgv(boolean includeHadoopFlags, int rowsPerStmt,
    int statementsPerTx, String... additionalArgv) {
  // we need different class names per test, or the classloader will
  // just use the old class definition even though we've compiled a
  // new one!
  String[] args = newStrArray(additionalArgv, "--" + ExportTool.CALL_ARG,
      PROCEDURE_NAME, "--" + ExportTool.CLASS_NAME_ARG, getName(), "--"
          + ExportTool.CONN_MANAGER_CLASS_NAME,
      GenericJdbcManager.class.getName(), "--" + ExportTool.DRIVER_ARG,
      Driver.class.getName());
  return super
      .getArgv(includeHadoopFlags, rowsPerStmt, statementsPerTx, args);
}
 
Example #18
Source File: JdbiITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) {
  Driver.load();
  final DBI dbi = new DBI("jdbc:h2:mem:dbi", "sa", "");
  final Handle handle = dbi.open();
  handle.execute("CREATE TABLE employer (id INTEGER)");
  handle.close();

  TestUtil.checkSpan(new ComponentSpanCount("java-jdbc", 2));
}
 
Example #19
Source File: TestingH2JdbcModule.java    From presto with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
@ForBaseJdbc
public ConnectionFactory getConnectionFactory(BaseJdbcConfig config, CredentialProvider credentialProvider)
{
    return new DriverConnectionFactory(new Driver(), config, credentialProvider);
}
 
Example #20
Source File: Jdbi3ITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) {
  Driver.load();
  final Jdbi dbi = Jdbi.create("jdbc:h2:mem:dbi", "sa", "");
  try (final Handle handle = dbi.open()) {
    handle.execute("CREATE TABLE employer (id INTEGER)");
  }

  TestUtil.checkSpan(new ComponentSpanCount("java-jdbc", 2));
}
 
Example #21
Source File: AbstractServiceIntegrationTests.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@BeforeAll
static void beforeAll() throws Exception {
    DataSourceFactory dbConfig = new DataSourceFactory();
    dbConfig.setDriverClass(Driver.class.getName());
    dbConfig.setUrl("jdbc:h2:mem:./" + URIEL_JDBC_SUFFIX);
    dbConfig.setProperties(ImmutableMap.<String, String>builder()
            .put(DIALECT, H2Dialect.class.getName())
            .put(HBM2DDL_AUTO, "create")
            .put(GENERATE_STATISTICS, "false")
            .build());

    baseDataDir = Files.createTempDirectory("uriel");

    UrielApplicationConfiguration config = new UrielApplicationConfiguration(
            dbConfig,
            WebSecurityConfiguration.DEFAULT,
            new UrielConfiguration.Builder()
                    .baseDataDir(baseDataDir.toString())
                    .jophielConfig(JophielClientConfiguration.DEFAULT)
                    .sandalphonConfig(SandalphonClientConfiguration.DEFAULT)
                    .sealtielConfig(SealtielClientConfiguration.DEFAULT)
                    .gabrielConfig(GabrielClientConfiguration.DEFAULT)
                    .submissionConfig(SubmissionConfiguration.DEFAULT)
                    .fileConfig(FileConfiguration.DEFAULT)
                    .build());

    support = new DropwizardTestSupport<>(UrielApplication.class, config);
    support.before();
}
 
Example #22
Source File: AbstractServiceIntegrationTests.java    From judgels with GNU General Public License v2.0 5 votes vote down vote up
@BeforeAll
static void beforeAll() throws Exception {
    DataSourceFactory dbConfig = new DataSourceFactory();
    dbConfig.setDriverClass(Driver.class.getName());
    dbConfig.setUrl("jdbc:h2:mem:./" + JERAHMEEL_JDBC_SUFFIX);
    dbConfig.setProperties(ImmutableMap.<String, String>builder()
            .put(DIALECT, H2Dialect.class.getName())
            .put(HBM2DDL_AUTO, "create")
            .put(GENERATE_STATISTICS, "false")
            .build());

    baseDataDir = Files.createTempDirectory("jerahmeel");

    JerahmeelApplicationConfiguration config = new JerahmeelApplicationConfiguration(
            dbConfig,
            WebSecurityConfiguration.DEFAULT,
            new JerahmeelConfiguration.Builder()
                    .baseDataDir(baseDataDir.toString())
                    .jophielConfig(JophielClientConfiguration.DEFAULT)
                    .sandalphonConfig(SandalphonClientConfiguration.DEFAULT)
                    .gabrielConfig(GabrielClientConfiguration.DEFAULT)
                    .submissionConfig(SubmissionConfiguration.DEFAULT)
                    .build());

    support = new DropwizardTestSupport<>(JerahmeelApplication.class, config);
    support.before();
}
 
Example #23
Source File: JpaTckModule.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void configure() {
  H2DBTestServer server = H2DBTestServer.startDefault();
  install(
      new PersistTestModuleBuilder()
          .setDriver(Driver.class)
          .runningOn(server)
          .addEntityClasses(
              WorkspaceImpl.class,
              WorkspaceConfigImpl.class,
              ProjectConfigImpl.class,
              SourceStorageImpl.class,
              EnvironmentImpl.class,
              MachineConfigImpl.class,
              ServerConfigImpl.class,
              VolumeImpl.class,
              CommandImpl.class,
              AccountImpl.class,
              KubernetesRuntimeState.class,
              KubernetesRuntimeCommandImpl.class,
              KubernetesMachineImpl.class,
              MachineId.class,
              KubernetesServerImpl.class,
              ServerId.class,
              // devfile
              ActionImpl.class,
              org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl.class,
              ComponentImpl.class,
              DevfileImpl.class,
              EndpointImpl.class,
              EntrypointImpl.class,
              EnvImpl.class,
              ProjectImpl.class,
              SourceImpl.class,
              org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl.class)
          .addEntityClass(
              "org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl$Attribute")
          .addClass(SerializableConverter.class)
          .setExceptionHandler(H2ExceptionHandler.class)
          .build());

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

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

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

  bind(KubernetesRuntimeStateCache.class).to(JpaKubernetesRuntimeStateCache.class);
  bind(KubernetesMachineCache.class).to(JpaKubernetesMachineCache.class);

  bind(SchemaInitializer.class)
      .toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
  bind(DBInitializer.class).asEagerSingleton();
  bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));
}
 
Example #24
Source File: ConnectionFactory.java    From tutorials with MIT License 4 votes vote down vote up
private ConnectionFactory() {
    dataSource = new BasicDataSource();
    dataSource.setDriver(new Driver());
    dataSource.setUrl("jdbc:h2:mem:db;DB_CLOSE_DELAY=-1");
}
 
Example #25
Source File: WorkspaceTckModule.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void configure() {
  H2DBTestServer server = H2DBTestServer.startDefault();
  install(
      new PersistTestModuleBuilder()
          .setDriver(Driver.class)
          .runningOn(server)
          .addEntityClasses(
              AccountImpl.class,
              WorkspaceImpl.class,
              WorkspaceConfigImpl.class,
              ProjectConfigImpl.class,
              EnvironmentImpl.class,
              RecipeImpl.class,
              MachineConfigImpl.class,
              SourceStorageImpl.class,
              ServerConfigImpl.class,
              CommandImpl.class,
              RecipeImpl.class,
              VolumeImpl.class,
              ActionImpl.class,
              org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl.class,
              ComponentImpl.class,
              DevfileImpl.class,
              EndpointImpl.class,
              EntrypointImpl.class,
              EnvImpl.class,
              ProjectImpl.class,
              SourceImpl.class,
              org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl.class)
          .addEntityClass(
              "org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl$Attribute")
          .addClass(SerializableConverter.class)
          .setExceptionHandler(H2ExceptionHandler.class)
          .build());
  bind(DBInitializer.class).asEagerSingleton();
  bind(SchemaInitializer.class)
      .toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
  bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));

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

  bind(WorkspaceDao.class).to(JpaWorkspaceDao.class);
}
 
Example #26
Source File: AbstractServiceIntegrationTests.java    From judgels with GNU General Public License v2.0 4 votes vote down vote up
@BeforeAll
static void beforeAll() throws Exception {
    DataSourceFactory dbConfig = new DataSourceFactory();
    dbConfig.setDriverClass(Driver.class.getName());
    dbConfig.setUrl("jdbc:h2:mem:./" + UUID.randomUUID().toString());
    dbConfig.setProperties(ImmutableMap.<String, String>builder()
            .put(DIALECT, H2Dialect.class.getName())
            .put(HBM2DDL_AUTO, "create")
            .put(GENERATE_STATISTICS, "false")
            .build());

    baseDataDir = Files.createTempDirectory("jophiel");

    JophielConfiguration jophielConfig = new JophielConfiguration.Builder()
            .baseDataDir(baseDataDir.toString())
            .mailerConfig(new MailerConfiguration.Builder()
                    .host("localhost")
                    .port(2500)
                    .useSsl(false)
                    .username("wiser")
                    .password("wiser")
                    .sender("[email protected]")
                    .build())
            .userRegistrationConfig(UserRegistrationConfiguration.DEFAULT)
            .userResetPasswordConfig(UserResetPasswordConfiguration.DEFAULT)
            .userAvatarConfig(UserAvatarConfiguration.DEFAULT)
            .superadminCreatorConfig(SuperadminCreatorConfiguration.DEFAULT)
            .build();

    JophielApplicationConfiguration config = new JophielApplicationConfiguration(
            dbConfig,
            WebSecurityConfiguration.DEFAULT,
            jophielConfig);

    support = new DropwizardTestSupport<>(JophielApplication.class, config);
    support.before();

    adminHeader = AuthHeader.of(createService(SessionService.class)
            .logIn(Credentials.of("superadmin", "superadmin"))
            .getToken());
}
 
Example #27
Source File: FactoryTckModule.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void configure() {
  H2DBTestServer server = H2DBTestServer.startDefault();
  install(
      new PersistTestModuleBuilder()
          .setDriver(Driver.class)
          .runningOn(server)
          .addEntityClasses(
              UserImpl.class,
              AccountImpl.class,
              FactoryImpl.class,
              OnAppClosedImpl.class,
              OnProjectsLoadedImpl.class,
              OnAppLoadedImpl.class,
              ActionImpl.class,
              ButtonImpl.class,
              IdeImpl.class,
              WorkspaceConfigImpl.class,
              ProjectConfigImpl.class,
              EnvironmentImpl.class,
              RecipeImpl.class,
              MachineImpl.class,
              MachineConfigImpl.class,
              SourceStorageImpl.class,
              ServerConfigImpl.class,
              CommandImpl.class,
              VolumeImpl.class)
          .addEntityClass(
              "org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl$Attribute")
          .setExceptionHandler(H2ExceptionHandler.class)
          .setProperty("eclipselink.logging.level", "OFF")
          .build());
  bind(DBInitializer.class).asEagerSingleton();
  bind(SchemaInitializer.class)
      .toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
  bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));

  bind(FactoryDao.class).to(JpaFactoryDao.class);

  bind(new TypeLiteral<TckRepository<FactoryImpl>>() {})
      .toInstance(new JpaTckRepository<>(FactoryImpl.class));
  bind(new TypeLiteral<TckRepository<UserImpl>>() {})
      .toInstance(new JpaTckRepository<>(UserImpl.class));
}
 
Example #28
Source File: TestConfiguration.java    From jwala with Apache License 2.0 4 votes vote down vote up
@Bean
public DataSource getDataSource() {
    return new SimpleDriverDataSource(new Driver(), "jdbc:h2:mem:test-persistence;DB_CLOSE_DELAY=-1;LOCK_MODE=0",
                                      "sa", "");
}
 
Example #29
Source File: JpaTckModule.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void configure() {
  H2DBTestServer server = H2DBTestServer.startDefault();
  install(
      new PersistTestModuleBuilder()
          .setDriver(Driver.class)
          .runningOn(server)
          .addEntityClasses(
              AccountImpl.class,
              UserImpl.class,
              WorkspaceImpl.class,
              WorkspaceConfigImpl.class,
              ProjectConfigImpl.class,
              EnvironmentImpl.class,
              WorkerImpl.class,
              MachineConfigImpl.class,
              SourceStorageImpl.class,
              ServerConfigImpl.class,
              CommandImpl.class,
              RecipeImpl.class,
              VolumeImpl.class,
              // devfile
              ActionImpl.class,
              org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl.class,
              ComponentImpl.class,
              DevfileImpl.class,
              EndpointImpl.class,
              EntrypointImpl.class,
              EnvImpl.class,
              ProjectImpl.class,
              SourceImpl.class,
              org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl.class)
          .addEntityClass(
              "org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl$Attribute")
          .addClass(SerializableConverter.class)
          .setExceptionHandler(H2ExceptionHandler.class)
          .build());

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

  bind(WorkerDao.class).to(JpaWorkerDao.class);
  bind(new TypeLiteral<TckRepository<WorkerImpl>>() {})
      .toInstance(new JpaTckRepository<>(WorkerImpl.class));
  bind(new TypeLiteral<TckRepository<UserImpl>>() {})
      .toInstance(new JpaTckRepository<>(UserImpl.class));
  bind(new TypeLiteral<TckRepository<AccountImpl>>() {})
      .toInstance(new JpaTckRepository<>(AccountImpl.class));

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

  bind(SchemaInitializer.class)
      .toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
  bind(DBInitializer.class).asEagerSingleton();
  bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));
}
 
Example #30
Source File: WorkspaceTckModule.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected void configure() {
  H2DBTestServer server = H2DBTestServer.startDefault();
  install(
      new PersistTestModuleBuilder()
          .setDriver(Driver.class)
          .runningOn(server)
          .addEntityClasses(
              AccountImpl.class,
              UserImpl.class,
              WorkspaceImpl.class,
              WorkspaceConfigImpl.class,
              ProjectConfigImpl.class,
              EnvironmentImpl.class,
              WorkerImpl.class,
              MachineConfigImpl.class,
              SourceStorageImpl.class,
              ServerConfigImpl.class,
              CommandImpl.class,
              RecipeImpl.class,
              VolumeImpl.class,
              // devfile
              ActionImpl.class,
              org.eclipse.che.api.workspace.server.model.impl.devfile.CommandImpl.class,
              ComponentImpl.class,
              DevfileImpl.class,
              EndpointImpl.class,
              EntrypointImpl.class,
              EnvImpl.class,
              ProjectImpl.class,
              SourceImpl.class,
              org.eclipse.che.api.workspace.server.model.impl.devfile.VolumeImpl.class)
          .addEntityClass(
              "org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl$Attribute")
          .addClass(SerializableConverter.class)
          .setExceptionHandler(H2ExceptionHandler.class)
          .build());
  bind(DBInitializer.class).asEagerSingleton();
  bind(SchemaInitializer.class)
      .toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
  bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));

  bind(new TypeLiteral<TckRepository<AccountImpl>>() {})
      .toInstance(new JpaTckRepository<>(AccountImpl.class));
  bind(new TypeLiteral<TckRepository<WorkspaceImpl>>() {}).toInstance(new WorkspaceRepository());
  bind(new TypeLiteral<TckRepository<UserImpl>>() {})
      .toInstance(new JpaTckRepository<>(UserImpl.class));
  bind(new TypeLiteral<TckRepository<WorkerImpl>>() {})
      .toInstance(new JpaTckRepository<>(WorkerImpl.class));

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

  bind(WorkerDao.class).to(JpaWorkerDao.class);
  bind(WorkspaceDao.class).to(JpaWorkspaceDao.class);
}