Author: kris
Date: Tue Jan 23 12:57:09 2007
New Revision: 499130

URL: http://svn.apache.org/viewvc?view=rev&rev=499130
Log:
Format/whitespace changes only - prep for 17388 fix

Modified:
    
jakarta/taglibs/proper/standard/trunk/src/org/apache/taglibs/standard/tag/common/sql/QueryTagSupport.java

Modified: 
jakarta/taglibs/proper/standard/trunk/src/org/apache/taglibs/standard/tag/common/sql/QueryTagSupport.java
URL: 
http://svn.apache.org/viewvc/jakarta/taglibs/proper/standard/trunk/src/org/apache/taglibs/standard/tag/common/sql/QueryTagSupport.java?view=diff&rev=499130&r1=499129&r2=499130
==============================================================================
--- 
jakarta/taglibs/proper/standard/trunk/src/org/apache/taglibs/standard/tag/common/sql/QueryTagSupport.java
 (original)
+++ 
jakarta/taglibs/proper/standard/trunk/src/org/apache/taglibs/standard/tag/common/sql/QueryTagSupport.java
 Tue Jan 23 12:57:09 2007
@@ -20,22 +20,27 @@
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+
 import java.util.ArrayList;
 import java.util.List;
 
 import javax.servlet.jsp.JspException;
 import javax.servlet.jsp.JspTagException;
 import javax.servlet.jsp.PageContext;
+
 import javax.servlet.jsp.jstl.core.Config;
+
 import javax.servlet.jsp.jstl.sql.Result;
 import javax.servlet.jsp.jstl.sql.SQLExecutionTag;
+
 import javax.servlet.jsp.tagext.BodyTagSupport;
 import javax.servlet.jsp.tagext.TryCatchFinally;
+
 import javax.sql.DataSource;
 
 import org.apache.taglibs.standard.resources.Resources;
-import org.apache.taglibs.standard.tag.common.core.Util;
 
+import org.apache.taglibs.standard.tag.common.core.Util;
 
 /**
  * <p>Tag handler for &lt;Query&gt; in JSTL.  
@@ -81,13 +86,13 @@
     private void init() {
         startRow = 0;
         maxRows = -1;
-       maxRowsSpecified = dataSourceSpecified = false;
-       isPartOfTransaction = false;
-       conn = null;
-       rawDataSource = null;
-       parameters = null;
-       sql = null;
-       var = null;
+        maxRowsSpecified = dataSourceSpecified = false;
+        isPartOfTransaction = false;
+        conn = null;
+        rawDataSource = null;
+        parameters = null;
+        sql = null;
+        var = null;
         scope = PageContext.PAGE_SCOPE;
     }
 
@@ -100,7 +105,7 @@
      * result.
      */
     public void setVar(String var) {
-       this.var = var;
+        this.var = var;
     }
 
     /**
@@ -119,10 +124,10 @@
      * parameter values.
      */
     public void addSQLParameter(Object o) {
-       if (parameters == null) {
-           parameters = new ArrayList();
-       }
-       parameters.add(o);
+        if (parameters == null) {
+            parameters = new ArrayList();
+        }
+        parameters.add(o);
     }
 
     //*********************************************************************
@@ -135,33 +140,31 @@
     public int doStartTag() throws JspException {
 
         if (!maxRowsSpecified) {
-           Object obj = Config.find(pageContext, Config.SQL_MAX_ROWS);
-           if (obj != null) {
-               if (obj instanceof Integer) {
-                   maxRows = ((Integer) obj).intValue();
-               } else if (obj instanceof String) {
-                   try {
-                       maxRows = Integer.parseInt((String) obj);
-                   } catch (NumberFormatException nfe) {
-                       throw new JspException(
-                           Resources.getMessage("SQL_MAXROWS_PARSE_ERROR",
-                                                (String) obj),
-                           nfe);
-                   }
-               } else {
-                   throw new JspException(
-                        Resources.getMessage("SQL_MAXROWS_INVALID"));
-               }
+            Object obj = Config.find(pageContext, Config.SQL_MAX_ROWS);
+            if (obj != null) {
+                if (obj instanceof Integer) {
+                    maxRows = ((Integer) obj).intValue();
+                } else if (obj instanceof String) {
+                    try {
+                        maxRows = Integer.parseInt((String) obj);
+                    } catch (NumberFormatException nfe) {
+                        throw new 
JspException(Resources.getMessage("SQL_MAXROWS_PARSE_ERROR",
+                                                                    (String) 
obj),
+                                               nfe);
+                    }
+                } else {
+                    throw new 
JspException(Resources.getMessage("SQL_MAXROWS_INVALID"));
+                }
             }
         }
 
-       try {
-           conn = getConnection();
-       } catch (SQLException e) {
-           throw new JspException(sql + ": " + e.getMessage(), e);
-       }
+        try {
+            conn = getConnection();
+        } catch (SQLException e) {
+            throw new JspException(sql + ": " + e.getMessage(), e);
+        }
 
-       return EVAL_BODY_BUFFERED;
+        return EVAL_BODY_BUFFERED;
     }
 
     /**
@@ -178,64 +181,62 @@
      * named <code>javax.servlet.jstl.sql.dataSource</code>.
      */
     public int doEndTag() throws JspException {
-       /*
-        * Use the SQL statement specified by the sql attribute, if any,
-        * otherwise use the body as the statement.
-        */
-       String sqlStatement = null;
-       if (sql != null) {
-           sqlStatement = sql;
-       }
-       else if (bodyContent != null) {
-           sqlStatement = bodyContent.getString();
-       }
-       if (sqlStatement == null || sqlStatement.trim().length() == 0) {
-           throw new JspTagException(
-                Resources.getMessage("SQL_NO_STATEMENT"));
-       }
+        /*
+         * Use the SQL statement specified by the sql attribute, if any,
+         * otherwise use the body as the statement.
+         */
+        String sqlStatement = null;
+        if (sql != null) {
+            sqlStatement = sql;
+        }
+        else if (bodyContent != null) {
+            sqlStatement = bodyContent.getString();
+        }
+        if (sqlStatement == null || sqlStatement.trim().length() == 0) {
+            throw new 
JspTagException(Resources.getMessage("SQL_NO_STATEMENT"));
+        }
         /*
          * We shouldn't have a negative startRow or illegal maxrows
          */
         if ((startRow < 0) || (maxRows < -1)) {
-            throw new JspException(
-                Resources.getMessage("PARAM_BAD_VALUE"));
+            throw new JspException(Resources.getMessage("PARAM_BAD_VALUE"));
         }
 
-       Result result = null;
-       /* 
-        * Note! We must not use the setMaxRows() method on the
-        * the statement to limit the number of rows, since the
-        * Result factory must be able to figure out the correct
-        * value for isLimitedByMaxRows(); there's no way to check
-        * if it was from the ResultSet.
-          */
-       PreparedStatement ps = null;
-       try {
-           ps = conn.prepareStatement(sqlStatement);
-           setParameters(ps, parameters);
-           ResultSet rs = ps.executeQuery();
-           result = new ResultImpl(rs, startRow, maxRows);
-       }
-       catch (Throwable e) {
-           throw new JspException(sqlStatement + ": " + e.getMessage(), e);
-       } finally {
-           if (ps != null) {
-               try {
-                   ps.close();
-               } catch (SQLException sqe) {
-                   throw new JspException(sqe.getMessage(), sqe);
-               }
-           }
-       }
-       pageContext.setAttribute(var, result, scope);
-       return EVAL_PAGE;
+        Result result = null;
+        /* 
+         * Note! We must not use the setMaxRows() method on the
+         * the statement to limit the number of rows, since the
+         * Result factory must be able to figure out the correct
+         * value for isLimitedByMaxRows(); there's no way to check
+         * if it was from the ResultSet.
+         */
+        PreparedStatement ps = null;
+        try {
+            ps = conn.prepareStatement(sqlStatement);
+            setParameters(ps, parameters);
+            ResultSet rs = ps.executeQuery();
+            result = new ResultImpl(rs, startRow, maxRows);
+        }
+        catch (Throwable e) {
+            throw new JspException(sqlStatement + ": " + e.getMessage(), e);
+        } finally {
+            if (ps != null) {
+                try {
+                    ps.close();
+                } catch (SQLException sqe) {
+                    throw new JspException(sqe.getMessage(), sqe);
+                }
+            }
+        }
+        pageContext.setAttribute(var, result, scope);
+        return EVAL_PAGE;
     }
 
     /**
      * Just rethrows the Throwable.
      */
     public void doCatch(Throwable t) throws Throwable {
-       throw t;
+        throw t;
     }
 
     /**
@@ -243,14 +244,14 @@
      * as part of a transaction.
      */
     public void doFinally() {
-       if (conn != null && !isPartOfTransaction) {
-           try {
-               conn.close();
-           } catch (SQLException e) {} // Not much we can do
-       }
+        if (conn != null && !isPartOfTransaction) {
+            try {
+                conn.close();
+            } catch (SQLException e) {} // Not much we can do
+        }
 
-       conn = null;
-       parameters = null;
+        conn = null;
+        parameters = null;
     }
 
 
@@ -258,50 +259,46 @@
     // Private utility methods
 
     private Connection getConnection() throws JspException, SQLException {
-       // Fix: Add all other mechanisms
-       Connection conn = null;
-       isPartOfTransaction = false;
-
-       TransactionTagSupport parent = (TransactionTagSupport) 
-           findAncestorWithClass(this, TransactionTagSupport.class);
-       if (parent != null) {
+        // Fix: Add all other mechanisms
+        Connection conn = null;
+        isPartOfTransaction = false;
+
+        TransactionTagSupport parent = 
(TransactionTagSupport)findAncestorWithClass(this, TransactionTagSupport.class);
+        if (parent != null) {
             if (dataSourceSpecified) {
-                throw new JspTagException(
-                    Resources.getMessage("ERROR_NESTED_DATASOURCE"));
+                throw new 
JspTagException(Resources.getMessage("ERROR_NESTED_DATASOURCE"));
             }
-           conn = parent.getSharedConnection();
+            conn = parent.getSharedConnection();
             isPartOfTransaction = true;
-       } else {
-           if ((rawDataSource == null) && dataSourceSpecified) {
-               throw new JspException(
-                   Resources.getMessage("SQL_DATASOURCE_NULL"));
-           }
-           DataSource dataSource = DataSourceUtil.getDataSource(rawDataSource,
-                                                                pageContext);
+        } else {
+            if ((rawDataSource == null) && dataSourceSpecified) {
+                throw new 
JspException(Resources.getMessage("SQL_DATASOURCE_NULL"));
+            }
+            DataSource dataSource = DataSourceUtil.getDataSource(rawDataSource,
+                                                                 pageContext);
             try {
-               conn = dataSource.getConnection();
+                conn = dataSource.getConnection();
             } catch (Exception ex) {
-                throw new JspException(
-                    Resources.getMessage("DATASOURCE_INVALID", 
-                                         ex.toString()));
+                throw new 
JspException(Resources.getMessage("DATASOURCE_INVALID", 
+                                                            ex.toString()));
             }
-       }
+        }
 
-       return conn;
+        return conn;
     }
 
     private void setParameters(PreparedStatement ps, List parameters) 
         throws SQLException
     {
-       if (parameters != null) {
-           for (int i = 0; i < parameters.size(); i++) {
+        if (parameters != null) {
+            for (int i = 0; i < parameters.size(); i++) {
                 /* The first parameter has index 1.  If a null
                  * is passed to setObject the parameter will be
                  * set to JDBC null so an explicit call to
                  * ps.setNull is not required.
                  */
-               ps.setObject(i + 1, parameters.get(i));
-           }
-       }
+                ps.setObject(i + 1, parameters.get(i));
+            }
+        }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to