Class com.ibm.etools.sqltoxml.SQLToXML

java.lang.Object
        com.ibm.etools.sqltoxml.SQLToXML

public 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.Exception

Executes 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 Exception

Deprecated. 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.

execute

public void execute(String params,
                    PrintWriter xml,
                    String dtdfile,
                    String xsdfile,
                    PrintWriter xsl) throws Exception

Deprecated. 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.

execute

public void execute(String xmlfile,
                    String dtdfile,
                    String xsdfile,
                    String xslfile) throws Exception

Deprecated. 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.

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 Exception

Returns a database connection. If no connection exists, this method creates a new connection using the values from QueryProperties.

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.

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.

getDTDFile

public java.lang.String getDTDFile()

Returns current DTD file name to be generated.

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.

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.

getParameters

public java.lang.String getParameters()

Returns the parameter values for the where clause.

getXMLFile

public java.lang.String getXMLFile()

Returns current XML file name to be generated.

getXMLWriter

public java.io.PrintWriter getXMLWriter()

Returns current PrintWriter for the XML output.

getXSDFile

public java.lang.String getXSDFile()

Returns current XML schema file name to be generated.

getXSLFile

public java.lang.String getXSLFile()

Returns current XSL file name to be generated.

getXSLWriter

public java.io.PrintWriter getXSLWriter()

Returns current PrintWriter for the XSL output.

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.

setDTDFile

public void setDTDFile(java.lang.String filename)
           throws java.lang.Exception

Sets the DTD file name to be generated. This method cannot be used in combination with setXSDFile(String).

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.

setIndenting

public void setIndenting(Boolean flag)

Sets the indentation on and off. Indentation is on by default.

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.

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 = :empno 
From 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); 

setQueryProperties

public void setQueryProperties(QueryProperties qProperties)

Overrides current queryProperties.

setXMLFile

public void setXMLFile(java.lang.String filename)
           throws java.lang.Exception

Sets the XML file name to be generated. This method cannot be used in combination with setXMLWriter(PrintWriter).

setXMLWriter

public void setXMLWriter(java.io.PrintWriter writer)
           throws java.lang.Exception

Sets the PrintWriter to which the generated XML is directed. This method cannot be used in combination with setXMLFile(String).

setXSDFile

public void setXSDFile(java.lang.String filename)
           throws java.lang.Exception

Sets the XML schema file name to be generated. This method cannot be used in combination with setDTDFile(String).

setXSLFile

public void setXSLFile(java.lang.String filename)
           throws java.lang.Exception

Sets the XSL file name to be generated. This method cannot be used in combination with setXSLWriter(PrintWriter).

setXSLWriter

public void setXSLWriter(java.io.PrintWriter writer)
           throws java.lang.Exception

Sets the PrintWriter to which the generated XSL is directed. This method cannot be used in combination with setXSLFile(String).

 

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