4512 lines · 210.7 KB · Java
RawDownload
     /**     * The <code>java.util.Map</code> object that contains entries mapping     * SQL type names to classes in the Java programming language for the     * custom mapping of user-defined types.     * @serial     */    private Map<String, Class<?>> map;     /**     * A <code>Vector</code> object that holds the list of listeners     * that have registered with this <code>RowSet</code> object.     * @serial     */    private Vector<RowSetListener> listeners;     /**     * A <code>Vector</code> object that holds the parameters set     * for this <code>RowSet</code> object's current command.     * @serial     */    private Hashtable<Integer, Object> params; // could be transient?     /**     * Constructs a new <code>BaseRowSet</code> object initialized with     * a default <code>Vector</code> object for its <code>listeners</code>     * field. The other default values with which it is initialized are listed     * in Section 6.0 of the class comment for this class.     */    public BaseRowSet() {        // allocate the listeners collection        listeners = new Vector<RowSetListener>();    }     /**     * Performs the necessary internal configurations and initializations     * to allow any JDBC <code>RowSet</code> implementation to start using     * the standard facilities provided by a <code>BaseRowSet</code>     * instance. This method <b>should</b> be called after the <code>RowSet</code> object     * has been instantiated to correctly initialize all parameters. This method     * <b>should</b> never be called by an application, but is called from with     * a <code>RowSet</code> implementation extending this class.     */    protected void initParams() {        params = new Hashtable<Integer, Object>();    }     //--------------------------------------------------------------------    // Events    //--------------------------------------------------------------------     /**    * The listener will be notified whenever an event occurs on this <code>RowSet</code>    * object.    * <P>    * A listener might, for example, be a table or graph that needs to    * be updated in order to accurately reflect the current state of    * the <code>RowSet</code> object.    * <p>    * <b>Note</b>: if the <code>RowSetListener</code> object is    * <code>null</code>, this method silently discards the <code>null</code>    * value and does not add a null reference to the set of listeners.    * <p>    * <b>Note</b>: if the listener is already set, and the new <code>RowSetListerner</code>    * instance is added to the set of listeners already registered to receive    * event notifications from this <code>RowSet</code>.    *    * @param listener an object that has implemented the    *     <code>javax.sql.RowSetListener</code> interface and wants to be notified    *     of any events that occur on this <code>RowSet</code> object; May be    *     null.    * @see #removeRowSetListener    */    public void addRowSetListener(RowSetListener listener) {        listeners.add(listener);    }     /**    * Removes the designated object from this <code>RowSet</code> object's list of listeners.    * If the given argument is not a registered listener, this method    * does nothing.    *    *  <b>Note</b>: if the <code>RowSetListener</code> object is    * <code>null</code>, this method silently discards the <code>null</code>    * value.    *    * @param listener a <code>RowSetListener</code> object that is on the list    *        of listeners for this <code>RowSet</code> object    * @see #addRowSetListener    */    public void removeRowSetListener(RowSetListener listener) {        listeners.remove(listener);    }     /**     * Determine if instance of this class extends the RowSet interface.     */    private void checkforRowSetInterface() throws SQLException {        if ((this instanceof javax.sql.RowSet) == false) {            throw new SQLException("The class extending abstract class BaseRowSet " +                "must implement javax.sql.RowSet or one of it's sub-interfaces.");        }    }     /**    * Notifies all of the listeners registered with this    * <code>RowSet</code> object that its cursor has moved.    * <P>    * When an application calls a method to move the cursor,    * that method moves the cursor and then calls this method    * internally. An application <b>should</b> never invoke    * this method directly.    *    * @throws SQLException if the class extending the <code>BaseRowSet</code>    *     abstract class does not implement the <code>RowSet</code> interface or    *     one of it's sub-interfaces.    */    protected void notifyCursorMoved() throws SQLException {        checkforRowSetInterface();        if (listeners.isEmpty() == false) {            RowSetEvent event = new RowSetEvent((RowSet)this);            for (Iterator i = listeners.iterator(); i.hasNext(); ) {                ((RowSetListener)i.next()).cursorMoved(event);            }        }    }     /**    * Notifies all of the listeners registered with this <code>RowSet</code> object that    * one of its rows has changed.    * <P>    * When an application calls a method that changes a row, such as    * the <code>CachedRowSet</code> methods <code>insertRow</code>,    * <code>updateRow</code>, or <code>deleteRow</code>,    * that method calls <code>notifyRowChanged</code>    * internally. An application <b>should</b> never invoke    * this method directly.    *    * @throws SQLException if the class extending the <code>BaseRowSet</code>    *     abstract class does not implement the <code>RowSet</code> interface or    *     one of it's sub-interfaces.    */    protected void notifyRowChanged() throws SQLException {        checkforRowSetInterface();        if (listeners.isEmpty() == false) {                RowSetEvent event = new RowSetEvent((RowSet)this);                for (Iterator i = listeners.iterator(); i.hasNext(); ) {                        ((RowSetListener)i.next()).rowChanged(event);                }        }    }    /**    * Notifies all of the listeners registered with this <code>RowSet</code>    * object that its entire contents have changed.    * <P>    * When an application calls methods that change the entire contents    * of the <code>RowSet</code> object, such as the <code>CachedRowSet</code> methods    * <code>execute</code>, <code>populate</code>, <code>restoreOriginal</code>,    * or <code>release</code>, that method calls <code>notifyRowSetChanged</code>    * internally (either directly or indirectly). An application <b>should</b>    * never invoke this method directly.    *    * @throws SQLException if the class extending the <code>BaseRowSet</code>    *     abstract class does not implement the <code>RowSet</code> interface or    *     one of it's sub-interfaces.    */    protected void notifyRowSetChanged() throws SQLException {        checkforRowSetInterface();        if (listeners.isEmpty() == false) {                RowSetEvent event = new RowSetEvent((RowSet)this);                for (Iterator i = listeners.iterator(); i.hasNext(); ) {                        ((RowSetListener)i.next()).rowSetChanged(event);                }        }}     /**     * Retrieves the SQL query that is the command for this     * <code>RowSet</code> object. The command property contains the query that     * will be executed to populate this <code>RowSet</code> object.     * <P>     * The SQL query returned by this method is used by <code>RowSet</code> methods     * such as <code>execute</code> and <code>populate</code>, which may be implemented     * by any class that extends the <code>BaseRowSet</code> abstract class and     * implements one or more of the standard JSR-114 <code>RowSet</code>     * interfaces.     * <P>     * The command is used by the <code>RowSet</code> object's     * reader to obtain a <code>ResultSet</code> object.  The reader then     * reads the data from the <code>ResultSet</code> object and uses it to     * to populate this <code>RowSet</code> object.     * <P>     * The default value for the <code>command</code> property is <code>null</code>.     *     * @return the <code>String</code> that is the value for this     *         <code>RowSet</code> object's <code>command</code> property;     *         may be <code>null</code>     * @see #setCommand     */    public String getCommand() {        return command;    }     /**     * Sets this <code>RowSet</code> object's <code>command</code> property to     * the given <code>String</code> object and clears the parameters, if any,     * that were set for the previous command.     * <P>     * The <code>command</code> property may not be needed if the <code>RowSet</code>     * object gets its data from a source that does not support commands,     * such as a spreadsheet or other tabular file.     * Thus, this property is optional and may be <code>null</code>.     *     * @param cmd a <code>String</code> object containing an SQL query     *            that will be set as this <code>RowSet</code> object's command     *            property; may be <code>null</code> but may not be an empty string     * @throws SQLException if an empty string is provided as the command value     * @see #getCommand     */    public void setCommand(String cmd) throws SQLException {        // cmd equal to null or        // cmd with length 0 (implies url =="")        // are not independent events.         if(cmd == null) {           command = null;        } else if (cmd.length() == 0) {            throw new SQLException("Invalid command string detected. " +            "Cannot be of length less than 0");        } else {            // "unbind" any parameters from any previous command.            if(params == null){                 throw new SQLException("Set initParams() before setCommand");            }            params.clear();            command = cmd;        }     }     /**     * Retrieves the JDBC URL that this <code>RowSet</code> object's     * <code>javax.sql.Reader</code> object uses to make a connection     * with a relational database using a JDBC technology-enabled driver.     *<P>     * The <code>Url</code> property will be <code>null</code> if the underlying data     * source is a non-SQL data source, such as a spreadsheet or an XML     * data source.     *     * @return a <code>String</code> object that contains the JDBC URL     *         used to establish the connection for this <code>RowSet</code>     *         object; may be <code>null</code> (default value) if not set     * @throws SQLException if an error occurs retrieving the URL value     * @see #setUrl     */    public String getUrl() throws SQLException {        return URL;    }     /**     * Sets the Url property for this <code>RowSet</code> object     * to the given <code>String</code> object and sets the dataSource name     * property to <code>null</code>. The Url property is a     * JDBC URL that is used when     * the connection is created using a JDBC technology-enabled driver     * ("JDBC driver") and the <code>DriverManager</code>.     * The correct JDBC URL for the specific driver to be used can be found     * in the driver documentation.  Although there are guidelines for for how     * a JDBC URL is formed,     * a driver vendor can specify any <code>String</code> object except     * one with a length of <code>0</code> (an empty string).     * <P>     * Setting the Url property is optional if connections are established using     * a <code>DataSource</code> object instead of the <code>DriverManager</code>.     * The driver will use either the URL property or the     * dataSourceName property to create a connection, whichever was     * specified most recently. If an application uses a JDBC URL, it     * must load a JDBC driver that accepts the JDBC URL before it uses the     * <code>RowSet</code> object to connect to a database.  The <code>RowSet</code>     * object will use the URL internally to create a database connection in order     * to read or write data.     *     * @param url a <code>String</code> object that contains the JDBC URL     *     that will be used to establish the connection to a database for this     *     <code>RowSet</code> object; may be <code>null</code> but must not     *     be an empty string     * @throws SQLException if an error occurs setting the Url property or the     *     parameter supplied is a string with a length of <code>0</code> (an     *     empty string)     * @see #getUrl     */    public void setUrl(String url) throws SQLException {        if(url == null) {           url = null;        } else if (url.length() < 1) {            throw new SQLException("Invalid url string detected. " +            "Cannot be of length less than 1");        } else {            URL = url;        }         dataSource = null;     }     /**     * Returns the logical name that when supplied to a naming service     * that uses the Java Naming and Directory Interface (JNDI) API, will     * retrieve a <code>javax.sql.DataSource</code> object. This     * <code>DataSource</code> object can be used to establish a connection     * to the data source that it represents.     * <P>     * Users should set either the url or the data source name property.     * The driver will use the property set most recently to establish a     * connection.     *     * @return a <code>String</code> object that identifies the     *         <code>DataSource</code> object to be used for making a     *         connection; if no logical name has been set, <code>null</code>     *         is returned.     * @see #setDataSourceName     */    public String getDataSourceName() {        return dataSource;    }      /**     * Sets the <code>DataSource</code> name property for this <code>RowSet</code>     * object to the given logical name and sets this <code>RowSet</code> object's     * Url property to <code>null</code>. The name must have been bound to a     * <code>DataSource</code> object in a JNDI naming service so that an     * application can do a lookup using that name to retrieve the     * <code>DataSource</code> object bound to it. The <code>DataSource</code>     * object can then be used to establish a connection to the data source it     * represents.     * <P>     * Users should set either the Url property or the dataSourceName property.     * If both properties are set, the driver will use the property set most recently.     *     * @param name a <code>String</code> object with the name that can be supplied     *     to a naming service based on JNDI technology to retrieve the     *     <code>DataSource</code> object that can be used to get a connection;     *     may be <code>null</code> but must not be an empty string     * @throws SQLException if an empty string is provided as the <code>DataSource</code>     *    name     * @see #getDataSourceName     */    public void setDataSourceName(String name) throws SQLException {         if (name == null) {            dataSource = null;        } else if (name.equals("")) {           throw new SQLException("DataSource name cannot be empty string");        } else {           dataSource = name;        }         URL = null;    }     /**     * Returns the user name used to create a database connection.  Because it     * is not serialized, the username property is set at runtime before     * calling the method <code>execute</code>.     *     * @return the <code>String</code> object containing the user name that     *         is supplied to the data source to create a connection; may be     *         <code>null</code> (default value) if not set     * @see #setUsername     */    public String getUsername() {        return username;    }     /**     * Sets the username property for this <code>RowSet</code> object     * to the given user name. Because it     * is not serialized, the username property is set at run time before     * calling the method <code>execute</code>.     *     * @param name the <code>String</code> object containing the user name that     *     is supplied to the data source to create a connection. It may be null.     * @see #getUsername     */    public void setUsername(String name) {        if(name == null)        {           username = null;        } else {           username = name;        }    }     /**     * Returns the password used to create a database connection for this     * <code>RowSet</code> object.  Because the password property is not     * serialized, it is set at run time before calling the method     * <code>execute</code>. The default value is <code>null</code>     *     * @return the <code>String</code> object that represents the password     *         that must be supplied to the database to create a connection     * @see #setPassword     */    public String getPassword() {        return password;    }     /**     * Sets the password used to create a database connection for this     * <code>RowSet</code> object to the given <code>String</code>     * object.  Because the password property is not     * serialized, it is set at run time before calling the method     * <code>execute</code>.     *     * @param pass the <code>String</code> object that represents the password     *     that is supplied to the database to create a connection. It may be     *     null.     * @see #getPassword     */    public void setPassword(String pass) {        if(pass == null)        {           password = null;        } else {           password = pass;        }    }     /**     * Sets the type for this <code>RowSet</code> object to the specified type.     * The default type is <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>.     *     * @param type one of the following constants:     *             <code>ResultSet.TYPE_FORWARD_ONLY</code>,     *             <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or     *             <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>     * @throws SQLException if the parameter supplied is not one of the     *         following constants:     *          <code>ResultSet.TYPE_FORWARD_ONLY</code> or     *          <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>     *          <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>     * @see #getConcurrency     * @see #getType     */    public void setType(int type) throws SQLException {         if ((type != ResultSet.TYPE_FORWARD_ONLY) &&           (type != ResultSet.TYPE_SCROLL_INSENSITIVE) &&           (type != ResultSet.TYPE_SCROLL_SENSITIVE)) {                throw new SQLException("Invalid type of RowSet set. Must be either " +                "ResultSet.TYPE_FORWARD_ONLY or ResultSet.TYPE_SCROLL_INSENSITIVE " +                "or ResultSet.TYPE_SCROLL_SENSITIVE.");        }        this.rowSetType = type;    }     /**     * Returns the type of this <code>RowSet</code> object. The type is initially     * determined by the statement that created the <code>RowSet</code> object.     * The <code>RowSet</code> object can call the method     * <code>setType</code> at any time to change its     * type.  The default is <code>TYPE_SCROLL_INSENSITIVE</code>.     *     * @return the type of this JDBC <code>RowSet</code>     *         object, which must be one of the following:     *         <code>ResultSet.TYPE_FORWARD_ONLY</code>,     *         <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or     *         <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>     * @throws SQLException if an error occurs getting the type of     *     of this <code>RowSet</code> object     * @see #setType     */    public int getType() throws SQLException {        return rowSetType;    }     /**     * Sets the concurrency for this <code>RowSet</code> object to     * the specified concurrency. The default concurrency for any <code>RowSet</code>     * object (connected or disconnected) is <code>ResultSet.CONCUR_UPDATABLE</code>,     * but this method may be called at any time to change the concurrency.     * <P>     * @param concurrency one of the following constants:     *                    <code>ResultSet.CONCUR_READ_ONLY</code> or     *                    <code>ResultSet.CONCUR_UPDATABLE</code>     * @throws SQLException if the parameter supplied is not one of the     *         following constants:     *          <code>ResultSet.CONCUR_UPDATABLE</code> or     *          <code>ResultSet.CONCUR_READ_ONLY</code>     * @see #getConcurrency     * @see #isReadOnly     */    public void setConcurrency(int concurrency) throws SQLException {         if((concurrency != ResultSet.CONCUR_READ_ONLY) &&           (concurrency != ResultSet.CONCUR_UPDATABLE)) {                throw new SQLException("Invalid concurrency set. Must be either " +                "ResultSet.CONCUR_READ_ONLY or ResultSet.CONCUR_UPDATABLE.");

Lines 501–1000 of 4512. Previous lines