Permalink
Browse files

replaced spaces with tab to be uniform

  • Loading branch information...
Jakub Holy
Jakub Holy committed Apr 18, 2011
1 parent 5967c8d commit 7f288d0fb69941afc1eb24aef5604b2c13255e24
View
@@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name="aspectj_code_injection" default="inject_binaries">
<description>
- Inject the AspectJ aspect into the compiled target .class via AspectJ Ant task
- </description>
+ Inject the AspectJ aspect into the compiled target .class via AspectJ Ant task
+ </description>
<!-- =================================
- target: inject_binaries
- ================================= -->
+ target: inject_binaries
+ ================================= -->
<target name="inject_binaries">
<!--
@@ -19,30 +19,30 @@
class LoggingStatementDecorator implements InvocationHandler {
private PreparedStatement target;
- private List<List<Object>> batch = new LinkedList<List<Object>>();
- private List<Object> currentRow = new LinkedList<Object>();
- private int successfulBatchCounter = 0;
-
- private LoggingStatementDecorator(PreparedStatement target) {
- if (target == null) throw new IllegalArgumentException("'target' can't be null.");
- this.target = target;
- }
-
- @Override
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
-
- try {
- Object result = method.invoke(target, args);
- updateLog(method, args);
- return result;
- } catch (InvocationTargetException e) {
- Throwable cause = e.getTargetException();
- tryLogFailure(cause);
- throw cause;
- }
-
- }
+ private List<List<Object>> batch = new LinkedList<List<Object>>();
+ private List<Object> currentRow = new LinkedList<Object>();
+ private int successfulBatchCounter = 0;
+
+ private LoggingStatementDecorator(PreparedStatement target) {
+ if (target == null) throw new IllegalArgumentException("'target' can't be null.");
+ this.target = target;
+ }
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+
+ try {
+ Object result = method.invoke(target, args);
+ updateLog(method, args);
+ return result;
+ } catch (InvocationTargetException e) {
+ Throwable cause = e.getTargetException();
+ tryLogFailure(cause);
+ throw cause;
+ }
+
+ }
private void tryLogFailure(Throwable cause) {
if (cause instanceof BatchUpdateException) {
@@ -61,60 +61,60 @@ private void tryLogFailure(Throwable cause) {
private void updateLog(Method method, Object[] args) {
// All the interesting set<Something> methods have the signature: (int index, Something value [, ...])
if (method.getName().startsWith("setNull")
- && (args.length >=1 && Integer.TYPE == method.getParameterTypes()[0] ) ) {
- handleSetSomething((Integer) args[0], null);
- } else if (method.getName().startsWith("set")
- && (args.length >=2 && Integer.TYPE == method.getParameterTypes()[0] ) ) {
- handleSetSomething((Integer) args[0], args[1]);
- } else if ("addBatch".equals(method.getName())) {
- handleAddBatch();
- } else if ("executeBatch".equals(method.getName())) {
- handleExecuteBatch();
- }
+ && (args.length >=1 && Integer.TYPE == method.getParameterTypes()[0] ) ) {
+ handleSetSomething((Integer) args[0], null);
+ } else if (method.getName().startsWith("set")
+ && (args.length >=2 && Integer.TYPE == method.getParameterTypes()[0] ) ) {
+ handleSetSomething((Integer) args[0], args[1]);
+ } else if ("addBatch".equals(method.getName())) {
+ handleAddBatch();
+ } else if ("executeBatch".equals(method.getName())) {
+ handleExecuteBatch();
+ }
}
- private void handleExecuteBatch() {
- ++successfulBatchCounter;
- batch.clear();
+ private void handleExecuteBatch() {
+ ++successfulBatchCounter;
+ batch.clear();
}
private void handleSetSomething(int index, Object value) {
- currentRow.add(value);
- }
-
- private void handleAddBatch() {
- batch.add(currentRow);
- currentRow = new LinkedList<Object>();
- }
-
- public List<List<Object>> getValues() {
- return batch;
- }
-
- public PreparedStatement getTarget() { return target; }
-
- /** Values as comma-separated values. */
- public String getValuesAsCsv() {
- StringBuilder csv = new StringBuilder();
- for (List<Object> row : getValues()) {
- for (Object field : row) {
- // Escape Strings
- if (field instanceof String) {
- field = "'" + ((String) field).replaceAll("'", "''") + "'";
- }
- csv.append(field).append(",");
- }
- csv.append("\n");
- }
- return csv.toString();
- } /* getValuesAsCsv */
-
- public static PreparedStatement createProxy(PreparedStatement target) {
- return (PreparedStatement) Proxy.newProxyInstance(
- PreparedStatement.class.getClassLoader(),
- new Class[] { PreparedStatement.class },
- new LoggingStatementDecorator(target));
- };
+ currentRow.add(value);
+ }
+
+ private void handleAddBatch() {
+ batch.add(currentRow);
+ currentRow = new LinkedList<Object>();
+ }
+
+ public List<List<Object>> getValues() {
+ return batch;
+ }
+
+ public PreparedStatement getTarget() { return target; }
+
+ /** Values as comma-separated values. */
+ public String getValuesAsCsv() {
+ StringBuilder csv = new StringBuilder();
+ for (List<Object> row : getValues()) {
+ for (Object field : row) {
+ // Escape Strings
+ if (field instanceof String) {
+ field = "'" + ((String) field).replaceAll("'", "''") + "'";
+ }
+ csv.append(field).append(",");
+ }
+ csv.append("\n");
+ }
+ return csv.toString();
+ } /* getValuesAsCsv */
+
+ public static PreparedStatement createProxy(PreparedStatement target) {
+ return (PreparedStatement) Proxy.newProxyInstance(
+ PreparedStatement.class.getClassLoader(),
+ new Class[] { PreparedStatement.class },
+ new LoggingStatementDecorator(target));
+ };
}
@@ -3,13 +3,13 @@ Configuration for the AspectJ load-time weaver: it requires us to
explicitly specify the aspects it should inject.
-->
<aspectj>
- <aspects>
- <aspect name="iterate.jz2011.codeinjection.aspectj.LoggingAspect"/>
- </aspects>
+ <aspects>
+ <aspect name="iterate.jz2011.codeinjection.aspectj.LoggingAspect"/>
+ </aspects>
<!--
See http://www.eclipse.org/aspectj/doc/released/devguide/ltw-configuration.html#weaver-options
Interesting additional options: -debug
-->
- <weaver options="-verbose -showWeaveInfo" />
+ <weaver options="-verbose -showWeaveInfo" />
</aspectj>

0 comments on commit 7f288d0

Please sign in to comment.