Author: vgritsenko
Date: Mon May  2 13:54:58 2005
New Revision: 165684

URL: http://svn.apache.org/viewcvs?rev=165684&view=rev
Log:
Use start/endTextRecording instead of start/endSerializedXMLEncoding: 
SQLTransformer
needs text only, not XML.
Remove xml-encoding configuration parameter: no char to byte conversion taking 
place.

Modified:
    
cocoon/blocks/unsupported/databases/trunk/java/org/apache/cocoon/transformation/SQLTransformer.java
    cocoon/trunk/status.xml

Modified: 
cocoon/blocks/unsupported/databases/trunk/java/org/apache/cocoon/transformation/SQLTransformer.java
URL: 
http://svn.apache.org/viewcvs/cocoon/blocks/unsupported/databases/trunk/java/org/apache/cocoon/transformation/SQLTransformer.java?rev=165684&r1=165683&r2=165684&view=diff
==============================================================================
--- 
cocoon/blocks/unsupported/databases/trunk/java/org/apache/cocoon/transformation/SQLTransformer.java
 (original)
+++ 
cocoon/blocks/unsupported/databases/trunk/java/org/apache/cocoon/transformation/SQLTransformer.java
 Mon May  2 13:54:58 2005
@@ -31,12 +31,9 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
-import java.util.Properties;
 import java.util.TreeMap;
 import java.util.Vector;
 
-import javax.xml.transform.OutputKeys;
-
 import org.apache.avalon.excalibur.datasource.DataSourceComponent;
 import org.apache.avalon.framework.activity.Disposable;
 import org.apache.avalon.framework.configuration.Configurable;
@@ -63,21 +60,17 @@
 import org.xml.sax.helpers.AttributesImpl;
 
 /**
+ * Executes SQL queries from the incoming SAX stream and outputs their results.
  *
- * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Donald Ball</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Sven Beauprez</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">Alfio Saglimbeni</a>
  * @version $Id$
  */
 public class SQLTransformer extends AbstractSAXTransformer
                             implements Disposable, Configurable {
 
-    /** The SQL namespace **/
+    /** The SQL transformer namespace */
     public static final String NAMESPACE = "http://apache.org/cocoon/SQL/2.0";;
 
-    /** The SQL namespace element names **/
+    // The SQL trasformer namespace element names
     public static final String MAGIC_EXECUTE_QUERY = "execute-query";
     public static final String MAGIC_CONNECTION = "use-connection";
     public static final String MAGIC_DBURL = "dburl";
@@ -112,7 +105,7 @@
     public static final String MAGIC_UPDATE_ATTRIBUTE = "isupdate";
     public static final String CLOB_ENCODING = "clob-encoding";
 
-    /** The states we are allowed to be in **/
+    // The states we are allowed to be in
     protected static final int STATE_OUTSIDE = 0;
     protected static final int STATE_INSIDE_EXECUTE_QUERY_ELEMENT = 1;
     protected static final int STATE_INSIDE_VALUE_ELEMENT = 2;
@@ -128,13 +121,13 @@
     //
 
     /** Is the old-driver turned on? (default is off) */
-    protected boolean oldDriver = false;
+    protected boolean oldDriver;
 
     /** How many connection attempts to do? (default is 5 times) */
-    protected int connectAttempts = 5;
+    protected int connectAttempts;
 
     /** How long wait between connection attempts? (default is 5000 ms) */
-    protected int connectWaittime = 5;
+    protected int connectWaittime;
 
     //
     // State
@@ -161,9 +154,6 @@
     /** The database selector */
     protected ServiceSelector dbSelector;
 
-    /** The format for serializing xml */
-    protected Properties format;
-
     protected XMLSerializer compiler;
     protected XMLDeserializer interpreter;
     protected SAXParser parser;
@@ -171,9 +161,6 @@
     /** Encoding we use for CLOB field */
     protected String clobEncoding;
 
-    /** The default encoding for xml */
-    protected String xmlDefaultEncoding;
-
     /** The connection used by all top level queries */
     protected Connection conn;
 
@@ -181,9 +168,6 @@
      * Constructor
      */
     public SQLTransformer() {
-        this.format = new Properties();
-        this.format.put(OutputKeys.METHOD, "text");
-        this.format.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
         super.defaultNamespaceURI = NAMESPACE;
     }
 
@@ -250,8 +234,6 @@
 
         this.connectAttempts = 
conf.getChild("connect-attempts").getValueAsInteger(5);
         this.connectWaittime = 
conf.getChild("connect-waittime").getValueAsInteger(5000);
-
-        this.xmlDefaultEncoding = 
conf.getChild("xml-encoding").getValue("ISO-8859-1");
     }
 
     /**
@@ -262,9 +244,6 @@
     throws ProcessingException, SAXException, IOException {
         super.setup(resolver, objectModel, source, parameters);
 
-        // Set encoding
-        this.format.put(OutputKeys.ENCODING, 
parameters.getParameter("xml-encoding", this.xmlDefaultEncoding));
-
         // Setup instance variables
         this.current_query_index = -1;
         this.current_state = SQLTransformer.STATE_OUTSIDE;
@@ -292,7 +271,7 @@
     protected void executeQuery(int index)
     throws SAXException {
         if (getLogger().isDebugEnabled()) {
-            getLogger().debug("SQLTransformer executing query nr " + index);
+            getLogger().debug("Executing query nr " + index);
         }
 
         this.outUri = 
getCurrentQuery().properties.getParameter(SQLTransformer.MAGIC_NS_URI_ELEMENT, 
NAMESPACE);
@@ -362,7 +341,7 @@
             }
 
         } catch (SQLException e) {
-            getLogger().debug("SQLTransformer.executeQuery()", e);
+            getLogger().debug("Exception in executeQuery()", e);
             throw new SAXException(e);
         } finally {
             query.close();
@@ -418,7 +397,7 @@
     throws SAXException {
         switch (current_state) {
             case SQLTransformer.STATE_INSIDE_EXECUTE_QUERY_ELEMENT:
-                startSerializedXMLRecording(format);
+                startTextRecording();
                 Query q = getCurrentQuery();
                 current_state = SQLTransformer.STATE_INSIDE_QUERY_ELEMENT;
 
@@ -447,7 +426,7 @@
     throws ProcessingException, SAXException {
         switch (current_state) {
             case SQLTransformer.STATE_INSIDE_QUERY_ELEMENT:
-                final String value = endSerializedXMLRecording();
+                final String value = endTextRecording();
                 if (value.length() > 0) {
                     getCurrentQuery().addQueryPart(value);
                     if (getLogger().isDebugEnabled()) {
@@ -507,7 +486,7 @@
                     level = Integer.parseInt(attributes.getValue(NAMESPACE,
                                                                  
SQLTransformer.MAGIC_ANCESTOR_VALUE_LEVEL_ATTRIBUTE));
                 } catch (Exception e) {
-                    getLogger().debug("SQLTransformer", e);
+                    getLogger().debug("Exception in 
startAncestorValueElement", e);
                     throwIllegalStateException("Ancestor value elements must 
have a " +
                                                
SQLTransformer.MAGIC_ANCESTOR_VALUE_LEVEL_ATTRIBUTE + " attribute");
                 }
@@ -522,7 +501,7 @@
                     getLogger().debug("ANCESTOR VALUE " + level + " " + name);
                 }
 
-                final String value = this.endSerializedXMLRecording();
+                final String value = endTextRecording();
                 if (value.length() > 0) {
                     getCurrentQuery().addQueryPart(value);
                     if (getLogger().isDebugEnabled()) {
@@ -530,7 +509,7 @@
                     }
                 }
                 getCurrentQuery().addQueryPart(av);
-                startSerializedXMLRecording(format);
+                startTextRecording();
 
                 current_state = 
SQLTransformer.STATE_INSIDE_ANCESTOR_VALUE_ELEMENT;
                 break;
@@ -560,7 +539,7 @@
                     getLogger().debug("SUBSTITUTE VALUE " + substitute);
                 }
 
-                final String value = endSerializedXMLRecording();
+                final String value = endTextRecording();
                 if (value.length() > 0) {
                     getCurrentQuery().addQueryPart(value);
                     if (getLogger().isDebugEnabled()) {
@@ -568,7 +547,7 @@
                     }
                 }
                 getCurrentQuery().addQueryPart(substitute);
-                startSerializedXMLRecording(format);
+                startTextRecording();
 
                 current_state = 
SQLTransformer.STATE_INSIDE_SUBSTITUTE_VALUE_ELEMENT;
                 break;
@@ -586,7 +565,7 @@
     throws ProcessingException, SAXException {
         switch (current_state) {
             case SQLTransformer.STATE_INSIDE_QUERY_ELEMENT:
-                final String value = endSerializedXMLRecording();
+                final String value = endTextRecording();
                 if (value.length() > 0) {
                     getCurrentQuery().addQueryPart(value);
                     if (getLogger().isDebugEnabled()) {
@@ -616,7 +595,7 @@
                         getLogger().debug("QUERY IS \"" + value + "\"");
                     }
                 }
-                startSerializedXMLRecording(format);
+                startTextRecording();
                 current_state = SQLTransformer.STATE_INSIDE_QUERY_ELEMENT;
                 break;
 
@@ -720,10 +699,6 @@
     public void startTransformingElement(String uri, String name, String raw,
                                          Attributes attributes)
     throws ProcessingException, SAXException {
-        if (getLogger().isDebugEnabled()) {
-            getLogger().debug("RECEIVED START ELEMENT " + name);
-        }
-
         if (name.equals(SQLTransformer.MAGIC_EXECUTE_QUERY)) {
             startExecuteQueryElement();
         } else if (name.equals(SQLTransformer.MAGIC_QUERY)) {
@@ -749,10 +724,6 @@
     public void endTransformingElement(String uri, String name,
                                        String raw)
     throws ProcessingException, IOException, SAXException {
-        if (getLogger().isDebugEnabled()) {
-            getLogger().debug("RECEIVED END ELEMENT " + name + "(" + uri + 
")");
-        }
-
         if (name.equals(SQLTransformer.MAGIC_EXECUTE_QUERY)) {
             endExecuteQueryElement();
         } else if (name.equals(SQLTransformer.MAGIC_QUERY)) {
@@ -1264,6 +1235,7 @@
                         if (transformer.interpreter == null) {
                             transformer.interpreter = (XMLDeserializer) 
manager.lookup(XMLDeserializer.ROLE);
                         }
+
                         transformer.parser.parse(new InputSource(new 
StringReader("<root>" + stripped + "</root>")),
                                                  transformer.compiler);
 
@@ -1296,12 +1268,12 @@
                 for (int i = 1; i <= md.getColumnCount(); i++) {
                     String columnName = getColumnName(md.getColumnName(i));
                     transformer.start(columnName, attr);
-                    this.serializeData(manager, getColumnValue(i));
+                    serializeData(manager, getColumnValue(i));
                     transformer.end(columnName);
                 }
             } else if (isupdate && !isstoredprocedure) {
                 transformer.start("returncode", attr);
-                this.serializeData(manager, String.valueOf(rv));
+                serializeData(manager, String.valueOf(rv));
                 transformer.end("returncode");
                 rv = -1; // we only want the return code shown once.
             }
@@ -1321,11 +1293,11 @@
                     Integer counter = (Integer) itOutKeys.next();
                     try {
                         if (cst == null) {
-                            getTheLogger().debug("SQLTransformer: cst is 
null");
+                            getTheLogger().debug("cst is null");
                         }
 
                         if (counter == null) {
-                            getTheLogger().debug("SQLTransformer: counter is 
null");
+                            getTheLogger().debug("counter is null");
                         }
 
                         Object obj = cst.getObject(counter.intValue());

Modified: cocoon/trunk/status.xml
URL: 
http://svn.apache.org/viewcvs/cocoon/trunk/status.xml?rev=165684&r1=165683&r2=165684&view=diff
==============================================================================
--- cocoon/trunk/status.xml (original)
+++ cocoon/trunk/status.xml Mon May  2 13:54:58 2005
@@ -430,6 +430,10 @@
    </action>
   </release>
   <release version="2.1.8" date="TBD">
+    <action dev="VG" type="remove">
+      Databases: Removed xml-encoding parameter from the SQLTransformer 
configuration.
+      The latest SQLTransformer has no byte to character conversions.
+    </action>
     <action dev="AG" type="update">
       Updated ant to 1.6.3.
     </action>


Reply via email to