Revision: 517
Author: dbrosius
Date: 2006-05-04 22:55:31 -0700 (Thu, 04 May 2006)
ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=517&view=rev
Log Message:
-----------
javadoc
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SQLInLoop.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SQLInLoop.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SQLInLoop.java 2006-05-05 05:51:49 UTC (rev 516)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SQLInLoop.java 2006-05-05 05:55:31 UTC (rev 517)
@@ -1,3 +1,21 @@
+/*
+ * fb-contrib - Auxilliary detectors for Java programs
+ * Copyright (C) 2005-2006 Dave Brosius
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
package com.mebigfatguy.fbcontrib.detect;
import java.util.ArrayList;
@@ -12,6 +30,11 @@
import edu.umd.cs.findbugs.BytecodeScanningDetector;
import edu.umd.cs.findbugs.ba.ClassContext;
+/**
+ * looks for the execution of sql queries inside a loop. This pattern tends to be inefficient,
+ * and often can be improved upon, by collecting all the keys needed for the query and issuing just
+ * one query using an in clause with all the keys for all the queries previously needed in the loop.
+ */
public class SQLInLoop extends BytecodeScanningDetector
{
private static final Set<String> queryClasses = new HashSet<String>();
@@ -30,10 +53,19 @@
List<Integer> queryLocations;
List<LoopLocation> loops;
+ /**
+ * constructs a SIL detector given the reporter to report bugs on
+ * @param bugReporter the sync of bug reports
+ */
public SQLInLoop(BugReporter bugReporter) {
this.bugReporter = bugReporter;
}
+ /**
+ * implements the visitor to create and clear the query locations and loops collections
+ *
+ * @param classContext the context object for the currently parsed java class
+ */
@Override
public void visitClassContext(ClassContext classContext) {
try {
@@ -46,6 +78,11 @@
}
}
+ /**
+ * implements the visitor to clear the collections, and report the query locations that are in loops
+ *
+ * @param obj the context object for the currently parsed code block
+ */
@Override
public void visitCode(Code obj) {
queryLocations.clear();
@@ -64,6 +101,11 @@
}
}
+ /**
+ * implements the visitor to collect positions of queries and loops
+ *
+ * @param seen the opcode of the currently parsed instruction
+ */
@Override
public void sawOpcode(int seen) {
if (seen == INVOKEINTERFACE) {
@@ -81,6 +123,9 @@
}
}
+ /**
+ * holds the start and end position of a loop
+ */
private static class LoopLocation {
private int startPC;
private int endPC;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|