Skip to content

Commit

Permalink
fix W5*(miss edit in sdb test), update readme and solve warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
cococo2000 committed Mar 4, 2024
1 parent 0b5fbe6 commit bcf1118
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 257 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<java.version>8</java.version>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<java.version>11</java.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<build>
Expand All @@ -39,7 +39,7 @@
</manifest>
</archive>
</configuration>
</plugin>
</plugin>
</plugins>
</build>

Expand Down
13 changes: 11 additions & 2 deletions src/main/java/com/olxpbenchmark/api/StatementDialects.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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<DialectsType> result = (JAXBElement<DialectsType>) 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<DialectsType> result = (JAXBElement<DialectsType>) unmarshaller.unmarshal(streamSource,
DialectsType.class);
dialects = result.getValue();
} catch (JAXBException ex) {
// Convert some linked exceptions to more friendly errors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/olxpbenchmark/util/ClassUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public static <T> Constructor<T> getConstructor(Class<T> target_class, Class<?>.
* @param expected the expected parent class or interface
* @return a new object
*/
@SuppressWarnings("unchecked")
public static <T> T newInstance(Class<?> theClass, Class<T> expected) {
T result;
try {
Expand Down
24 changes: 4 additions & 20 deletions src/main/java/com/olxpbenchmark/util/CollectionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -220,34 +221,16 @@ public static <T> T random(Iterable<T> it, Random rand) {
return (CollectionUtil.random(list, rand));
}

public static <E extends Enum<?>> Set<E> getAllExcluding(E elements[], E... excluding) {
Set<E> exclude_set = new HashSet<E>();
for (E e : excluding)
exclude_set.add(e);

Set<E> elements_set = new HashSet<E>();
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
*
* @param <T>
* @param data
* @param items
*/
@SuppressWarnings("unchecked")
public static <T> Collection<T> addAll(Collection<T> data, T... items) {
for (T i : (T[]) items) {
data.add(i);
}
data.addAll(Arrays.asList(items));
return (data);
}

Expand Down Expand Up @@ -393,6 +376,7 @@ public static <T> T last(Iterable<T> items) {
* @param items
* @return
*/
@SuppressWarnings("unchecked")
public static <T> T last(T... items) {
if (items != null && items.length > 0) {
return (items[items.length - 1]);
Expand Down
51 changes: 15 additions & 36 deletions src/main/java/com/olxpbenchmark/util/EventObservable.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,32 @@

package com.olxpbenchmark.util;

import java.util.Observable;
import java.util.ArrayList;
import java.util.List;

/**
* EventObservable
*
*/
public class EventObservable<T> {

protected class InnerObservable extends Observable {
@Override
public synchronized void setChanged() {
super.setChanged();
}

public EventObservable<T> getEventObservable() {
return (EventObservable.this);
}
}
private final List<EventObserver<T>> observers = new ArrayList<>();

private final InnerObservable observable;
private int observer_ctr = 0;

public EventObservable() {
this.observable = new InnerObservable();
}

public synchronized void addObserver(EventObserver<T> o) {
if (o != null) {
this.observable.addObserver(o.getObserver());
this.observer_ctr++;
public synchronized void addObserver(EventObserver<T> observer) {
if (observer != null) {
observers.add(observer);
}
}

public synchronized void deleteObserver(EventObserver<T> o) {
this.observable.deleteObserver(o.getObserver());
this.observer_ctr--;
public synchronized void deleteObserver(EventObserver<T> 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();
}

/**
Expand All @@ -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<T> 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
}
19 changes: 7 additions & 12 deletions src/main/java/com/olxpbenchmark/util/EventObserver.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,18 @@

package com.olxpbenchmark.util;

import java.util.*;

/**
* EventObservable
* EventObserver
*/
public abstract class EventObserver<T> {

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<T> o, T arg) {
EventObserver.this.update(o, arg);
}

public EventObserver<T> getEventObserver() {
return (EventObserver.this);
return EventObserver.this;
}
}

Expand All @@ -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<T> o, T arg);
Expand Down
Loading

0 comments on commit bcf1118

Please sign in to comment.