RuleHelper extends Helper implements SessionManager { public String formatSQL(Object obj, Object expr) { String sql = null; if (expr instanceof String) { sql = (String)expr; if (log.isLoggable(Level.FINEST)) { log.finest("SQL retrieved from state = "+sql); } } else if (obj != null) { sql = toString(obj); if (sql != null) { if (sql.startsWith("prep")) { sql = sql.replaceFirst("prep[0-9]*: ", ""); } sql = sql.replaceAll("X'.*'", BINARY_SQL_MARKER); } if (log.isLoggable(Level.FINEST)) { log.finest("SQL derived from context = "+sql); } } return sql; } protected  RuleHelper(Rule rule); String getRuleName(); TraceCollector collector(); String createUUID(); String getID(String type, Object obj); boolean isInstanceOf(Object obj, Class<?> clz); T cast(Object obj, Class<T> clz); String simpleClassName(Object obj); String toString(Object obj); int hashCode(Object obj); String formatSQL(Object obj, Object expr); String faultName(Object fault); String faultDescription(Object fault); String removeSuffix(String original, String suffix); String removeAfter(String original, String marker); ArrayBuilder createArrayBuilder(); Map<String, String> getHeaders(String type, Object target); @Override boolean activate(String uri, String operation, String id); @Override boolean activate(String uri, String operation); @Override boolean isActive(); @Override void deactivate(); @Override void retainNode(String id); @Override void releaseNode(String id); @Override Node retrieveNode(String id); @Override void initiateCorrelation(String id); @Override boolean isCorrelated(String id); @Override void correlate(String id); @Override void completeCorrelation(String id, boolean allowSpawn); @Override void unlink(); @Override void suppress(); @Override void ignoreNode(); @Override void assertComplete(); String getTraceId(); String getTransactionName(); String getLevel(); void initInBuffer(Object obj); boolean isInBufferActive(Object obj); void appendInBuffer(Object obj, byte[] data, int offset, int len, boolean close); void recordInBuffer(Object obj); void initOutBuffer(Object obj); boolean isOutBufferActive(Object obj); void appendOutBuffer(Object obj, byte[] data, int offset, int len, boolean close); void recordOutBuffer(Object obj); boolean isInProcessed(); boolean isInContentProcessed(); boolean isOutProcessed(); boolean isOutContentProcessed(); OutputStream createInOutputStream(OutputStream os); OutputStream createInOutputStream(OutputStream os, String linkId); OutputStream createOutOutputStream(OutputStream os); OutputStream createOutOutputStream(OutputStream os, String linkId); InputStream createInInputStream(InputStream is); InputStream createOutInputStream(InputStream is); @Override void setState(Object context, String name, Object value, boolean session); @Override Object getState(Object context, String name, boolean session); static final String BINARY_SQL_MARKER; }
@Test public void testFormatSQL() { RuleHelper helper = new RuleHelper(null); String pretext = "prep79: "; String sql = "select performanc0_.show_id as show_id3_0_1_, performanc0_.id as id1_5_1_, performanc0_.id " + "as id1_5_0_, performanc0_.date as date2_5_0_, performanc0_.show_id as show_id3_5_0_ from " + "Performance performanc0_ where performanc0_.show_id=? order by performanc0_.date {1: 1}"; String result = helper.formatSQL(pretext + sql, null); assertEquals(sql, result); }
@Test public void testFormatSQL2() { RuleHelper helper = new RuleHelper(null); String pretext = "prep102: "; String sql = "select mediaitem0_.id as id1_4_0_, mediaitem0_.mediaType as mediaTyp2_4_0_, mediaitem0_.url " + "as url3_4_0_ from MediaItem mediaitem0_ where mediaitem0_.id=? {1: 22}"; String result = helper.formatSQL(pretext + sql, null); assertEquals(sql, result); }
@Test public void testFormatSQLWithBinary() { RuleHelper helper = new RuleHelper(null); String pretext = "update SectionAllocation set allocated=?, occupiedCount=?, performance_id=?, " + "section_id=?, version=? where id=? and version=? {1: "; String binary = "X'aced0005757200035b5b4afe76f8764a55dfbd020000787000000014757200025b4a782004b512b1759" + "3020000787000000064ffffffffffffffffffffffffffffffff00000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000000000000007571007e000200000064000000000000" + "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'"; String posttext = ", 2: 4, 3: 1, 4: 1, 5: 2, 6: 1, 7: }"; String pre = pretext + binary + posttext; String expected = pretext + RuleHelper.BINARY_SQL_MARKER + posttext; String result = helper.formatSQL(pre, null); assertEquals(expected, result); }
@Test public void testFormatSQLWithSupplidExpression() { RuleHelper helper = new RuleHelper(null); String expr = "theExpression"; String context = "theContext"; String result = helper.formatSQL(context, expr); assertEquals(expr, result); }