cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ba...@locus.apache.org
Subject cvs commit: xml-cocoon/src/org/apache/cocoon/processor/sql ColumnFormatter.java ConnectionCreator.java SQLProcessor.java Utils.java
Date Fri, 04 Feb 2000 05:17:35 GMT
balld       00/02/03 21:17:35

  Modified:    src/org/apache/cocoon/processor/sql ColumnFormatter.java
                        ConnectionCreator.java SQLProcessor.java Utils.java
  Log:
  Submitted by:	"Stevenson, Chris (SSABSA)" <chris@ssabsa.sa.gov.au>
  Reviewed by:	Donald Ball <balld@webslingerZ.com>
  Patched column formatter and DriverManager timeout bugs.
  
  Revision  Changes    Path
  1.4       +22 -15    xml-cocoon/src/org/apache/cocoon/processor/sql/ColumnFormatter.java
  
  Index: ColumnFormatter.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/sql/ColumnFormatter.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ColumnFormatter.java	2000/02/03 19:23:31	1.3
  +++ ColumnFormatter.java	2000/02/04 05:17:34	1.4
  @@ -2,34 +2,34 @@
    ============================================================================
                      The Apache Software License, Version 1.1
    ============================================================================
  - 
  +
       Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
  - 
  +
    Redistribution and use in source and binary forms, with or without modifica-
    tion, are permitted provided that the following conditions are met:
  - 
  +
    1. Redistributions of  source code must  retain the above copyright  notice,
       this list of conditions and the following disclaimer.
  - 
  +
    2. Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
  - 
  +
    3. The end-user documentation included with the redistribution, if any, must
       include  the following  acknowledgment:  "This product includes  software
       developed  by the  Apache Software Foundation  (http://www.apache.org/)."
       Alternately, this  acknowledgment may  appear in the software itself,  if
       and wherever such third-party acknowledgments normally appear.
  - 
  +
    4. The names "Cocoon" and  "Apache Software Foundation"  must not be used to
       endorse  or promote  products derived  from this  software without  prior
       written permission. For written permission, please contact
       apache@apache.org.
  - 
  +
    5. Products  derived from this software may not  be called "Apache", nor may
       "Apache" appear  in their name,  without prior written permission  of the
       Apache Software Foundation.
  - 
  +
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  @@ -40,10 +40,10 @@
    ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
    (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  - 
  +
    This software  consists of voluntary contributions made  by many individuals
    on  behalf of the Apache Software  Foundation and was  originally created by
  - Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache 
  + Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
    Software Foundation, please see <http://www.apache.org/>.
    */
   
  @@ -102,17 +102,24 @@
   		return format;
   	}
   
  -	protected void addColumnNode(Document document, Element parent, Column column, ResultSet
rs, int i, String value) throws SQLException {
  +	protected void addColumnNode(Document document, Element parent, Column column, Object
value, int i) throws SQLException {
   		String format = getFormat(column);
   		if (format != null) {
   			if (column.type.equals("timestamp") || column.type.equals("time") || column.type.equals("date")
|| column.type.equals("datetime")) {
  -				SimpleDateFormat date_format = new SimpleDateFormat(format);
  -				parent.appendChild(document.createTextNode(date_format.format(rs.getDate(i))));
  +                                if (value instanceof java.util.Date) {
  +				    SimpleDateFormat date_format = new SimpleDateFormat(format);
  +				    parent.appendChild(document.createTextNode(date_format.format((java.util.Date)value)));
  +                                }
  +                                else {
  +            	                    //We can't format this object as a Date 'cos it isn't
one!
  +    	                            //Fall back to simple String format
  +				    parent.appendChild(document.createTextNode(value.toString()));
  +                                }
   				return;
   			} else if (column.type.equals("varchar") || column.type.equals("text")) {
   				if (format.equals("br")) {
   					StringBuffer sb = new StringBuffer();
  -					StringCharacterIterator iter = new StringCharacterIterator(rs.getString(i));
  +					StringCharacterIterator iter = new StringCharacterIterator(value.toString());
   					for (char c = iter.first(); c != iter.DONE; c = iter.next()) {
   						if (c == '\n') {
   							if (sb.length() > 0) {
  @@ -131,7 +138,7 @@
   				}
   			}
   		}
  -		parent.appendChild(document.createTextNode(value));
  +                parent.appendChild(document.createTextNode(value.toString()));
   	}
   
   }
  
  
  
  1.6       +33 -15    xml-cocoon/src/org/apache/cocoon/processor/sql/ConnectionCreator.java
  
  Index: ConnectionCreator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/sql/ConnectionCreator.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ConnectionCreator.java	1999/12/03 08:42:28	1.5
  +++ ConnectionCreator.java	2000/02/04 05:17:34	1.6
  @@ -2,34 +2,34 @@
    ============================================================================
                      The Apache Software License, Version 1.1
    ============================================================================
  - 
  +
       Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
  - 
  +
    Redistribution and use in source and binary forms, with or without modifica-
    tion, are permitted provided that the following conditions are met:
  - 
  +
    1. Redistributions of  source code must  retain the above copyright  notice,
       this list of conditions and the following disclaimer.
  - 
  +
    2. Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
  - 
  +
    3. The end-user documentation included with the redistribution, if any, must
       include  the following  acknowledgment:  "This product includes  software
       developed  by the  Apache Software Foundation  (http://www.apache.org/)."
       Alternately, this  acknowledgment may  appear in the software itself,  if
       and wherever such third-party acknowledgments normally appear.
  - 
  +
    4. The names "Cocoon" and  "Apache Software Foundation"  must not be used to
       endorse  or promote  products derived  from this  software without  prior
       written permission. For written permission, please contact
       apache@apache.org.
  - 
  +
    5. Products  derived from this software may not  be called "Apache", nor may
       "Apache" appear  in their name,  without prior written permission  of the
       Apache Software Foundation.
  - 
  +
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  @@ -40,10 +40,10 @@
    ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
    (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  - 
  +
    This software  consists of voluntary contributions made  by many individuals
    on  behalf of the Apache Software  Foundation and was  originally created by
  - Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache 
  + Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
    Software Foundation, please see <http://www.apache.org/>.
   */
   
  @@ -56,7 +56,7 @@
    * Utility methods for this processor.
    *
    * @author <a href="mailto:balld@webslingerZ.com">Donald Ball</a>
  - * @version $Revision: 1.5 $ $Date: 1999/12/03 08:42:28 $
  + * @version $Revision: 1.6 $ $Date: 2000/02/04 05:17:34 $
    */
   
   public class ConnectionCreator {
  @@ -64,18 +64,36 @@
       protected String dburl;
       protected String username;
       protected String password;
  +    /*
  +     * -1 is a marker to use default timeout,
  +     * since 0 may mean never timeout
  +     */
  +    protected int loginTimeout = -1;
   
       public ConnectionCreator(Properties props) {
           this.dburl = props.getProperty("dburl");
           this.username = props.getProperty("username");
           this.password = props.getProperty("password");
  +        this.loginTimeout = Integer.parseInt(props.getProperty("login-timeout", "-1"));
       }
   
       public Connection getConnection() throws SQLException {
  -        if (username != null && password != null)
  -            return DriverManager.getConnection(dburl,username,password);
  -        else
  -            return DriverManager.getConnection(dburl);
  +    	Connection retval = null;
  +    	int oldLoginTimeout = -1;
  +    	if (loginTimeout>=0) {
  +    		oldLoginTimeout = DriverManager.getLoginTimeout();
  +    		DriverManager.setLoginTimeout(loginTimeout);
  +    	}
  +        if (username != null && password != null) {
  +            retval = DriverManager.getConnection(dburl,username,password);
  +        }
  +        else {
  +            retval = DriverManager.getConnection(dburl);
  +        }
  +    	if (loginTimeout>=0) {
  +            DriverManager.setLoginTimeout(oldLoginTimeout);
  +    	}
  +        return retval;
       }
   
   }
  
  
  
  1.9       +16 -15    xml-cocoon/src/org/apache/cocoon/processor/sql/SQLProcessor.java
  
  Index: SQLProcessor.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/sql/SQLProcessor.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- SQLProcessor.java	2000/02/03 19:23:31	1.8
  +++ SQLProcessor.java	2000/02/04 05:17:34	1.9
  @@ -2,34 +2,34 @@
    ============================================================================
                      The Apache Software License, Version 1.1
    ============================================================================
  - 
  +
       Copyright (C) 1999 The Apache Software Foundation. All rights reserved.
  - 
  +
    Redistribution and use in source and binary forms, with or without modifica-
    tion, are permitted provided that the following conditions are met:
  - 
  +
    1. Redistributions of  source code must  retain the above copyright  notice,
       this list of conditions and the following disclaimer.
  - 
  +
    2. Redistributions in binary form must reproduce the above copyright notice,
       this list of conditions and the following disclaimer in the documentation
       and/or other materials provided with the distribution.
  - 
  +
    3. The end-user documentation included with the redistribution, if any, must
       include  the following  acknowledgment:  "This product includes  software
       developed  by the  Apache Software Foundation  (http://www.apache.org/)."
       Alternately, this  acknowledgment may  appear in the software itself,  if
       and wherever such third-party acknowledgments normally appear.
  - 
  +
    4. The names "Cocoon" and  "Apache Software Foundation"  must not be used to
       endorse  or promote  products derived  from this  software without  prior
       written permission. For written permission, please contact
       apache@apache.org.
  - 
  +
    5. Products  derived from this software may not  be called "Apache", nor may
       "Apache" appear  in their name,  without prior written permission  of the
       Apache Software Foundation.
  - 
  +
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
    FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
  @@ -40,10 +40,10 @@
    ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
    (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
    THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  - 
  +
    This software  consists of voluntary contributions made  by many individuals
    on  behalf of the Apache Software  Foundation and was  originally created by
  - Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache 
  + Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
    Software Foundation, please see <http://www.apache.org/>.
    */
   
  @@ -62,7 +62,7 @@
    * A processor that performs SQL database queries.
    *
    * @author <a href="mailto:balld@webslingerZ.com">Donald Ball</a>
  - * @version $Revision: 1.8 $ $Date: 2000/02/03 19:23:31 $
  + * @version $Revision: 1.9 $ $Date: 2000/02/04 05:17:34 $
    */
   
   public class SQLProcessor extends AbstractActor implements Processor, Status {
  @@ -268,9 +268,10 @@
                       }
   
                       for (int i=0; i<columns.length; i++) {
  -						String value = rs.getString(i+1);
  -                        if (create_row_elements && create_id_attribute &&
id_attribute_column_index == i) {
  -                            row_element.setAttribute(id_attribute,value);
  +                		Object value = rs.getObject(i+1);
  +                        if (create_row_elements && create_id_attribute
  +                		  && id_attribute_column_index == i) {
  +                            row_element.setAttribute(id_attribute, value.toString());
                               continue;
                           }
                           if (value == null && null_mode == OMIT_NULLS) continue;
  @@ -279,7 +280,7 @@
                               column_element.setAttribute("NULL","YES");
                               column_element.appendChild(document.createTextNode(""));
                           } else {
  -							formatter.addColumnNode(document,column_element,columns[i],rs,i+1,value);
  +                            formatter.addColumnNode(document,column_element,columns[i],value,i+1);
                           }
                           row_node.appendChild(column_element);
                       }
  
  
  
  1.7       +2 -1      xml-cocoon/src/org/apache/cocoon/processor/sql/Utils.java
  
  Index: Utils.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/sql/Utils.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Utils.java	1999/12/08 07:37:09	1.6
  +++ Utils.java	2000/02/04 05:17:34	1.7
  @@ -1,4 +1,5 @@
   /*
  +testing
    ============================================================================
                      The Apache Software License, Version 1.1
    ============================================================================
  @@ -59,7 +60,7 @@
    * Utility methods for this processor.
    *
    * @author <a href="mailto:balld@webslingerZ.com">Donald Ball</a>
  - * @version $Revision: 1.6 $ $Date: 1999/12/08 07:37:09 $
  + * @version $Revision: 1.7 $ $Date: 2000/02/04 05:17:34 $
    */
   
   public class Utils {
  
  
  

Mime
View raw message