diff --git a/pom.xml b/pom.xml index 56e09d7..bd6f435 100644 --- a/pom.xml +++ b/pom.xml @@ -12,9 +12,9 @@ UTF-8 UTF-8 - 8 - 8 - 8 + 11 + 11 + 11 @@ -39,7 +39,7 @@ - + diff --git a/src/main/java/com/olxpbenchmark/api/StatementDialects.java b/src/main/java/com/olxpbenchmark/api/StatementDialects.java index e7fe076..95c431d 100644 --- a/src/main/java/com/olxpbenchmark/api/StatementDialects.java +++ b/src/main/java/com/olxpbenchmark/api/StatementDialects.java @@ -17,6 +17,8 @@ package com.olxpbenchmark.api; import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.StringWriter; import java.net.URL; import java.util.ArrayList; @@ -33,6 +35,7 @@ import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; +import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; @@ -110,12 +113,18 @@ protected boolean load() { SchemaFactory sf = SchemaFactory.newInstance(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI); Schema schema = sf.newSchema(this.xmlSchemaURL); Unmarshaller unmarshaller = jc.createUnmarshaller(); - // But did not shoot unmarshaller! unmarshaller.setSchema(schema); // Disable External Entity Resolution unmarshaller.setProperty("javax.xml.stream.isReplacingEntityReferences", false); unmarshaller.setProperty("javax.xml.stream.isSupportingExternalEntities", false); - JAXBElement result = (JAXBElement) unmarshaller.unmarshal(this.xmlFile); + StreamSource streamSource; + try { + streamSource = new StreamSource(new FileInputStream(this.xmlFile)); + } catch (FileNotFoundException ex) { + throw new RuntimeException(String.format("Error reading XML file '%s'", this.xmlFile), ex); + } + JAXBElement result = (JAXBElement) unmarshaller.unmarshal(streamSource, + DialectsType.class); dialects = result.getValue(); } catch (JAXBException ex) { // Convert some linked exceptions to more friendly errors. diff --git a/src/main/java/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W51.java b/src/main/java/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W51.java index a13596a..eddfec6 100755 --- a/src/main/java/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W51.java +++ b/src/main/java/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W51.java @@ -55,20 +55,41 @@ public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int // Create statement and set parameters query_stmt = this.getPreparedStatement(conn, query_stmtSQL, value); - if (LOG.isDebugEnabled()) { + // Log query + if (debug) { LOG.debug(queryToString(query_stmt)); } - if (trace) - LOG.trace("query_stmt W51 UpdateQuery2 START"); - // int affectedRows = query_stmt.executeUpdate(); - query_stmt.executeUpdate(); + if (trace) { + LOG.trace("Query" + classname + " START"); + } + int affectedRows = 0; // Number of rows affected + ResultSet rs = null; + // Execute query and commit + if (isExplainAnalyze) { + // Use executeQuery for explain analyze + rs = query_stmt.executeQuery(); + } else { + // Use executeUpdate for normal query + affectedRows = query_stmt.executeUpdate(); + } conn.commit(); - if (trace) - LOG.trace("query_stmt W51 UpdateQuery2 END"); + if (trace) { + LOG.trace("Query" + classname + " END"); + } + + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } else { + if (debug) { + LOG.debug("Affected Rows: " + affectedRows); + } + } - // long latency_ns = getTimeFromRS(rs); - // rs.close(); return 0; } } diff --git a/src/main/java/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W52.java b/src/main/java/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W52.java index f6710f8..10e643f 100755 --- a/src/main/java/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W52.java +++ b/src/main/java/com/olxpbenchmark/benchmarks/web3benchmark/procedures/W52.java @@ -53,26 +53,47 @@ public long run(Connection conn, Random gen, WEB3Worker w, int startNumber, int classname_note + (isExplainAnalyze ? SQL_EXPLAIN_ANALYZE : "") + query); // Create statement and set parameters query_stmt = this.getPreparedStatement(conn, query_stmtSQL); - if (LOG.isDebugEnabled()) { + + // Log query + if (debug) { LOG.debug(queryToString(query_stmt)); } // set autocommit to true conn.setAutoCommit(true); - if (trace) - LOG.trace("query_stmt UpdateQuery3 START"); - // int affectedRows = query_stmt.executeUpdate(); - query_stmt.executeUpdate(); - // conn.commit(); - if (trace) - LOG.trace("query_stmt UpdateQuery3 END"); + if (trace) { + LOG.trace("Query" + classname + " START"); + } + int affectedRows = 0; // Number of rows affected + ResultSet rs = null; + // Execute query and commit + if (isExplainAnalyze) { + // Use executeQuery for explain analyze + rs = query_stmt.executeQuery(); + } else { + // Use executeUpdate for normal query + affectedRows = query_stmt.executeUpdate(); + } + if (trace) { + LOG.trace("Query" + classname + " END"); + } // reset autocommit to false conn.setAutoCommit(false); - // long latency_ns = getTimeFromRS(rs); - // rs.close(); + if (isExplainAnalyze) { + // If explain analyze, then return the latency + // Get the latency from the result set + long latency_ns = getTimeFromRS(rs); + rs.close(); + return latency_ns; + } else { + if (debug) { + LOG.debug("Affected Rows: " + affectedRows); + } + } + return 0; } } diff --git a/src/main/java/com/olxpbenchmark/jdbc/AutoIncrementPreparedStatement.java b/src/main/java/com/olxpbenchmark/jdbc/AutoIncrementPreparedStatement.java index 34b8f34..2edc7c2 100644 --- a/src/main/java/com/olxpbenchmark/jdbc/AutoIncrementPreparedStatement.java +++ b/src/main/java/com/olxpbenchmark/jdbc/AutoIncrementPreparedStatement.java @@ -33,6 +33,7 @@ import java.sql.ResultSetMetaData; import java.sql.RowId; import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; import java.sql.SQLWarning; import java.sql.SQLXML; import java.sql.Time; @@ -359,9 +360,9 @@ public void setAsciiStream(int parameterIndex, InputStream x, int length) throws this.stmt.setAsciiStream(parameterIndex, x, length); } - @Override + @Deprecated public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { - this.stmt.setUnicodeStream(parameterIndex, x, length); + throw new SQLFeatureNotSupportedException(); } @Override @@ -378,7 +379,6 @@ public void clearParameters() throws SQLException { public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { this.stmt.setObject(parameterIndex, x, targetSqlType); // TODO Auto-generated method stub - } @Override diff --git a/src/main/java/com/olxpbenchmark/util/ClassUtil.java b/src/main/java/com/olxpbenchmark/util/ClassUtil.java index fa36d6d..9c67e65 100644 --- a/src/main/java/com/olxpbenchmark/util/ClassUtil.java +++ b/src/main/java/com/olxpbenchmark/util/ClassUtil.java @@ -250,6 +250,7 @@ public static Constructor getConstructor(Class target_class, Class. * @param expected the expected parent class or interface * @return a new object */ + @SuppressWarnings("unchecked") public static T newInstance(Class theClass, Class expected) { T result; try { diff --git a/src/main/java/com/olxpbenchmark/util/CollectionUtil.java b/src/main/java/com/olxpbenchmark/util/CollectionUtil.java index bded00e..20bc18f 100644 --- a/src/main/java/com/olxpbenchmark/util/CollectionUtil.java +++ b/src/main/java/com/olxpbenchmark/util/CollectionUtil.java @@ -18,6 +18,7 @@ import java.util.AbstractList; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Enumeration; import java.util.HashSet; @@ -220,23 +221,6 @@ public static T random(Iterable it, Random rand) { return (CollectionUtil.random(list, rand)); } - public static > Set getAllExcluding(E elements[], E... excluding) { - Set exclude_set = new HashSet(); - for (E e : excluding) - exclude_set.add(e); - - Set elements_set = new HashSet(); - for (int i = 0; i < elements.length; i++) { - if (!exclude_set.contains(elements[i])) - elements_set.add(elements[i]); - } // FOR - return (elements_set); - // Crappy java.... - // Object new_elements[] = new Object[elements_set.size()]; - // elements_set.toArray(new_elements); - // return ((E[])new_elements); - } - /** * Add all the items in the array to a Collection * @@ -244,10 +228,9 @@ public static > Set getAllExcluding(E elements[], E... excl * @param data * @param items */ + @SuppressWarnings("unchecked") public static Collection addAll(Collection data, T... items) { - for (T i : (T[]) items) { - data.add(i); - } + data.addAll(Arrays.asList(items)); return (data); } @@ -393,6 +376,7 @@ public static T last(Iterable items) { * @param items * @return */ + @SuppressWarnings("unchecked") public static T last(T... items) { if (items != null && items.length > 0) { return (items[items.length - 1]); diff --git a/src/main/java/com/olxpbenchmark/util/EventObservable.java b/src/main/java/com/olxpbenchmark/util/EventObservable.java index 6c368bf..c7605ce 100644 --- a/src/main/java/com/olxpbenchmark/util/EventObservable.java +++ b/src/main/java/com/olxpbenchmark/util/EventObservable.java @@ -16,51 +16,32 @@ package com.olxpbenchmark.util; -import java.util.Observable; +import java.util.ArrayList; +import java.util.List; /** * EventObservable - * */ public class EventObservable { - protected class InnerObservable extends Observable { - @Override - public synchronized void setChanged() { - super.setChanged(); - } - - public EventObservable getEventObservable() { - return (EventObservable.this); - } - } + private final List> observers = new ArrayList<>(); - private final InnerObservable observable; - private int observer_ctr = 0; - - public EventObservable() { - this.observable = new InnerObservable(); - } - - public synchronized void addObserver(EventObserver o) { - if (o != null) { - this.observable.addObserver(o.getObserver()); - this.observer_ctr++; + public synchronized void addObserver(EventObserver observer) { + if (observer != null) { + observers.add(observer); } } - public synchronized void deleteObserver(EventObserver o) { - this.observable.deleteObserver(o.getObserver()); - this.observer_ctr--; + public synchronized void deleteObserver(EventObserver observer) { + observers.remove(observer); } public synchronized void deleteObservers() { - this.observable.deleteObservers(); - this.observer_ctr = 0; + observers.clear(); } public int countObservers() { - return (this.observer_ctr); + return observers.size(); } /** @@ -69,17 +50,15 @@ public int countObservers() { * @param arg - the state that changed */ public void notifyObservers(T arg) { - this.observable.setChanged(); - if (this.observer_ctr > 0) - this.observable.notifyObservers(arg); + for (EventObserver observer : observers) { + observer.update(this, arg); + } } /** * Notifies the Observers that a changed occurred */ public void notifyObservers() { - this.observable.setChanged(); - if (this.observer_ctr > 0) - this.observable.notifyObservers(); + notifyObservers(null); } -} // END CLASS +} diff --git a/src/main/java/com/olxpbenchmark/util/EventObserver.java b/src/main/java/com/olxpbenchmark/util/EventObserver.java index 76701b8..2273e6d 100644 --- a/src/main/java/com/olxpbenchmark/util/EventObserver.java +++ b/src/main/java/com/olxpbenchmark/util/EventObserver.java @@ -16,23 +16,18 @@ package com.olxpbenchmark.util; -import java.util.*; - /** - * EventObservable + * EventObserver */ public abstract class EventObserver { - protected class InnerObserver implements Observer { - @SuppressWarnings({ "unchecked", "rawtypes" }) - @Override - public void update(Observable o, Object arg) { - assert (o instanceof EventObservable.InnerObservable); - EventObserver.this.update(((EventObservable.InnerObservable) o).getEventObservable(), (T) arg); + protected class InnerObserver { + public void update(EventObservable o, T arg) { + EventObserver.this.update(o, arg); } public EventObserver getEventObserver() { - return (EventObserver.this); + return EventObserver.this; } } @@ -42,8 +37,8 @@ public EventObserver() { this.observer = new InnerObserver(); } - protected Observer getObserver() { - return (this.observer); + protected InnerObserver getObserver() { + return this.observer; } public abstract void update(EventObservable o, T arg); diff --git a/src/main/java/com/olxpbenchmark/util/JSONUtil.java b/src/main/java/com/olxpbenchmark/util/JSONUtil.java index 33301cc..e289047 100644 --- a/src/main/java/com/olxpbenchmark/util/JSONUtil.java +++ b/src/main/java/com/olxpbenchmark/util/JSONUtil.java @@ -506,48 +506,6 @@ public static void readFieldValue(final JSONObject json_object, final String jso } } - /** - * For the given enum, load in the values from the JSON object into the current - * object - * This will throw errors if a field is missing - * - * @param - * @param json_object - * @param catalog_db - * @param members - * @throws JSONException - */ - public static , T> void fieldsFromJSON(JSONObject json_object, T object, - Class base_class, E... members) throws JSONException { - JSONUtil.fieldsFromJSON(json_object, object, base_class, false, members); - } - - /** - * For the given enum, load in the values from the JSON object into the current - * object - * If ignore_missing is false, then JSONUtil will not throw an error if a field - * is missing - * - * @param - * @param - * @param json_object - * @param catalog_db - * @param object - * @param base_class - * @param ignore_missing - * @param members - * @throws JSONException - */ - public static , T> void fieldsFromJSON(JSONObject json_object, T object, - Class base_class, boolean ignore_missing, E... members) throws JSONException { - try { - fieldsFromJSON(json_object, object, base_class, ignore_missing, - ClassUtil.getFieldsFromMembersEnum(base_class, members)); - } catch (NoSuchFieldException ex) { - throw new JSONException(ex); - } - } - /** * For the given list of Fields, load in the values from the JSON object into * the current object @@ -586,8 +544,6 @@ public static , T> void fieldsFromJSON(JSONObject json_object, try { readFieldValue(json_object, json_key, field_handle, object); } catch (Exception ex) { - // System.err.println(field_class + ": " + - // ClassUtil.getSuperClasses(field_class)); LOG.error("Unable to deserialize field '" + json_key + "' from " + base_class.getSimpleName(), ex); throw new JSONException(ex); } diff --git a/src/main/java/com/olxpbenchmark/util/ResultUploader.java b/src/main/java/com/olxpbenchmark/util/ResultUploader.java index a98f7f4..075d1a4 100644 --- a/src/main/java/com/olxpbenchmark/util/ResultUploader.java +++ b/src/main/java/com/olxpbenchmark/util/ResultUploader.java @@ -193,7 +193,7 @@ public void uploadResult(List activeTXTypes) throws ParseExcept CloseableHttpResponse response = httpclient.execute(httppost); try { HttpEntity resEntity = response.getEntity(); - LOG.info(IOUtils.toString(resEntity.getContent())); + LOG.info(IOUtils.toString(resEntity.getContent(), "UTF-8")); EntityUtils.consume(resEntity); } finally { response.close(); diff --git a/src/main/java/com/olxpbenchmark/util/json/JSONArray.java b/src/main/java/com/olxpbenchmark/util/json/JSONArray.java index b027787..106c848 100644 --- a/src/main/java/com/olxpbenchmark/util/json/JSONArray.java +++ b/src/main/java/com/olxpbenchmark/util/json/JSONArray.java @@ -153,7 +153,7 @@ public JSONArray(JSONTokener x) throws JSONException { case ']': case ')': if (q != c) { - throw x.syntaxError("Expected a '" + new Character(q) + "'"); + throw x.syntaxError("Expected a '" + Character.valueOf(q) + "'"); } return; default: @@ -581,87 +581,22 @@ public String optString(int index, String defaultValue) { } /** - * Append a boolean value. This increases the array's length by one. - * - * @param value A boolean value. - * @return this. - */ - public JSONArray put(boolean value) { - put(value ? Boolean.TRUE : Boolean.FALSE); - return this; - } - - /** - * Put a value in the JSONArray, where the value will be a - * JSONArray which is produced from a Collection. + * Put a value in the JSONArray. * - * @param value A Collection value. - * @return this. - */ - public JSONArray put(Collection value) { - put(new JSONArray(value)); - return this; - } - - /** - * Append a double value. This increases the array's length by one. - * - * @param value A double value. - * @throws JSONException if the value is not finite. - * @return this. - */ - public JSONArray put(double value) throws JSONException { - Double d = new Double(value); - JSONObject.testValidity(d); - put(d); - return this; - } - - /** - * Append an int value. This increases the array's length by one. - * - * @param value An int value. - * @return this. - */ - public JSONArray put(int value) { - put(new Integer(value)); - return this; - } - - /** - * Append an long value. This increases the array's length by one. - * - * @param value A long value. - * @return this. - */ - public JSONArray put(long value) { - put(new Long(value)); - return this; - } - - /** - * Put a value in the JSONArray, where the value will be a - * JSONObject which is produced from a Map. - * - * @param value A Map value. - * @return this. - */ - public JSONArray put(Map value) { - put(new JSONObject(value)); - return this; - } - - /** - * Append an object value. This increases the array's length by one. - * - * @param value An object value. The value should be a - * Boolean, Double, Integer, JSONArray, JSONObject, Long, or - * String, or the - * JSONObject.NULL object. + * @param value A boolean value, Collection, double value, int value, long + * value, Map value, or object value. * @return this. + * @throws JSONException if the value is not valid for JSON. */ public JSONArray put(Object value) { - this.myArrayList.add(value); + if (value instanceof Boolean || value instanceof Double || value instanceof Integer || value instanceof Long + || value instanceof String || value == JSONObject.NULL) { + this.myArrayList.add(value); + } else if (value instanceof Collection) { + put(new JSONArray((Collection) value)); + } else if (value instanceof Map) { + put(new JSONObject((Map) value)); + } return this; } @@ -707,7 +642,7 @@ public JSONArray put(int index, Collection value) throws JSONException { * not finite. */ public JSONArray put(int index, double value) throws JSONException { - put(index, new Double(value)); + put(index, Double.valueOf(value)); return this; } @@ -722,7 +657,7 @@ public JSONArray put(int index, double value) throws JSONException { * @throws JSONException If the index is negative. */ public JSONArray put(int index, int value) throws JSONException { - put(index, new Integer(value)); + put(index, Integer.valueOf(value)); return this; } @@ -737,7 +672,7 @@ public JSONArray put(int index, int value) throws JSONException { * @throws JSONException If the index is negative. */ public JSONArray put(int index, long value) throws JSONException { - put(index, new Long(value)); + put(index, Long.valueOf(value)); return this; } diff --git a/src/main/java/com/olxpbenchmark/util/json/JSONObject.java b/src/main/java/com/olxpbenchmark/util/json/JSONObject.java index 7a905e4..32e3f0a 100644 --- a/src/main/java/com/olxpbenchmark/util/json/JSONObject.java +++ b/src/main/java/com/olxpbenchmark/util/json/JSONObject.java @@ -832,7 +832,7 @@ public double optDouble(String key) { public double optDouble(String key, double defaultValue) { try { Object o = opt(key); - return o instanceof Number ? ((Number) o).doubleValue() : new Double((String) o).doubleValue(); + return o instanceof Number ? ((Number) o).doubleValue() : Double.parseDouble((String) o); } catch (Exception e) { return defaultValue; } @@ -973,7 +973,7 @@ public JSONObject put(String key, boolean value) throws JSONException { * @throws JSONException If the key is null or if the number is invalid. */ public JSONObject put(String key, double value) throws JSONException { - put(key, new Double(value)); + put(key, Double.valueOf(value)); return this; } @@ -986,7 +986,7 @@ public JSONObject put(String key, double value) throws JSONException { * @throws JSONException If the key is null. */ public JSONObject put(String key, int value) throws JSONException { - put(key, new Integer(value)); + put(key, Integer.valueOf(value)); return this; } @@ -999,7 +999,7 @@ public JSONObject put(String key, int value) throws JSONException { * @throws JSONException If the key is null. */ public JSONObject put(String key, long value) throws JSONException { - put(key, new Long(value)); + put(key, Long.valueOf(value)); return this; } @@ -1198,40 +1198,24 @@ static public Object stringToValue(String s) { * non-JSON forms as long as it accepts all correct JSON forms. */ - char b = s.charAt(0); - if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') { - if (b == '0') { - if (s.length() > 2 && - (s.charAt(1) == 'x' || s.charAt(1) == 'X')) { - try { - return new Integer(Integer.parseInt(s.substring(2), - 16)); - } catch (Exception e) { - /* Ignore the error */ - } - } else { - try { - return new Integer(Integer.parseInt(s, 8)); - } catch (Exception e) { - /* Ignore the error */ - } - } + try { + // Try parsing as Integer or Long + if (s.startsWith("0x") || s.startsWith("0X")) { + return Long.decode(s); + } else if (s.startsWith("0")) { + return Integer.parseInt(s, 8); + } else { + return Integer.parseInt(s); } + } catch (NumberFormatException e) { try { - return new Integer(s); - } catch (Exception e) { - try { - return new Long(s); - } catch (Exception f) { - try { - return new Double(s); - } catch (Exception g) { - /* Ignore the error */ - } - } + // Try parsing as Double + return Double.parseDouble(s); + } catch (NumberFormatException f) { + // Return original string if parsing fails + return s; } } - return s; } /** diff --git a/src/main/java/com/olxpbenchmark/util/json/JSONWriter.java b/src/main/java/com/olxpbenchmark/util/json/JSONWriter.java index 64a89a4..8425fa9 100644 --- a/src/main/java/com/olxpbenchmark/util/json/JSONWriter.java +++ b/src/main/java/com/olxpbenchmark/util/json/JSONWriter.java @@ -329,7 +329,7 @@ public JSONWriter value(boolean b) throws JSONException { * @throws JSONException If the number is not finite. */ public JSONWriter value(double d) throws JSONException { - return this.value(new Double(d)); + return this.value(Double.valueOf(d)); } /**