Class com.ibm.etools.sqltoxml.SQLToXML
java.lang.Object com.ibm.etools.sqltoxml.SQLToXMLpublic class SQLToXML extends java.lang.Object
This class provides methods used by applications (such as the SQL to XML wizard) to perform database queries. The query result is obtained in an XML format. Optionally, corresponding DTD, XML schema, and XSL files of the result can be generated.
Table 1. Constructor Index Constructor Description SQLToXML(QueryProperties) This is the only constructor.
Table 2. Method Index Method Description void execute() Executes a query based on information from QueryProperties given as the constructor argument. void execute(PrintWriter, , String, PrintWriter) Deprecated. Executes a query based on information from QueryProperties and the results are written to the PrintWriters or files or both. void execute(String, PrintWriter, String, String, PrintWriter) Deprecated. Executes a query based on information from QueryProperties and the results are written to the PrintWriters or files or both. void execute(String, String, String, String) Deprecated. Executes a query based on information from QueryProperties and the results are written to the files. void finalize() Closes the connection if this was created by SQLToXML. Connection getConnection() Returns a database connection. Document getCurrentDocument() Returns the XML document that is a result of the most recent call to execute() method. Document[] getCurrentDocuments() Returns an XML documents array that is a result of the most recent call to execute() method. String getDTDFile() Returns current DTD file name to be generated. String getNextAllQuery() Returns a valid query string. Vector getNextQueries() Returns a sequence of valid query strings. String getParameters() Returns the parameter values for the where clause. String getXMLFile() Returns current XML file name to be generated. PrintWriter getXMLWriter() Returns current PrintWriter for the XML output. String getXSDFile() Returns current XML schema file name to be generated. String getXSLFile() Returns current XSL file name to be generated. PrintWriter getXSLWriter() Returns current PrintWriter for the XSL output void setConnection(Connection) Provides a JDBC connection to be used for generating the XML files. void setDTDFile(String) Sets the DTD file name to be generated. void setGenDocType(Boolean) Deprecated. Controls whether or not to generate a DTD or an XML schema file for validation purpose. void setIndenting(Boolean) Sets the indentation on and off. void setMaxRows(int) Sets the limit for the maximum number of rows to be retrieved in the generated XML to max. void setParameters(String) Sets the parameter values for the where clause. void setQueryProperties(QueryProperties) Overrides current queryProperties. void setXMLFile(String) Sets the XML file name to be generated. void setXMLWriter(String) Sets the PrintWriter to which the generated XML is directed. void setXSDFile(String) Sets the XML schema file name to be generated. void setXSLFile(String) Sets the XSL file name to be generated. void setXSLWriter(String) Sets the PrintWriter to which the generated XSL is directed.
Methods inherited from class java.lang.Object equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructors
SQLToXML
public SQLToXML(QueryProperties qProperties)This is the only constructor.
Methods
execute
public void execute() throws java.lang.ExceptionExecutes a query based on information from QueryProperties given as the constructor argument. The artifacts that can be generated include XML, XML schema, DTD, and XSL files. To generate artifacts other than XML, the file names or PrintWriters need to be provided by using relevant set accessors before using this method. Additionally the XML output can be obtained as a DOM document through the getCurrentDocument() or getCurrentDocuments() method call.
Throws: java.lang.Exception - Thrown when the execution fails
execute
public void execute(PrintWriter xml, String dtdfile, String xsdfile, PrintWriter xsl) throws ExceptionDeprecated. Executes a query based on information from QueryProperties and the results are written to the PrintWriters and/or files. When any argument other than 'xml' is null, no result is generated for that particular argument. Also, if both dtdfile and xsdfile are specified, only xsdfile is generated.
- Parameters
- xml - A PrintWriter for an XML result.
- dtdfile - A DTD file name for the xml.
- xsdfile - An XML schema file name for the xml.
- xsl - A PrintWriter for a default XSL.
- Throws
- Exception Thrown when the execution fails.
- See Also
execute
public void execute(String params, PrintWriter xml, String dtdfile, String xsdfile, PrintWriter xsl) throws ExceptionDeprecated. Executes a query based on information from QueryProperties and the results are written to the PrintWriters and/or files. When any argument other than 'xml' is null, no result is generated for that particular argument. Also, if both dtdfile and xsdfile are specified, only xsdfile is generated. This method is used when the query contains a where clause and its constraints are given in 'params' String argument. These constraint parameters are delimited using comma (,) in the argument.
- Parameters
- params - where clause constraint parameters delimited by comma(',').
- xml - A PrintWriter for an XML result.
- dtdfile - A DTD file name for the xml.
- xsdfile - An XML schema file name for the xml.
- xsl - A PrintWriter for a default XSL.
- Throws
- Exception Thrown when the execution fails.
- See Also
execute
public void execute(String xmlfile, String dtdfile, String xsdfile, String xslfile) throws ExceptionDeprecated. Executes a query based on information from QueryProperties and the results are written to the files. When any argument other than 'xml' is null, no result is generated for that particular argument. Also, if both dtdfile and xsdfile are specified, only xsdfile is generated.
- Parameters
- xmlfile - An XML file name for the query result.
- dtdfile - A DTD file name for the xmlfile.
- xsdfile - An XML schema file name for the xmlfile.
- xslfile - An XSL file name for a default XSL.
- Throws
- Exception Thrown when the execution fails.
- See Also
finalize
public void finalize()Closes the connection if this was created by SQLToXML. If the connection was supplied externally (by using setConnection()), the connection is not closed. This method is called by the JVM when SQLToXML is garbage-collected.
getConnection
public Connection getConnection() throws ExceptionReturns a database connection. If no connection exists, this method creates a new connection using the values from QueryProperties.
- Returns
- A JDBC connection used for the query
- Throws
- Exception Thrown when a connection is not available.
getCurrentDocument
public Document getCurrentDocument()Returns the XML document that is a result of the most recent call to execute() method. If the GENERATE_ID_AND_IDREF with RECURSIVE option is used, the main XML document is returned.
- Returns
- An XML document
- See Also
- getCurrentDocuments
getCurrentDocuments
public Document[] getCurrentDocuments()Returns an XML documents array that is a result of the most recent call to execute() method. Unless the GENERATE_ID_AND_IDREF with RECURSIVE option is used, the result contains only one document.
- Returns
- An array of XML documents.
- See Also
- getCurrentDocument
getDTDFile
public java.lang.String getDTDFile()Returns current DTD file name to be generated.
- Returns
- A DTD file name.
- See Also
- setDTDFile
getNextAllQuery
public String getNextAllQuery()Returns a valid query string. This method returns a valid query string only when
1) Format option is ID_AND_IDREF, and 2) Recurse option is 'TRUE'For example, when a column from the current query is a foreign key to a primary key column of table A, this returns the string 'select * from A'. Refer to the sample servlet XMLIntegratorServlet.java for a typical use of this method.
- Returns
- A select statement for a table referenced by a foreign key
getNextQueries
public Vector getNextQueries()Returns a sequence of valid query strings. This method returns a Vector of valid query strings only when
1) Format option is ID_AND_IDREF, and 2) Recurse option is 'TRUE'For example, when a column from the current query is a foreign key to a primary key column ID (with value 123) of table A, this returns the string 'select * from A where ID = 123'. Refer to the sample servlet XMLIntegratorServlet.java for a typical use of this method.
- Returns
- A select statement (with where clause) for a table row referenced by a foreign key
getParameters
public java.lang.String getParameters()Returns the parameter values for the where clause.
- Returns
- The where clause parameter values when they exist. If they do not exist, it returns a value of null.
- See Also
- setParameters
getXMLFile
public java.lang.String getXMLFile()Returns current XML file name to be generated.
- Returns
- An XML file name.
- See Also
- setXMLFile
getXMLWriter
public java.io.PrintWriter getXMLWriter()Returns current PrintWriter for the XML output.
- Returns
- A PrintWriter for the XML output.
- See Also
- setXMLWriter
getXSDFile
public java.lang.String getXSDFile()Returns current XML schema file name to be generated.
- Returns
- An XML schema file name.
- See Also
- setXSDfile
getXSLFile
public java.lang.String getXSLFile()Returns current XSL file name to be generated.
- Returns
- An XSL file name.
- See Also
- setXSLFile
getXSLWriter
public java.io.PrintWriter getXSLWriter()Returns current PrintWriter for the XSL output.
- Returns
- A PrintWriter for the XSL output.
- See Also
- setXSLWriter
setConnection
public void setConnection(Connection jdbcConnection)Provides a JDBC connection to be used for generating the XML files. This method becomes useful when an application program wants to use its own connection management mechanism such as connection pooling. If this method is not called before any of the execute() methods, SQLToXML creates its own connection using the values from QueryProperties.
- Parameters
- jdbcConnection - A JDBC connection
setDTDFile
public void setDTDFile(java.lang.String filename) throws java.lang.ExceptionSets the DTD file name to be generated. This method cannot be used in combination with setXSDFile(String).
- Parameters
- filename - A DTD file name to be generated
- Throws
- java.lang.Exception Thrown if setXSDFile(String) has been called already.
setGenDocType
public void setGenDocType(Boolean value)Deprecated. Controls whether to generate a DTD or an XML schema file for validation purpose. By default, the value is set to true for development time, and to false for run time. Setting the value to true for run-time applications such as servlets causes some performance decrease.
- Parameters
- value - true for not generating a validation file, and false otherwise.
setIndenting
public void setIndenting(Boolean flag)Sets the indentation on and off. Indentation is on by default.
- Parameters
- flag - false if indentation should be off.
setMaxRows
public void setMaxRows(int max)Sets the limit for the maximum number of rows to be retrieved in the generated XML to max. By default, there is no limit.
- Parameters
- max - The limit for the number of rows. Zero means there is no limit.
setParameters
public void setParameters(java.lang.String parameters)Sets the parameter values for the where-clause. This method is intended to be used when the query contains the where-clause. For example,
select * from EMPLOYEE where EMP_NO = :empnoFrom the above example, the value to be replaced for :empno is given in the parameters argument. If there are multiple constraint values, they are delimited using comma (,) in the parameters like in the following example.String params = "87316,'Toronto'"; sqltoxml.setParameters(params);
- Parameters
- parameters - The where-clause parameter values when they exist
setQueryProperties
public void setQueryProperties(QueryProperties qProperties)Overrides current queryProperties.
setXMLFile
public void setXMLFile(java.lang.String filename) throws java.lang.ExceptionSets the XML file name to be generated. This method cannot be used in combination with setXMLWriter(PrintWriter).
- Parameters
- filename - An XML file name to be generated
- Throws
- java.lang.Exception Thrown if setXMLWriter(PrintWriter) or setXSLWriter(PrintWriter) has been called already.
- See Also
- setXMLWriter
setXMLWriter
public void setXMLWriter(java.io.PrintWriter writer) throws java.lang.ExceptionSets the PrintWriter to which the generated XML is directed. This method cannot be used in combination with setXMLFile(String).
- Parameters
- filename - A PrintWriter where the XML is going to be directed.
- Throws
- java.lang.Exception Thrown if setXMLFile(PrintWriter) or setXSLFile(PrintWriter) has been called already.
- See Also
- setXMLFile
setXSDFile
public void setXSDFile(java.lang.String filename) throws java.lang.ExceptionSets the XML schema file name to be generated. This method cannot be used in combination with setDTDFile(String).
- Parameters
- filename - An XML schema file name to be generated
- Throws
- java.lang.Exception Thrown if setDTDFile(String) has been called already
setXSLFile
public void setXSLFile(java.lang.String filename) throws java.lang.ExceptionSets the XSL file name to be generated. This method cannot be used in combination with setXSLWriter(PrintWriter).
- Parameters
- filename - An XSL file name to be generated
- Throws
- java.lang.Exception Thrown if setXSLWriter(PrintWriter) or setXMLWriter(PrintWriter) has been called already.
- See Also
- setXSLWriter
setXSLWriter
public void setXSLWriter(java.io.PrintWriter writer) throws java.lang.ExceptionSets the PrintWriter to which the generated XSL is directed. This method cannot be used in combination with setXSLFile(String).
- Parameters
- filename - A PrintWriter where the XSL is going to be directed.
- Throws
- java.lang.Exception Thrown if setXSLFile(PrintWriter) or setXMLFile(PrintWriter) has been called already.
Related tasks
Generating XML from SQL using a wizard
Updating tables using the XMLToSQL class
Related reference
Class com.ibm.etools.sqltoxml.QueryProperties
Class com.ibm.etools.xmltosql.XMLToSQL
Class com.ibm.etools.xmltosql.SQLProperties