Skip to content

Commit

Permalink
Simplify the schema update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mrigger committed Sep 23, 2020
1 parent f5d1d44 commit d0d0d60
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 19 deletions.
6 changes: 5 additions & 1 deletion src/sqlancer/GlobalState.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ protected void setSchema(S schema) {
this.schema = schema;
}

protected abstract void updateSchema() throws SQLException;
public void updateSchema() throws SQLException {
setSchema(readSchema());
}

protected abstract S readSchema() throws SQLException;

}
4 changes: 2 additions & 2 deletions src/sqlancer/citus/CitusGlobalState.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public boolean getRepartition() {
}

@Override
public void updateSchema() throws SQLException {
setSchema(CitusSchema.fromConnection(getConnection(), getDatabaseName()));
public CitusSchema readSchema() throws SQLException {
return CitusSchema.fromConnection(getConnection(), getDatabaseName());
}

}
4 changes: 2 additions & 2 deletions src/sqlancer/clickhouse/ClickHouseProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public String getDatabaseName() {
}

@Override
protected void updateSchema() throws SQLException {
setSchema(ClickHouseSchema.fromConnection(getConnection(), getDatabaseName()));
protected ClickHouseSchema readSchema() throws SQLException {
return ClickHouseSchema.fromConnection(getConnection(), getDatabaseName());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/sqlancer/cockroachdb/CockroachDBProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ public Query getQuery(CockroachDBGlobalState state) throws SQLException {
public static class CockroachDBGlobalState extends GlobalState<CockroachDBOptions, CockroachDBSchema> {

@Override
protected void updateSchema() throws SQLException {
setSchema(CockroachDBSchema.fromConnection(getConnection(), getDatabaseName()));
protected CockroachDBSchema readSchema() throws SQLException {
return CockroachDBSchema.fromConnection(getConnection(), getDatabaseName());
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/sqlancer/duckdb/DuckDBProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ private static int mapActions(DuckDBGlobalState globalState, Action a) {
public static class DuckDBGlobalState extends GlobalState<DuckDBOptions, DuckDBSchema> {

@Override
protected void updateSchema() throws SQLException {
setSchema(DuckDBSchema.fromConnection(getConnection(), getDatabaseName()));
protected DuckDBSchema readSchema() throws SQLException {
return DuckDBSchema.fromConnection(getConnection(), getDatabaseName());
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/sqlancer/mariadb/MariaDBProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ public void generateDatabase(MariaDBGlobalState globalState) throws SQLException
public static class MariaDBGlobalState extends GlobalState<MariaDBOptions, MariaDBSchema> {

@Override
protected void updateSchema() throws SQLException {
setSchema(MariaDBSchema.fromConnection(getConnection(), getDatabaseName()));
protected MariaDBSchema readSchema() throws SQLException {
return MariaDBSchema.fromConnection(getConnection(), getDatabaseName());
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/sqlancer/mysql/MySQLGlobalState.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
public class MySQLGlobalState extends GlobalState<MySQLOptions, MySQLSchema> {

@Override
protected void updateSchema() throws SQLException {
setSchema(MySQLSchema.fromConnection(getConnection(), getDatabaseName()));
protected MySQLSchema readSchema() throws SQLException {
return MySQLSchema.fromConnection(getConnection(), getDatabaseName());
}

public boolean usesPQS() {
Expand Down
4 changes: 2 additions & 2 deletions src/sqlancer/postgres/PostgresGlobalState.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ public String getRandomOpclass() {
}

@Override
public void updateSchema() throws SQLException {
setSchema(PostgresSchema.fromConnection(getConnection(), getDatabaseName()));
public PostgresSchema readSchema() throws SQLException {
return PostgresSchema.fromConnection(getConnection(), getDatabaseName());
}

public void addFunctionAndType(String functionName, Character functionType) {
Expand Down
4 changes: 2 additions & 2 deletions src/sqlancer/sqlite3/SQLite3Provider.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public Query getQuery(SQLite3GlobalState state) throws SQLException {
public static class SQLite3GlobalState extends GlobalState<SQLite3Options, SQLite3Schema> {

@Override
protected void updateSchema() throws SQLException {
setSchema(SQLite3Schema.fromConnection(this));
protected SQLite3Schema readSchema() throws SQLException {
return SQLite3Schema.fromConnection(this);
}

}
Expand Down
4 changes: 2 additions & 2 deletions src/sqlancer/tidb/TiDBProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public Query getQuery(TiDBGlobalState state) throws SQLException {
public static class TiDBGlobalState extends GlobalState<TiDBOptions, TiDBSchema> {

@Override
protected void updateSchema() throws SQLException {
setSchema(TiDBSchema.fromConnection(getConnection(), getDatabaseName()));
protected TiDBSchema readSchema() throws SQLException {
return TiDBSchema.fromConnection(getConnection(), getDatabaseName());
}

}
Expand Down

0 comments on commit d0d0d60

Please sign in to comment.