|
19 | 19 | import com.oltpbenchmark.catalog.AbstractCatalog; |
20 | 20 | import com.oltpbenchmark.types.DatabaseType; |
21 | 21 | import com.oltpbenchmark.util.ClassUtil; |
| 22 | +import com.oltpbenchmark.util.FileUtil; |
22 | 23 | import com.oltpbenchmark.util.SQLUtil; |
23 | 24 | import com.oltpbenchmark.util.ScriptRunner; |
24 | 25 | import com.oltpbenchmark.util.ThreadUtil; |
| 26 | +import java.io.FileNotFoundException; |
25 | 27 | import java.io.IOException; |
26 | 28 | import java.io.InputStream; |
27 | 29 | import java.sql.Connection; |
@@ -89,8 +91,22 @@ public final Connection makeConnection() throws SQLException { |
89 | 91 |
|
90 | 92 | private String afterLoadScriptPath = null; |
91 | 93 |
|
92 | | - public final void setAfterLoadScriptPath(String scriptPath) { |
93 | | - this.afterLoadScriptPath = scriptPath; |
| 94 | + public final void setAfterLoadScriptPath(String scriptPath) throws FileNotFoundException { |
| 95 | + if (scriptPath != null) scriptPath = scriptPath.trim(); |
| 96 | + try { |
| 97 | + this.afterLoadScriptPath = FileUtil.checkPath(scriptPath, "afterload"); |
| 98 | + return; |
| 99 | + } catch (FileNotFoundException ex) { |
| 100 | + this.afterLoadScriptPath = null; |
| 101 | + } |
| 102 | + |
| 103 | + if (this.afterLoadScriptPath == null && scriptPath != null && !scriptPath.isEmpty()) { |
| 104 | + if (this.getClass().getResourceAsStream(scriptPath) == null) { |
| 105 | + throw new FileNotFoundException( |
| 106 | + "Couldn't find " + scriptPath + " as local file or resource."); |
| 107 | + } |
| 108 | + this.afterLoadScriptPath = scriptPath; |
| 109 | + } |
94 | 110 | } |
95 | 111 |
|
96 | 112 | public String getAfterLoadScriptPath() { |
@@ -241,8 +257,23 @@ public final void runScript(String scriptPath) throws SQLException, IOException |
241 | 257 | try (Connection conn = this.makeConnection()) { |
242 | 258 | DatabaseType dbType = this.workConf.getDatabaseType(); |
243 | 259 | ScriptRunner runner = new ScriptRunner(conn, true, true); |
244 | | - LOG.debug("Executing script [{}] for database type [{}]", scriptPath, dbType); |
245 | | - runner.runScript(scriptPath); |
| 260 | + LOG.debug( |
| 261 | + "Checking for script [{}] on local filesystem for database type [{}]", |
| 262 | + scriptPath, |
| 263 | + dbType); |
| 264 | + if (FileUtil.exists(scriptPath)) { |
| 265 | + LOG.debug( |
| 266 | + "Executing script [{}] from local filesystem for database type [{}]", |
| 267 | + scriptPath, |
| 268 | + dbType); |
| 269 | + runner.runExternalScript(scriptPath); |
| 270 | + } else { |
| 271 | + LOG.debug( |
| 272 | + "Executing script [{}] from resource stream for database type [{}]", |
| 273 | + scriptPath, |
| 274 | + dbType); |
| 275 | + runner.runScript(scriptPath); |
| 276 | + } |
246 | 277 | } |
247 | 278 | } |
248 | 279 |
|
@@ -274,11 +305,13 @@ public final Loader<? extends BenchmarkModule> loadDatabase() |
274 | 305 |
|
275 | 306 | if (this.afterLoadScriptPath != null) { |
276 | 307 | LOG.debug( |
277 | | - "Running script after load for {} benchmark...", |
| 308 | + "Running script {} after load for {} benchmark...", |
| 309 | + this.afterLoadScriptPath, |
278 | 310 | this.workConf.getBenchmarkName().toUpperCase()); |
279 | 311 | runScript(this.afterLoadScriptPath); |
280 | 312 | LOG.debug( |
281 | | - "Finished running script after load for {} benchmark...", |
| 313 | + "Finished running script {} after load for {} benchmark...", |
| 314 | + this.afterLoadScriptPath, |
282 | 315 | this.workConf.getBenchmarkName().toUpperCase()); |
283 | 316 | } |
284 | 317 |
|
|
0 commit comments