Skip to content

Commit 62e302e

Browse files
committed
Continuation of Reworking Connection to DB to support non-SQL connections
These adaptations to the code fix now the compilation issues of the earlier commit. Additionally, a lot of times it was necessary to change Query to SQLQueryAdapter in the DBMS specific packages.
1 parent f6bf8a8 commit 62e302e

File tree

160 files changed

+413
-507
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+413
-507
lines changed

src/sqlancer/AbstractAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
public interface AbstractAction<G> {
66

7-
Query getQuery(G globalState) throws Exception;
7+
Query<?> getQuery(G globalState) throws Exception;
88

99
/**
1010
* Specifies whether it makes sense to request a {@link Query}, when the previous call to {@link #getQuery(Object)}

src/sqlancer/ComparatorHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ static boolean equals(double a, double b) {
3535
return Math.abs(a - b) < 0.001 * Math.max(Math.abs(a), Math.abs(b)) + 0.001;
3636
}
3737

38-
public static List<String> getResultSetFirstColumnAsString(String queryString,
39-
ExpectedErrors errors, SQLGlobalState<?, ?> state) throws SQLException {
38+
public static List<String> getResultSetFirstColumnAsString(String queryString, ExpectedErrors errors,
39+
SQLGlobalState<?, ?> state) throws SQLException {
4040
if (state.getOptions().logEachSelect()) {
4141
// TODO: refactor me
4242
state.getLogger().writeCurrent(queryString);

src/sqlancer/DatabaseProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
import sqlancer.common.log.LoggableFactory;
44

5-
public interface DatabaseProvider<G extends GlobalState<O, ?, C>, O extends DBMSSpecificOptions<?>,
6-
C extends SQLancerDBConnection> {
5+
public interface DatabaseProvider<G extends GlobalState<O, ?, C>, O extends DBMSSpecificOptions<?>, C extends SQLancerDBConnection> {
76

87
/**
98
* Gets the the {@link GlobalState} class.

src/sqlancer/GlobalState.java

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public abstract class GlobalState<O extends DBMSSpecificOptions<?>, S extends Ab
1414
private S schema;
1515
private Main.StateLogger logger;
1616
private StateToReproduce state;
17-
private Main.QueryManager manager;
17+
private Main.QueryManager<C> manager;
1818
private String databaseName;
1919

2020
public void setConnection(C con) {
@@ -34,7 +34,6 @@ public O getDmbsSpecificOptions() {
3434
return dmbsSpecificOptions;
3535
}
3636

37-
3837
public void setRandomly(Randomly r) {
3938
this.r = r;
4039
}
@@ -67,11 +66,11 @@ public StateToReproduce getState() {
6766
return state;
6867
}
6968

70-
public Main.QueryManager getManager() {
69+
public Main.QueryManager<C> getManager() {
7170
return manager;
7271
}
7372

74-
public void setManager(Main.QueryManager manager) {
73+
public void setManager(Main.QueryManager<C> manager) {
7574
this.manager = manager;
7675
}
7776

@@ -83,7 +82,7 @@ public void setDatabaseName(String databaseName) {
8382
this.databaseName = databaseName;
8483
}
8584

86-
private ExecutionTimer executePrologue(Query q) throws Exception {
85+
private ExecutionTimer executePrologue(Query<?> q) throws Exception {
8786
boolean logExecutionTime = getOptions().logExecutionTime();
8887
ExecutionTimer timer = null;
8988
if (logExecutionTime) {
@@ -102,27 +101,16 @@ private ExecutionTimer executePrologue(Query q) throws Exception {
102101
return timer;
103102
}
104103

105-
private void executeEpilogue(Query q, boolean success, ExecutionTimer timer) throws Exception {
106-
boolean logExecutionTime = getOptions().logExecutionTime();
107-
if (success && getOptions().printSucceedingStatements()) {
108-
System.out.println(q.getQueryString());
109-
}
110-
if (logExecutionTime) {
111-
getLogger().writeCurrent(" -- " + timer.end().asString());
112-
}
113-
if (q.couldAffectSchema()) {
114-
updateSchema();
115-
}
116-
}
104+
protected abstract void executeEpilogue(Query<?> q, boolean success, ExecutionTimer timer) throws Exception;
117105

118-
public boolean executeStatement(Query q, String... fills) throws Exception {
106+
public boolean executeStatement(Query<C> q, String... fills) throws Exception {
119107
ExecutionTimer timer = executePrologue(q);
120108
boolean success = manager.execute(q, fills);
121109
executeEpilogue(q, success, timer);
122110
return success;
123111
}
124112

125-
public SQLancerResultSet executeStatementAndGet(Query q, String... fills) throws Exception {
113+
public SQLancerResultSet executeStatementAndGet(Query<C> q, String... fills) throws Exception {
126114
ExecutionTimer timer = executePrologue(q);
127115
SQLancerResultSet result = manager.executeAndGet(q, fills);
128116
boolean success = result != null;

src/sqlancer/Main.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private void printState(FileWriter writer, StateToReproduce state) {
208208
sb.append(databaseProvider.getLoggableFactory()
209209
.getInfo(state.getDatabaseName(), state.getDatabaseVersion(), state.getSeedValue()).getLogString());
210210

211-
for (Query s : state.getStatements()) {
211+
for (Query<?> s : state.getStatements()) {
212212
sb.append(s.getQueryString());
213213
sb.append('\n');
214214
}
@@ -221,23 +221,23 @@ private void printState(FileWriter writer, StateToReproduce state) {
221221

222222
}
223223

224-
public static class QueryManager {
224+
public static class QueryManager<C extends SQLancerDBConnection> {
225225

226-
private final GlobalState<?, ?, ?> globalState;
226+
private final GlobalState<?, ?, C> globalState;
227227

228-
QueryManager(GlobalState<?, ?, ?> globalState) {
228+
QueryManager(GlobalState<?, ?, C> globalState) {
229229
this.globalState = globalState;
230230
}
231231

232-
public boolean execute(Query q, String... fills) throws Exception {
232+
public boolean execute(Query<C> q, String... fills) throws Exception {
233233
globalState.getState().logStatement(q);
234234
boolean success;
235235
success = q.execute(globalState, fills);
236236
Main.nrSuccessfulActions.addAndGet(1);
237237
return success;
238238
}
239239

240-
public SQLancerResultSet executeAndGet(Query q, String... fills) throws Exception {
240+
public SQLancerResultSet executeAndGet(Query<C> q, String... fills) throws Exception {
241241
globalState.getState().logStatement(q);
242242
SQLancerResultSet result;
243243
result = q.executeAndGet(globalState, fills);
@@ -259,8 +259,7 @@ public static void main(String[] args) {
259259
System.exit(executeMain(args));
260260
}
261261

262-
public static class DBMSExecutor<G extends GlobalState<O, ?, C>, O extends DBMSSpecificOptions<?>, C
263-
extends SQLancerDBConnection> {
262+
public static class DBMSExecutor<G extends GlobalState<O, ?, C>, O extends DBMSSpecificOptions<?>, C extends SQLancerDBConnection> {
264263

265264
private final DatabaseProvider<G, O, C> provider;
266265
private final MainOptions options;
@@ -309,7 +308,7 @@ public void run() throws Exception {
309308
state.setMainOptions(options);
310309
state.setDmbsSpecificOptions(command);
311310
try (C con = provider.createDatabase(state)) {
312-
QueryManager manager = new QueryManager(state);
311+
QueryManager<C> manager = new QueryManager<>(state);
313312
try {
314313
stateToRepro.databaseVersion = con.getDatabaseVersion();
315314
} catch (Exception e) {
@@ -354,8 +353,7 @@ public StateToReproduce getStateToReproduce() {
354353
}
355354
}
356355

357-
public static class DBMSExecutorFactory<G extends GlobalState<O, ?, C>, O extends DBMSSpecificOptions<?>,
358-
C extends SQLancerDBConnection> {
356+
public static class DBMSExecutorFactory<G extends GlobalState<O, ?, C>, O extends DBMSSpecificOptions<?>, C extends SQLancerDBConnection> {
359357

360358
private final DatabaseProvider<G, O, C> provider;
361359
private final MainOptions options;

src/sqlancer/ProviderAdapter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
import sqlancer.StateToReproduce.OracleRunReproductionState;
77
import sqlancer.common.oracle.CompositeTestOracle;
88
import sqlancer.common.oracle.TestOracle;
9+
import sqlancer.common.schema.AbstractSchema;
910

10-
public abstract class ProviderAdapter<G extends GlobalState<O, ?, C>, O extends DBMSSpecificOptions<? extends OracleFactory<G>>,
11-
C extends SQLancerDBConnection> implements DatabaseProvider<G, O, C> {
11+
public abstract class ProviderAdapter<G extends GlobalState<O, ? extends AbstractSchema<G, ?>, C>, O extends DBMSSpecificOptions<? extends OracleFactory<G>>, C extends SQLancerDBConnection>
12+
implements DatabaseProvider<G, O, C> {
1213

1314
private final Class<G> globalClass;
1415
private final Class<O> optionClass;

src/sqlancer/SQLConnection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public SQLConnection(Connection connection) {
1414
}
1515

1616
@Override
17-
public String getDatabaseVersion() throws SQLException{
17+
public String getDatabaseVersion() throws SQLException {
1818
DatabaseMetaData meta = connection.getMetaData();
1919
return meta.getDatabaseProductVersion();
2020
}
@@ -28,7 +28,7 @@ public Statement prepareStatement(String arg) throws SQLException {
2828
return connection.prepareStatement(arg);
2929
}
3030

31-
public Statement createStatement() throws SQLException{
31+
public Statement createStatement() throws SQLException {
3232
return connection.createStatement();
3333
}
3434
}

src/sqlancer/SQLGlobalState.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package sqlancer;
22

3+
import sqlancer.common.query.Query;
34
import sqlancer.common.schema.AbstractSchema;
45

56
/**
@@ -11,5 +12,19 @@
1112
* the schema parameter
1213
*/
1314
public abstract class SQLGlobalState<O extends DBMSSpecificOptions<?>, S extends AbstractSchema<?, ?>>
14-
extends GlobalState<O, S, SQLConnection> {
15+
extends GlobalState<O, S, SQLConnection> {
16+
17+
@Override
18+
protected void executeEpilogue(Query<?> q, boolean success, ExecutionTimer timer) throws Exception {
19+
boolean logExecutionTime = getOptions().logExecutionTime();
20+
if (success && getOptions().printSucceedingStatements()) {
21+
System.out.println(q.getQueryString());
22+
}
23+
if (logExecutionTime) {
24+
getLogger().writeCurrent(" -- " + timer.end().asString());
25+
}
26+
if (q.couldAffectSchema()) {
27+
updateSchema();
28+
}
29+
}
1530
}

src/sqlancer/SQLProviderAdapter.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package sqlancer;
22

3+
import java.util.List;
4+
35
import sqlancer.common.log.LoggableFactory;
46
import sqlancer.common.log.SQLLoggableFactory;
57
import sqlancer.common.query.SQLQueryAdapter;
6-
import sqlancer.common.schema.AbstractRelationalTable;
7-
8-
import java.util.List;
8+
import sqlancer.common.schema.AbstractSchema;
9+
import sqlancer.common.schema.AbstractTable;
910

10-
public abstract class SQLProviderAdapter<G extends SQLGlobalState<O, ?>, O extends DBMSSpecificOptions<? extends OracleFactory<G>>>
11+
public abstract class SQLProviderAdapter<G extends SQLGlobalState<O, ? extends AbstractSchema<G, ?>>, O extends DBMSSpecificOptions<? extends OracleFactory<G>>>
1112
extends ProviderAdapter<G, O, SQLConnection> {
1213
public SQLProviderAdapter(Class<G> globalClass, Class<O> optionClass) {
1314
super(globalClass, optionClass);
@@ -20,8 +21,8 @@ public LoggableFactory getLoggableFactory() {
2021

2122
@Override
2223
protected void checkViewsAreValid(G globalState) {
23-
List<? extends AbstractRelationalTable<?, ?, G>> views = globalState.getSchema().getViews();
24-
for (AbstractRelationalTable<?, ?, G> view : views) {
24+
List<? extends AbstractTable<?, ?, ?>> views = globalState.getSchema().getViews();
25+
for (AbstractTable<?, ?, ?> view : views) {
2526
SQLQueryAdapter q = new SQLQueryAdapter("SELECT 1 FROM " + view.getName() + " LIMIT 1");
2627
try {
2728
q.execute(globalState);

src/sqlancer/StateToReproduce.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
public class StateToReproduce {
1111

12-
private final List<Query> statements = new ArrayList<>();
12+
private final List<Query<?>> statements = new ArrayList<>();
1313

1414
private final String databaseName;
1515

@@ -59,22 +59,22 @@ public void logStatement(String queryString) {
5959
* @param query
6060
* the query to be logged
6161
*/
62-
public void logStatement(Query query) {
62+
public void logStatement(Query<?> query) {
6363
if (query == null) {
6464
throw new IllegalArgumentException();
6565
}
6666
statements.add(query);
6767
}
6868

69-
public List<Query> getStatements() {
69+
public List<Query<?>> getStatements() {
7070
return Collections.unmodifiableList(statements);
7171
}
7272

7373
@Deprecated
7474
public void commentStatements() {
7575
for (int i = 0; i < statements.size(); i++) {
76-
Query statement = statements.get(i);
77-
Query newQuery = databaseProvider.getLoggableFactory().commentOutQuery(statement);
76+
Query<?> statement = statements.get(i);
77+
Query<?> newQuery = databaseProvider.getLoggableFactory().commentOutQuery(statement);
7878
statements.set(i, newQuery);
7979
}
8080
}
@@ -98,7 +98,7 @@ public OracleRunReproductionState getLocalState() {
9898
*/
9999
public class OracleRunReproductionState implements Closeable {
100100

101-
private final List<Query> statements = new ArrayList<>();
101+
private final List<Query<?>> statements = new ArrayList<>();
102102

103103
public boolean success;
104104

0 commit comments

Comments
 (0)