Skip to content

Commit bfc24b0

Browse files
committed
Resolved bug of sql queries picking up global credentials datastore when query specific credentials were specified
1 parent e52df20 commit bfc24b0

File tree

7 files changed

+139
-99
lines changed

7 files changed

+139
-99
lines changed

.idea/workspace.xml

Lines changed: 105 additions & 95 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/blobcity/db/Db.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public static <T extends Db> Object execute(final Credentials credentials, final
324324
throw new InternalAdapterException("No collection name set. Table name is a mandatory field queries.");
325325
}
326326

327-
final String queryStr = query.asSql();
327+
final String queryStr = query.asSql(credentials.getDb());
328328

329329
final DbQueryResponse response = QueryExecuter.executeSql(DbQueryRequest.create(credentials, queryStr));
330330

src/main/java/com/blobcity/db/search/OrderElement.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public String asSql() {
5050
return columnName + " " + order;
5151
}
5252

53+
@Override
54+
public String asSql(final String ds) {
55+
throw new RuntimeException("Incorrect invocation. Sqlable.asSql(ds) should not be invoked by OrderElement class");
56+
}
57+
5358
@Override
5459
protected OrderElement clone() {
5560
return new OrderElement(columnName, order);

src/main/java/com/blobcity/db/search/ParamOperator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,9 @@ private ParamOperator(final String sqlText) {
5959
public String asSql() {
6060
return sqlText == null ? name() : sqlText;
6161
}
62+
63+
@Override
64+
public String asSql(final String ds) {
65+
throw new RuntimeException("Incorrect invocation. Sqlable.asSql(ds) should not be invoked by ParamOperator class");
66+
}
6267
}

src/main/java/com/blobcity/db/search/Query.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ public JsonObject asJson() {
212212

213213
@Override
214214
public String asSql() {
215+
throw new RuntimeException("Incorrect invocation. Sqlable.asSql() should not be invoked by Query class");
216+
}
217+
218+
@Override
219+
public String asSql(final String ds) {
215220
final StringBuffer sb = new StringBuffer();
216221
sb.append("SELECT ").append(StringUtil.join(selectColumnNames, ", ", "*", "`"));
217222

@@ -228,9 +233,9 @@ public String asSql() {
228233
final int fromTableCount = binaryClassNames ? fromTables.size() : fromTablesString.size();
229234
for (int i = 0; i < fromTableCount; i++) {
230235
if(binaryClassNames) {
231-
sb.append('`').append(Db.getDs(fromTables.get(i))).append("`.`").append(Db.getCollection(fromTables.get(i)));
236+
sb.append('`').append(ds).append("`.`").append(Db.getCollection(fromTables.get(i)));
232237
}else{
233-
sb.append('`').append(Db.getDs()).append("`.`").append(fromTablesString.get(i));
238+
sb.append('`').append(ds).append("`.`").append(fromTablesString.get(i));
234239
}
235240

236241
if (i < fromTableCount - 1) {

src/main/java/com/blobcity/db/search/SearchParam.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ public String asSql() {
254254
return sb.toString();
255255
}
256256

257+
@Override
258+
public String asSql(final String ds) {
259+
throw new RuntimeException("Incorrect invocation. Sqlable.asSql(ds) should not be invoked by SearchParam class");
260+
}
261+
257262
/**
258263
* Method is internally called whenever the {@link #condition} and/or {@link #args} are updated.
259264
*

src/main/java/com/blobcity/db/search/Sqlable.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,23 @@
1212
*
1313
* @see Jsonable
1414
* @author Karun AB
15+
* @author Sanket Sarang
1516
*/
1617
interface Sqlable {
1718

1819
/**
1920
* Provides a legal SQL form of the implementing class
2021
*
21-
* @return instance of a legal SQL format as a {@link String}
22+
* @return instance of a legal SQL format as a (@link String}
2223
*/
24+
2325
public String asSql();
26+
27+
/**
28+
* Provides a legal SQL form of the implementing class with the generated SQL being for the specified datastore
29+
*
30+
* @param ds name of datastore
31+
* @return instance of a legal SQL format as a {@link String}
32+
*/
33+
public String asSql(final String ds);
2434
}

0 commit comments

Comments
 (0)