コード例 #1
0
    public String getTemplate(final String statementName, final StatementContext context)
        throws Exception {
      StringTemplate template;

      try {
        template = templateGroup.getInstanceOf(statementName);
      } catch (IllegalArgumentException ex) {
        LOG.info("Didn't find a template when expected: %s: %s", groupName, statementName);
        return defaultLocate(statementName, context);
      }

      // This can be used by timing collectors to figure out which statement was used.
      context.setAttribute(STATEMENT_CLASS, className);
      context.setAttribute(STATEMENT_GROUP, groupName);
      context.setAttribute(STATEMENT_NAME, statementName);

      template.setAttributes(context.getAttributes());

      final String sql = template.toString();

      LOG.trace("SQL for %s: %s", groupName, sql);

      return sql;
    }