|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.cocoon.pipeline.component.AbstractPipelineComponent org.apache.cocoon.sax.AbstractSAXPipelineComponent org.apache.cocoon.sax.AbstractSAXProducer org.apache.cocoon.sax.AbstractSAXTransformer org.apache.cocoon.sax.component.SQLTransformer
public class SQLTransformer
The SQLTransformer
can be plugged into a pipeline to transform
SAX events into updated or queries and responses to/from a SQL interface.
It is declared and configured as follows:
<map:transformers default="..."> <map:transformer name="sql" src="org.apache.cocoon.transformation.SQLTransformer"> <old-driver>false</old-driver> <connection-attempts>5</connection-attempts> <connection-waittime>5000</connection-waittime> </map:transformer> </map:transformers>
It can be used in the sitemap pipeline as follows:
<map:transform type="sql">
<map:parameter name="own-connection" value="..."/>
<map:parameter name="use-connection" value="..."/>
<map:parameter name="dburl" value="..."/>
<map:parameter name="username" value="..."/>
<map:parameter name="password" value="..."/>
<map:parameter name="show-nr-or-rows" value="false"/>
<map:parameter name="doc-element" value="rowset"/>
<map:parameter name="row-element" value="row"/>
<map:parameter name="namespace-uri" value="http://apache.org/cocoon/SQL/2.0"/>
<map:parameter name="namespace-prefix" value="sql"/>
<map:parameter name="clob-encoding" value=""/>
</map:transform>
The following DTD is valid:
<!ENTITY % param "(own-connection?,(use-connection|(dburl,username,password))?,show-nr-or-rows?,doc-element?,row-element?,namespace-uri?,namespace-prefix?,clob-encoding?)">
<!ELEMENT execute-query (query,(in-parameter|out-parameter)*,execute-query?, %param;)>
<!ELEMENT own-connection (#PCDATA)>
<!ELEMENT use-connection (#PCDATA)>
<!ELEMENT query (#PCDATA | substitute-value | ancestor-value | escape-string)*>
<!ATTLIST query name CDATA #IMPLIED isstoredprocedure (true|false) "false" isupdate (true|false) "false">
<!ELEMENT substitute-value EMPTY>
<!ATTLIST substitute-value name CDATA #REQUIRED>
<!ELEMENT ancestor-value EMPTY>
<!ATTLIST ancestor-value name CDATA #REQUIRED level CDATA #REQUIRED>
<!ELEMENT in-parameter EMPTY>
<!ATTLIST in-parameter nr CDATA #REQUIRED type CDATA #REQUIRED>
<!ELEMENT out-parameter EMPTY>
<!ATTLIST out-parameter nr CDATA #REQUIRED name CDATA #REQUIRED type CDATA #REQUIRED>
<!ELEMENT escape-string (#PCDATA)>
Each query can override default transformer parameters. Nested queries do not inherit parent query parameters, but only transformer parameters. Each query can have connection to different database, directly or using the connection pool. If database connection parameters are the same as for any of the ancestor queries, nested query will re-use ancestor query connection.
Connection sharing between queries can be disabled, globally or on per-query
basis, using own-connection
parameter.
By default, CLOBs are read from the database using character stream, so that
character decoding is performed by the database. Using
clob-encoding
parameter, this behavior can be overrided, so that
data is read as byte stream and decoded using specified character encoding.
TODO: Support inserting of the XML data into the database without need to escape it. Can be implemented by introducing new <sql:xml/> tag to indicate that startSerializedXMLRecording(...) should be used.
Constructor Summary | |
---|---|
SQLTransformer()
FIXME: Constructor |
Method Summary | |
---|---|
protected void |
data(String data)
Helper method for generating SAX events |
protected void |
end(String uri,
String prefix,
String name)
Helper method for generating SAX events |
protected void |
endAncestorValueElement()
</ancestor-value> |
void |
endElement(String uri,
String name,
String raw)
Process the SAX event. |
protected void |
endEscapeStringElement()
</escape-string> |
protected void |
endExecuteQueryElement()
</execute-query> |
protected void |
endInParameterElement()
</in-parameter> |
protected void |
endOutParameterElement()
</out-parameter> |
protected void |
endQueryElement()
</query> |
protected void |
endSubstituteValueElement()
</substitute-value> |
void |
endTransformingElement(String uri,
String name,
String raw)
ContentHandler method |
protected void |
endValueElement()
</*> |
protected String |
nsQualify(String name,
String prefix)
Qualifies an element name by giving it a prefix. |
void |
recycle()
Recycle this component |
void |
setConfiguration(Map<String,? extends Object> configuration)
Configure transformer. |
protected void |
start(String uri,
String prefix,
String name,
Attributes attr)
Helper method for generating SAX events |
protected void |
startAncestorValueElement(Attributes attributes)
<ancestor-value> |
void |
startElement(String uri,
String name,
String raw,
Attributes attr)
Process the SAX event. |
protected void |
startEscapeStringElement(Attributes attributes)
<escape-string> |
protected void |
startExecuteQueryElement()
<execute-query> |
protected void |
startInParameterElement(Attributes attributes)
<in-parameter> |
protected void |
startOutParameterElement(Attributes attributes)
<out-parameter> |
protected void |
startQueryElement(Attributes attributes)
<query> |
protected void |
startSubstituteValueElement(Attributes attributes)
<substitute-value> |
void |
startTransformingElement(String uri,
String name,
String raw,
Attributes attributes)
ContentHandler method |
protected void |
startValueElement(String name)
<*> |
protected static void |
throwIllegalStateException(String message)
|
Methods inherited from class org.apache.cocoon.sax.AbstractSAXTransformer |
---|
characters, comment, endCDATA, endDocument, endDTD, endEntity, endPrefixMapping, endSAXRecording, endTextRecording, findPrefixMapping, ignorableWhitespace, processingInstruction, removeRecorder, sendEndPrefixMapping, sendStartPrefixMapping, setDocumentLocator, setRecorder, skippedEntity, startCDATA, startDocument, startDTD, startEntity, startPrefixMapping, startSAXRecording, startTextRecording |
Methods inherited from class org.apache.cocoon.sax.AbstractSAXProducer |
---|
getSAXConsumer, setConsumer, setSAXConsumer, toString |
Methods inherited from class org.apache.cocoon.pipeline.component.AbstractPipelineComponent |
---|
finish, setup |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.xml.sax.ContentHandler |
---|
characters, endDocument, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping |
Methods inherited from interface org.xml.sax.ext.LexicalHandler |
---|
comment, endCDATA, endDTD, endEntity, startCDATA, startDTD, startEntity |
Methods inherited from interface org.apache.cocoon.pipeline.component.PipelineComponent |
---|
finish, setup |
Field Detail |
---|
public static final String CONNECT_ATTEMPTS
public static final String NAMESPACE
public static final String MAGIC_EXECUTE_QUERY
public static final String MAGIC_CONNECTION
public static final String MAGIC_DBURL
public static final String MAGIC_USERNAME
public static final String MAGIC_PASSWORD
public static final String MAGIC_NR_OF_ROWS
public static final String MAGIC_QUERY
public static final String MAGIC_VALUE
public static final String MAGIC_COLUMN_CASE
public static final String MAGIC_DOC_ELEMENT
public static final String MAGIC_ROW_ELEMENT
public static final String MAGIC_IN_PARAMETER
public static final String MAGIC_IN_PARAMETER_NR_ATTRIBUTE
public static final String MAGIC_IN_PARAMETER_VALUE_ATTRIBUTE
public static final String MAGIC_OUT_PARAMETER
public static final String MAGIC_OUT_PARAMETER_NAME_ATTRIBUTE
public static final String MAGIC_OUT_PARAMETER_NR_ATTRIBUTE
public static final String MAGIC_OUT_PARAMETER_TYPE_ATTRIBUTE
public static final String MAGIC_ESCAPE_STRING
public static final String MAGIC_ERROR
public static final String MAGIC_NS_URI_ELEMENT
public static final String MAGIC_NS_PREFIX_ELEMENT
public static final String MAGIC_ANCESTOR_VALUE
public static final String MAGIC_ANCESTOR_VALUE_LEVEL_ATTRIBUTE
public static final String MAGIC_ANCESTOR_VALUE_NAME_ATTRIBUTE
public static final String MAGIC_SUBSTITUTE_VALUE
public static final String MAGIC_SUBSTITUTE_VALUE_NAME_ATTRIBUTE
public static final String MAGIC_NAME_ATTRIBUTE
public static final String MAGIC_STORED_PROCEDURE_ATTRIBUTE
public static final String MAGIC_UPDATE_ATTRIBUTE
public static final String CLOB_ENCODING
protected static final int STATE_OUTSIDE
protected static final int STATE_INSIDE_EXECUTE_QUERY_ELEMENT
protected static final int STATE_INSIDE_VALUE_ELEMENT
protected static final int STATE_INSIDE_QUERY_ELEMENT
protected static final int STATE_INSIDE_ANCESTOR_VALUE_ELEMENT
protected static final int STATE_INSIDE_SUBSTITUTE_VALUE_ELEMENT
protected static final int STATE_INSIDE_IN_PARAMETER_ELEMENT
protected static final int STATE_INSIDE_OUT_PARAMETER_ELEMENT
protected static final int STATE_INSIDE_ESCAPE_STRING
protected boolean oldDriver
protected int connectAttempts
protected int connectWaittime
protected org.apache.cocoon.sax.component.SQLTransformer.Query query
protected int state
protected String connName
protected Connection conn
protected SAXParser parser
protected final Stack<String> stack
protected int ignoreEventsCount
protected int ignoreHooksCount
Constructor Detail |
---|
public SQLTransformer()
Method Detail |
---|
public void recycle()
public void setConfiguration(Map<String,? extends Object> configuration)
setConfiguration
in interface PipelineComponent
setConfiguration
in class AbstractPipelineComponent
configuration
- The Map
of configuration parameters.public void startElement(String uri, String name, String raw, Attributes attr) throws SAXException
startTransformingElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
hook is called.
startElement
in interface ContentHandler
startElement
in class AbstractSAXTransformer
SAXException
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
public void endElement(String uri, String name, String raw) throws SAXException
endTransformingElement(java.lang.String, java.lang.String, java.lang.String)
hook is called.
endElement
in interface ContentHandler
endElement
in class AbstractSAXTransformer
SAXException
ContentHandler.endElement(java.lang.String, java.lang.String, java.lang.String)
protected static void throwIllegalStateException(String message)
protected void startExecuteQueryElement()
protected void startValueElement(String name) throws SAXException
SAXException
protected void startQueryElement(Attributes attributes) throws SAXException
SAXException
protected void endQueryElement() throws SAXException
SAXException
protected void endValueElement() throws SAXException
SAXException
protected void endExecuteQueryElement() throws SAXException
SAXException
protected void startAncestorValueElement(Attributes attributes) throws SAXException
SAXException
protected void endAncestorValueElement()
protected void startSubstituteValueElement(Attributes attributes) throws SAXException
SAXException
protected void endSubstituteValueElement()
protected void startEscapeStringElement(Attributes attributes) throws SAXException
SAXException
protected void endEscapeStringElement() throws SAXException
SAXException
protected void startInParameterElement(Attributes attributes)
protected void endInParameterElement()
protected void startOutParameterElement(Attributes attributes)
protected void endOutParameterElement()
public void startTransformingElement(String uri, String name, String raw, Attributes attributes) throws SAXException
SAXException
public void endTransformingElement(String uri, String name, String raw) throws IOException, SAXException
IOException
SAXException
protected String nsQualify(String name, String prefix)
name
- the element nameprefix
- the prefix to qualify with
protected void start(String uri, String prefix, String name, Attributes attr) throws SAXException
SAXException
protected void end(String uri, String prefix, String name) throws SAXException
SAXException
protected void data(String data) throws SAXException
SAXException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |