예제 #1
0
  public void testSqlExtractFunction() {
    String fragment = "extract( year from col )";
    String template =
        Template.renderWhereStringTemplate(fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY);

    assertEquals("extract(year from " + Template.TEMPLATE + ".col)", template);
  }
예제 #2
0
 /**
  * The map of defined filters. This is expected to be in format where the filter names are the map
  * keys, and the defined conditions are the values.
  *
  * @param filters The map of defined filters.
  * @param dialect The sql dialect
  * @param functionRegistry The SQL function registry
  */
 public FilterHelper(Map filters, Dialect dialect, SQLFunctionRegistry functionRegistry) {
   int filterCount = filters.size();
   filterNames = new String[filterCount];
   filterConditions = new String[filterCount];
   Iterator iter = filters.entrySet().iterator();
   filterCount = 0;
   while (iter.hasNext()) {
     final Map.Entry entry = (Map.Entry) iter.next();
     filterNames[filterCount] = (String) entry.getKey();
     filterConditions[filterCount] =
         Template.renderWhereStringTemplate(
             (String) entry.getValue(), FilterImpl.MARKER, dialect, functionRegistry);
     filterConditions[filterCount] =
         StringHelper.replace(
             filterConditions[filterCount], ":", ":" + filterNames[filterCount] + ".");
     filterCount++;
   }
 }
예제 #3
0
  public void testSqlTrimFunction() {
    String fragment = "trim( col )";
    String template =
        Template.renderWhereStringTemplate(fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY);
    assertEquals("trim(" + Template.TEMPLATE + ".col)", template);

    fragment = "trim( from col )";
    template =
        Template.renderWhereStringTemplate(fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY);
    assertEquals("trim(from " + Template.TEMPLATE + ".col)", template);

    fragment = "trim( both from col )";
    template =
        Template.renderWhereStringTemplate(fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY);
    assertEquals("trim(both from " + Template.TEMPLATE + ".col)", template);

    fragment = "trim( leading from col )";
    template =
        Template.renderWhereStringTemplate(fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY);
    assertEquals("trim(leading from " + Template.TEMPLATE + ".col)", template);

    fragment = "trim( TRAILING from col )";
    template =
        Template.renderWhereStringTemplate(fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY);
    assertEquals("trim(TRAILING from " + Template.TEMPLATE + ".col)", template);

    fragment = "trim( 'b' from col )";
    template =
        Template.renderWhereStringTemplate(fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY);
    assertEquals("trim('b' from " + Template.TEMPLATE + ".col)", template);

    fragment = "trim( both 'b' from col )";
    template =
        Template.renderWhereStringTemplate(fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY);
    assertEquals("trim(both 'b' from " + Template.TEMPLATE + ".col)", template);
  }
예제 #4
0
 public String doStandardRendering(String fragment) {
   return Template.renderOrderByStringTemplate(fragment, MAPPER, null, DIALECT, FUNCTION_REGISTRY);
 }
예제 #5
0
 public String getTemplate(Dialect dialect, SQLFunctionRegistry functionRegistry) {
   return hasCustomRead()
       ? Template.renderWhereStringTemplate(customRead, dialect, functionRegistry)
       : Template.TEMPLATE + '.' + getQuotedName(dialect);
 }