test_class.declarator: EXPECTED_QUERY = "BASE GROUP BY FIRST(TEST_TABLE.TEST_COLUMN), MAX(TEST_TABLE.TEST_COLUMN) HAVING COUNT(TEST_TABLE2.TEST_COLUMN2) > ? "
test_class.modifier: protected static final
test_class.original_string: protected static final String EXPECTED_QUERY = "BASE GROUP BY FIRST(TEST_TABLE.TEST_COLUMN), MAX(TEST_TABLE.TEST_COLUMN) HAVING COUNT(TEST_TABLE2.TEST_COLUMN2) > ? ";
test_class.type: String
test_class.var_name: EXPECTED_QUERY
test_class.file: cosmic-core/framework/db/src/test/java/com/cloud/utils/db/GroupByTest.java
test_class.identifier: GroupByTest
test_case.body: @Test
      public void testToSql() {
          // Prepare
          final StringBuilder sb = new StringBuilder("BASE");
          final GroupByExtension groupBy = new GroupByExtension(new SearchBaseExtension(String.class, String.class));
  
          final Attribute att = new Attribute("TEST_TABLE", "TEST_COLUMN");
          final Pair<Func, Attribute> pair1 = new Pair<>(SearchCriteria.Func.FIRST, att);
          final Pair<Func, Attribute> pair2 = new Pair<>(SearchCriteria.Func.MAX, att);
          groupBy._groupBys = new ArrayList<>();
          groupBy._groupBys.add(pair1);
          groupBy._groupBys.add(pair2);
          groupBy.having(SearchCriteria.Func.COUNT, att, Op.GT, "SOME_VALUE");
  
          // Execute
          groupBy.toSql(sb);
  
          // Assert
          assertTrue("It didn't create the expected SQL query.", sb.toString().equals(EXPECTED_QUERY));
      }
test_case.class_method_signature: GroupByTest.testToSql()
test_case.full_signature: @Test public void testToSql()
test_case.identifier: testToSql
test_case.invocations: add add having toSql assertTrue equals toString
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testToSql()
focal_class.declarator: _builder
focal_class.original_string: J _builder;
focal_class.type: J
focal_class.var_name: _builder
focal_class.declarator: _groupBys
focal_class.original_string: List<Pair<Func, Attribute>> _groupBys;
focal_class.type: List<Pair<Func, Attribute>>
focal_class.var_name: _groupBys
focal_class.declarator: _having
focal_class.original_string: Having _having;
focal_class.type: Having
focal_class.var_name: _having
focal_class.file: cosmic-core/framework/db/src/main/java/com/cloud/utils/db/GroupBy.java
focal_class.identifier: GroupBy
focal_class.class_method_signature: GroupBy.GroupBy(final J builder)
focal_class.full_signature: public  GroupBy(final J builder)
focal_class.identifier: GroupBy
focal_class.modifiers: public
focal_class.parameters: (final J builder)
focal_class.signature:  GroupBy(final J builder)
focal_class.class_method_signature: GroupBy.init(final J builder)
focal_class.full_signature: protected void init(final J builder)
focal_class.identifier: init
focal_class.modifiers: protected
focal_class.parameters: (final J builder)
focal_class.return: void
focal_class.signature: void init(final J builder)
focal_class.class_method_signature: GroupBy.group(final Object useless)
focal_class.full_signature: public GroupBy<J, T, R> group(final Object useless)
focal_class.identifier: group
focal_class.modifiers: public
focal_class.parameters: (final Object useless)
focal_class.return: GroupBy<J, T, R>
focal_class.signature: GroupBy<J, T, R> group(final Object useless)
focal_class.class_method_signature: GroupBy.group(final Func func, final Object useless)
focal_class.full_signature: public GroupBy<J, T, R> group(final Func func, final Object useless)
focal_class.identifier: group
focal_class.modifiers: public
focal_class.parameters: (final Func func, final Object useless)
focal_class.return: GroupBy<J, T, R>
focal_class.signature: GroupBy<J, T, R> group(final Func func, final Object useless)
focal_class.class_method_signature: GroupBy.having(final Func func, final Object obj, final Op op, final Object value)
focal_class.full_signature: public J having(final Func func, final Object obj, final Op op, final Object value)
focal_class.identifier: having
focal_class.modifiers: public
focal_class.parameters: (final Func func, final Object obj, final Op op, final Object value)
focal_class.return: J
focal_class.signature: J having(final Func func, final Object obj, final Op op, final Object value)
focal_class.class_method_signature: GroupBy.toSql(final StringBuilder builder)
focal_class.full_signature: public void toSql(final StringBuilder builder)
focal_class.identifier: toSql
focal_class.modifiers: public
focal_class.parameters: (final StringBuilder builder)
focal_class.return: void
focal_class.signature: void toSql(final StringBuilder builder)
focal_method.body: public void toSql(final StringBuilder builder) {
          builder.append(" GROUP BY ");
          for (final Pair<Func, Attribute> groupBy : _groupBys) {
              if (groupBy.first() != null) {
                  String func = groupBy.first().toString();
                  func = func.replaceFirst("@", groupBy.second().table + "." + groupBy.second().columnName);
                  builder.append(func);
              } else {
                  builder.append(groupBy.second().table + "." + groupBy.second().columnName);
              }
  
              builder.append(", ");
          }
  
          builder.delete(builder.length() - 2, builder.length());
          if (_having != null) {
              _having.toSql(builder);
          }
      }
focal_method.class_method_signature: GroupBy.toSql(final StringBuilder builder)
focal_method.full_signature: public void toSql(final StringBuilder builder)
focal_method.identifier: toSql
focal_method.invocations: append first toString first replaceFirst second second append append second second append delete length length toSql
focal_method.modifiers: public
focal_method.parameters: (final StringBuilder builder)
focal_method.return: void
focal_method.signature: void toSql(final StringBuilder builder)