コード例 #1
0
    @Override
    public String getStatementName(StatementContext statementContext) {
      final Object classObj = statementContext.getAttribute(NameStrategies.STATEMENT_CLASS);
      final Object nameObj = statementContext.getAttribute(NameStrategies.STATEMENT_NAME);

      if (classObj == null || nameObj == null) {
        return null;
      }

      final String className = (String) classObj;
      final String statementName = (String) nameObj;

      final int dotPos = className.lastIndexOf('.');
      if (dotPos == -1) {
        return null;
      }

      final String shortName = className.substring(dotPos + 1);

      final String oldClassName = shortClassNames.putIfAbsent(shortName, className);
      if (oldClassName == null || oldClassName.equals(className)) {
        return name(baseJmxName, shortName, statementName);
      } else {
        return name(baseJmxName, className, statementName);
      }
    }
コード例 #2
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;
    }
コード例 #3
0
    @Override
    public String getStatementName(StatementContext statementContext) {
      final Class<?> clazz = statementContext.getSqlObjectType();
      final Method method = statementContext.getSqlObjectMethod();
      if (clazz != null && method != null) {
        final String className = clazz.getName();
        final String statementName = method.getName();

        final int dotPos = className.lastIndexOf('.');
        if (dotPos == -1) {
          return null;
        }

        final String shortName = className.substring(dotPos + 1);

        final String oldClassName = shortClassNames.putIfAbsent(shortName, className);
        if (oldClassName == null || oldClassName.equals(className)) {
          return name(baseJmxName, shortName, statementName);
        } else {
          return name(baseJmxName, className, statementName);
        }
      }
      return null;
    }