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

The following examples show how to use org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder. 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: HsqlDatabaseBuilder.java    From c2mon with GNU Lesser General Public License v3.0 6 votes vote down vote up
public DataSource toDataSource() {
  DataSource dataSource;

  if (url == null || url.contains("hsqldb:mem")) {
    log.debug("Creating in memory HSQL database");
    // Start an in-process, in-memory HSQL server
    dataSource = new EmbeddedDatabaseBuilder().setType(HSQL).setName("c2mondb").build();
  } else {
    log.debug("Creating HSQL database at URL {}",url);
    dataSource = DataSourceBuilder.create().url(url).username(username).password(password).build();
  }

  if (!scripts.isEmpty()) {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator(scripts.toArray(new Resource[scripts.size()]));
    populator.setContinueOnError(true);
    DatabasePopulatorUtils.execute(populator, dataSource);
  }

  return dataSource;
}
 
Example #2
Source File: JpaConfig.java    From Project with 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/jpa/schema.sql");
  edb.addScript("spittr/db/jpa/test-data.sql");
  EmbeddedDatabase embeddedDatabase = edb.build();
  return embeddedDatabase;
}
 
Example #3
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 #4
Source File: WithLazyReplicationConnectionDataSourceProxyConfig.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("lazyWriteDb")
            .setType(EmbeddedDatabaseType.H2)
            .setScriptEncoding("UTF-8")
            .addScript("classpath:/writedb.sql");
    return builder.build();
}
 
Example #5
Source File: OrderConfig.java    From spring-data-examples with Apache License 2.0 5 votes vote down vote up
@Bean
DataSource orderDataSource() {

	return new EmbeddedDatabaseBuilder().//
			setType(EmbeddedDatabaseType.HSQL).//
			setName("orders").//
			build();
}
 
Example #6
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 #7
Source File: InferredDataSourceTransactionalSqlScriptsTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource2() {
	return new EmbeddedDatabaseBuilder()//
	.setName("database2")//
	.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
	.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
	.build();
}
 
Example #8
Source File: WithRoutingDataSourceConfig.java    From replication-datasource with Apache License 2.0 5 votes vote down vote up
@Bean(destroyMethod = "shutdown")
public DataSource readDataSource() {
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
            .setName("routingReadDb")
            .setType(EmbeddedDatabaseType.H2)
            .setScriptEncoding("UTF-8")
            .addScript("classpath:/readdb.sql");
    return builder.build();
}
 
Example #9
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 #10
Source File: InferredDataSourceTransactionalSqlScriptsTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource1() {
	return new EmbeddedDatabaseBuilder()//
	.setName("database1")//
	.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
	.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
	.build();
}
 
Example #11
Source File: DatabaseConfig.java    From java-master with Apache License 2.0 5 votes vote down vote up
/**
 * 使用内嵌数据库
 */
@Bean
public DataSource h2DataSource() {
    return new EmbeddedDatabaseBuilder()
            .setType(EmbeddedDatabaseType.H2)
            .addScript("sql-script/schema.sql")
            .addScript("sql-script/data.sql")
            .build();
}
 
Example #12
Source File: DataConfig.java    From Project with 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 #13
Source File: DataSourceConfig.java    From Spring-Security-Third-Edition with 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 #14
Source File: PersistenceConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource() {
    return new EmbeddedDatabaseBuilder()
      .setType(EmbeddedDatabaseType.H2)
      .addScript("schema.sql")
      .addScript("data.sql")
      .build();
}
 
Example #15
Source File: DataSourceConfig.java    From Spring-Security-Third-Edition with 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 #16
Source File: InferredDataSourceSqlScriptsTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource2() {
	return new EmbeddedDatabaseBuilder()//
	.setName("database2")//
	.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
	.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
	.build();
}
 
Example #17
Source File: MultipleDataSourcesAndTransactionManagersSqlScriptsTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource1() {
	return new EmbeddedDatabaseBuilder()//
	.setName("database1")//
	.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
	.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
	.build();
}
 
Example #18
Source File: InferredDataSourceTransactionalSqlScriptsTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource dataSource1() {
	return new EmbeddedDatabaseBuilder()//
	.setName("database1")//
	.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
	.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
	.build();
}
 
Example #19
Source File: PopulatedSchemaDatabaseConfig.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource dataSource() {
	return new EmbeddedDatabaseBuilder()//
	.setName("populated-sql-scripts-test-db")//
	.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") //
	.build();
}
 
Example #20
Source File: LightminServer.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:org/tuxdevelop/spring/batch/lightmin/repository/drop_schema_h2.sql")
            .addScript("classpath:org/tuxdevelop/spring/batch/lightmin/repository/schema_h2.sql")
            .addScript("classpath:properties/sample/server/sql/inserts.sql")
            .setType(EmbeddedDatabaseType.H2).build();
}
 
Example #21
Source File: H2DataSource.java    From spring-embedded-database with MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource() {

	EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
	EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.H2).addScript("db/sql/create-db.sql").addScript("db/sql/insert-data.sql").build();
	return db;

}
 
Example #22
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 #23
Source File: DataSourceConfiguration.java    From spring-boot-starter-batch-web with Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource dataSourcePartner() {
	return new EmbeddedDatabaseBuilder()//
			.setType(EmbeddedDatabaseType.HSQL)//
			.ignoreFailedDrops(true)//
			.addScripts("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql",
					"classpath:org/springframework/batch/core/schema-hsqldb.sql", "classpath:schema-partner.sql")//
			.build();
}
 
Example #24
Source File: AppConfig.java    From Spring-Framework-Essentials with MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource() {
    return new EmbeddedDatabaseBuilder()
            .generateUniqueName(true)
            .setType(EmbeddedDatabaseType.H2)
            .setScriptEncoding("UTF-8")
            .ignoreFailedDrops(true)
            .addScript("schema.sql")
            .addScripts("data.sql")
            .build();
}
 
Example #25
Source File: TestContextConfiguration7.java    From spring-boot-starter-quartz with Apache License 2.0 5 votes vote down vote up
@Bean("otherDataSource")
@Primary
public DataSource otherDataSource() {
	
	return new EmbeddedDatabaseBuilder().generateUniqueName(true)
            .setType(EmbeddedDatabaseType.H2)
            .setScriptEncoding("UTF-8")
            .ignoreFailedDrops(true).build();
}
 
Example #26
Source File: MultipleDataSourcesAndTransactionManagersTransactionalSqlScriptsTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource1() {
	return new EmbeddedDatabaseBuilder()//
	.setName("database1")//
	.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")//
	.addScript("classpath:/org/springframework/test/context/jdbc/data.sql")//
	.build();
}
 
Example #27
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 #28
Source File: AnnotationConfigTransactionalTestNGSpringContextTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Bean
DataSource dataSource() {
	return new EmbeddedDatabaseBuilder()//
	.addScript("classpath:/org/springframework/test/jdbc/schema.sql")//
	.addScript("classpath:/org/springframework/test/jdbc/data.sql")//
	.build();
}
 
Example #29
Source File: ProgrammaticTxMgmtSpringRuleTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource() {
	return new EmbeddedDatabaseBuilder()//
	.generateUniqueName(true)//
	.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") //
	.build();
}
 
Example #30
Source File: EmbeddedPersonDatabaseTestsConfig.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource() {
	return new EmbeddedDatabaseBuilder()//
	.generateUniqueName(true)//
	.addScript("classpath:/org/springframework/test/jdbc/schema.sql") //
	.build();
}