11package sqlancer .cockroachdb .oracle ;
22
3- import java .sql .Connection ;
43import java .sql .ResultSet ;
54import java .sql .SQLException ;
65import java .util .ArrayList ;
109import java .util .Set ;
1110import java .util .stream .Collectors ;
1211
12+ import sqlancer .GlobalState ;
1313import sqlancer .IgnoreMeException ;
1414import sqlancer .Query ;
1515import sqlancer .QueryAdapter ;
@@ -56,13 +56,11 @@ public void check() throws SQLException {
5656 gen = new CockroachDBExpressionGenerator (globalState ).setColumns (tables .getColumns ());
5757 List <CockroachDBExpression > joinExpressions = getJoins (tableList , globalState );
5858 CockroachDBExpression whereCondition = gen .generateExpression (CockroachDBDataType .BOOL .get ());
59- int optimizableCount = getOptimizedResult (globalState .getConnection (), whereCondition , tableList , errors ,
60- joinExpressions );
59+ int optimizableCount = getOptimizedResult (whereCondition , tableList , errors , joinExpressions );
6160 if (optimizableCount == -1 ) {
6261 throw new IgnoreMeException ();
6362 }
64- int nonOptimizableCount = getNonOptimizedResult (globalState .getConnection (), whereCondition , tableList , errors ,
65- joinExpressions );
63+ int nonOptimizableCount = getNonOptimizedResult (whereCondition , tableList , errors , joinExpressions );
6664 if (nonOptimizableCount == -1 ) {
6765 throw new IgnoreMeException ();
6866 }
@@ -104,9 +102,8 @@ public static List<CockroachDBExpression> getJoins(List<CockroachDBExpression> t
104102 return joinExpressions ;
105103 }
106104
107- private int getOptimizedResult (Connection con , CockroachDBExpression whereCondition ,
108- List <CockroachDBExpression > tableList , Set <String > errors , List <CockroachDBExpression > joinExpressions )
109- throws SQLException {
105+ private int getOptimizedResult (CockroachDBExpression whereCondition , List <CockroachDBExpression > tableList ,
106+ Set <String > errors , List <CockroachDBExpression > joinExpressions ) throws SQLException {
110107 CockroachDBSelect select = new CockroachDBSelect ();
111108 CockroachDBColumn c = new CockroachDBColumn ("COUNT(*)" , null , false , false );
112109 select .setFetchColumns (Arrays .asList (new CockroachDBColumnReference (c )));
@@ -122,12 +119,11 @@ private int getOptimizedResult(Connection con, CockroachDBExpression whereCondit
122119 }
123120 this .optimizableQueryString = s ;
124121 Query q = new QueryAdapter (s , errors );
125- return getCount (con , q );
122+ return getCount (globalState , q );
126123 }
127124
128- private int getNonOptimizedResult (Connection con , CockroachDBExpression whereCondition ,
129- List <CockroachDBExpression > tableList , Set <String > errors , List <CockroachDBExpression > joinList )
130- throws SQLException {
125+ private int getNonOptimizedResult (CockroachDBExpression whereCondition , List <CockroachDBExpression > tableList ,
126+ Set <String > errors , List <CockroachDBExpression > joinList ) throws SQLException {
131127 String fromString = tableList .stream ().map (t -> ((CockroachDBTableReference ) t ).getTable ().getName ())
132128 .collect (Collectors .joining (", " ));
133129 if (!tableList .isEmpty () && !joinList .isEmpty ()) {
@@ -141,12 +137,12 @@ private int getNonOptimizedResult(Connection con, CockroachDBExpression whereCon
141137 }
142138 this .unoptimizedQuery = s ;
143139 Query q = new QueryAdapter (s , errors );
144- return getCount (con , q );
140+ return getCount (globalState , q );
145141 }
146142
147- private int getCount (Connection con , Query q ) throws AssertionError {
143+ private int getCount (GlobalState <?> globalState , Query q ) throws AssertionError {
148144 int count = 0 ;
149- try (ResultSet rs = q .executeAndGet (con )) {
145+ try (ResultSet rs = q .executeAndGet (globalState )) {
150146 if (rs == null ) {
151147 return -1 ;
152148 }
0 commit comments