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

The following examples show how to use org.springframework.jdbc.datasource.embedded.EmbeddedDatabase. 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: celerio   Source File: MetaDataExtractorTest.java    License: 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 3
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 4
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 5
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 6
@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 7
@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 8
@Bean @Qualifier("mainDataSource")
public DataSource dataSource(){
	EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
	EmbeddedDatabase db = builder
			.setType(EmbeddedDatabaseType.H2)
			.build();
	return db;
}
 
Example 9
@Bean @Qualifier("mainDataSource")
public DataSource dataSource(){
	EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
	EmbeddedDatabase db = builder
			.setType(EmbeddedDatabaseType.H2)
			.build();
	return db;
}
 
Example 10
Source Project: saluki   Source File: MybatisConfiguration.java    License: 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 11
Source Project: saluki   Source File: MybatisConfiguration.java    License: 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 12
@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 13
@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 14
@Bean
public DataSource dataSource() {
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
    EmbeddedDatabase db = builder
            .setType(EmbeddedDatabaseType.HSQL)
            .addScript("schema.sql")
            .addScript("data.sql")
            .build();
    return db;
}
 
Example 15
Source Project: minitwit   Source File: DatabaseConfig.java    License: 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 16
@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 17
Source Project: celerio   Source File: MetaDataExtractorTest.java    License: 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 18
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 19
Source Project: spring-embedded-database   Source File: DerbyDataSource.java    License: 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 20
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 21
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 22
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 23
@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 24
@Bean
public EmbeddedDatabase dataSource() {
    return new EmbeddedDatabaseBuilder()
            .setType(EmbeddedDatabaseType.H2)
            .addScript("org/springframework/session/jdbc/schema-h2.sql").build();
}
 
Example 25
Source Project: audit4j-demo   Source File: PersistanceConfig.java    License: 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 26
Source Project: celerio   Source File: CelerioProducerTest.java    License: 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 Project: celerio   Source File: MetaDataExtractorTest.java    License: 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 28
Source Project: spring-session   Source File: Config.java    License: 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
@Bean
EmbeddedDatabase dataSource() {
	return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2)
			.addScript("org/springframework/session/jdbc/schema-h2.sql").build();
}
 
Example 30
@Bean
EmbeddedDatabase dataSource() {
	return new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.DERBY)
			.addScript("org/springframework/session/jdbc/schema-derby.sql").build();
}