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

The following examples show how to use org.springframework.jdbc.datasource.embedded.EmbeddedDatabase. 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: MetaDataExtractorTest.java    From celerio with Apache License 2.0 6 votes vote down vote up
@Test
public void outputIsSameAsInput() throws ClassNotFoundException, SQLException, XmlMappingException, IOException {
    EmbeddedDatabase embeddedDatabase = createMinimalEmbeddedDatabase(ALL_RELATIONS_SCRIPT);

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


    assertThat(countTables(meta)).isEqualTo(18);
    assertThat(countColumns(meta)).isEqualTo(49);
    assertThat(countPrimaryKeys(meta)).isEqualTo(18);
    assertThat(countIndexes(meta)).isEqualTo(21);
    assertThat(countEnums(meta)).isEqualTo(3);

    File tempFile = File.createTempFile(getClass().getName(), ".xml");
    tempFile.deleteOnExit();
    loader.write(meta, tempFile);

    Metadata loadedMeta = loader.load(tempFile);
    assertThat(countTables(meta)).isEqualTo(countTables(loadedMeta));
    assertThat(countColumns(meta)).isEqualTo(countColumns(loadedMeta));
    assertThat(countPrimaryKeys(meta)).isEqualTo(countPrimaryKeys(loadedMeta));
    assertThat(countIndexes(meta)).isEqualTo(countIndexes(loadedMeta));
    assertThat(countEnums(meta)).isEqualTo(countEnums(loadedMeta));

    embeddedDatabase.shutdown();
}
 
Example #2
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 #3
Source File: HistoryLevelDeterminatorJdbcTemplateImplTestApplication.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@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 #4
Source File: RepositoryTestConfig.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/hibernate4/schema.sql");
  edb.addScript("spittr/db/hibernate4/test-data.sql");
  EmbeddedDatabase embeddedDatabase = edb.build();
  return embeddedDatabase;
}
 
Example #5
Source File: HsqlDataSource.java    From netty.book.kor with 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 #6
Source File: HsqlDataSource.java    From netty.book.kor with 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 #7
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 #8
Source File: DerbyDataSource.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.DERBY).addScript("db/sql/create-db.sql").addScript("db/sql/insert-data.sql").build();
	return db;

}
 
Example #9
Source File: HsqlDataSource.java    From spring-embedded-database with 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 #10
Source File: MetaDataExtractorTest.java    From celerio with Apache License 2.0 5 votes vote down vote up
@Test
public void minimal() throws ClassNotFoundException, SQLException, JAXBException, IOException {
    EmbeddedDatabase embeddedDatabase = createMinimalEmbeddedDatabase(MINIMAL_SCRIPT);
    Metadata meta = extractor.extract(embeddedDatabase.getConnection());

    assertThat(countTables(meta)).isEqualTo(6);
    assertThat(countColumns(meta)).isEqualTo(29);
    assertThat(countPrimaryKeys(meta)).isEqualTo(9);
    assertThat(countImportedKeys(meta)).isEqualTo(4);
    assertThat(countIndexes(meta)).isEqualTo(13);
    assertThat(countEnums(meta)).isZero();

    embeddedDatabase.shutdown();
}
 
Example #11
Source File: HistoryLevelDeterminatorJdbcTemplateImplTestApplication.java    From camunda-bpm-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@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 #12
Source File: DatabaseConfig.java    From minitwit with MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource() {
	
	EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
	EmbeddedDatabase db = builder
			.setType(EmbeddedDatabaseType.HSQL)
			.addScript("sql/create-db.sql")
			.addScript("sql/insert-data.sql")
			.build();
	return db;
}
 
Example #13
Source File: SpringMvcDatabaseConfig.java    From Hands-On-High-Performance-with-Spring-5 with MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource() throws PropertyVetoException, SQLException {
	EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
	EmbeddedDatabase db = builder
			.setType(EmbeddedDatabaseType.H2)
			.addScript("schema.sql")
			.addScript("users.sql")
			.addScript("authorities.sql")
			.build();
    return db;
}
 
Example #14
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 #15
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 #16
Source File: SpringMvcDatabaseConfig.java    From Hands-On-High-Performance-with-Spring-5 with MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource() throws PropertyVetoException, SQLException {
	EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
	EmbeddedDatabase db = builder
			.setType(EmbeddedDatabaseType.H2)
			.addScript("schema.sql")
			.addScript("users.sql")
			.addScript("authorities.sql")
			.build();
    return db;
}
 
Example #17
Source File: Spring4Config.java    From JUnit-5-Quick-Start-Guide-and-Framework-Support with MIT License 5 votes vote down vote up
@Bean
public DataSource dataSource() {
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
    EmbeddedDatabase db = builder
            .setType(EmbeddedDatabaseType.HSQL)
            .addScript("schema.sql")
            .addScript("data.sql")
            .build();
    return db;
}
 
Example #18
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 #19
Source File: DemoOauth2Application.java    From Oauth2-Stateless-Authentication-with-Spring-and-JWT-Token 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 #20
Source File: MybatisConfiguration.java    From saluki with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean(EmbeddedDatabase.class)
public EmbeddedDatabase dataSource() {
  EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
  EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.H2) //
      .setName("grpcmonitor")//
      .addScript("mapper/create-db.sql")//
      .build();
  return db;
}
 
Example #21
Source File: MybatisConfiguration.java    From saluki with Apache License 2.0 5 votes vote down vote up
@Bean(name = "sqlSessionFactory")
public SqlSessionFactory sqlSessionFactoryBean(EmbeddedDatabase dataSource) {
  SqlSessionFactoryBean bean = new SqlSessionFactoryBean();
  bean.setDataSource(dataSource);
  bean.setTypeAliasesPackage("io.github.saluki.monitor.dao.domain");
  ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
  try {
    bean.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));
    return bean.getObject();
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
Example #22
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 #23
Source File: Spring5Config.java    From JUnit-5-Quick-Start-Guide-and-Framework-Support with 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) //.H2 or .DERBY
            .addScript("schema.sql")
            .addScript("data.sql")
            .build();
    return db;
}
 
Example #24
Source File: MetaDataExtractorTest.java    From celerio with Apache License 2.0 4 votes vote down vote up
private EmbeddedDatabase createMinimalEmbeddedDatabase(String sqlScript) {
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
    return builder.setType(EmbeddedDatabaseType.H2).addScript(sqlScript).build();
}
 
Example #25
Source File: SshShellSessionConfigurationTest.java    From ssh-shell-spring-boot with Apache License 2.0 4 votes vote down vote up
@Bean
public EmbeddedDatabase dataSource() {
    return new EmbeddedDatabaseBuilder()
            .setType(EmbeddedDatabaseType.H2)
            .addScript("org/springframework/session/jdbc/schema-h2.sql").build();
}
 
Example #26
Source File: CelerioProducerTest.java    From celerio with Apache License 2.0 4 votes vote down vote up
private Metadata getMetaDataFromH2Script(String sqlResource) throws ClassNotFoundException, SQLException {
    EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).addScript(sqlResource).build();
    return extractor.extract(embeddedDatabase.getConnection());
}
 
Example #27
Source File: PersistanceConfig.java    From audit4j-demo with Apache License 2.0 4 votes vote down vote up
@Bean
public DataSource dataSource() {
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
    EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.HSQL).build();
    return db;
}
 
Example #28
Source File: Config.java    From spring-session with Apache License 2.0 4 votes vote down vote up
@Bean
public EmbeddedDatabase dataSource() {
	return new EmbeddedDatabaseBuilder() // <2>
			.setType(EmbeddedDatabaseType.H2).addScript("org/springframework/session/jdbc/schema-h2.sql").build();
}
 
Example #29
Source File: H2JdbcIndexedSessionRepositoryITests.java    From spring-session with Apache License 2.0 4 votes vote down vote up
@Bean
EmbeddedDatabase dataSource() {
	return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
			.addScript("org/springframework/session/jdbc/schema-h2.sql").build();
}
 
Example #30
Source File: DerbyJdbcIndexedSessionRepositoryITests.java    From spring-session with Apache License 2.0 4 votes vote down vote up
@Bean
EmbeddedDatabase dataSource() {
	return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.DERBY)
			.addScript("org/springframework/session/jdbc/schema-derby.sql").build();
}