Example usage for org.springframework.jdbc.datasource.embedded EmbeddedDatabase shutdown

List of usage examples for org.springframework.jdbc.datasource.embedded EmbeddedDatabase shutdown

Introduction

In this page you can find the example usage for org.springframework.jdbc.datasource.embedded EmbeddedDatabase shutdown.

Prototype

void shutdown();

Source Link

Document

Shut down this embedded database.

Usage

From source file:sf.wicklet.gwt.site.server.db.H2Configurator.java

public static void addApplicationListener(final EmbeddedDatabase db, final String path) {
    Application.get().getApplicationListeners().add(new IApplicationListener() {
        @Override//from w  w w . ja v a2s  .com
        public void onBeforeDestroyed(final Application application) {
            if (Config.DEBUG) {
                System.out.println("# Shutting down database: " + path);
            }
            db.shutdown();
        }

        @Override
        public void onAfterInitialized(final Application application) {
        }
    });
}

From source file:com.jaxio.celerio.configuration.database.support.MetaDataExtractorTest.java

@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();
}

From source file:com.jaxio.celerio.configuration.database.support.MetaDataExtractorTest.java

@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();
}

From source file:no.magott.training.BusinessSchemaDbIntegrationTest.java

@Test
public void createAndInsertIntoSpursMatch() {
    EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
    EmbeddedDatabase db = builder.addScript("classpath:business-schema.sql").build();
    String sql = "INSERT INTO SPURS_MATCH(MATCH_DATE, COMPETITION, OPPOSITION, VENUE, HALF_TIME_SCORE, GOALS_FOR, GOALS_AGAINST) VALUES(:date, :competition, :opposition, :venue, :halfTimeScore, :spursGoals, :oppositionGoals)";
    NamedParameterJdbcTemplate jdbcTemplate = new NamedParameterJdbcTemplate(db);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("date", new Date());
    params.put("opposition", "Ar5ena1");
    params.put("halfTimeScore", "(2-0)");
    params.put("venue", "WHL");
    params.put("spursGoals", 5);
    params.put("oppositionGoals", 1);
    params.put("competition", "FACUP");
    jdbcTemplate.update(sql, params);//from   w w  w. j  a  va  2 s . c  o  m
    db.shutdown();
}

From source file:io.github.benas.easyproperties.PropertiesInjectorImplTest.java

@Test
public void testConfigurationHotReloading() throws Exception {
    //given/*from w  w  w .  j  a v  a  2  s.co m*/
    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();
}

From source file:com.jaxio.celerio.configuration.database.support.MetaDataExtractorTest.java

@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();//from  w ww. ja  va 2  s.  co  m
    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();
}