|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.avalon.framework.logger.AbstractLogEnabled org.apache.cocoon.xml.AbstractXMLProducer org.apache.cocoon.xml.AbstractXMLPipe org.apache.cocoon.transformation.AbstractTransformer org.apache.cocoon.transformation.AbstractSAXTransformer org.apache.cocoon.transformation.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|in-xml-parameter|out-parameter)*,execute-query?, %param;)>
<!ELEMENT own-connection (#PCDATA)>
<!ELEMENT use-connection (#PCDATA)>
<!ELEMENT query (#PCDATA | substitute-value | ancestor-value | escape-string| xml)*>
<!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 in-xml-parameter EMPTY>
<!ATTLIST in-xml-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)>
<!ELEMENT xml (#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 getSubString, 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.
Inserting of XML data can be done by using the new sql:xml or SQL:in-xml-parameter tags. - sql:xml must be used like sql:escape-string - sql:in-xml-parameter must be used like sql:in-parameter.
Fields inherited from class org.apache.cocoon.transformation.AbstractSAXTransformer |
---|
context, defaultNamespaceURI, EMPTY_ATTRIBUTES, emptyAttributes, ignoreEmptyCharacters, ignoreEventsCount, ignoreHooksCount, ignoreWhitespaces, manager, namespaceURI, objectModel, parameters, recorderStack, request, resolver, response, source, stack |
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer |
---|
contentHandler, EMPTY_CONTENT_HANDLER, lexicalHandler, xmlConsumer |
Fields inherited from interface org.apache.cocoon.transformation.Transformer |
---|
ROLE |
Constructor Summary | |
---|---|
SQLTransformer()
Constructor |
Method Summary | |
---|---|
void |
configure(Configuration conf)
Configure transformer. |
protected void |
data(String data)
Helper method for generating SAX events |
void |
dispose()
Dispose |
protected void |
end(String uri,
String prefix,
String name)
Helper method for generating SAX events |
protected void |
endAncestorValueElement()
</ancestor-value> |
protected void |
endEscapeStringElement()
</escape-string> |
protected void |
endExecuteQueryElement()
</execute-query> |
protected void |
endInParameterElement()
</in-parameter> |
protected void |
endInXmlParameterElement()
</xml> |
protected void |
endOutParameterElement()
</out-parameter> |
protected void |
endQueryElement()
</query> |
protected void |
endSubstituteValueElement()
</substitute-value> |
String |
endTextRecording()
Stop recording of text and return the recorded information. |
void |
endTransformingElement(String uri,
String name,
String raw)
ContentHandler method |
protected void |
endValueElement()
</*> |
protected void |
endXmlElement()
</xml> |
protected String |
nsQualify(String name,
String prefix)
Qualifies an element name by giving it a prefix. |
void |
recycle()
Recycle this component |
void |
service(ServiceManager manager)
Serviceable |
void |
setup(SourceResolver resolver,
Map objectModel,
String source,
Parameters parameters)
Setup for the current request. |
protected void |
start(String uri,
String prefix,
String name,
Attributes attr)
Helper method for generating SAX events |
protected void |
startAncestorValueElement(Attributes attributes)
<ancestor-value> |
protected void |
startEscapeStringElement(Attributes attributes)
<escape-string> |
protected void |
startExecuteQueryElement()
<execute-query> |
protected void |
startInParameterElement(Attributes attributes)
<in-parameter> |
protected void |
startInXmlParameterElement(Attributes attributes)
<xml> |
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 void |
startXmlElement(Attributes attributes)
<xml> |
protected static void |
throwIllegalStateException(String message)
|
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer |
---|
setConsumer, setContentHandler, setLexicalHandler |
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled |
---|
enableLogging, getLogger, setupLogger, setupLogger, setupLogger |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface org.apache.cocoon.xml.XMLProducer |
---|
setConsumer |
Field Detail |
---|
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_PROP
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_XML
public static final String MAGIC_IN_XML_PARAMETER
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 static final int STATE_INSIDE_XML
protected static final int STATE_INSIDE_IN_XML_PARAMETER_ELEMENT
protected boolean oldDriver
protected int connectAttempts
protected int connectWaittime
protected org.apache.cocoon.transformation.SQLTransformer.Query query
protected int state
protected ServiceSelector datasources
protected String connName
protected Connection conn
protected XMLSerializer compiler
protected XMLDeserializer interpreter
protected SAXParser parser
Constructor Detail |
---|
public SQLTransformer()
Method Detail |
---|
public void service(ServiceManager manager) throws ServiceException
service
in interface Serviceable
service
in class AbstractSAXTransformer
ServiceException
public void configure(Configuration conf) throws ConfigurationException
configure
in interface Configurable
configure
in class AbstractSAXTransformer
ConfigurationException
public void setup(SourceResolver resolver, Map objectModel, String source, Parameters parameters) throws ProcessingException, SAXException, IOException
setup
in interface SitemapModelComponent
setup
in class AbstractSAXTransformer
ProcessingException
SAXException
IOException
public void recycle()
recycle
in interface Recyclable
recycle
in class AbstractSAXTransformer
public void dispose()
dispose
in interface Disposable
dispose
in class AbstractSAXTransformer
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 ProcessingException, SAXException
ProcessingException
SAXException
protected void endValueElement() throws SAXException
SAXException
protected void endExecuteQueryElement() throws SAXException
SAXException
protected void startAncestorValueElement(Attributes attributes) throws ProcessingException, SAXException
ProcessingException
SAXException
protected void endAncestorValueElement()
protected void startSubstituteValueElement(Attributes attributes) throws ProcessingException, SAXException
ProcessingException
SAXException
protected void endSubstituteValueElement()
protected void startEscapeStringElement(Attributes attributes) throws ProcessingException, SAXException
ProcessingException
SAXException
protected void endEscapeStringElement() throws SAXException
SAXException
protected void startXmlElement(Attributes attributes) throws ProcessingException, SAXException
ProcessingException
SAXException
protected void endXmlElement() throws ProcessingException, SAXException
ProcessingException
SAXException
protected void startInXmlParameterElement(Attributes attributes) throws ProcessingException, SAXException
ProcessingException
SAXException
protected void endInXmlParameterElement() throws ProcessingException, SAXException
ProcessingException
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 ProcessingException, SAXException
startTransformingElement
in class AbstractSAXTransformer
uri
- The namespace of the element.name
- The local name of the element.raw
- The qualified name of the element.attributes
- The attributes of the element.
ProcessingException
SAXException
public void endTransformingElement(String uri, String name, String raw) throws ProcessingException, IOException, SAXException
endTransformingElement
in class AbstractSAXTransformer
uri
- The namespace of the element.name
- The local name of the element.raw
- The qualified name of the element.
ProcessingException
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
public String endTextRecording() throws SAXException
endTextRecording
in class AbstractSAXTransformer
SAXException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |