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

The following examples show how to use org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType. 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: DataSourceConfig.java    From Spring-Security-Third-Edition with 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 #2
Source File: DataSourceConfig.java    From Spring-Security-Third-Edition with 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 #3
Source File: LazyReplicationConnectionDataSourceProxyConnectionIntegrationTest.java    From replication-datasource with Apache License 2.0 6 votes vote down vote up
@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 File: MetaDataExtractorTest.java    From celerio with 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 #5
Source File: DataSourceConfig.java    From Spring-Security-Third-Edition with 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 #6
Source File: DataStoreConfig.java    From tutorials with 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 #7
Source File: DbUtil.java    From new-bull with 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 #8
Source File: ITPersistenceConfiguration.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource dataSource() {
    final EmbeddedDatabaseBuilder embeddedDatabaseBuilder = new EmbeddedDatabaseBuilder();
    return embeddedDatabaseBuilder.addScript("classpath:create.sql")
            .setType(EmbeddedDatabaseType.H2)
            .build();
}
 
Example #9
Source File: ReadWriteDataSourceConfig.java    From EasyReport with 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 #10
Source File: InfrastructureConfig.java    From Learning-Path-Spring-5-End-to-End-Programming with MIT License 5 votes vote down vote up
@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 #11
Source File: InfrastructureConfig.java    From Learning-Path-Spring-5-End-to-End-Programming with MIT License 5 votes vote down vote up
@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 #12
Source File: TestDataConfig.java    From Spring with 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 #13
Source File: TestDataConfig.java    From Spring with 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 #14
Source File: WithRoutingDataSourceConfig.java    From replication-datasource with Apache License 2.0 5 votes vote down vote up
@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 #15
Source File: DataSourceConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource() {
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
    return builder.setType(EmbeddedDatabaseType.HSQL)
        .addScripts("db/sql/create-db.sql", "db/sql/insert-data.sql")
        .build();
}
 
Example #16
Source File: SecurityEnabledServerConfiguration.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
@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 #17
Source File: DataConfig.java    From spring-data-examples with 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 #18
Source File: TestConfig.java    From database-rider with 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 #19
Source File: AppConfig.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Profile("test")
@Bean(destroyMethod="shutdown")
public DataSource dataSource(){
    return new EmbeddedDatabaseBuilder()
    		.setType(EmbeddedDatabaseType.H2)
    		.addScript("classpath:schema.sql")
    		.addScript("classpath:testData.sql")
    		.build();
}
 
Example #20
Source File: TestConfig.java    From database-rider with 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();
}
 
Example #21
Source File: ManyToManyTestConfiguration.java    From tutorials with 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 #22
Source File: AppConfig.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean(destroyMethod="shutdown")
public DataSource dataSource(){
    return new EmbeddedDatabaseBuilder()
    		.setType(EmbeddedDatabaseType.H2)
    		.addScript("classpath:schema.sql")
    		.addScript("classpath:testData.sql")
    		.build();
}
 
Example #23
Source File: AppConfig.java    From Spring5Tutorial with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Bean(destroyMethod="shutdown")
public DataSource dataSource(){
    return new EmbeddedDatabaseBuilder()
    		.setType(EmbeddedDatabaseType.H2)
    		.addScript("classpath:schema.sql")
    		.addScript("classpath:testData.sql")
    		.build();
}
 
Example #24
Source File: JdbcComponentTestIT.java    From components with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    db = new EmbeddedDatabaseBuilder().generateUniqueName(true).setType(EmbeddedDatabaseType.DERBY).setName("testdb")
            .setScriptEncoding("UTF-8").addScript("/org/talend/components/service/rest/schema.sql")
            .addScript("/org/talend/components/service/rest/data_users.sql").build();
    // addresss: Starting embedded database:
    // url='jdbc:derby:memory:2dc86c66-5d3a-48fd-b903-56aa27d20e3b;create=true',
    // username='sa'
    try (Connection connection = db.getConnection()) {
        dbUrl = connection.getMetaData().getURL();
    }

    RestAssured.port = localServerPort;
}
 
Example #25
Source File: Oauth2Application.java    From Using-Spring-Oauth2-to-secure-REST with MIT License 5 votes vote down vote up
@Bean @Qualifier("mainDataSource")
public DataSource dataSource(){
	EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
	EmbeddedDatabase db = builder
			.setType(EmbeddedDatabaseType.H2)
			.build();
	return db;
}
 
Example #26
Source File: TxIntegrationConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource() {
    return new EmbeddedDatabaseBuilder()
            .setType(EmbeddedDatabaseType.H2)
            .addScript("classpath:table.sql")
            .build();
}
 
Example #27
Source File: Spring_2_IT_Configuration.java    From spring-test-examples with Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource dataSource() {

  EmbeddedDatabase db = new EmbeddedDatabaseBuilder()
      .generateUniqueName(true)
      .setType(EmbeddedDatabaseType.H2)
      .setScriptEncoding("UTF-8")
      .ignoreFailedDrops(true)
      .addScript("classpath:me/chanjar/domain/foo-ddl.sql")
      .build();
  return db;
}
 
Example #28
Source File: Spring_1_IT_Configuration.java    From spring-test-examples with Apache License 2.0 5 votes vote down vote up
@Bean(destroyMethod = "shutdown")
public DataSource dataSource() {

  return new EmbeddedDatabaseBuilder()
      .generateUniqueName(true)
      .setType(EmbeddedDatabaseType.H2)
      .setScriptEncoding("UTF-8")
      .ignoreFailedDrops(true)
      .addScript("classpath:me/chanjar/domain/foo-ddl.sql")
      .build();
}
 
Example #29
Source File: DBRiderSpringDataSourceIT.java    From database-rider with 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("scripts/schema2.sql")
      .build();
}
 
Example #30
Source File: DataSourceConfig.java    From Spring-Security-Third-Edition with MIT License 5 votes vote down vote up
/**
 * Custom H2 implementation for our {@link EmbeddedDatabase}
 * @return
 */
@Bean
public DataSource dataSource() {
    return new EmbeddedDatabaseBuilder()
            .setName("dataSource")
            .setType(EmbeddedDatabaseType.H2)
            .addScript("/database/h2/calendar-schema.sql")
            .addScript("/database/h2/calendar-data.sql")
            .addScript("/database/h2/security-schema.sql")
            .addScript("/database/h2/security-users.sql")
            .addScript("/database/h2/security-user-authorities.sql")
            .build();
}