Permalink
Browse files

Use a URL object instead of File for ddl.sql files so we can run from

a jar.  Add a pom.xml to build a standalone jar.
  • Loading branch information...
treilly-nuodb committed Sep 19, 2013
1 parent 42951ee commit 13e9738ea5b62a95fca979d3916596920f2758be
View
@@ -14,4 +14,7 @@ output.res
## Backup artifacts
## -------------------------------
~*
-*~
+*~
+
+# maven output
+target
View
Binary file not shown.
View
154 pom.xml
@@ -0,0 +1,154 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
+ http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.oltpbenchmark</groupId>
+ <artifactId>oltpbench</artifactId>
+ <version>1.0</version>
+ <packaging>jar</packaging>
+ <build>
+ <sourceDirectory>src</sourceDirectory>
+ <resources>
+ <resource>
+ <directory>src</directory>
+ <includes>
+ <include>**/*.sql</include>
+ </includes>
+ </resource>
+ </resources>
+ <plugins>
+ <!-- In addition to the standard JAR file,this will create an executable
+ JAR with dependencies -->
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>com.oltpbenchmark.DBWorkload</mainClass>
+ </manifest>
+ </archive>
+ <descriptorRefs>
+ <descriptorRef>jar-with-dependencies</descriptorRef>
+ </descriptorRefs>
+ </configuration>
+ <executions>
+ <execution>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <dependencies>
+ <dependency>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb-j5</artifactId>
+ <version>2.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.persistence</groupId>
+ <artifactId>persistence-api</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.17</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.2.1</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sourceforge.collections</groupId>
+ <artifactId>collections-generic</artifactId>
+ <version>4.01</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-configuration</groupId>
+ <artifactId>commons-configuration</artifactId>
+ <version>1.6</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.opencsv</groupId>
+ <artifactId>opencsv</artifactId>
+ <version>2.3</version>
+ </dependency>
+ <dependency>
+ <groupId>ch.ethz.ganymed</groupId>
+ <artifactId>ganymed-ssh2</artifactId>
+ <version>261</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-math3</artifactId>
+ <version>3.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-cli</groupId>
+ <artifactId>commons-cli</artifactId>
+ <version>1.2</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.jdo</groupId>
+ <artifactId>jdo2-api</artifactId>
+ <version>2.3-eb</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.persistence</groupId>
+ <artifactId>org.eclipse.persistence.jpa</artifactId>
+ <version>2.4.2</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <version>3.3.0.GA</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.openjpa</groupId>
+ <artifactId>openjpa-persistence-jdbc</artifactId>
+ <version>1.0.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate.javax.persistence</groupId>
+ <artifactId>hibernate-jpa-2.0-api</artifactId>
+ <version>1.0.1.Final</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-entitymanager</artifactId>
+ <version>3.6.10.Final</version>
+ </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-annotations</artifactId>
+ <version>3.5.6-Final</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-jxpath</groupId>
+ <artifactId>commons-jxpath</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.2</version>
+ </dependency>
+
+ <!--
+ Because this isn't an open source jar this is required:
+ $ mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.1.0 -Dpackaging=jar -Dfile=lib/ojdbc14-10.2.jar -DgeneratePom=true
+-->
+ <dependency>
+ <groupId>com.oracle</groupId>
+ <artifactId>ojdbc14</artifactId>
+ <version>10.2.0.1.0</version>
+ </dependency>
+ </dependencies>
+</project>
@@ -168,17 +168,17 @@ public Random rng() {
*
* @return
*/
- public File getDatabaseDDL() {
+ public URL getDatabaseDDL() {
return (this.getDatabaseDDL(this.workConf.getDBType()));
}
/**
- * Return the File handle to the DDL used to load the benchmark's database
+ * Return the URL handle to the DDL used to load the benchmark's database
* schema.
* @param conn
* @throws SQLException
*/
- public File getDatabaseDDL(DatabaseType db_type) {
+ public URL getDatabaseDDL(DatabaseType db_type) {
String ddlNames[] = {
this.benchmarkName + "-" + (db_type != null ? db_type.name().toLowerCase() : "") + "-ddl.sql",
this.benchmarkName + "-ddl.sql",
@@ -187,7 +187,7 @@ public File getDatabaseDDL(DatabaseType db_type) {
for (String ddlName : ddlNames) {
if (ddlName == null) continue;
URL ddlURL = this.getClass().getResource(ddlName);
- if (ddlURL != null) return new File(ddlURL.getPath());
+ if (ddlURL != null) return ddlURL;
} // FOR
LOG.error("Failed to find DDL file for " + this.benchmarkName);
return null;
@@ -233,11 +233,10 @@ public final void createDatabase() {
*/
public final void createDatabase(DatabaseType dbType, Connection conn) throws SQLException {
try {
- File ddl = this.getDatabaseDDL(dbType);
+ URL ddl = this.getDatabaseDDL(dbType);
assert(ddl != null) : "Failed to get DDL for " + this;
- assert(ddl.exists()) : "The file '" + ddl + "' does not exist";
ScriptRunner runner = new ScriptRunner(conn, true, true);
- if (LOG.isDebugEnabled()) LOG.debug("Executing script '" + ddl.getName() + "'");
+ if (LOG.isDebugEnabled()) LOG.debug("Executing script '" + ddl + "'");
runner.runScript(ddl);
} catch (Exception ex) {
throw new RuntimeException(String.format("Unexpected error when trying to create the %s database", this.benchmarkName), ex);
@@ -252,7 +251,7 @@ public final void runScript(String script) {
Connection conn = this.makeConnection();
ScriptRunner runner = new ScriptRunner(conn, true, true);
File scriptFile= new File(script);
- runner.runScript(scriptFile);
+ runner.runScript(scriptFile.toURI().toURL());
conn.close();
} catch (SQLException ex) {
throw new RuntimeException(String.format("Unexpected error when trying to run: %s", script), ex);
@@ -372,24 +371,6 @@ public final WorkloadConfiguration getWorkloadConfiguration() {
return (this.workConf);
}
- /**
- * Execute a SQL file using the ScriptRunner
- * @param c
- * @param path
- * @return
- */
- protected final boolean executeFile(Connection c, File path) {
- ScriptRunner runner = new ScriptRunner(c, true, false);
- try {
- runner.runScript(path);
- } catch (Exception ex) {
- ex.printStackTrace();
- LOG.error("Failed to execute script '" + path + "'", ex);
- return (false);
- }
- return (true);
- }
-
/**
* Return a mapping from TransactionTypes to Procedure invocations
* @param txns
@@ -19,7 +19,8 @@
******************************************************************************/
package com.oltpbenchmark.catalog;
-import java.io.File;
+import java.io.IOException;
+import java.net.URL;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
@@ -36,11 +37,11 @@
import java.util.regex.Pattern;
import org.apache.log4j.Logger;
+import org.apache.commons.io.IOUtils;
import com.oltpbenchmark.api.BenchmarkModule;
import com.oltpbenchmark.types.DatabaseType;
import com.oltpbenchmark.types.SortDirectionType;
-import com.oltpbenchmark.util.FileUtil;
import com.oltpbenchmark.util.Pair;
import com.oltpbenchmark.util.SQLUtil;
import com.oltpbenchmark.util.StringUtil;
@@ -289,8 +290,13 @@ protected void init() throws SQLException {
protected Map<String, String> getOriginalTableNames() {
Map<String, String> origTableNames = new HashMap<String, String>();
Pattern p = Pattern.compile("CREATE[\\s]+TABLE[\\s]+(.*?)[\\s]+", Pattern.CASE_INSENSITIVE);
- File ddl = this.benchmark.getDatabaseDDL(DatabaseType.HSQLDB);
- String ddlContents = FileUtil.readFile(ddl);
+ URL ddl = this.benchmark.getDatabaseDDL(DatabaseType.HSQLDB);
+ String ddlContents;
+ try {
+ ddlContents = IOUtils.toString(ddl);
+ } catch(IOException ioe) {
+ throw new RuntimeException(ioe);
+ }
assert(ddlContents.isEmpty() == false);
Matcher m = p.matcher(ddlContents);
while (m.find()) {
@@ -20,8 +20,8 @@
*/
package com.oltpbenchmark.util;
-import java.io.File;
-import java.io.FileReader;
+import java.net.URL;
+import java.io.InputStreamReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.io.PrintWriter;
@@ -91,8 +91,8 @@ public void setErrorLogWriter(PrintWriter errorLogWriter) {
* @param reader
* - the source of the script
*/
- public void runScript(File file) throws IOException, SQLException {
- Reader reader = new FileReader(file);
+ public void runScript(URL resource) throws IOException, SQLException {
+ Reader reader = new InputStreamReader(resource.openStream());
try {
boolean originalAutoCommit = connection.getAutoCommit();
try {
@@ -20,6 +20,9 @@
package com.oltpbenchmark.api;
import java.io.File;
+import java.net.URL;
+
+import org.apache.commons.io.IOUtils;
import com.oltpbenchmark.catalog.Catalog;
import com.oltpbenchmark.catalog.Table;
@@ -33,9 +36,9 @@
* testGetDatabaseDDL
*/
public void testGetDatabaseDDL() throws Exception {
- File ddl = this.benchmark.getDatabaseDDL();
+ URL ddl = this.benchmark.getDatabaseDDL();
assertNotNull(ddl);
- assert (ddl.exists());
+ assertNotNull (IOUtils.toString(ddl));
}
/**
@@ -30,12 +30,12 @@ protected Loader makeLoaderImpl(Connection conn) throws SQLException {
return null;
}
@Override
- public File getDatabaseDDL(DatabaseType db_type) {
+ public URL getDatabaseDDL(DatabaseType db_type) {
// Get our sample DDL file
URL testDDLURL = MockBenchmark.class.getResource("test-ddl.sql");
assert(testDDLURL != null);
File testDDL = new File(testDDLURL.getPath());
assert(testDDL.exists()) : testDDL.getAbsolutePath();
- return (testDDL);
+ return (testDDLURL);
}
} // END CLASS
@@ -6,8 +6,9 @@
import junit.framework.TestCase;
+import org.apache.commons.io.IOUtils;
+
import com.oltpbenchmark.api.MockBenchmark;
-import com.oltpbenchmark.util.FileUtil;
import com.oltpbenchmark.util.SQLUtil;
public class TestCatalog extends TestCase {
@@ -51,7 +52,7 @@ public void testGetOriginalTableNames() throws Exception {
*/
public void testInit() throws Exception {
// Count the number of CREATE TABLEs in our test file
- String contents = FileUtil.readFile(this.benchmark.getDatabaseDDL());
+ String contents = IOUtils.toString(this.benchmark.getDatabaseDDL());
assertFalse(contents.isEmpty());
int offset = 0;
int num_tables = 0;

0 comments on commit 13e9738

Please sign in to comment.