Java Code Examples for org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType

The following examples show how to use org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType. These examples are extracted from open source projects. 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 Project: celerio   Source File: MetaDataExtractorTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void noTable() throws ClassNotFoundException, SQLException, JAXBException, IOException {
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
    EmbeddedDatabase embeddedDatabase = builder.setType(EmbeddedDatabaseType.H2).build();

    Metadata meta = extractor.extract(embeddedDatabase.getConnection());

    assertThat(countTables(meta)).isZero();
    assertThat(countColumns(meta)).isZero();
    assertThat(countPrimaryKeys(meta)).isZero();
    assertThat(countImportedKeys(meta)).isZero();
    assertThat(countIndexes(meta)).isZero();
    assertThat(countEnums(meta)).isZero();

    embeddedDatabase.shutdown();
}
 
Example 2
Source Project: Spring-Security-Third-Edition   Source File: DataSourceConfig.java    License: MIT License 6 votes vote down vote up
/**
 * Custom H2 implementation for our {@link EmbeddedDatabase}
 * @return
 */
@Bean
public DataSource dataSource() {

    // no need shutdown, EmbeddedDatabaseFactoryBean will take care of this
    return new EmbeddedDatabaseBuilder()
            //Starting embedded database: url='jdbc:h2:mem:dataSource;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false', username='sa'
            .setName("dataSource")
            // Lets not get upset as we are only debugging ;-)
            .ignoreFailedDrops(true)
            .continueOnError(true)
            // DB Details:
            .setType(EmbeddedDatabaseType.H2)
            .addScript("/database/h2/calendar-schema.sql")
            .addScript("/database/h2/calendar-data.sql")
            // Authority tables
            .addScript("/database/h2/calendar-authorities.sql")
            .addScript("/database/h2/calendar-sha256.sql")
            .build();
}
 
Example 3
@BeforeClass
public static void setUpClass() throws Exception {
    DataSource writeDataSource = new EmbeddedDatabaseBuilder()
            .setName("writeDb")
            .setType(EmbeddedDatabaseType.H2)
            .setScriptEncoding("UTF-8")
            .addScript("classpath:/writedb.sql").build();

    DataSource readDataSource = new EmbeddedDatabaseBuilder()
            .setName("readDb")
            .setType(EmbeddedDatabaseType.H2)
            .setScriptEncoding("UTF-8")
            .addScript("classpath:/readdb.sql").build();
    
    replicationDataSource = new LazyReplicationConnectionDataSourceProxy(writeDataSource, readDataSource);
}
 
Example 4
Source Project: Spring-Security-Third-Edition   Source File: DataSourceConfig.java    License: MIT License 6 votes vote down vote up
/**
     * Custom H2 implementation for our {@link EmbeddedDatabase}
     * @return
     */
    @Bean
    public DataSource dataSource() {

        // no need shutdown, EmbeddedDatabaseFactoryBean will take care of this
        return new EmbeddedDatabaseBuilder()
                //Starting embedded database: url='jdbc:h2:mem:dataSource;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false', username='sa'
                .setName("dataSource")
                // Lets not get upset as we are only debugging ;-)
                .ignoreFailedDrops(true)
                .continueOnError(true)
                // DB Details:
                .setType(EmbeddedDatabaseType.H2)
                .addScript("/database/h2/calendar-schema.sql")
                .addScript("/database/h2/calendar-data.sql")
                // Authority tables
                .addScript("/database/h2/calendar-authorities.sql")
//                .addScript("/database/h2/calendar-saltedsha256.sql")
                .addScript("/database/h2/calendar-bcrypt.sql")
                .build();
    }
 
Example 5
Source Project: Spring-Security-Third-Edition   Source File: DataSourceConfig.java    License: MIT License 6 votes vote down vote up
/**
 * Custom H2 implementation for our {@link EmbeddedDatabase}
 * @return
 */
@Bean
public DataSource dataSource() {

    // no need shutdown, EmbeddedDatabaseFactoryBean will take care of this
    return new EmbeddedDatabaseBuilder()
            //Starting embedded database: url='jdbc:h2:mem:dataSource;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false', username='sa'
            .setName("dataSource")
            // Lets not get upset as we are only debugging ;-)
            .ignoreFailedDrops(true)
            .continueOnError(true)
            // DB Details:
            .setType(EmbeddedDatabaseType.H2)
            .addScript("/database/h2/calendar-schema.sql")
            .addScript("/database/h2/calendar-data.sql")
            // Authority tables
            .addScript("/database/h2/calendar-authorities.sql")
            .build();
}
 
Example 6
Source Project: spring-embedded-database   Source File: HsqlDataSource.java    License: MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource() {
	
	// no need shutdown, EmbeddedDatabaseFactoryBean will take care of this
	EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
	EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.HSQL).addScript("db/sql/create-db.sql").addScript("db/sql/insert-data.sql").build();
	return db;
}
 
Example 7
Source Project: tutorials   Source File: ManyToManyTestConfiguration.java    License: MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource() {
    EmbeddedDatabaseBuilder dbBuilder = new EmbeddedDatabaseBuilder();
    return dbBuilder.setType(EmbeddedDatabaseType.H2)
        .addScript("classpath:/manytomany/db.sql")
        .build();
}
 
Example 8
Source Project: Spring-Security-Third-Edition   Source File: DataSourceConfig.java    License: MIT License 5 votes vote down vote up
/**
 * Embedded H2 database
 * Connect to running database with the following details:
 *
 * URL: jdbc:h2:mem:dataSource
 * Driver Class: org.h2.Driver
 * Username: sa
 * Password: [blank]
 *
 * @return
 */
@Bean
public DataSource dataSource() {
    final EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
    database = builder.setType(EmbeddedDatabaseType.H2)
            .setName("dataSource")
            .ignoreFailedDrops(true)
            .continueOnError(false)
            .addScript("classpath:database/h2/calendar-schema.sql")
            .addScript("classpath:database/h2/calendar-data.sql")
            .build();
    return database;
}
 
Example 9
Source Project: pmq   Source File: InMemoryDbDatasourceConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
@Bean(name = "inMemoryDbDataSource")
    @Primary
    public DataSource inMemoryDbDataSource() {
//        DataSource dataSource = new DruidDataSource();
//        return dataSource;
    	return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
                .addScript("classpath:sql/schema.sql").build();
    }
 
Example 10
Source Project: spring-data-examples   Source File: DataConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource() {
  EmbeddedDatabaseFactoryBean databaseFactoryBean = new EmbeddedDatabaseFactoryBean();
  databaseFactoryBean.setDatabaseType(EmbeddedDatabaseType.H2);
  databaseFactoryBean.afterPropertiesSet();
  return databaseFactoryBean.getObject();
}
 
Example 11
Source Project: Project   Source File: DataConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource dataSource() {
  return new EmbeddedDatabaseBuilder()
          .setType(EmbeddedDatabaseType.H2)
          .addScript("schema.sql")
          .build();
}
 
Example 12
Source Project: Project   Source File: RepositoryTestConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource dataSource() {
  EmbeddedDatabaseBuilder edb = new EmbeddedDatabaseBuilder();
  edb.setType(EmbeddedDatabaseType.H2);
  edb.addScript("spittr/db/hibernate4/schema.sql");
  edb.addScript("spittr/db/hibernate4/test-data.sql");
  EmbeddedDatabase embeddedDatabase = edb.build();
  return embeddedDatabase;
}
 
Example 13
@Bean
public DataSource dataSource() {
    LOGGER.debug("Running embedded database builder");
    return new EmbeddedDatabaseBuilder()
            .setType(EmbeddedDatabaseType.HSQL)
            .addScript("classpath:sql/hsql/schema.sql")
            .build();
}
 
Example 14
@Bean(destroyMethod = "shutdown")
public DataSource writeDataSource() {
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
            .setName("lazyWriteDb")
            .setType(EmbeddedDatabaseType.H2)
            .setScriptEncoding("UTF-8")
            .addScript("classpath:/writedb.sql");
    return builder.build();
}
 
Example 15
Source Project: tutorials   Source File: SpringbatchPartitionConfig.java    License: MIT License 5 votes vote down vote up
private DataSource dataSource() {
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
    return builder.setType(EmbeddedDatabaseType.HSQL)
      .addScript("classpath:org/springframework/batch/core/schema-drop-h2.sql")
      .addScript("classpath:org/springframework/batch/core/schema-h2.sql")
      .build();
}
 
Example 16
Source Project: database-rider   Source File: TestConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean(name = "data-source-1")
@Primary
public DataSource dataSourcePrimary() {
    return new EmbeddedDatabaseBuilder()
            .generateUniqueName(true)
            .setType(EmbeddedDatabaseType.HSQL)
            .setScriptEncoding("UTF-8")
            .addScript("schema.sql")
            .build();
}
 
Example 17
Source Project: Project   Source File: DataConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource dataSource() {
  return new EmbeddedDatabaseBuilder()
          .setType(EmbeddedDatabaseType.H2)
          .addScript("schema.sql")
          .build();
}
 
Example 18
Source Project: Project   Source File: DataConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource dataSource() {
  return new EmbeddedDatabaseBuilder()
          .setType(EmbeddedDatabaseType.H2)
          .addScript("schema.sql")
          .build();
}
 
Example 19
@Bean
DataSource hsqlDataSource() {
	return new EmbeddedDatabaseBuilder().setName("geode_security").setScriptEncoding("UTF-8")
			.setType(EmbeddedDatabaseType.HSQL).addScript("sql/geode-security-schema-ddl.sql")
			.addScript("sql/define-roles-table-ddl.sql").addScript("sql/define-roles-permissions-table-ddl.sql")
			.addScript("sql/define-users-table-ddl.sql").addScript("sql/define-users-roles-table-ddl.sql")
			.addScript("sql/insert-roles-dml.sql").addScript("sql/insert-roles-permissions-dml.sql")
			.addScript("sql/insert-users-dml.sql").addScript("sql/insert-users-roles-dml.sql").build();
}
 
Example 20
Source Project: tutorials   Source File: DataStoreConfig.java    License: MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource() {
    return new EmbeddedDatabaseBuilder()
            .setType(EmbeddedDatabaseType.H2)
            .setName("socketDB")
            .addScript("classpath:schema.sql")
            .addScript("classpath:data.sql")
            .setScriptEncoding("UTF-8")
            .continueOnError(true)
            .ignoreFailedDrops(true)
            .build();
}
 
Example 21
@Bean(destroyMethod = "shutdown")
public DataSource writeDataSource() {
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
            .setName("routingWriteDb")
            .setType(EmbeddedDatabaseType.H2)
            .setScriptEncoding("UTF-8")
            .addScript("classpath:/writedb.sql");
    return builder.build();
}
 
Example 22
Source Project: Spring   Source File: TestDataConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource dataSource() {
    return new EmbeddedDatabaseBuilder()
            .setType(EmbeddedDatabaseType.H2)
            .addScript("classpath:db/schema.sql")
            .addScript("classpath:db/test-data.sql")
            .build();
}
 
Example 23
Source Project: Spring   Source File: TestDataConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource dataSource() {
    return new EmbeddedDatabaseBuilder()
            .setType(EmbeddedDatabaseType.H2)
            .addScript("classpath:db/schema.sql")
            .addScript("classpath:db/test-data.sql")
            .build();
}
 
Example 24
@Bean
public DataSource dataSource(){
	EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2);//in-memory
	builder.addScript("schema.sql");
	builder.addScript("data.sql");
	return builder.build();
}
 
Example 25
@Bean
public DataSource dataSource(){
	EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2);//in-memory
	builder.addScript("schema.sql");
	builder.addScript("data.sql");
	return builder.build();
}
 
Example 26
Source Project: EasyReport   Source File: ReadWriteDataSourceConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean(name = "masterDataSource")
public DataSource masterDataSource() {
    return new EmbeddedDatabaseBuilder()
        .setType(EmbeddedDatabaseType.H2)
        .setScriptEncoding("UTF-8")
        .ignoreFailedDrops(true)
        .setName("mybatis_sample_master")
        .addScript("sql/schema.sql")
        .addScripts("sql/data.sql")
        .build();
}
 
Example 27
@Bean
public DataSource dataSource() {
    final EmbeddedDatabaseBuilder embeddedDatabaseBuilder = new EmbeddedDatabaseBuilder();
    return embeddedDatabaseBuilder.addScript("classpath:create.sql")
            .setType(EmbeddedDatabaseType.H2)
            .build();
}
 
Example 28
Source Project: new-bull   Source File: DbUtil.java    License: MIT License 5 votes vote down vote up
public static JdbcTemplate create() {
    DataSource ds = new EmbeddedDatabaseBuilder()
            .setType(EmbeddedDatabaseType.H2)
            .setName("testdb;mode=MySQL")
            .setScriptEncoding("UTF-8")
            .ignoreFailedDrops(true)
            .addScript("schema.sql").build();

    return new JdbcTemplate(ds);
}
 
Example 29
@Profile("test")
@Bean(destroyMethod="shutdown")
public DataSource dataSource(){
    return new EmbeddedDatabaseBuilder()
    		.setType(EmbeddedDatabaseType.H2)
    		.addScript("classpath:schema.sql")
    		.addScript("classpath:testData.sql")
    		.build();
}
 
Example 30
Source Project: database-rider   Source File: TestConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean(name = "data-source-2")
public DataSource dataSourceSecondary() {
    return new EmbeddedDatabaseBuilder()
        .generateUniqueName(true)
        .setType(EmbeddedDatabaseType.HSQL)
        .setScriptEncoding("UTF-8")
        .addScript("schema2.sql")
        .build();
}