private static void setupEmbeddedDatabase() throws NamingException{ SimpleNamingContextBuilder builder = SimpleNamingContextBuilder .emptyActivatedContextBuilder(); EmbeddedDatabaseBuilder dbBuilder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase db = dbBuilder .setType(EmbeddedDatabaseType.DERBY) .setName("usciitg") .setScriptEncoding("UTF-8") .ignoreFailedDrops(true) .addScript("org/partners/usciitg_prep/terminology/jpa/create-db.sql") .addScript("org/partners/usciitg_prep/terminology/jpa/insert-data.sql") .build(); builder.bind(System.getProperty("usciitg.datasource"), db); }
private static void setupEmbeddedDatabase() throws NamingException{ SimpleNamingContextBuilder builder = SimpleNamingContextBuilder .emptyActivatedContextBuilder(); EmbeddedDatabaseBuilder dbBuilder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase db = dbBuilder .setType(EmbeddedDatabaseType.DERBY) .setName("usciitg") .setScriptEncoding("UTF-8") .ignoreFailedDrops(true) .addScript("org/partners/usciitg_prep/terminology/jpa/create-db.sql") .addScript("org/partners/usciitg_prep/fhir/cql/insert-data.sql") .build(); builder.bind(System.getProperty("usciitg.datasource"), db); }
private static void setupEmbeddedDatabase() throws NamingException{ SimpleNamingContextBuilder builder = SimpleNamingContextBuilder .emptyActivatedContextBuilder(); EmbeddedDatabaseBuilder dbBuilder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase db = dbBuilder .setType(EmbeddedDatabaseType.DERBY) .setName("usciitg") .setScriptEncoding("UTF-8") .ignoreFailedDrops(true) .addScript("org/partners/usciitg_prep/terminology/jpa/create-db.sql") .addScript("org/partners/usciitg_prep/fhir/cql/insert-data.sql") .addScript("org/partners/usciitg_prep/fhir/create-db.sql") .addScript("org/partners/usciitg_prep/fhir/insert-data.sql") .build(); builder.bind(System.getProperty("usciitg.datasource"), db); }
@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; }
@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; }
@Override @Bean(name = "dataSource") public DataSource getDataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase embeddedDb = builder .setType(EmbeddedDatabaseType.DERBY) .ignoreFailedDrops(true) .addScript("sql/create_tables.sql") .addScript("sql/insert_just_category_data.sql") .build(); return embeddedDb; }
public static void main(final String[] args) throws SQLException { LOGGER.info("==========================================================="); // r�cup�ration du contexte via les annotations � partir d'un package ApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfiguration.class); LOGGER.info("==========================================================="); // notre contexte est charg� LOGGER.info("context is loaded : {}", context); LOGGER.info("-----------------------------------------------------------"); EmbeddedDatabase dataSource = context.getBean(EmbeddedDatabase.class); LOGGER.info("Datasource : {}, connection : {}", dataSource, dataSource.getConnection().isClosed()); // fermeture de la base embarqu�e dataSource.shutdown(); }
@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(); }
@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(); }
@Test public void testConfigurationHotReloading() throws Exception { //given EmbeddedDatabase database = new EmbeddedDatabaseBuilder().setName("test").addScript("database.sql").build(); System.setProperty("sp", "foo"); HotReloadableConfig config = new HotReloadableConfig(); //when propertiesInjector.injectProperties(config); //then assertThat(config.getSystemProperty()).isEqualTo("foo"); assertThat(config.getName()).isEqualTo("Foo"); // Properties changes should be reloaded System.setProperty("sp","bar"); new JdbcTemplate(database).update("update ApplicationProperties set value = ? where key = ?", "Bar", "name"); sleep(2 * 1000); assertThat(config.getSystemProperty()).isEqualTo("bar"); assertThat(config.getName()).isEqualTo("Bar"); database.shutdown(); }
@Bean public DataSource dataSource() { //TODO:just for test, replace by your own datasource EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase db = builder .setType(EmbeddedDatabaseType.H2) //.H2 or .DERBY .addScript("db/sql/create-db.sql") .addScript("db/sql/insert-data.sql") .build(); return db; }
@Bean public DataSource dataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.H2) .addScript("db/create-db.sql") .addScript("db/insert-data.sql").build(); return db; }
@Bean @Qualifier("mainDataSource") public DataSource dataSource(){ EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase db = builder .setType(EmbeddedDatabaseType.H2) .build(); return db; }
@Bean public DataSource dataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.H2) .addScript("/jdbc/schema.sql") .addScript("/jdbc/data.sql") .build(); return db; }
@Bean(name = "sqlSessionFactory") public SqlSessionFactory sqlSessionFactoryBean(EmbeddedDatabase dataSource) { SqlSessionFactoryBean bean = new SqlSessionFactoryBean(); bean.setDataSource(dataSource); bean.setTypeAliasesPackage("com.quancheng.saluki.domain"); ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); try { bean.setMapperLocations(resolver.getResources("classpath:mapper/*.xml")); return bean.getObject(); } catch (Exception e) { throw new RuntimeException(e); } }
@Override @Bean(name = "dataSource") public DataSource getDataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase embeddedDb = builder .setType(EmbeddedDatabaseType.DERBY) .ignoreFailedDrops(true) // .addScript("sql/drop_tables.sql") .addScript("sql/create_tables.sql") .addScript("sql/insert_data.sql") .build(); return embeddedDb; }
@AfterEach public void tearDown() throws Exception { DataSource dataSource = (DataSource) ctx.getBean("dataSource"); if (dataSource instanceof EmbeddedDatabase) { ((EmbeddedDatabase) dataSource).shutdown(); } }
@Override @Bean(name = "dataSource") public DataSource getDataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase embeddedDb = builder .setType(EmbeddedDatabaseType.DERBY) .ignoreFailedDrops(true) .addScript("sql/create_tables.sql") // NO DATA .build(); return embeddedDb; }
@Bean public DataSource getDataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase db = builder.setName("testdb").setType(EmbeddedDatabaseType.HSQL) .addScript("db/sql/create-db.sql").addScript("db/sql/insert-data.sql").build(); return db; }
@Bean public DataSource dataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.HSQL). addScript("META-INF/data/schema.sql"). addScript("META-INF/data/data.sql").build(); return db; }
@Bean public DataSource routingDataSource() throws SQLException { EmbeddedDatabase embeddedDatabase = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2).addScript("classpath:/test-init.sql").build(); ReplicationRoutingDataSource proxy = new ReplicationRoutingDataSource(embeddedDatabase, null); proxy.addSlave(embeddedDatabase); proxy.addSlave(embeddedDatabase); proxy.addSlave(embeddedDatabase); return proxy; }
private void dropTableDummyTable() { EmbeddedDatabase dataSource = new EmbeddedDatabaseBuilder() .setType(EmbeddedDatabaseType.HSQL) .build(); executeUpdate("drop table DUMMYTABLE", dataSource); }
@Bean @Profile("test") public DataSource getTestDataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.H2) // .H2 or .addScript("userRole.sql").build(); return db; }
@Bean public EmbeddedDatabase dataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase db = builder .setType(EmbeddedDatabaseType.HSQL) .addScript("classpath:sql/test/user_role_init_datatables.sql") .addScript("classpath:sql/test/user_role_init_data.sql") .build(); return db; }
@Bean public EmbeddedDatabase dataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase db = builder .setType(EmbeddedDatabaseType.HSQL) .addScript("classpath:sql/test/web_init_datatables.sql") .addScript("classpath:sql/test/web_init_data.sql") .build(); return db; }
@Bean public EmbeddedDatabase dataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); EmbeddedDatabase db = builder .setType(EmbeddedDatabaseType.HSQL) .addScript("classpath:sql/test/login_init_datatables.sql") .addScript("classpath:sql/test/login_init_data.sql") .build(); return db; }
public EmbeddedDatabase getEmbeddedDatabase() { EmbeddedDatabaseConnection connection = this.environment.getProperty( "spring.test.database.connection", EmbeddedDatabaseConnection.class, EmbeddedDatabaseConnection.NONE); if (EmbeddedDatabaseConnection.NONE.equals(connection)) { connection = EmbeddedDatabaseConnection.get(getClass().getClassLoader()); } return new EmbeddedDatabaseBuilder().setType(connection.getType()).build(); }
@Bean public EmbeddedDatabase dataSource() { EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder() .setType(EmbeddedDatabaseConnection.get(this.classLoader).getType()); this.database = builder.setName(this.properties.getName()).build(); return this.database; }
@Bean public DataSource dataSource() { final EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); final EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.HSQL).build(); return db; }
@Bean public EmbeddedDatabase dataSource() { return new EmbeddedDatabaseBuilder() .generateUniqueName(true) .setType(H2) .setScriptEncoding("UTF-8") .ignoreFailedDrops(true) .addScripts("schema.sql", "data.sql") .build(); }
/** * Création de la datasource de test * @return datasource pour les tests */ @Bean public EmbeddedDatabase dataSource() { return new EmbeddedDatabaseBuilder() .setName("TESTDB") .setType(H2) .setScriptEncoding("UTF-8") .ignoreFailedDrops(true) .addScripts("schema.sql", "data.sql") .build(); }