X-Git-Url: https://juplo.de/gitweb/?p=hibernate4-maven-plugin;a=blobdiff_plain;f=src%2Fit%2Fhibernate4-maven-plugin-envers-sample%2Fsrc%2Ftest%2Fjava%2Forg%2Fbitbucket%2Ffbascheper%2Ftutorial%2Fenvers%2Futil%2FInitScriptRunner.java;fp=src%2Fit%2Fhibernate4-maven-plugin-envers-sample%2Fsrc%2Ftest%2Fjava%2Forg%2Fbitbucket%2Ffbascheper%2Ftutorial%2Fenvers%2Futil%2FInitScriptRunner.java;h=b7c9e041136ddf4892b1e513b646d87f83e79892;hp=0000000000000000000000000000000000000000;hb=25079f13c0eda6807d5aee67086a21ddde313213;hpb=69458703cddc2aea1f67e06db43bce6950c6f3cb diff --git a/src/it/hibernate4-maven-plugin-envers-sample/src/test/java/org/bitbucket/fbascheper/tutorial/envers/util/InitScriptRunner.java b/src/it/hibernate4-maven-plugin-envers-sample/src/test/java/org/bitbucket/fbascheper/tutorial/envers/util/InitScriptRunner.java new file mode 100644 index 00000000..b7c9e041 --- /dev/null +++ b/src/it/hibernate4-maven-plugin-envers-sample/src/test/java/org/bitbucket/fbascheper/tutorial/envers/util/InitScriptRunner.java @@ -0,0 +1,87 @@ +/** + * Copyright 2013 F.B.A. Scheper. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. * + */ +package org.bitbucket.fbascheper.tutorial.envers.util; + +import org.springframework.core.io.Resource; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.test.jdbc.JdbcTestUtils; + +import javax.sql.DataSource; + +/** + * A initialization script runner. + * + * @author Erik-Berndt Scheper + * @since 11-09-2013 + */ +public interface InitScriptRunner { + + /** + * Run the database creation script. + */ + public void runScript(); + + /** + * Return the datasource used to run the script + * + * @return the datasource + */ + public DataSource getDataSource(); + + + /** + * Default implementation for the runner of the creation script. + */ + public static class InitScriptRunnerImpl implements InitScriptRunner { + + private final DataSource dataSource; + private final Resource dbDropScriptLocation; + private final Resource dbCreateScriptLocation; + + + /** + * Initializing constructor. + * + * @param dataSource the raw {@link javax.sql.DataSource} to return + * @param dbDropScriptLocation location of the create DB drop script to run + * @param dbCreateScriptLocation location of the create DB create script to run + */ + public InitScriptRunnerImpl(DataSource dataSource, + Resource dbDropScriptLocation, + Resource dbCreateScriptLocation) { + this.dataSource = dataSource; + this.dbDropScriptLocation = dbDropScriptLocation; + this.dbCreateScriptLocation = dbCreateScriptLocation; + } + + @Override + public void runScript() { + + JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); + JdbcTestUtils.executeSqlScript(jdbcTemplate, dbDropScriptLocation, false); + JdbcTestUtils.executeSqlScript(jdbcTemplate, dbCreateScriptLocation, false); + + } + + @Override + public DataSource getDataSource() { + + return this.dataSource; + + } + } + +}