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

The following examples show how to use org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder. 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
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
@Bean
public DataSource dataSource() {
    LOGGER.debug("Running embedded database builder");
    return new EmbeddedDatabaseBuilder()
            .setType(EmbeddedDatabaseType.HSQL)
            .addScript("classpath:sql/hsql/schema.sql")
            .build();
}
 
Example 3
@Bean
@Primary
public DataSource myDataSource() {
	EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder()
			.setType(EmbeddedDatabaseType.H2).setName("myDataSource");
	return builder.build();
}
 
Example 4
@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 5
Source Project: spring-data-examples   Source File: OrderConfig.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
DataSource orderDataSource() {

	return new EmbeddedDatabaseBuilder().//
			setType(EmbeddedDatabaseType.HSQL).//
			setName("orders").//
			build();
}
 
Example 6
@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 7
Source Project: netty.book.kor   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")
			.setName("NETTY_EXAMPLE_DB")
			.build();
	return db;
}
 
Example 8
Source Project: spring-analysis-note   Source File: PrimaryDataSourceTests.java    License: MIT License 5 votes vote down vote up
@Primary
@Bean
public DataSource primaryDataSource() {
	// @formatter:off
	return new EmbeddedDatabaseBuilder()
			.generateUniqueName(true)
			.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql")
			.build();
	// @formatter:on
}
 
Example 9
@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 10
@Bean
public DataSource dataSource() {
  EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
  EmbeddedDatabase db = builder.setName("testdbForHistoryLevelDetermination").setType(EmbeddedDatabaseType.H2)
      .addScript("/org/camunda/bpm/engine/db/create/activiti.h2.create.engine.sql").addScript("db/sql/insert-history-data.sql").continueOnError(true).build();
  return db;
}
 
Example 11
Source Project: sakai   Source File: BaseStorageTest.java    License: Educational Community License v2.0 5 votes vote down vote up
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    hsqldb = new EmbeddedDatabaseBuilder().addScripts("db/migration/hsqldb.sql").build();

    db = new DB() {
        @Override
        protected DBConnection wrapConnection(Connection conn) {
            if ( connectionWrapSupplier == null ) {
                return super.wrapConnection(conn);
            } else {
                return connectionWrapSupplier.apply(conn);
            }
        }
    };
    db.setDataSource(hsqldb);
    db.setVendor("hsqldb");

    tagCollectionStorage = new TagCollectionStorage();
    tagCollectionStorage.setDb(db);
    tagCollectionStorage.setSessionManager(sessionManager);
    tagCollectionStorage.setEventTrackingService(tagCollectionsEventTrackingService);
    tagCollectionStorage.setTimestampProvider(tagCollectionTimestampProvider);

    tagStorage = new TagStorage();
    tagStorage.setDb(db);
    tagStorage.setSessionManager(sessionManager);
    tagStorage.setEventTrackingService(tagsEventTrackingService);
    tagStorage.setTimestampProvider(tagTimestampProvider);

    when(tagTimestampProvider.get()).thenReturn(now()); // some reasonable defaulting
    when(tagCollectionTimestampProvider.get()).thenReturn(now()); // some reasonable defaulting
    when(sessionManager.getCurrentSessionUserId()).thenReturn("thisuserid");
}
 
Example 12
@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 13
@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 14
Source Project: java-master   Source File: DatabaseConfig.java    License: 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 15
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 16
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 17
Source Project: tutorials   Source File: PersistenceConfig.java    License: 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 18
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 19
Source Project: Project   Source File: JpaConfig.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/jpa/schema.sql");
  edb.addScript("spittr/db/jpa/test-data.sql");
  EmbeddedDatabase embeddedDatabase = edb.build();
  return embeddedDatabase;
}
 
Example 20
@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 21
@Bean
public DataSource dataSource() {
	return new EmbeddedDatabaseBuilder()//
	.setName("populated-sql-scripts-test-db")//
	.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") //
	.build();
}
 
Example 22
Source Project: spring-batch-lightmin   Source File: LightminServer.java    License: 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 23
Source Project: spring-embedded-database   Source File: H2DataSource.java    License: 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 24
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 25
@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 26
@Bean @Qualifier("mainDataSource")
public DataSource dataSource(){
	EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
	EmbeddedDatabase db = builder
			.setType(EmbeddedDatabaseType.H2)
			.build();
	return db;
}
 
Example 27
@Bean
DataSource dataSource() {
	return new EmbeddedDatabaseBuilder()//
	.addScript("classpath:/org/springframework/test/jdbc/schema.sql")//
	.addScript("classpath:/org/springframework/test/jdbc/data.sql")//
	.build();
}
 
Example 28
@Bean
public DataSource dataSource() {
	return new EmbeddedDatabaseBuilder()//
	.generateUniqueName(true)//
	.addScript("classpath:/org/springframework/test/jdbc/schema.sql") //
	.build();
}
 
Example 29
@Bean
public DataSource dataSource() {
	return new EmbeddedDatabaseBuilder()//
	.generateUniqueName(true)//
	.addScript("classpath:/org/springframework/test/context/jdbc/schema.sql") //
	.build();
}
 
Example 30
@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();
}