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 ConnectionCreator.java ConnectionDefs.java SQLProcessor.java SQLQueryCreator.java Utils.java
Date Thu, 02 Dec 1999 09:07:46 GMT
balld       99/12/02 01:07:46

  Modified:    src/org/apache/cocoon/processor/sql ConnectionCreator.java
                        ConnectionDefs.java SQLProcessor.java
                        SQLQueryCreator.java Utils.java
  Log:
  Merged changes from transition between java.apache.org and xml.apache.org,
  mostly bug fixes, will summarize new features in an email to xml-cocoon list.
  
  Revision  Changes    Path
  1.4       +4 -5      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ConnectionCreator.java	1999/11/09 02:30:47	1.3
  +++ ConnectionCreator.java	1999/12/02 09:07:45	1.4
  @@ -1,5 +1,4 @@
  -/*-- $Id: ConnectionCreator.java,v 1.3 1999/11/09 02:30:47 dirkx Exp $ -- 
  -
  +/*
    ============================================================================
                      The Apache Software License, Version 1.1
    ============================================================================
  @@ -46,8 +45,8 @@
    on  behalf of the Apache Software  Foundation and was  originally created by
    Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache 
    Software Foundation, please see <http://www.apache.org/>.
  - 
  - */
  +*/
  +
   package org.apache.cocoon.processor.sql;
   
   import java.sql.*;
  @@ -57,7 +56,7 @@
    * Utility methods for this processor.
    *
    * @author <a href="mailto:balld@webslingerZ.com">Donald Ball</a>
  - * @version $Revision: 1.3 $ $Date: 1999/11/09 02:30:47 $
  + * @version $Revision: 1.4 $ $Date: 1999/12/02 09:07:45 $
    */
   
   public class ConnectionCreator {
  
  
  
  1.4       +11 -8     xml-cocoon/src/org/apache/cocoon/processor/sql/ConnectionDefs.java
  
  Index: ConnectionDefs.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/sql/ConnectionDefs.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ConnectionDefs.java	1999/11/09 02:30:47	1.3
  +++ ConnectionDefs.java	1999/12/02 09:07:46	1.4
  @@ -1,5 +1,4 @@
  -/*-- $Id: ConnectionDefs.java,v 1.3 1999/11/09 02:30:47 dirkx Exp $ -- 
  -
  +/*
    ============================================================================
                      The Apache Software License, Version 1.1
    ============================================================================
  @@ -46,8 +45,8 @@
    on  behalf of the Apache Software  Foundation and was  originally created by
    Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache 
    Software Foundation, please see <http://www.apache.org/>.
  - 
    */
  +
   package org.apache.cocoon.processor.sql;
   
   import org.w3c.dom.*;
  @@ -58,7 +57,7 @@
    * Default connection values.
    *
    * @author <a href="mailto:balld@webslingerZ.com">Donald Ball</a>
  - * @version $Revision: 1.3 $ $Date: 1999/11/09 02:30:47 $
  + * @version $Revision: 1.4 $ $Date: 1999/12/02 09:07:46 $
    */
   
   public class ConnectionDefs {
  @@ -93,6 +92,7 @@
           master_default_query_props.put("query-attribute","");
           master_default_query_props.put("skip-rows-attribute","");
           master_default_query_props.put("max-rows-attribute","");
  +        master_default_query_props.put("update-rows-attribute","");
           master_default_query_props.put("variable-left-delimiter","{@");
           master_default_query_props.put("variable-right-delimiter","}");
           master_default_query_props.put("session-variable-left-delimiter","{@session.");
  @@ -178,13 +178,16 @@
           ConnectionCreator creator = (ConnectionCreator)creators.get(name);
           return creator.getConnection();
       }
  -
  -    public Properties getQueryProperties() { return default_query_props; }
   
  +    public Properties getQueryProperties() { 
  +		return (Properties)default_query_props.clone(); 
  +	}
   
       public Properties getQueryProperties(String name) {
  -        if (name == null) return default_query_props;
  -        return (Properties)query_props_table.get(name);
  +        if (name == null || name.equals("")) return getQueryProperties();
  +		Properties props = (Properties)query_props_table.get(name);
  +		if (props != null) return getQueryProperties();
  +		return (Properties)props.clone();
       }
   
   }
  
  
  
  1.4       +79 -59    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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SQLProcessor.java	1999/11/09 02:30:47	1.3
  +++ SQLProcessor.java	1999/12/02 09:07:46	1.4
  @@ -1,5 +1,4 @@
  -/*-- $Id: SQLProcessor.java,v 1.3 1999/11/09 02:30:47 dirkx Exp $ -- 
  -
  +/*
    ============================================================================
                      The Apache Software License, Version 1.1
    ============================================================================
  @@ -46,12 +45,13 @@
    on  behalf of the Apache Software  Foundation and was  originally created by
    Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache 
    Software Foundation, please see <http://www.apache.org/>.
  - 
    */
  +
   package org.apache.cocoon.processor.sql;
   
   import java.net.URLEncoder;
   import java.sql.*;
  +import java.text.*;
   import java.util.*;
   import javax.servlet.http.HttpServletRequest;
   import org.w3c.dom.*;
  @@ -62,7 +62,7 @@
    * A processor that performs SQL database queries.
    *
    * @author <a href="mailto:balld@webslingerZ.com">Donald Ball</a>
  - * @version $Revision: 1.3 $ $Date: 1999/11/09 02:30:47 $
  + * @version $Revision: 1.4 $ $Date: 1999/12/02 09:07:46 $
    */
   
   public class SQLProcessor extends AbstractActor implements Processor, Status {
  @@ -169,9 +169,15 @@
           String query_attribute = query_props.getProperty("query-attribute");
           String skip_rows_attribute = query_props.getProperty("skip-rows-attribute");
           String max_rows_attribute = query_props.getProperty("max-rows-attribute");
  +        String update_rows_attribute = query_props.getProperty("update-rows-attribute");
           String query = query_props.getProperty("query");
  +        String namespace = query_props.getProperty("namespace");
  +		DateFormat timestamp_format = null;
  +		String timestamp_format_string = query_props.getProperty("timestamp_format");
  +		if (timestamp_format_string != null)
  +			timestamp_format = new SimpleDateFormat(timestamp_format_string);
           try {
  -            if (query.equals("")) {
  +            if (query == null || query.equals("")) {
                   SQLQueryCreator query_creator;
                   if (query_creator_name != null) {
                       if (query_creators.containsKey(query_creator_name)) {
  @@ -193,14 +199,14 @@
                   }
                   query = query_creator.getQuery(conn,query_buffer.toString(),query_element,query_props,parameters);
               }
  -			System.err.println("QUERY IS "+query);
               Statement st = conn.createStatement();
               ResultSet rs;
               Node results_node;
  +            Element results_element = null;
               if (doc_element_name.equals("")) {
                   results_node = document.createDocumentFragment();
               } else {
  -                Element results_element = document.createElement(doc_element_name);
  +                results_element = Utils.createElement(document,namespace,doc_element_name);
                   results_node = results_element;
                   if (!count_attribute.equals("")) {
                       String count_query = getCountQuery(query);
  @@ -218,71 +224,85 @@
                   if (!max_rows_attribute.equals(""))
                       results_element.setAttribute(max_rows_attribute,""+max_rows);
               }
  -            rs = st.executeQuery(query);
  -            ResultSetMetaData md = rs.getMetaData();
  -            Column columns[] = getColumns(md,tag_case);
  -            int id_attribute_column_index = -1;
  -            if (create_id_attribute) {
  -                for (int i=0; i<columns.length; i++) {
  -                    if (columns[i].name.equals(id_attribute_column)) {
  -                        id_attribute_column_index = i;
  +            if (!update_rows_attribute.equals("")) {
  +                int update_rows = st.executeUpdate(query);
  +                if (results_element != null)
  +                    results_element.setAttribute(update_rows_attribute,""+update_rows);
  +            } else {
  +                rs = st.executeQuery(query);
  +                ResultSetMetaData md = rs.getMetaData();
  +                Column columns[] = getColumns(md,tag_case);
  +                int id_attribute_column_index = -1;
  +                if (create_id_attribute) {
  +                    for (int i=0; i<columns.length; i++) {
  +                        if (columns[i].name.equals(id_attribute_column)) {
  +                            id_attribute_column_index = i;
  +                        }
                       }
                   }
  -            }
  -
  -            int null_mode = OMIT_NULLS;
  -            if (null_indicator.equals("y")) {
  -                null_mode = ATTRIBUTE_NULLS;
  -            } else if (null_indicator.equals("yes")) {
  -                null_mode = ATTRIBUTE_NULLS;
  -            }
  -
  -            Element column_element;
  -            Node row_node = results_node;
  -            Element row_element = null;
  -            String value;
  -            int count = 0;
  -            if (skip_rows > 0) {
  -                while (rs.next()) {
  -                    count++;
  -                    if (count == skip_rows) break;
  +                int null_mode = OMIT_NULLS;
  +                if (null_indicator.equals("y")) {
  +                    null_mode = ATTRIBUTE_NULLS;
  +                } else if (null_indicator.equals("yes")) {
  +                    null_mode = ATTRIBUTE_NULLS;
                   }
  -            }
   
  -            while (rs.next()) {
  -                if (create_row_elements) {
  -                    row_element = document.createElement(row_element_name);
  -                    row_node = row_element;
  -                    if (create_id_attribute && id_attribute_column_index == -1)
{
  -                        row_element.setAttribute(id_attribute,"" + count);
  +                Element column_element;
  +                Node row_node = results_node;
  +                Element row_element = null;
  +                String value;
  +                int count = 0;
  +                if (skip_rows > 0) {
  +                    while (rs.next()) {
  +                        count++;
  +                        if (count == skip_rows) break;
                       }
                   }
   
  -                for (int i=0; i<columns.length; i++) {
  -                    value = rs.getString(i+1);
  -                    if (create_row_elements && create_id_attribute && id_attribute_column_index
== i) {
  -                        row_element.setAttribute(id_attribute,value);
  -                        continue;
  +                while (rs.next()) {
  +                    if (create_row_elements) {
  +                        row_element = Utils.createElement(document,namespace,row_element_name);
  +                        row_node = row_element;
  +                        if (create_id_attribute && id_attribute_column_index ==
-1) {
  +                            row_element.setAttribute(id_attribute,"" + count);
  +                        }
                       }
  -                    if (value == null && null_mode == OMIT_NULLS) continue;
  -                    column_element = document.createElement(columns[i].name);
  -                    if (value == null && null_mode == ATTRIBUTE_NULLS) {
  -                        column_element.setAttribute("NULL","YES");
  -                        column_element.appendChild(document.createTextNode(""));
  -                    } else {
  -                        column_element.appendChild(document.createTextNode(value));
  +
  +                    for (int i=0; i<columns.length; i++) {
  +						switch(columns[i].type) {
  +							case Types.TIMESTAMP:
  +								if (timestamp_format != null)
  +									value = timestamp_format.format(rs.getDate(i+1));
  +								else
  +                        			value = rs.getString(i+1);
  +								break;
  +							default:
  +								value = rs.getString(i+1);
  +						}
  +                        if (create_row_elements && create_id_attribute &&
id_attribute_column_index == i) {
  +                            row_element.setAttribute(id_attribute,value);
  +                            continue;
  +                        }
  +                        if (value == null && null_mode == OMIT_NULLS) continue;
  +                        column_element = Utils.createElement(document,namespace,columns[i].name);
  +                        if (value == null && null_mode == ATTRIBUTE_NULLS) {
  +                            column_element.setAttribute("NULL","YES");
  +                            column_element.appendChild(document.createTextNode(""));
  +                        } else {
  +                            column_element.appendChild(document.createTextNode(value));
  +                        }
  +                        row_node.appendChild(column_element);
                       }
  -                    row_node.appendChild(column_element);
  +                    if (create_row_elements) results_node.appendChild(row_node);
  +                    if (count-skip_rows == max_rows-1) break;
  +                    count++;
                   }
  -                if (create_row_elements) results_node.appendChild(row_node);
  -                if (count-skip_rows == max_rows-1) break;
  -                count++;
  +                rs.close();
               }
  -
  -            rs.close(); st.close(); conn.commit();
  +            st.close(); conn.commit();
               query_element.getParentNode().replaceChild(results_node,query_element);
           } catch (SQLException e) {
  -            Element error_element = Utils.createErrorElement(document,query_props,e);
  +            Element error_element = Utils.createErrorElement(document,namespace,query_props,e);
               query_element.getParentNode().replaceChild(error_element,query_element);
               conn.rollback();
           } finally {
  
  
  
  1.4       +3 -4      xml-cocoon/src/org/apache/cocoon/processor/sql/SQLQueryCreator.java
  
  Index: SQLQueryCreator.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/processor/sql/SQLQueryCreator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- SQLQueryCreator.java	1999/11/09 02:30:48	1.3
  +++ SQLQueryCreator.java	1999/12/02 09:07:46	1.4
  @@ -1,5 +1,4 @@
  -/*-- $Id: SQLQueryCreator.java,v 1.3 1999/11/09 02:30:48 dirkx Exp $ -- 
  -
  +/*
    ============================================================================
                      The Apache Software License, Version 1.1
    ============================================================================
  @@ -46,8 +45,8 @@
    on  behalf of the Apache Software  Foundation and was  originally created by
    Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache 
    Software Foundation, please see <http://www.apache.org/>.
  - 
    */
  +
   package org.apache.cocoon.processor.sql;
   
   import java.sql.*;
  @@ -63,7 +62,7 @@
    * object keyed from "request".
    *
    * @author <a href="mailto:balld@webslingerZ.com">Donald Ball</a>
  - * @version $Revision: 1.3 $ $Date: 1999/11/09 02:30:48 $
  + * @version $Revision: 1.4 $ $Date: 1999/12/02 09:07:46 $
    */
   
   public class SQLQueryCreator {
  
  
  
  1.4       +72 -9     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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Utils.java	1999/11/09 02:30:48	1.3
  +++ Utils.java	1999/12/02 09:07:46	1.4
  @@ -1,5 +1,4 @@
  -/*-- $Id: Utils.java,v 1.3 1999/11/09 02:30:48 dirkx Exp $ -- 
  -
  +/*
    ============================================================================
                      The Apache Software License, Version 1.1
    ============================================================================
  @@ -46,21 +45,21 @@
    on  behalf of the Apache Software  Foundation and was  originally created by
    Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache 
    Software Foundation, please see <http://www.apache.org/>.
  - 
    */
  +
   package org.apache.cocoon.processor.sql;
   
  -import java.io.PrintWriter;
  -import java.io.StringWriter;
  +import java.io.*;
   import java.text.StringCharacterIterator;
  -import java.util.Properties;
  +import java.util.*;
   import org.w3c.dom.*;
  +import javax.servlet.http.*;
   
   /**
    * Utility methods for this processor.
    *
    * @author <a href="mailto:balld@webslingerZ.com">Donald Ball</a>
  - * @version $Revision: 1.3 $ $Date: 1999/11/09 02:30:48 $
  + * @version $Revision: 1.4 $ $Date: 1999/12/02 09:07:46 $
    */
   
   public class Utils {
  @@ -72,7 +71,7 @@
       public static final String ERROR_STACKTRACE_ELEMENT = "error-stacktrace-element";
       public static final String ERROR_MESSAGE_TEXT = "error-message-text";
   
  -    public static Element createErrorElement(Document document, Properties props, Exception
e) {
  +    public static Element createErrorElement(Document document, String namespace, Properties
props, Exception e) {
           Element element = document.createElement(props.getProperty(ERROR_ELEMENT));
           String message_attribute = props.getProperty(ERROR_MESSAGE_ATTRIBUTE);
           String message_element = props.getProperty(ERROR_MESSAGE_ELEMENT);
  @@ -88,7 +87,7 @@
           String stacktrace_attribute = props.getProperty(ERROR_STACKTRACE_ATTRIBUTE);
           String stacktrace_element = props.getProperty(ERROR_STACKTRACE_ELEMENT);
           String stacktrace = null;
  -        if (!stacktrace_attribute.equals("") && !stacktrace_element.equals(""))
{
  +        if (!stacktrace_attribute.equals("") || !stacktrace_element.equals("")) {
               StringWriter sw = new StringWriter();
               PrintWriter pw = new PrintWriter(sw);
               e.printStackTrace(pw);
  @@ -111,5 +110,69 @@
                   if (c == target) sb.append(replacement); else sb.append(c);
           return sb.toString();
       }
  +
  +	public static Element createElement(Document document, String namespace, String name)
{
  +		if (namespace == null)
  +			return document.createElement(name);
  +		return document.createElement(namespace+':'+name);
  +	}
  +
  +	public static Hashtable getValues(HttpServletRequest req) {
  +		Hashtable table = new Hashtable();
  +		Enumeration e = req.getParameterNames();
  +		while (e.hasMoreElements()) {
  +			String name = (String)e.nextElement();
  +			String values[] = req.getParameterValues(name);
  +			if (values.length == 1) table.put(name,values[0]);
  +			else table.put(name,values);
  +		}
  +		return table;
  +	}
  +
  +	public static Properties getAttributes(Element element, HttpServletRequest req, Properties
master) {
  +		Properties props;
  +		if (master == null) props = new Properties();
  +		else props = new Properties(master);
  +		NamedNodeMap attributes = element.getAttributes();
  +		for (int i=0; i<attributes.getLength(); i++) {
  +			Node attribute = attributes.item(i);
  +			props.put(attribute.getNodeName(),attribute.getNodeValue());
  +		}
  +		if (req != null) {
  +			Enumeration e = req.getParameterNames();
  +			while (e.hasMoreElements()) {
  +				String name = (String)e.nextElement();
  +				props.put(name,req.getParameter(name));
  +			}
  +		}
  +		return props;
  +	}
  +
  +	public static Vector split(String source, char seperator) {
  +		Vector results = new Vector();
  +		if (source == null) return results;
  +		StringBuffer sb = new StringBuffer();
  +		StringCharacterIterator iter = new StringCharacterIterator(source);
  +		char c;
  +        for (c = iter.first(); c != iter.DONE; c = iter.next())
  +			if (c == seperator) { 
  +				results.addElement(sb.toString());
  +				sb = new StringBuffer();
  +			} else sb.append(c);
  +		if (c != seperator) results.addElement(sb.toString());
  +		return results;
  +	}
  +
  +	public static String join(Vector vector, char joiner) {
  +		Enumeration e = vector.elements();
  +		StringBuffer sb = new StringBuffer();
  +		if (e.hasMoreElements()) sb.append(e.nextElement());
  +		while (e.hasMoreElements()) {
  +			sb.append(joiner);
  +			sb.append(e.nextElement());
  +		}
  +		return sb.toString();
  +	}
  +
   
   }
  
  
  

Mime
View raw message