@@ -21,9 +21,11 @@ public class QuickstartDBHelper {
2121 private QuickstartDBHelper () {}
2222
2323 private static final Logger logger = LoggerFactory .getLogger ( QuickstartDBHelper .class );
24-
25- public static final String DEFAULT_DB_CONN_PATH = "quickstart_db/quickstart-db-conn.properties" ;
26- public static final String DEFAULT_DB_INIT_PATH = "quickstart_db/hsqldb" ;
24+
25+ private static final String DEFAULT_DB_CONN_PATH = "quickstart_db/quickstart-db-conn.properties" ;
26+ private static final String DEFAULT_DB_INIT_PATH = "quickstart_db/hsqldb" ;
27+
28+ private static final String [] SQL_INIT_SCRIPTS = { "100_db_setup.sql" , "200_sample_db.sql" , "900_examples.sql" };
2729
2830 private static final String DRV = "db-mode-dc-drv" ;
2931 private static final String URL = "db-mode-dc-url" ;
@@ -48,21 +50,19 @@ public static void init()
4850 Properties props = new Properties ();
4951 props .load ( is );
5052 try ( Connection conn = newConnection ( props ) ) {
51- cf = props ;
52- ResScanner scanner = new ResScanner ();
53- List <String > initFiles = scanner .getResourceFiles ( DEFAULT_DB_INIT_PATH );
54- for ( String current : initFiles ) {
55- String res = DEFAULT_DB_INIT_PATH +"/" +current ;
56- logger .info ( "Current : {}" , res );
57- try ( SQLScriptReader reader = new SQLScriptReader ( QuickstartDBHelper .class .getClassLoader ().getResourceAsStream ( res ) ) ) {
58- SQLScriptFacade .executeAll (reader , conn );
59- cf = props ;
60- }
61- }
62- }
53+ for ( int k =0 ; k <SQL_INIT_SCRIPTS .length ; k ++ ) {
54+ String current = SQL_INIT_SCRIPTS [k ];
55+ String res = DEFAULT_DB_INIT_PATH +"/" +current ;
56+ logger .info ( "Current : {}" , res );
57+ try ( SQLScriptReader reader = new SQLScriptReader ( QuickstartDBHelper .class .getClassLoader ().getResourceAsStream ( res ) ) ) {
58+ SQLScriptFacade .executeAll (reader , conn );
59+
60+ }
61+ }
62+ }
63+ cf = props ;
6364 }
6465 } );
65-
6666 }
6767 }
6868
@@ -72,35 +72,3 @@ public static Connection newConnection() {
7272 }
7373
7474}
75-
76- class ResScanner {
77-
78- public List <String > getResourceFiles (String path ) throws IOException {
79- List <String > filenames = new ArrayList <>();
80-
81- try (
82- InputStream in = getResourceAsStream (path );
83- BufferedReader br = new BufferedReader (new InputStreamReader (in ))) {
84- String resource ;
85-
86- while ((resource = br .readLine ()) != null ) {
87- filenames .add (resource );
88- }
89- }
90-
91- return filenames ;
92- }
93-
94- private InputStream getResourceAsStream (String resource ) {
95- final InputStream in
96- = getContextClassLoader ().getResourceAsStream (resource );
97-
98- return in == null ? getClass ().getResourceAsStream (resource ) : in ;
99- }
100-
101- private ClassLoader getContextClassLoader () {
102- return Thread .currentThread ().getContextClassLoader ();
103- }
104-
105- }
106-
0 commit comments