jcs.xml.resultset
Class ResultSetXml

java.lang.Object
  |
  +--jcs.xml.JXml
        |
        +--jcs.xml.resultset.ResultSetXml

public class ResultSetXml
extends JXml
implements java.io.Serializable

A class to contain an XML document that represents an SQL result set.

See Also:
Serialized Form

Field Summary
static java.lang.String DTD
          The static final text of the DTD for SQL ResultSet documents.
static java.lang.String DTD_NAME
          The static final name of the ResultSet DTD.
 
Fields inherited from class jcs.xml.JXml
xmlText
 
Constructor Summary
ResultSetXml(java.lang.String xmlText)
          Constructs a ResultSetXml instance from an existing XML document.
ResultSetXml(java.lang.String query, java.lang.String cdataColumns, java.lang.String columnNameOption, java.lang.String server)
          Constructs a ResultSetXml instance from the SQL result set returned by the argument query.
 
Method Summary
 java.lang.Boolean allString(int columnNumber, java.lang.String compOp, java.lang.String comparand)
          Returns the universal quantification of a given comparison to a given column of the ResultSetVector.
 java.lang.String getColumn(int rowNumber, int columnNumber)
          Returns the String value of row 'rowNumber' column 'columnNumber'.
 java.lang.String getColumn(int rowNumber, java.lang.String columnName)
          Return the String value of row 'rowNumber' column 'columnName'.
 java.lang.String resolveExternal(java.lang.String publicId, java.lang.String systemId)
          Returns the ResultSet DTD.
 void setColumn(int rowNumber, int columnNumber, java.lang.String newValue)
          Update the value of row number i column number j and return the updated ResultSetXml document.
 void setColumn(int rowNumber, java.lang.String columnName, java.lang.String newValue)
          Updates the value of row number i column columnName, and returns the updated ResultSetXml document.
 java.lang.Boolean someString(int columnNumber, java.lang.String compOp, java.lang.String comparand)
          Returns the existential quantification of a given comparison to a given column of the ResultSetXml.
 ResultSetVector toResultSetVector()
          Constructs a ResultSetVector from a ResultSetXml document.
 java.lang.String toSqlScript(java.lang.String resultTableName, java.lang.String columnPrefix, java.lang.String goOption)
          Generates an SQL script from the ResultSetXml document.
 
Methods inherited from class jcs.xml.JXml
parse, parse, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DTD_NAME

public static final java.lang.String DTD_NAME
The static final name of the ResultSet DTD. This is the name that is used in the SYSTEM clause of external entity references to the ResultSet DTD. For example:
  <!DOCTYPE ResultSet SYSTEM "ResultSet.dtd">
  

DTD

public static final java.lang.String DTD
The static final text of the DTD for SQL ResultSet documents.
Constructor Detail

ResultSetXml

public ResultSetXml(java.lang.String xmlText)
             throws java.lang.Exception
Constructs a ResultSetXml instance from an existing XML document.
Parameters:
doc - a string that is an XML document. The document must be a valid SQL result set, using the JavaSqlResultSet DTD.
Throws:
java.lang.Exception - To be added

ResultSetXml

public ResultSetXml(java.lang.String query,
                    java.lang.String cdataColumns,
                    java.lang.String columnNameOption,
                    java.lang.String server)
             throws java.lang.ClassNotFoundException,
                    java.sql.SQLException,
                    java.lang.Exception
Constructs a ResultSetXml instance from the SQL result set returned by the argument query.

Example Java code:

 
  ResultSetXml rsx 
     = new ResultSetXml("select d.name, e.name, d.dno "
            +"from emps e, dept d "
            + " where e.dno = d.dno order by d.name, e.name",
           "000", "yes", "antibes:4000?user=sa"); 
  
Parameters:
query - a string that is the SQL query whose result set is to be returned as an XML document. The query must have no question mark parameters, and must return a single result set.
cdataColumns - a string indicating which columns of the result set should be specified as CDATA sections in the output XML document. See above.
columnNameOption - a string indicating whether (yes) or not (no) the <Column> tags in the output XML document should have column name attributes. See above.
server - a string that identifies the server in which to execute the query. See the connectTo method for a description of this parameter.
Throws:
java.lang.ClassNotFoundException - Thrown when the XML parser class cannot be loaded
java.sql.SQLException - Thrown for any exceptions raised during execution of the SQL statement
java.lang.Exception - Thrown for invalid parameters and other conditions
Method Detail

resolveExternal

public java.lang.String resolveExternal(java.lang.String publicId,
                                        java.lang.String systemId)
                                 throws org.xml.sax.SAXException
Returns the ResultSet DTD. This method is called by the parse method of the superclass JXml, to obtain the DTD for a given ID. The publicId and systemId parameters are the PUBLIC and SYSTEM values from an external entity declaration in the document being parsed. If the SYSTEM value is "ResultSet.dtd", then this method returns the ResultSet DTD. Otherwise, it raises an exception, which indicates that a document other than a Result Set XML document is being parsed as a ResultSet XML document.
Parameters:
publicId - a String with the PUBLIC value from an external entity declaration.
systemId - a String with the SYSTEM value from an external entity declaration.
Returns:
a string containing the ResultSet DTD.
Throws:
org.xml.sax.SAXException - Thrown when the systemId is not "ResultSet.dtd".
Overrides:
resolveExternal in class JXml

toSqlScript

public java.lang.String toSqlScript(java.lang.String resultTableName,
                                    java.lang.String columnPrefix,
                                    java.lang.String goOption)
                             throws java.lang.Exception
Generates an SQL script from the ResultSetXml document. The SQL script will contain an SQL create statement and a sequence of SQL insert statements that create and populate a table with the data of the result set.

The goOption parameter indicates whether you want the output script to include go commands after the create and insert statements. This depends on how you plan to execute the script: ISQL requires the go commands, and JDBC doesn't allow them.

Parameters:
resultTableName - a string that is the SQL table name to specify in the output create and insert statements
columnPrefix - a string to use as a prefix when generating column names in the output script. Such generated names are needed when the result set has columns with no names or with duplicate names.
goOption - a string indicating whether the output script should include go commands. This is indicated by yes or no. See above.

getColumn

public java.lang.String getColumn(int rowNumber,
                                  int columnNumber)
                           throws java.lang.Exception
Returns the String value of row 'rowNumber' column 'columnNumber'.
Parameters:
rowNumber - an int that is the number of a row of the result set
columnNumber - an int that is the number of a column of the result set
Returns:
a string that is the value of the given column of the given row, or is null if that element is null or doesn't exist.
Throws:
java.lang.Exception - Thrown if the document is invalid.

getColumn

public java.lang.String getColumn(int rowNumber,
                                  java.lang.String columnName)
                           throws java.lang.Exception
Return the String value of row 'rowNumber' column 'columnName'.
Parameters:
rowNumber - an int that is the number of a row of the result set
columnName - a string that is the name of a column of the result set
Returns:
a string that is the value of the given column of the given row, or is null if that element is null or doesn't exist.
Throws:
To - be added

setColumn

public void setColumn(int rowNumber,
                      java.lang.String columnName,
                      java.lang.String newValue)
               throws java.lang.Exception
Updates the value of row number i column columnName, and returns the updated ResultSetXml document.
Parameters:
rowNumber - an int that is the number of a row of the result set
columnName - a string that is the name of a column of the result set
newValue - a string that is the new value of the given column
Returns:
a string that is the value of the updated document
Throws:
java.lang.Exception - if the specified row and column don't exist.

setColumn

public void setColumn(int rowNumber,
                      int columnNumber,
                      java.lang.String newValue)
               throws java.lang.Exception
Update the value of row number i column number j and return the updated ResultSetXml document.
Parameters:
rowNumber - an int that is the number of a row of the result set
columnNumber - a string that is the number of a column of the result set
newValue - a string that is the new value of the given column
Returns:
a string that is the value of the updated document
Throws:
java.lang.Exception - if the specified row and column don't exist.

toResultSetVector

public ResultSetVector toResultSetVector()
                                  throws java.lang.Exception
Constructs a ResultSetVector from a ResultSetXml document.
Parameters:
xml - a string containing an XML document that is an SQL result set. It must conform to the JavaSqlResultSet DTD.
Returns:
a ResultSetVector containing a Vector representation of the SQL result set.
Throws:
java.lang.Exception - To be added

allString

public java.lang.Boolean allString(int columnNumber,
                                   java.lang.String compOp,
                                   java.lang.String comparand)
                            throws java.lang.Exception
Returns the universal quantification of a given comparison to a given column of the ResultSetVector.

Example Java code:

rsv.allString(i, "<=", "xxx")
returns true iff for all elements ci of column i of rsv,
ci <= "xxx"
The allString method performs only String comparisons.
Parameters:
columnNumber - the number of a column of the result set
compOp - a string that is one of "=,==,<,>,<>,!=, >=,<=".
comparand - a string that will be the second operand of the compares.
Returns:
a boolean indicating whether the universal quantification is true
Throws:
java.lang.Exception - Thrown if the document is invalid.

someString

public java.lang.Boolean someString(int columnNumber,
                                    java.lang.String compOp,
                                    java.lang.String comparand)
                             throws java.lang.Exception
Returns the existential quantification of a given comparison to a given column of the ResultSetXml.

Example Java code:

rsx.someString(i, "<=", "xxx")
returns true iff for some element ci of column i of rsx,
ci <= "xxx"
The someString method performs only String comparisons.
Parameters:
columnNumber - the number of a column of the result set
compOp - a string that is one of "=,==,<,>,<>,!=, >=,<=".
comparand - a string that will be the second operand of the compares.
Returns:
a boolean indicating whether the existential quantification is true
Throws:
java.lang.Exception - Thrown if the document is invalid.