cziegeler 01/11/28 03:45:39
Modified: . changes.xml
src/org/apache/cocoon/transformation SQLTransformer.java
Log:
Applied patch to SQLTransformer from Peter Seiderer [[EMAIL PROTECTED]]
Revision Changes Path
1.52 +5 -1 xml-cocoon2/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/xml-cocoon2/changes.xml,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -r1.51 -r1.52
--- changes.xml 2001/11/23 09:11:51 1.51
+++ changes.xml 2001/11/28 11:45:38 1.52
@@ -4,7 +4,7 @@
<!--
History of Cocoon changes
- $Id: changes.xml,v 1.51 2001/11/23 09:11:51 cziegeler Exp $
+ $Id: changes.xml,v 1.52 2001/11/28 11:45:38 cziegeler Exp $
-->
<changes title="History of Changes">
@@ -27,6 +27,10 @@
</devs>
<release version="2.1-dev" date="@date@">
+ <action dev="CZ" type="update">
+ Applied patch adding advanced error handling to SQLTransformer plus
escape-string element
+ from Peter Seiderer [[EMAIL PROTECTED]]
+ </action>
<action dev="CZ" type="update">
Restructured build system. A new ant task (SitemapTool) adds entries
of optional components to the sitemap. Warnings for not available
1.23 +82 -22
xml-cocoon2/src/org/apache/cocoon/transformation/SQLTransformer.java
Index: SQLTransformer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/transformation/SQLTransformer.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- SQLTransformer.java 2001/10/25 20:24:45 1.22
+++ SQLTransformer.java 2001/11/28 11:45:39 1.23
@@ -35,7 +35,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
* (PWR Organisation & Entwicklung)
* @author <a href="mailto:[EMAIL PROTECTED]">Sven Beauprez</a>
- * @version CVS $Revision: 1.22 $ $Date: 2001/10/25 20:24:45 $ $Author: bloritsch $
+ * @version CVS $Revision: 1.23 $ $Date: 2001/11/28 11:45:39 $ $Author: cziegeler $
*/
public class SQLTransformer extends AbstractTransformer implements Composable,
Recyclable, Disposable, Configurable {
@@ -62,6 +62,8 @@
public static final String MAGIC_OUT_PARAMETER_NAME_ATTRIBUTE = "name";
public static final String MAGIC_OUT_PARAMETER_NR_ATTRIBUTE = "nr";
public static final String MAGIC_OUT_PARAMETER_TYPE_ATTRIBUTE = "type";
+ public static final String MAGIC_ESCAPE_STRING = "escape-string";
+ public static final String MAGIC_ERROR = "error";
public static final String MAGIC_NS_URI_ELEMENT = "namespace-uri";
public static final String MAGIC_NS_PREFIX_ELEMENT = "namespace-prefix";
@@ -84,6 +86,7 @@
public static final int STATE_INSIDE_SUBSTITUTE_VALUE_ELEMENT = 5;
public static final int STATE_INSIDE_IN_PARAMETER_ELEMENT = 6;
public static final int STATE_INSIDE_OUT_PARAMETER_ELEMENT = 7;
+ public static final int STATE_INSIDE_ESCAPE_STRING = 8;
/** Default parameters that might apply to all queries **/
protected Properties default_properties;
@@ -262,29 +265,46 @@
getLogger().debug( "SQLTransformer executing query nr " + index );
AttributesImpl attr = new AttributesImpl();
Query query = (Query) queries.elementAt( index );
+ boolean query_failure = false;
try {
- query.execute();
-
- if ( showNrOfRows != null && showNrOfRows.equalsIgnoreCase( "true" ) ) {
- this.attribute( attr, query.nr_of_rows, String.valueOf(
query.getNrOfRows() ) );
- }
- String name = query.getName();
- if ( name != null ) {
- this.attribute( attr, query.name_attribute, name );
+ try {
+ query.execute();
+ } catch ( SQLException e ) {
+ getLogger().debug( "SQLTransformer:.executeQuery() query.execute
failed ", e );
+ AttributesImpl my_attr = new AttributesImpl();
+ this.start( query.rowset_name, my_attr );
+ this.start( MAGIC_ERROR, my_attr);
+ this.data( e.getMessage());
+ this.end( MAGIC_ERROR );
+ this.end( query.rowset_name );
+ query_failure = true;
}
- this.start( query.rowset_name, attr );
- attr = new AttributesImpl();
- if ( !query.isStoredProcedure() ) {
- while ( query.next() ) {
- this.start( query.row_name, attr );
- query.serializeRow();
- if ( index + 1 < queries.size() ) {
- executeQuery( index + 1 );
+ if ( !query_failure ) {
+
+ if ( showNrOfRows != null && showNrOfRows.equalsIgnoreCase( "true"
) ) {
+ attr.addAttribute( my_uri, query.nr_of_rows, query.nr_of_rows,
"CDATA",
+ String.valueOf( query.getNrOfRows() ) );
+ }
+ String name = query.getName();
+ if ( name != null ) {
+ attr.addAttribute( my_uri, query.name_attribute,
query.name_attribute, "CDATA",
+ name );
+ }
+ this.start( query.rowset_name, attr );
+ attr = new AttributesImpl();
+ if ( !query.isStoredProcedure() ) {
+ while ( query.next() ) {
+ this.start( query.row_name, attr );
+ query.serializeRow();
+ if ( index + 1 < queries.size() ) {
+ executeQuery( index + 1 );
+ }
+ this.end( query.row_name );
}
- this.end( query.row_name );
+ } else {
+ query.serializeStoredProcedure();
}
- } else {
- query.serializeStoredProcedure();
+ this.end( query.rowset_name );
}
} catch ( SQLException e ) {
getLogger().debug( "SQLTransformer.executeQuery()", e );
@@ -296,7 +316,6 @@
getLogger().warn( "SQLTransformer: Could not close JDBC
connection", e );
}
}
- this.end( query.rowset_name );
if ( !"".equals( outPrefix ) && !"".equals( outUri ) ) {
this.contentHandler.endPrefixMapping( outPrefix );
}
@@ -481,6 +500,42 @@
current_state = SQLTransformer.STATE_INSIDE_QUERY_ELEMENT;
}
+ protected void startEscapeStringElement( Attributes attributes ) {
+ switch ( current_state ) {
+ case SQLTransformer.STATE_INSIDE_QUERY_ELEMENT:
+ if ( current_value.length() > 0 ) {
+ getCurrentQuery().addQueryPart( current_value.toString() );
+ getLogger().debug( "QUERY IS \"" +
+ current_value.toString() + "\"" );
+ current_value.setLength( 0 );
+ }
+
+ current_state = SQLTransformer.STATE_INSIDE_ESCAPE_STRING;
+ break;
+ default:
+ throwIllegalStateException( "Not expecting a start escape-string
element" );
+ }
+ }
+
+ protected void endEscapeStringElement() {
+ switch ( current_state) {
+ case SQLTransformer.STATE_INSIDE_ESCAPE_STRING:
+ if ( current_value.length() > 0 ) {
+ String escape = current_value.toString();
+ escape = replaceCharWithString( escape, '\'', "''" );
+ escape = replaceCharWithString( escape, '\\', "\\\\" );
+ getCurrentQuery().addQueryPart( escape );
+ getLogger().debug( "QUERY IS \"" +
+ current_value.toString() + "\"" );
+ current_value.setLength( 0 );
+ }
+ current_state = SQLTransformer.STATE_INSIDE_QUERY_ELEMENT;
+ break;
+ default:
+ throwIllegalStateException( "Not expecting a end escape-string
element" );
+ }
+ }
+
protected void startInParameterElement( Attributes attributes ) {
switch ( current_state ) {
case SQLTransformer.STATE_INSIDE_EXECUTE_QUERY_ELEMENT:
@@ -615,6 +670,8 @@
startInParameterElement( attributes );
} else if ( name.equals( SQLTransformer.MAGIC_OUT_PARAMETER ) ) {
startOutParameterElement( attributes );
+ } else if ( name.equals( SQLTransformer.MAGIC_ESCAPE_STRING ) ) {
+ startEscapeStringElement( attributes );
} else {
startValueElement( name );
}
@@ -642,6 +699,8 @@
endOutParameterElement();
} else if ( name.equals( SQLTransformer.MAGIC_VALUE ) || current_state ==
SQLTransformer.STATE_INSIDE_VALUE_ELEMENT ) {
endValueElement();
+ } else if ( name.equals( SQLTransformer.MAGIC_ESCAPE_STRING ) ) {
+ endEscapeStringElement();
} else {
super.endElement( uri, name, raw );
}
@@ -650,7 +709,8 @@
public void characters( char ary[], int start,
int length ) throws SAXException {
if ( current_state != SQLTransformer.STATE_INSIDE_VALUE_ELEMENT &&
- current_state != SQLTransformer.STATE_INSIDE_QUERY_ELEMENT ) {
+ current_state != SQLTransformer.STATE_INSIDE_QUERY_ELEMENT &&
+ current_state != SQLTransformer.STATE_INSIDE_ESCAPE_STRING ) {
super.characters( ary, start, length );
}
getLogger().debug( "RECEIVED CHARACTERS: " +
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]