@@ -307,63 +307,63 @@ public Set<String> keySet() {
307307 */
308308 static protected Bson queryObjToBsonFilter (Query inQuery ) {
309309 QueryType type = inQuery .type ();
310-
310+
311311 // Handle the query according to its type
312- if ( inQuery .isCombinationOperator () ) {
312+ if ( inQuery .isCombinationOperator ()) {
313313 // Lets convert each of the subquery
314314 List <Bson > remappedQuery = new ArrayList <>();
315- for ( Query subQuery : inQuery .childrenQuery () ) {
316- remappedQuery .add ( queryObjToBsonFilter (subQuery ) );
315+ for ( Query subQuery : inQuery .childrenQuery ()) {
316+ remappedQuery .add (queryObjToBsonFilter (subQuery ));
317317 }
318318 // Combination type (AND, OR, NOT)
319- if ( type == QueryType .AND ) {
320- return Filters .and ( remappedQuery );
319+ if ( type == QueryType .AND ) {
320+ return Filters .and (remappedQuery );
321321 }
322- if ( type == QueryType .OR ) {
323- return Filters .or ( remappedQuery );
322+ if ( type == QueryType .OR ) {
323+ return Filters .or (remappedQuery );
324324 }
325- if ( type == QueryType .NOT ) {
326- if ( remappedQuery .size () > 0 ) {
325+ if ( type == QueryType .NOT ) {
326+ if ( remappedQuery .size () > 0 ) {
327327 throw new RuntimeException ("NOT operator, expects only 1 subquery" );
328328 }
329- return Filters .not ( remappedQuery .get (0 ) );
329+ return Filters .not (remappedQuery .get (0 ));
330330 }
331331 } else {
332332 // Basic operator
333- if ( type == QueryType .EQUALS ) {
334- return Filters .eq ( inQuery .fieldName (), inQuery .defaultArgumentValue () );
333+ if ( type == QueryType .EQUALS ) {
334+ return Filters .eq (inQuery .fieldName (), inQuery .defaultArgumentValue ());
335335 }
336- if ( type == QueryType .NOT_EQUALS ) {
337- return Filters .ne ( inQuery .fieldName (), inQuery .defaultArgumentValue () );
336+ if ( type == QueryType .NOT_EQUALS ) {
337+ return Filters .ne (inQuery .fieldName (), inQuery .defaultArgumentValue ());
338338 }
339- if ( type == QueryType .LESS_THAN ) {
340- return Filters .lt ( inQuery .fieldName (), inQuery .defaultArgumentValue () );
339+ if ( type == QueryType .LESS_THAN ) {
340+ return Filters .lt (inQuery .fieldName (), inQuery .defaultArgumentValue ());
341341 }
342- if ( type == QueryType .LESS_THAN_OR_EQUALS ) {
343- return Filters .lte ( inQuery .fieldName (), inQuery .defaultArgumentValue () );
342+ if ( type == QueryType .LESS_THAN_OR_EQUALS ) {
343+ return Filters .lte (inQuery .fieldName (), inQuery .defaultArgumentValue ());
344344 }
345- if ( type == QueryType .MORE_THAN ) {
346- return Filters .gt ( inQuery .fieldName (), inQuery .defaultArgumentValue () );
345+ if ( type == QueryType .MORE_THAN ) {
346+ return Filters .gt (inQuery .fieldName (), inQuery .defaultArgumentValue ());
347347 }
348- if ( type == QueryType .MORE_THAN_OR_EQUALS ) {
349- return Filters .gte ( inQuery .fieldName (), inQuery .defaultArgumentValue () );
348+ if ( type == QueryType .MORE_THAN_OR_EQUALS ) {
349+ return Filters .gte (inQuery .fieldName (), inQuery .defaultArgumentValue ());
350350 }
351- if ( type == QueryType .LIKE ) {
351+ if ( type == QueryType .LIKE ) {
352352 // Because the LIKE operator does not natively exists,
353353 // we will generates its REGEX equivalent
354-
355- String val = GenericConvert .toString ( inQuery .defaultArgumentValue () );
356- val = val .replaceAll ("*" ,"\\ *" );
357- val = val .replaceAll ("%" ,".*" );
358- val = val .replaceAll ("_" ,".+" );
359-
360- return Filters .regex ( inQuery .fieldName (), val );
354+
355+ String val = GenericConvert .toString (inQuery .defaultArgumentValue ());
356+ val = val .replaceAll ("*" , "\\ *" );
357+ val = val .replaceAll ("%" , ".*" );
358+ val = val .replaceAll ("_" , ".+" );
359+
360+ return Filters .regex (inQuery .fieldName (), val );
361361 }
362362 }
363-
364- throw new RuntimeException ("Unkown query type : " + inQuery .type ());
363+
364+ throw new RuntimeException ("Unkown query type : " + inQuery .type ());
365365 }
366-
366+
367367 /**
368368 * Performs a search query, and returns the respective DataObject keys.
369369 *
@@ -380,54 +380,54 @@ public String[] query_id(Query queryClause, String orderByStr, int offset, int l
380380
381381 // The query filter to use, use "all" if queryClause is null
382382 Bson bsonFilter = null ;
383- if ( queryClause != null ) {
383+ if ( queryClause != null ) {
384384 // Lets convert the SQL where clause to bsonFilter
385385 bsonFilter = queryObjToBsonFilter (queryClause );
386386 } else {
387387 // our equivalent of all filter
388388 bsonFilter = Filters .exists ("_oid" , true );
389389 }
390-
390+
391391 // Lets fetch the data, for the various _oid
392392 FindIterable <Document > search = collection .find (bsonFilter );
393393 search = search .projection (Projections .include ("_oid" ));
394394
395395 // Build the orderBy clause
396- if ( orderByStr != null && orderByStr .length () > 0 ) {
396+ if ( orderByStr != null && orderByStr .length () > 0 ) {
397397 // The final sorting BSON
398398 Document sortBson = new Document ();
399-
399+
400400 // Split it accordingly
401401 String [] orderSeq = orderByStr .split ("," );
402- for (int i = 0 ; i < orderSeq .length ; ++i ) {
402+ for (int i = 0 ; i < orderSeq .length ; ++i ) {
403403 String subSeq = orderSeq [i ];
404404 String subSeq_uc = subSeq .toUpperCase ();
405-
405+
406406 // Append the order by rule accordingly
407- if ( subSeq_uc .endsWith ("ASC" ) ) {
408- sortBson .append ( subSeq .substring (0 , subSeq .length ()- 3 ).trim (), 1 );
409- } else if ( subSeq .endsWith ("DESC" ) ) {
410- sortBson .append ( subSeq .substring (0 , subSeq .length ()- 4 ).trim (), -1 );
407+ if ( subSeq_uc .endsWith ("ASC" )) {
408+ sortBson .append (subSeq .substring (0 , subSeq .length () - 3 ).trim (), 1 );
409+ } else if ( subSeq .endsWith ("DESC" )) {
410+ sortBson .append (subSeq .substring (0 , subSeq .length () - 4 ).trim (), -1 );
411411 } else {
412412 // DEFAULT is ASC
413- sortBson .append ( subSeq .trim (), 1 );
413+ sortBson .append (subSeq .trim (), 1 );
414414 }
415415 }
416-
416+
417417 // Apply the sorting
418- search .sort ( sortBson );
418+ search .sort (sortBson );
419419 }
420-
420+
421421 // Handle offset
422- if ( offset > 0 ) {
422+ if ( offset > 0 ) {
423423 search .skip (offset );
424424 }
425-
425+
426426 // And length
427- if ( limit >= 0 ) {
427+ if ( limit >= 0 ) {
428428 search .limit (limit );
429429 }
430-
430+
431431 // The return list
432432 List <String > ret = new ArrayList <String >();
433433
@@ -453,10 +453,10 @@ public String[] query_id(Query queryClause, String orderByStr, int offset, int l
453453 @ Override
454454 public long queryCount (String whereClause , Object [] whereValues ) {
455455 // return collection count, if there is no where clause
456- if ( whereClause == null ) {
456+ if ( whereClause == null ) {
457457 return collection .countDocuments ();
458458 }
459-
459+
460460 // The query filter to use, use "all" if queryClause is null
461461 Bson bsonFilter = queryObjToBsonFilter (Query .build (whereClause , whereValues ));
462462
@@ -478,7 +478,7 @@ public long queryCount(String whereClause, Object[] whereValues) {
478478 public String randomObjectID () {
479479 // Aggregation sample
480480 Document doc = collection .aggregate (Arrays .asList (Aggregates .sample (1 ))).first ();
481- if ( doc != null ) {
481+ if ( doc != null ) {
482482 return doc .getString ("_oid" );
483483 }
484484 return null ;
@@ -518,28 +518,28 @@ public String randomObjectID() {
518518 public String looselyIterateObjectID (String currentID ) {
519519 // The query filter to use, use "all" if queryClause is null
520520 Bson bsonFilter = null ;
521- if ( currentID == null ) {
521+ if ( currentID == null ) {
522522 // our equivalent of all filter
523523 bsonFilter = Filters .exists ("_oid" , true );
524524 } else {
525525 // greater then
526526 bsonFilter = Filters .gt ("_oid" , currentID );
527527 }
528-
528+
529529 // Lets fetch the data, for the various _oid
530530 FindIterable <Document > search = collection .find (bsonFilter );
531531 search = search .projection (Projections .include ("_oid" ));
532-
532+
533533 // The final sorting BSON
534534 Document sortBson = new Document ();
535535 sortBson .append ("_oid" , 1 );
536-
536+
537537 // Apply the sorting
538- search .sort ( sortBson );
539-
538+ search .sort (sortBson );
539+
540540 // Apply the limit of 1
541541 search .limit (1 );
542-
542+
543543 // Get the Document object
544544 Document resObj = search .first ();
545545 if (resObj == null ) {
0 commit comments