@@ -21,9 +21,11 @@ public class QuickstartDBHelper {
21
21
private QuickstartDBHelper () {}
22
22
23
23
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" };
27
29
28
30
private static final String DRV = "db-mode-dc-drv" ;
29
31
private static final String URL = "db-mode-dc-url" ;
@@ -48,21 +50,19 @@ public static void init()
48
50
Properties props = new Properties ();
49
51
props .load ( is );
50
52
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 ;
63
64
}
64
65
} );
65
-
66
66
}
67
67
}
68
68
@@ -72,35 +72,3 @@ public static Connection newConnection() {
72
72
}
73
73
74
74
}
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