feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
101
jdkSrc/jdk8/com/sun/rowset/internal/BaseRow.java
Normal file
101
jdkSrc/jdk8/com/sun/rowset/internal/BaseRow.java
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.rowset.internal;
|
||||
|
||||
import java.sql.*;
|
||||
import java.io.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* The abstract base class from which the classes <code>Row</code>
|
||||
* The class <code>BaseRow</code> stores
|
||||
* a row's original values as an array of <code>Object</code>
|
||||
* values, which can be retrieved with the method <code>getOrigRow</code>.
|
||||
* This class also provides methods for getting and setting individual
|
||||
* values in the row.
|
||||
* <P>
|
||||
* A row's original values are the values it contained before it was last
|
||||
* modified. For example, when the <code>CachedRowSet</code>method
|
||||
* <code>acceptChanges</code> is called, it will reset a row's original
|
||||
* values to be the row's current values. Then, when the row is modified,
|
||||
* the values that were previously the current values will become the row's
|
||||
* original values (the values the row had immediately before it was modified).
|
||||
* If a row has not been modified, its original values are its initial values.
|
||||
* <P>
|
||||
* Subclasses of this class contain more specific details, such as
|
||||
* the conditions under which an exception is thrown or the bounds for
|
||||
* index parameters.
|
||||
*/
|
||||
public abstract class BaseRow implements Serializable, Cloneable {
|
||||
|
||||
/**
|
||||
* Specify the serialVersionUID
|
||||
*/
|
||||
private static final long serialVersionUID = 4152013523511412238L;
|
||||
|
||||
/**
|
||||
* The array containing the original values for this <code>BaseRow</code>
|
||||
* object.
|
||||
* @serial
|
||||
*/
|
||||
protected Object[] origVals;
|
||||
|
||||
/**
|
||||
* Retrieves the values that this row contained immediately
|
||||
* prior to its last modification.
|
||||
*
|
||||
* @return an array of <code>Object</code> values containing this row's
|
||||
* original values
|
||||
*/
|
||||
public Object[] getOrigRow() {
|
||||
Object[] origRow = this.origVals;
|
||||
return (origRow == null) ? null: Arrays.copyOf(origRow, origRow.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the array element at the given index, which is
|
||||
* the original value of column number <i>idx</i> in this row.
|
||||
*
|
||||
* @param idx the index of the element to return
|
||||
* @return the <code>Object</code> value at the given index into this
|
||||
* row's array of original values
|
||||
* @throws SQLException if there is an error
|
||||
*/
|
||||
public abstract Object getColumnObject(int idx) throws SQLException;
|
||||
|
||||
/**
|
||||
* Sets the element at the given index into this row's array of
|
||||
* original values to the given value. Implementations of the classes
|
||||
* <code>Row</code> and determine what happens
|
||||
* when the cursor is on the insert row and when it is on any other row.
|
||||
*
|
||||
* @param idx the index of the element to be set
|
||||
* @param obj the <code>Object</code> to which the element at index
|
||||
* <code>idx</code> to be set
|
||||
* @throws SQLException if there is an error
|
||||
*/
|
||||
public abstract void setColumnObject(int idx, Object obj) throws SQLException;
|
||||
}
|
||||
510
jdkSrc/jdk8/com/sun/rowset/internal/CachedRowSetReader.java
Normal file
510
jdkSrc/jdk8/com/sun/rowset/internal/CachedRowSetReader.java
Normal file
@@ -0,0 +1,510 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.rowset.internal;
|
||||
|
||||
import java.sql.*;
|
||||
import javax.sql.*;
|
||||
import javax.naming.*;
|
||||
import java.io.*;
|
||||
import java.lang.reflect.*;
|
||||
|
||||
import com.sun.rowset.*;
|
||||
import javax.sql.rowset.*;
|
||||
import javax.sql.rowset.spi.*;
|
||||
|
||||
/**
|
||||
* The facility called by the <code>RIOptimisticProvider</code> object
|
||||
* internally to read data into it. The calling <code>RowSet</code> object
|
||||
* must have implemented the <code>RowSetInternal</code> interface
|
||||
* and have the standard <code>CachedRowSetReader</code> object set as its
|
||||
* reader.
|
||||
* <P>
|
||||
* This implementation always reads all rows of the data source,
|
||||
* and it assumes that the <code>command</code> property for the caller
|
||||
* is set with a query that is appropriate for execution by a
|
||||
* <code>PreparedStatement</code> object.
|
||||
* <P>
|
||||
* Typically the <code>SyncFactory</code> manages the <code>RowSetReader</code> and
|
||||
* the <code>RowSetWriter</code> implementations using <code>SyncProvider</code> objects.
|
||||
* Standard JDBC RowSet implementations provide an object instance of this
|
||||
* reader by invoking the <code>SyncProvider.getRowSetReader()</code> method.
|
||||
*
|
||||
* @author Jonathan Bruce
|
||||
* @see javax.sql.rowset.spi.SyncProvider
|
||||
* @see javax.sql.rowset.spi.SyncFactory
|
||||
* @see javax.sql.rowset.spi.SyncFactoryException
|
||||
*/
|
||||
public class CachedRowSetReader implements RowSetReader, Serializable {
|
||||
|
||||
/**
|
||||
* The field that keeps track of whether the writer associated with
|
||||
* this <code>CachedRowSetReader</code> object's rowset has been called since
|
||||
* the rowset was populated.
|
||||
* <P>
|
||||
* When this <code>CachedRowSetReader</code> object reads data into
|
||||
* its rowset, it sets the field <code>writerCalls</code> to 0.
|
||||
* When the writer associated with the rowset is called to write
|
||||
* data back to the underlying data source, its <code>writeData</code>
|
||||
* method calls the method <code>CachedRowSetReader.reset</code>,
|
||||
* which increments <code>writerCalls</code> and returns <code>true</code>
|
||||
* if <code>writerCalls</code> is 1. Thus, <code>writerCalls</code> equals
|
||||
* 1 after the first call to <code>writeData</code> that occurs
|
||||
* after the rowset has had data read into it.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private int writerCalls = 0;
|
||||
|
||||
private boolean userCon = false;
|
||||
|
||||
private int startPosition;
|
||||
|
||||
private JdbcRowSetResourceBundle resBundle;
|
||||
|
||||
public CachedRowSetReader() {
|
||||
try {
|
||||
resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
|
||||
} catch(IOException ioe) {
|
||||
throw new RuntimeException(ioe);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads data from a data source and populates the given
|
||||
* <code>RowSet</code> object with that data.
|
||||
* This method is called by the rowset internally when
|
||||
* the application invokes the method <code>execute</code>
|
||||
* to read a new set of rows.
|
||||
* <P>
|
||||
* After clearing the rowset of its contents, if any, and setting
|
||||
* the number of writer calls to <code>0</code>, this reader calls
|
||||
* its <code>connect</code> method to make
|
||||
* a connection to the rowset's data source. Depending on which
|
||||
* of the rowset's properties have been set, the <code>connect</code>
|
||||
* method will use a <code>DataSource</code> object or the
|
||||
* <code>DriverManager</code> facility to make a connection to the
|
||||
* data source.
|
||||
* <P>
|
||||
* Once the connection to the data source is made, this reader
|
||||
* executes the query in the calling <code>CachedRowSet</code> object's
|
||||
* <code>command</code> property. Then it calls the rowset's
|
||||
* <code>populate</code> method, which reads data from the
|
||||
* <code>ResultSet</code> object produced by executing the rowset's
|
||||
* command. The rowset is then populated with this data.
|
||||
* <P>
|
||||
* This method's final act is to close the connection it made, thus
|
||||
* leaving the rowset disconnected from its data source.
|
||||
*
|
||||
* @param caller a <code>RowSet</code> object that has implemented
|
||||
* the <code>RowSetInternal</code> interface and had
|
||||
* this <code>CachedRowSetReader</code> object set as
|
||||
* its reader
|
||||
* @throws SQLException if there is a database access error, there is a
|
||||
* problem making the connection, or the command property has not
|
||||
* been set
|
||||
*/
|
||||
public void readData(RowSetInternal caller) throws SQLException
|
||||
{
|
||||
Connection con = null;
|
||||
try {
|
||||
CachedRowSet crs = (CachedRowSet)caller;
|
||||
|
||||
// Get rid of the current contents of the rowset.
|
||||
|
||||
/**
|
||||
* Checking added to verify whether page size has been set or not.
|
||||
* If set then do not close the object as certain parameters need
|
||||
* to be maintained.
|
||||
*/
|
||||
|
||||
if(crs.getPageSize() == 0 && crs.size() >0 ) {
|
||||
// When page size is not set,
|
||||
// crs.size() will show the total no of rows.
|
||||
crs.close();
|
||||
}
|
||||
|
||||
writerCalls = 0;
|
||||
|
||||
// Get a connection. This reader assumes that the necessary
|
||||
// properties have been set on the caller to let it supply a
|
||||
// connection.
|
||||
userCon = false;
|
||||
|
||||
con = this.connect(caller);
|
||||
|
||||
// Check our assumptions.
|
||||
if (con == null || crs.getCommand() == null)
|
||||
throw new SQLException(resBundle.handleGetObject("crsreader.connecterr").toString());
|
||||
|
||||
try {
|
||||
con.setTransactionIsolation(crs.getTransactionIsolation());
|
||||
} catch (Exception ex) {
|
||||
;
|
||||
}
|
||||
// Use JDBC to read the data.
|
||||
PreparedStatement pstmt = con.prepareStatement(crs.getCommand());
|
||||
// Pass any input parameters to JDBC.
|
||||
|
||||
decodeParams(caller.getParams(), pstmt);
|
||||
try {
|
||||
pstmt.setMaxRows(crs.getMaxRows());
|
||||
pstmt.setMaxFieldSize(crs.getMaxFieldSize());
|
||||
pstmt.setEscapeProcessing(crs.getEscapeProcessing());
|
||||
pstmt.setQueryTimeout(crs.getQueryTimeout());
|
||||
} catch (Exception ex) {
|
||||
/*
|
||||
* drivers may not support the above - esp. older
|
||||
* drivers being used by the bridge..
|
||||
*/
|
||||
throw new SQLException(ex.getMessage());
|
||||
}
|
||||
|
||||
if(crs.getCommand().toLowerCase().indexOf("select") != -1) {
|
||||
// can be (crs.getCommand()).indexOf("select")) == 0
|
||||
// because we will be getting resultset when
|
||||
// it may be the case that some false select query with
|
||||
// select coming in between instead of first.
|
||||
|
||||
// if ((crs.getCommand()).indexOf("?")) does not return -1
|
||||
// implies a Prepared Statement like query exists.
|
||||
|
||||
ResultSet rs = pstmt.executeQuery();
|
||||
if(crs.getPageSize() == 0){
|
||||
crs.populate(rs);
|
||||
}
|
||||
else {
|
||||
/**
|
||||
* If page size has been set then create a ResultSet object that is scrollable using a
|
||||
* PreparedStatement handle.Also call the populate(ResultSet,int) function to populate
|
||||
* a page of data as specified by the page size.
|
||||
*/
|
||||
pstmt = con.prepareStatement(crs.getCommand(),ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
|
||||
decodeParams(caller.getParams(), pstmt);
|
||||
try {
|
||||
pstmt.setMaxRows(crs.getMaxRows());
|
||||
pstmt.setMaxFieldSize(crs.getMaxFieldSize());
|
||||
pstmt.setEscapeProcessing(crs.getEscapeProcessing());
|
||||
pstmt.setQueryTimeout(crs.getQueryTimeout());
|
||||
} catch (Exception ex) {
|
||||
/*
|
||||
* drivers may not support the above - esp. older
|
||||
* drivers being used by the bridge..
|
||||
*/
|
||||
throw new SQLException(ex.getMessage());
|
||||
}
|
||||
rs = pstmt.executeQuery();
|
||||
crs.populate(rs,startPosition);
|
||||
}
|
||||
rs.close();
|
||||
} else {
|
||||
pstmt.executeUpdate();
|
||||
}
|
||||
|
||||
// Get the data.
|
||||
pstmt.close();
|
||||
try {
|
||||
con.commit();
|
||||
} catch (SQLException ex) {
|
||||
;
|
||||
}
|
||||
// only close connections we created...
|
||||
if (getCloseConnection() == true)
|
||||
con.close();
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
// Throw an exception if reading fails for any reason.
|
||||
throw ex;
|
||||
} finally {
|
||||
try {
|
||||
// only close connections we created...
|
||||
if (con != null && getCloseConnection() == true) {
|
||||
try {
|
||||
if (!con.getAutoCommit()) {
|
||||
con.rollback();
|
||||
}
|
||||
} catch (Exception dummy) {
|
||||
/*
|
||||
* not an error condition, we're closing anyway, but
|
||||
* we'd like to clean up any locks if we can since
|
||||
* it is not clear the connection pool will clean
|
||||
* these connections in a timely manner
|
||||
*/
|
||||
}
|
||||
con.close();
|
||||
con = null;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
// will get exception if something already went wrong, but don't
|
||||
// override that exception with this one
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the writer associated with this reader needs
|
||||
* to reset its state. The writer will need to initialize its state
|
||||
* if new contents have been read since the writer was last called.
|
||||
* This method is called by the writer that was registered with
|
||||
* this reader when components were being wired together.
|
||||
*
|
||||
* @return <code>true</code> if writer associated with this reader needs
|
||||
* to reset the values of its fields; <code>false</code> otherwise
|
||||
* @throws SQLException if an access error occurs
|
||||
*/
|
||||
public boolean reset() throws SQLException {
|
||||
writerCalls++;
|
||||
return writerCalls == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes a connection with the data source for the given
|
||||
* <code>RowSet</code> object. If the rowset's <code>dataSourceName</code>
|
||||
* property has been set, this method uses the JNDI API to retrieve the
|
||||
* <code>DataSource</code> object that it can use to make the connection.
|
||||
* If the url, username, and password properties have been set, this
|
||||
* method uses the <code>DriverManager.getConnection</code> method to
|
||||
* make the connection.
|
||||
* <P>
|
||||
* This method is used internally by the reader and writer associated with
|
||||
* the calling <code>RowSet</code> object; an application never calls it
|
||||
* directly.
|
||||
*
|
||||
* @param caller a <code>RowSet</code> object that has implemented
|
||||
* the <code>RowSetInternal</code> interface and had
|
||||
* this <code>CachedRowSetReader</code> object set as
|
||||
* its reader
|
||||
* @return a <code>Connection</code> object that represents a connection
|
||||
* to the caller's data source
|
||||
* @throws SQLException if an access error occurs
|
||||
*/
|
||||
public Connection connect(RowSetInternal caller) throws SQLException {
|
||||
|
||||
// Get a JDBC connection.
|
||||
if (caller.getConnection() != null) {
|
||||
// A connection was passed to execute(), so use it.
|
||||
// As we are using a connection the user gave us we
|
||||
// won't close it.
|
||||
userCon = true;
|
||||
return caller.getConnection();
|
||||
}
|
||||
else if (((RowSet)caller).getDataSourceName() != null) {
|
||||
// Connect using JNDI.
|
||||
try {
|
||||
Context ctx = new InitialContext();
|
||||
DataSource ds = (DataSource)ctx.lookup
|
||||
(((RowSet)caller).getDataSourceName());
|
||||
|
||||
// Check for username, password,
|
||||
// if it exists try getting a Connection handle through them
|
||||
// else try without these
|
||||
// else throw SQLException
|
||||
|
||||
if(((RowSet)caller).getUsername() != null) {
|
||||
return ds.getConnection(((RowSet)caller).getUsername(),
|
||||
((RowSet)caller).getPassword());
|
||||
} else {
|
||||
return ds.getConnection();
|
||||
}
|
||||
}
|
||||
catch (javax.naming.NamingException ex) {
|
||||
SQLException sqlEx = new SQLException(resBundle.handleGetObject("crsreader.connect").toString());
|
||||
sqlEx.initCause(ex);
|
||||
throw sqlEx;
|
||||
}
|
||||
} else if (((RowSet)caller).getUrl() != null) {
|
||||
// Connect using the driver manager.
|
||||
return DriverManager.getConnection(((RowSet)caller).getUrl(),
|
||||
((RowSet)caller).getUsername(),
|
||||
((RowSet)caller).getPassword());
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parameter placeholders
|
||||
* in the rowset's command (the given <code>PreparedStatement</code>
|
||||
* object) with the parameters in the given array.
|
||||
* This method, called internally by the method
|
||||
* <code>CachedRowSetReader.readData</code>, reads each parameter, and
|
||||
* based on its type, determines the correct
|
||||
* <code>PreparedStatement.setXXX</code> method to use for setting
|
||||
* that parameter.
|
||||
*
|
||||
* @param params an array of parameters to be used with the given
|
||||
* <code>PreparedStatement</code> object
|
||||
* @param pstmt the <code>PreparedStatement</code> object that is the
|
||||
* command for the calling rowset and into which
|
||||
* the given parameters are to be set
|
||||
* @throws SQLException if an access error occurs
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
private void decodeParams(Object[] params,
|
||||
PreparedStatement pstmt) throws SQLException {
|
||||
// There is a corresponding decodeParams in JdbcRowSetImpl
|
||||
// which does the same as this method. This is a design flaw.
|
||||
// Update the JdbcRowSetImpl.decodeParams when you update
|
||||
// this method.
|
||||
|
||||
// Adding the same comments to JdbcRowSetImpl.decodeParams.
|
||||
|
||||
int arraySize;
|
||||
Object[] param = null;
|
||||
|
||||
for (int i=0; i < params.length; i++) {
|
||||
if (params[i] instanceof Object[]) {
|
||||
param = (Object[])params[i];
|
||||
|
||||
if (param.length == 2) {
|
||||
if (param[0] == null) {
|
||||
pstmt.setNull(i + 1, ((Integer)param[1]).intValue());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (param[0] instanceof java.sql.Date ||
|
||||
param[0] instanceof java.sql.Time ||
|
||||
param[0] instanceof java.sql.Timestamp) {
|
||||
System.err.println(resBundle.handleGetObject("crsreader.datedetected").toString());
|
||||
if (param[1] instanceof java.util.Calendar) {
|
||||
System.err.println(resBundle.handleGetObject("crsreader.caldetected").toString());
|
||||
pstmt.setDate(i + 1, (java.sql.Date)param[0],
|
||||
(java.util.Calendar)param[1]);
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
throw new SQLException(resBundle.handleGetObject("crsreader.paramtype").toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (param[0] instanceof Reader) {
|
||||
pstmt.setCharacterStream(i + 1, (Reader)param[0],
|
||||
((Integer)param[1]).intValue());
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
* What's left should be setObject(int, Object, scale)
|
||||
*/
|
||||
if (param[1] instanceof Integer) {
|
||||
pstmt.setObject(i + 1, param[0], ((Integer)param[1]).intValue());
|
||||
continue;
|
||||
}
|
||||
|
||||
} else if (param.length == 3) {
|
||||
|
||||
if (param[0] == null) {
|
||||
pstmt.setNull(i + 1, ((Integer)param[1]).intValue(),
|
||||
(String)param[2]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (param[0] instanceof java.io.InputStream) {
|
||||
switch (((Integer)param[2]).intValue()) {
|
||||
case CachedRowSetImpl.UNICODE_STREAM_PARAM:
|
||||
pstmt.setUnicodeStream(i + 1,
|
||||
(java.io.InputStream)param[0],
|
||||
((Integer)param[1]).intValue());
|
||||
break;
|
||||
case CachedRowSetImpl.BINARY_STREAM_PARAM:
|
||||
pstmt.setBinaryStream(i + 1,
|
||||
(java.io.InputStream)param[0],
|
||||
((Integer)param[1]).intValue());
|
||||
break;
|
||||
case CachedRowSetImpl.ASCII_STREAM_PARAM:
|
||||
pstmt.setAsciiStream(i + 1,
|
||||
(java.io.InputStream)param[0],
|
||||
((Integer)param[1]).intValue());
|
||||
break;
|
||||
default:
|
||||
throw new SQLException(resBundle.handleGetObject("crsreader.paramtype").toString());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* no point at looking at the first element now;
|
||||
* what's left must be the setObject() cases.
|
||||
*/
|
||||
if (param[1] instanceof Integer && param[2] instanceof Integer) {
|
||||
pstmt.setObject(i + 1, param[0], ((Integer)param[1]).intValue(),
|
||||
((Integer)param[2]).intValue());
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new SQLException(resBundle.handleGetObject("crsreader.paramtype").toString());
|
||||
|
||||
} else {
|
||||
// common case - this catches all SQL92 types
|
||||
pstmt.setObject(i + 1, params[i]);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
// Try to get all the params to be set here
|
||||
pstmt.setObject(i + 1, params[i]);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Assists in determining whether the current connection was created by this
|
||||
* CachedRowSet to ensure incorrect connections are not prematurely terminated.
|
||||
*
|
||||
* @return a boolean giving the status of whether the connection has been closed.
|
||||
*/
|
||||
protected boolean getCloseConnection() {
|
||||
if (userCon == true)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This sets the start position in the ResultSet from where to begin. This is
|
||||
* called by the Reader in the CachedRowSetImpl to set the position on the page
|
||||
* to begin populating from.
|
||||
* @param pos integer indicating the position in the <code>ResultSet</code> to begin
|
||||
* populating from.
|
||||
*/
|
||||
public void setStartPosition(int pos){
|
||||
startPosition = pos;
|
||||
}
|
||||
|
||||
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
|
||||
// Default state initialization happens here
|
||||
ois.defaultReadObject();
|
||||
// Initialization of Res Bundle happens here .
|
||||
try {
|
||||
resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
|
||||
} catch(IOException ioe) {
|
||||
throw new RuntimeException(ioe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static final long serialVersionUID =5049738185801363801L;
|
||||
}
|
||||
1470
jdkSrc/jdk8/com/sun/rowset/internal/CachedRowSetWriter.java
Normal file
1470
jdkSrc/jdk8/com/sun/rowset/internal/CachedRowSetWriter.java
Normal file
File diff suppressed because it is too large
Load Diff
179
jdkSrc/jdk8/com/sun/rowset/internal/InsertRow.java
Normal file
179
jdkSrc/jdk8/com/sun/rowset/internal/InsertRow.java
Normal file
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.rowset.internal;
|
||||
|
||||
import com.sun.rowset.JdbcRowSetResourceBundle;
|
||||
import java.sql.*;
|
||||
import javax.sql.*;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* A class used internally to manage a <code>CachedRowSet</code> object's
|
||||
* insert row. This class keeps track of the number of columns in the
|
||||
* insert row and which columns have had a value inserted. It provides
|
||||
* methods for retrieving a column value, setting a column value, and finding
|
||||
* out whether the insert row is complete.
|
||||
*/
|
||||
public class InsertRow extends BaseRow implements Serializable, Cloneable {
|
||||
|
||||
/**
|
||||
* An internal <code>BitSet</code> object used to keep track of the
|
||||
* columns in this <code>InsertRow</code> object that have had a value
|
||||
* inserted.
|
||||
*/
|
||||
private BitSet colsInserted;
|
||||
|
||||
/**
|
||||
* The number of columns in this <code>InsertRow</code> object.
|
||||
*/
|
||||
private int cols;
|
||||
|
||||
private JdbcRowSetResourceBundle resBundle;
|
||||
|
||||
/**
|
||||
* Creates an <code>InsertRow</code> object initialized with the
|
||||
* given number of columns, an array for keeping track of the
|
||||
* original values in this insert row, and a
|
||||
* <code>BitSet</code> object with the same number of bits as
|
||||
* there are columns.
|
||||
*
|
||||
* @param numCols an <code>int</code> indicating the number of columns
|
||||
* in this <code>InsertRow</code> object
|
||||
*/
|
||||
public InsertRow(int numCols) {
|
||||
origVals = new Object[numCols];
|
||||
colsInserted = new BitSet(numCols);
|
||||
cols = numCols;
|
||||
try {
|
||||
resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
|
||||
} catch(IOException ioe) {
|
||||
throw new RuntimeException(ioe);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bit in this <code>InsertRow</code> object's internal
|
||||
* <code>BitSet</code> object that corresponds to the specified column
|
||||
* in this <code>InsertRow</code> object. Setting a bit indicates
|
||||
* that a value has been set.
|
||||
*
|
||||
* @param col the number of the column to be marked as inserted;
|
||||
* the first column is <code>1</code>
|
||||
*/
|
||||
protected void markColInserted(int col) {
|
||||
colsInserted.set(col);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether this <code>InsertRow</code> object has a value
|
||||
* for every column that cannot be null.
|
||||
* @param RowSetMD the <code>RowSetMetaData</code> object for the
|
||||
* <code>CachedRowSet</code> object that maintains this
|
||||
* <code>InsertRow</code> object
|
||||
* @return <code>true</code> if this <code>InsertRow</code> object is
|
||||
* complete; <code>false</code> otherwise
|
||||
* @throws SQLException if there is an error accessing data
|
||||
*/
|
||||
public boolean isCompleteRow(RowSetMetaData RowSetMD) throws SQLException {
|
||||
for (int i = 0; i < cols; i++) {
|
||||
if (colsInserted.get(i) == false &&
|
||||
RowSetMD.isNullable(i + 1) ==
|
||||
ResultSetMetaData.columnNoNulls) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears all the bits in the internal <code>BitSet</code> object
|
||||
* maintained by this <code>InsertRow</code> object. Clearing all the bits
|
||||
* indicates that none of the columns have had a value inserted.
|
||||
*/
|
||||
public void initInsertRow() {
|
||||
for (int i = 0; i < cols; i++) {
|
||||
colsInserted.clear(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the value of the designated column in this
|
||||
* <code>InsertRow</code> object. If no value has been inserted
|
||||
* into the designated column, this method throws an
|
||||
* <code>SQLException</code>.
|
||||
*
|
||||
* @param idx the column number of the value to be retrieved;
|
||||
* the first column is <code>1</code>
|
||||
* @throws SQLException if no value has been inserted into
|
||||
* the designated column
|
||||
*/
|
||||
public Object getColumnObject(int idx) throws SQLException {
|
||||
if (colsInserted.get(idx - 1) == false) {
|
||||
throw new SQLException(resBundle.handleGetObject("insertrow.novalue").toString());
|
||||
}
|
||||
return (origVals[idx - 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the element in this <code>InsertRow</code> object's
|
||||
* internal array of original values that corresponds to the
|
||||
* designated column with the given value. If the third
|
||||
* argument is <code>true</code>,
|
||||
* which means that the cursor is on the insert row, this
|
||||
* <code>InsertRow</code> object's internal <code>BitSet</code> object
|
||||
* is set so that the bit corresponding to the column being set is
|
||||
* turned on.
|
||||
*
|
||||
* @param idx the number of the column in the insert row to be set;
|
||||
* the first column is <code>1</code>
|
||||
* @param val the value to be set
|
||||
*/
|
||||
public void setColumnObject(int idx, Object val) {
|
||||
origVals[idx - 1] = val;
|
||||
markColInserted(idx - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method re populates the resBundle
|
||||
* during the deserialization process
|
||||
*
|
||||
*/
|
||||
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
|
||||
// Default state initialization happens here
|
||||
ois.defaultReadObject();
|
||||
// Initialization of transient Res Bundle happens here .
|
||||
try {
|
||||
resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
|
||||
} catch(IOException ioe) {
|
||||
throw new RuntimeException(ioe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static final long serialVersionUID = 1066099658102869344L;
|
||||
}
|
||||
341
jdkSrc/jdk8/com/sun/rowset/internal/Row.java
Normal file
341
jdkSrc/jdk8/com/sun/rowset/internal/Row.java
Normal file
@@ -0,0 +1,341 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.rowset.internal;
|
||||
|
||||
import java.sql.*;
|
||||
import java.io.*;
|
||||
import java.lang.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* A class that keeps track of a row's values. A <code>Row</code> object
|
||||
* maintains an array of current column values and an array of original
|
||||
* column values, and it provides methods for getting and setting the
|
||||
* value of a column. It also keeps track of which columns have
|
||||
* changed and whether the change was a delete, insert, or update.
|
||||
* <P>
|
||||
* Note that column numbers for rowsets start at <code>1</code>,
|
||||
* whereas the first element of an array or bitset is <code>0</code>.
|
||||
* The argument for the method <code>getColumnUpdated</code> refers to
|
||||
* the column number in the rowset (the first column is <code>1</code>);
|
||||
* the argument for <code>setColumnUpdated</code> refers to the index
|
||||
* into the rowset's internal bitset (the first bit is <code>0</code>).
|
||||
*/
|
||||
public class Row extends BaseRow implements Serializable, Cloneable {
|
||||
|
||||
static final long serialVersionUID = 5047859032611314762L;
|
||||
|
||||
/**
|
||||
* An array containing the current column values for this <code>Row</code>
|
||||
* object.
|
||||
* @serial
|
||||
*/
|
||||
private Object[] currentVals;
|
||||
|
||||
/**
|
||||
* A <code>BitSet</code> object containing a flag for each column in
|
||||
* this <code>Row</code> object, with each flag indicating whether or
|
||||
* not the value in the column has been changed.
|
||||
* @serial
|
||||
*/
|
||||
private BitSet colsChanged;
|
||||
|
||||
/**
|
||||
* A <code>boolean</code> indicating whether or not this <code>Row</code>
|
||||
* object has been deleted. <code>true</code> indicates that it has
|
||||
* been deleted; <code>false</code> indicates that it has not.
|
||||
* @serial
|
||||
*/
|
||||
private boolean deleted;
|
||||
|
||||
/**
|
||||
* A <code>boolean</code> indicating whether or not this <code>Row</code>
|
||||
* object has been updated. <code>true</code> indicates that it has
|
||||
* been updated; <code>false</code> indicates that it has not.
|
||||
* @serial
|
||||
*/
|
||||
private boolean updated;
|
||||
|
||||
/**
|
||||
* A <code>boolean</code> indicating whether or not this <code>Row</code>
|
||||
* object has been inserted. <code>true</code> indicates that it has
|
||||
* been inserted; <code>false</code> indicates that it has not.
|
||||
* @serial
|
||||
*/
|
||||
private boolean inserted;
|
||||
|
||||
/**
|
||||
* The number of columns in this <code>Row</code> object.
|
||||
* @serial
|
||||
*/
|
||||
private int numCols;
|
||||
|
||||
/**
|
||||
* Creates a new <code>Row</code> object with the given number of columns.
|
||||
* The newly-created row includes an array of original values,
|
||||
* an array for storing its current values, and a <code>BitSet</code>
|
||||
* object for keeping track of which column values have been changed.
|
||||
*/
|
||||
public Row(int numCols) {
|
||||
origVals = new Object[numCols];
|
||||
currentVals = new Object[numCols];
|
||||
colsChanged = new BitSet(numCols);
|
||||
this.numCols = numCols;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>Row</code> object with the given number of columns
|
||||
* and with its array of original values initialized to the given array.
|
||||
* The new <code>Row</code> object also has an array for storing its
|
||||
* current values and a <code>BitSet</code> object for keeping track
|
||||
* of which column values have been changed.
|
||||
*/
|
||||
public Row(int numCols, Object[] vals) {
|
||||
origVals = new Object[numCols];
|
||||
System.arraycopy(vals, 0, origVals, 0, numCols);
|
||||
currentVals = new Object[numCols];
|
||||
colsChanged = new BitSet(numCols);
|
||||
this.numCols = numCols;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* This method is called internally by the <code>CachedRowSet.populate</code>
|
||||
* methods.
|
||||
*
|
||||
* @param idx the number of the column in this <code>Row</code> object
|
||||
* that is to be set; the index of the first column is
|
||||
* <code>1</code>
|
||||
* @param val the new value to be set
|
||||
*/
|
||||
public void initColumnObject(int idx, Object val) {
|
||||
origVals[idx - 1] = val;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* This method is called internally by the <code>CachedRowSet.updateXXX</code>
|
||||
* methods.
|
||||
*
|
||||
* @param idx the number of the column in this <code>Row</code> object
|
||||
* that is to be set; the index of the first column is
|
||||
* <code>1</code>
|
||||
* @param val the new value to be set
|
||||
*/
|
||||
public void setColumnObject(int idx, Object val) {
|
||||
currentVals[idx - 1] = val;
|
||||
setColUpdated(idx - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the column value stored in the designated column of this
|
||||
* <code>Row</code> object.
|
||||
*
|
||||
* @param columnIndex the index of the column value to be retrieved;
|
||||
* the index of the first column is <code>1</code>
|
||||
* @return an <code>Object</code> in the Java programming language that
|
||||
* represents the value stored in the designated column
|
||||
* @throws SQLException if there is a database access error
|
||||
*/
|
||||
public Object getColumnObject(int columnIndex) throws SQLException {
|
||||
if (getColUpdated(columnIndex - 1)) {
|
||||
return(currentVals[columnIndex - 1]); // maps to array!!
|
||||
} else {
|
||||
return(origVals[columnIndex - 1]); // maps to array!!
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the designated column of this <code>Row</code> object
|
||||
* has been changed.
|
||||
* @param idx the index into the <code>BitSet</code> object maintained by
|
||||
* this <code>Row</code> object to keep track of which column
|
||||
* values have been modified; the index of the first bit is
|
||||
* <code>0</code>
|
||||
* @return <code>true</code> if the designated column value has been changed;
|
||||
* <code>false</code> otherwise
|
||||
*
|
||||
*/
|
||||
public boolean getColUpdated(int idx) {
|
||||
return colsChanged.get(idx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this <code>Row</code> object's <code>deleted</code> field
|
||||
* to <code>true</code>.
|
||||
*
|
||||
* @see #getDeleted
|
||||
*/
|
||||
public void setDeleted() { // %%% was public
|
||||
deleted = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the value of this <code>Row</code> object's <code>deleted</code> field,
|
||||
* which will be <code>true</code> if one or more of its columns has been
|
||||
* deleted.
|
||||
* @return <code>true</code> if a column value has been deleted; <code>false</code>
|
||||
* otherwise
|
||||
*
|
||||
* @see #setDeleted
|
||||
*/
|
||||
public boolean getDeleted() {
|
||||
return(deleted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the <code>deleted</code> field for this <code>Row</code> object to
|
||||
* <code>false</code>.
|
||||
*/
|
||||
public void clearDeleted() {
|
||||
deleted = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the value of this <code>Row</code> object's <code>inserted</code> field
|
||||
* to <code>true</code>.
|
||||
*
|
||||
* @see #getInserted
|
||||
*/
|
||||
public void setInserted() {
|
||||
inserted = true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the value of this <code>Row</code> object's <code>inserted</code> field,
|
||||
* which will be <code>true</code> if this row has been inserted.
|
||||
* @return <code>true</code> if this row has been inserted; <code>false</code>
|
||||
* otherwise
|
||||
*
|
||||
* @see #setInserted
|
||||
*/
|
||||
public boolean getInserted() {
|
||||
return(inserted);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the <code>inserted</code> field for this <code>Row</code> object to
|
||||
* <code>false</code>.
|
||||
*/
|
||||
public void clearInserted() { // %%% was public
|
||||
inserted = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the value of this <code>Row</code> object's
|
||||
* <code>updated</code> field.
|
||||
* @return <code>true</code> if this <code>Row</code> object has been
|
||||
* updated; <code>false</code> if it has not
|
||||
*
|
||||
* @see #setUpdated
|
||||
*/
|
||||
public boolean getUpdated() {
|
||||
return(updated);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the <code>updated</code> field for this <code>Row</code> object to
|
||||
* <code>true</code> if one or more of its column values has been changed.
|
||||
*
|
||||
* @see #getUpdated
|
||||
*/
|
||||
public void setUpdated() {
|
||||
// only mark something as updated if one or
|
||||
// more of the columns has been changed.
|
||||
for (int i = 0; i < numCols; i++) {
|
||||
if (getColUpdated(i) == true) {
|
||||
updated = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bit at the given index into this <code>Row</code> object's internal
|
||||
* <code>BitSet</code> object, indicating that the corresponding column value
|
||||
* (column <code>idx</code> + 1) has been changed.
|
||||
*
|
||||
* @param idx the index into the <code>BitSet</code> object maintained by
|
||||
* this <code>Row</code> object; the first bit is at index
|
||||
* <code>0</code>
|
||||
*
|
||||
*/
|
||||
private void setColUpdated(int idx) {
|
||||
colsChanged.set(idx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the <code>updated</code> field for this <code>Row</code> object to
|
||||
* <code>false</code>, sets all the column values in this <code>Row</code>
|
||||
* object's internal array of current values to <code>null</code>, and clears
|
||||
* all of the bits in the <code>BitSet</code> object maintained by this
|
||||
* <code>Row</code> object.
|
||||
*/
|
||||
public void clearUpdated() {
|
||||
updated = false;
|
||||
for (int i = 0; i < numCols; i++) {
|
||||
currentVals[i] = null;
|
||||
colsChanged.clear(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the column values in this <code>Row</code> object's internal
|
||||
* array of original values with the values in its internal array of
|
||||
* current values, sets all the values in this <code>Row</code>
|
||||
* object's internal array of current values to <code>null</code>,
|
||||
* clears all the bits in this <code>Row</code> object's internal bitset,
|
||||
* and sets its <code>updated</code> field to <code>false</code>.
|
||||
* <P>
|
||||
* This method is called internally by the <code>CachedRowSet</code>
|
||||
* method <code>makeRowOriginal</code>.
|
||||
*/
|
||||
public void moveCurrentToOrig() {
|
||||
for (int i = 0; i < numCols; i++) {
|
||||
if (getColUpdated(i) == true) {
|
||||
origVals[i] = currentVals[i];
|
||||
currentVals[i] = null;
|
||||
colsChanged.clear(i);
|
||||
}
|
||||
}
|
||||
updated = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the row on which the cursor is positioned.
|
||||
*
|
||||
* @return the <code>Row</code> object on which the <code>CachedRowSet</code>
|
||||
* implementation objects's cursor is positioned
|
||||
*/
|
||||
public BaseRow getCurrentRow() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
4868
jdkSrc/jdk8/com/sun/rowset/internal/SyncResolverImpl.java
Normal file
4868
jdkSrc/jdk8/com/sun/rowset/internal/SyncResolverImpl.java
Normal file
File diff suppressed because it is too large
Load Diff
237
jdkSrc/jdk8/com/sun/rowset/internal/WebRowSetXmlReader.java
Normal file
237
jdkSrc/jdk8/com/sun/rowset/internal/WebRowSetXmlReader.java
Normal file
@@ -0,0 +1,237 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.rowset.internal;
|
||||
|
||||
import java.sql.*;
|
||||
import javax.sql.*;
|
||||
import java.io.*;
|
||||
|
||||
import org.xml.sax.*;
|
||||
import org.xml.sax.helpers.*;
|
||||
import javax.xml.parsers.*;
|
||||
|
||||
import com.sun.rowset.*;
|
||||
import java.text.MessageFormat;
|
||||
import javax.sql.rowset.*;
|
||||
import javax.sql.rowset.spi.*;
|
||||
|
||||
/**
|
||||
* An implementation of the <code>XmlReader</code> interface, which
|
||||
* reads and parses an XML formatted <code>WebRowSet</code> object.
|
||||
* This implementation uses an <code>org.xml.sax.Parser</code> object
|
||||
* as its parser.
|
||||
*/
|
||||
public class WebRowSetXmlReader implements XmlReader, Serializable {
|
||||
|
||||
|
||||
private JdbcRowSetResourceBundle resBundle;
|
||||
|
||||
public WebRowSetXmlReader(){
|
||||
try {
|
||||
resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
|
||||
} catch(IOException ioe) {
|
||||
throw new RuntimeException(ioe);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the given <code>WebRowSet</code> object, getting its input from
|
||||
* the given <code>java.io.Reader</code> object. The parser will send
|
||||
* notifications of parse events to the rowset's
|
||||
* <code>XmlReaderDocHandler</code>, which will build the rowset as
|
||||
* an XML document.
|
||||
* <P>
|
||||
* This method is called internally by the method
|
||||
* <code>WebRowSet.readXml</code>.
|
||||
* <P>
|
||||
* If a parsing error occurs, the exception thrown will include
|
||||
* information for locating the error in the original XML document.
|
||||
*
|
||||
* @param caller the <code>WebRowSet</code> object to be parsed, whose
|
||||
* <code>xmlReader</code> field must contain a reference to
|
||||
* this <code>XmlReader</code> object
|
||||
* @param reader the <code>java.io.Reader</code> object from which
|
||||
* the parser will get its input
|
||||
* @exception SQLException if a database access error occurs or
|
||||
* this <code>WebRowSetXmlReader</code> object is not the
|
||||
* reader for the given rowset
|
||||
* @see XmlReaderContentHandler
|
||||
*/
|
||||
public void readXML(WebRowSet caller, java.io.Reader reader) throws SQLException {
|
||||
try {
|
||||
// Crimson Parser(as in J2SE 1.4.1 is NOT able to handle
|
||||
// Reader(s)(FileReader).
|
||||
//
|
||||
// But getting the file as a Stream works fine. So we are going to take
|
||||
// the reader but send it as a InputStream to the parser. Note that this
|
||||
// functionality needs to work against any parser
|
||||
// Crimson(J2SE 1.4.x) / Xerces(J2SE 1.5.x).
|
||||
InputSource is = new InputSource(reader);
|
||||
DefaultHandler dh = new XmlErrorHandler();
|
||||
XmlReaderContentHandler hndr = new XmlReaderContentHandler((RowSet)caller);
|
||||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
factory.setValidating(true);
|
||||
SAXParser parser = factory.newSAXParser() ;
|
||||
|
||||
parser.setProperty(
|
||||
"http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
|
||||
|
||||
XMLReader reader1 = parser.getXMLReader() ;
|
||||
reader1.setEntityResolver(new XmlResolver());
|
||||
reader1.setContentHandler(hndr);
|
||||
|
||||
reader1.setErrorHandler(dh);
|
||||
|
||||
reader1.parse(is);
|
||||
|
||||
} catch (SAXParseException err) {
|
||||
System.out.println (MessageFormat.format(resBundle.handleGetObject("wrsxmlreader.parseerr").toString(), new Object[]{ err.getMessage (), err.getLineNumber(), err.getSystemId()}));
|
||||
err.printStackTrace();
|
||||
throw new SQLException(err.getMessage());
|
||||
|
||||
} catch (SAXException e) {
|
||||
Exception x = e;
|
||||
if (e.getException () != null)
|
||||
x = e.getException();
|
||||
x.printStackTrace ();
|
||||
throw new SQLException(x.getMessage());
|
||||
|
||||
}
|
||||
|
||||
// Will be here if trying to write beyond the RowSet limits
|
||||
|
||||
catch (ArrayIndexOutOfBoundsException aie) {
|
||||
throw new SQLException(resBundle.handleGetObject("wrsxmlreader.invalidcp").toString());
|
||||
}
|
||||
catch (Throwable e) {
|
||||
throw new SQLException(MessageFormat.format(resBundle.handleGetObject("wrsxmlreader.readxml").toString() , e.getMessage()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses the given <code>WebRowSet</code> object, getting its input from
|
||||
* the given <code>java.io.InputStream</code> object. The parser will send
|
||||
* notifications of parse events to the rowset's
|
||||
* <code>XmlReaderDocHandler</code>, which will build the rowset as
|
||||
* an XML document.
|
||||
* <P>
|
||||
* Using streams is a much faster way than using <code>java.io.Reader</code>
|
||||
* <P>
|
||||
* This method is called internally by the method
|
||||
* <code>WebRowSet.readXml</code>.
|
||||
* <P>
|
||||
* If a parsing error occurs, the exception thrown will include
|
||||
* information for locating the error in the original XML document.
|
||||
*
|
||||
* @param caller the <code>WebRowSet</code> object to be parsed, whose
|
||||
* <code>xmlReader</code> field must contain a reference to
|
||||
* this <code>XmlReader</code> object
|
||||
* @param iStream the <code>java.io.InputStream</code> object from which
|
||||
* the parser will get its input
|
||||
* @throws SQLException if a database access error occurs or
|
||||
* this <code>WebRowSetXmlReader</code> object is not the
|
||||
* reader for the given rowset
|
||||
* @see XmlReaderContentHandler
|
||||
*/
|
||||
public void readXML(WebRowSet caller, java.io.InputStream iStream) throws SQLException {
|
||||
try {
|
||||
InputSource is = new InputSource(iStream);
|
||||
DefaultHandler dh = new XmlErrorHandler();
|
||||
|
||||
XmlReaderContentHandler hndr = new XmlReaderContentHandler((RowSet)caller);
|
||||
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||
factory.setNamespaceAware(true);
|
||||
factory.setValidating(true);
|
||||
|
||||
SAXParser parser = factory.newSAXParser() ;
|
||||
|
||||
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
|
||||
"http://www.w3.org/2001/XMLSchema");
|
||||
|
||||
XMLReader reader1 = parser.getXMLReader() ;
|
||||
reader1.setEntityResolver(new XmlResolver());
|
||||
reader1.setContentHandler(hndr);
|
||||
|
||||
reader1.setErrorHandler(dh);
|
||||
|
||||
reader1.parse(is);
|
||||
|
||||
} catch (SAXParseException err) {
|
||||
System.out.println (MessageFormat.format(resBundle.handleGetObject("wrsxmlreader.parseerr").toString(), new Object[]{err.getLineNumber(), err.getSystemId() }));
|
||||
System.out.println(" " + err.getMessage ());
|
||||
err.printStackTrace();
|
||||
throw new SQLException(err.getMessage());
|
||||
|
||||
} catch (SAXException e) {
|
||||
Exception x = e;
|
||||
if (e.getException () != null)
|
||||
x = e.getException();
|
||||
x.printStackTrace ();
|
||||
throw new SQLException(x.getMessage());
|
||||
|
||||
}
|
||||
|
||||
// Will be here if trying to write beyond the RowSet limits
|
||||
|
||||
catch (ArrayIndexOutOfBoundsException aie) {
|
||||
throw new SQLException(resBundle.handleGetObject("wrsxmlreader.invalidcp").toString());
|
||||
}
|
||||
|
||||
catch (Throwable e) {
|
||||
throw new SQLException(MessageFormat.format(resBundle.handleGetObject("wrsxmlreader.readxml").toString() , e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For code coverage purposes only right now
|
||||
*
|
||||
*/
|
||||
|
||||
public void readData(RowSetInternal caller) {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method re populates the resBundle
|
||||
* during the deserialization process
|
||||
*
|
||||
*/
|
||||
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
|
||||
// Default state initialization happens here
|
||||
ois.defaultReadObject();
|
||||
// Initialization of transient Res Bundle happens here .
|
||||
try {
|
||||
resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
|
||||
} catch(IOException ioe) {
|
||||
throw new RuntimeException(ioe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static final long serialVersionUID = -9127058392819008014L;
|
||||
}
|
||||
680
jdkSrc/jdk8/com/sun/rowset/internal/WebRowSetXmlWriter.java
Normal file
680
jdkSrc/jdk8/com/sun/rowset/internal/WebRowSetXmlWriter.java
Normal file
@@ -0,0 +1,680 @@
|
||||
/*
|
||||
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.rowset.internal;
|
||||
|
||||
import com.sun.rowset.JdbcRowSetResourceBundle;
|
||||
import java.sql.*;
|
||||
import javax.sql.*;
|
||||
import java.io.*;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
|
||||
import javax.sql.rowset.*;
|
||||
import javax.sql.rowset.spi.*;
|
||||
|
||||
/**
|
||||
* An implementation of the <code>XmlWriter</code> interface, which writes a
|
||||
* <code>WebRowSet</code> object to an output stream as an XML document.
|
||||
*/
|
||||
|
||||
public class WebRowSetXmlWriter implements XmlWriter, Serializable {
|
||||
|
||||
/**
|
||||
* The <code>java.io.Writer</code> object to which this <code>WebRowSetXmlWriter</code>
|
||||
* object will write when its <code>writeXML</code> method is called. The value
|
||||
* for this field is set with the <code>java.io.Writer</code> object given
|
||||
* as the second argument to the <code>writeXML</code> method.
|
||||
*/
|
||||
private transient java.io.Writer writer;
|
||||
|
||||
/**
|
||||
* The <code>java.util.Stack</code> object that this <code>WebRowSetXmlWriter</code>
|
||||
* object will use for storing the tags to be used for writing the calling
|
||||
* <code>WebRowSet</code> object as an XML document.
|
||||
*/
|
||||
private java.util.Stack<String> stack;
|
||||
|
||||
private JdbcRowSetResourceBundle resBundle;
|
||||
|
||||
public WebRowSetXmlWriter() {
|
||||
|
||||
try {
|
||||
resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
|
||||
} catch(IOException ioe) {
|
||||
throw new RuntimeException(ioe);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the given <code>WebRowSet</code> object as an XML document
|
||||
* using the given <code>java.io.Writer</code> object. The XML document
|
||||
* will include the <code>WebRowSet</code> object's data, metadata, and
|
||||
* properties. If a data value has been updated, that information is also
|
||||
* included.
|
||||
* <P>
|
||||
* This method is called by the <code>XmlWriter</code> object that is
|
||||
* referenced in the calling <code>WebRowSet</code> object's
|
||||
* <code>xmlWriter</code> field. The <code>XmlWriter.writeXML</code>
|
||||
* method passes to this method the arguments that were supplied to it.
|
||||
*
|
||||
* @param caller the <code>WebRowSet</code> object to be written; must
|
||||
* be a rowset for which this <code>WebRowSetXmlWriter</code> object
|
||||
* is the writer
|
||||
* @param wrt the <code>java.io.Writer</code> object to which
|
||||
* <code>caller</code> will be written
|
||||
* @exception SQLException if a database access error occurs or
|
||||
* this <code>WebRowSetXmlWriter</code> object is not the writer
|
||||
* for the given rowset
|
||||
* @see XmlWriter#writeXML
|
||||
*/
|
||||
public void writeXML(WebRowSet caller, java.io.Writer wrt)
|
||||
throws SQLException {
|
||||
|
||||
// create a new stack for tag checking.
|
||||
stack = new java.util.Stack<>();
|
||||
writer = wrt;
|
||||
writeRowSet(caller);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the given <code>WebRowSet</code> object as an XML document
|
||||
* using the given <code>java.io.OutputStream</code> object. The XML document
|
||||
* will include the <code>WebRowSet</code> object's data, metadata, and
|
||||
* properties. If a data value has been updated, that information is also
|
||||
* included.
|
||||
* <P>
|
||||
* Using stream is a faster way than using <code>java.io.Writer<code/>
|
||||
*
|
||||
* This method is called by the <code>XmlWriter</code> object that is
|
||||
* referenced in the calling <code>WebRowSet</code> object's
|
||||
* <code>xmlWriter</code> field. The <code>XmlWriter.writeXML</code>
|
||||
* method passes to this method the arguments that were supplied to it.
|
||||
*
|
||||
* @param caller the <code>WebRowSet</code> object to be written; must
|
||||
* be a rowset for which this <code>WebRowSetXmlWriter</code> object
|
||||
* is the writer
|
||||
* @param oStream the <code>java.io.OutputStream</code> object to which
|
||||
* <code>caller</code> will be written
|
||||
* @throws SQLException if a database access error occurs or
|
||||
* this <code>WebRowSetXmlWriter</code> object is not the writer
|
||||
* for the given rowset
|
||||
* @see XmlWriter#writeXML
|
||||
*/
|
||||
public void writeXML(WebRowSet caller, java.io.OutputStream oStream)
|
||||
throws SQLException {
|
||||
|
||||
// create a new stack for tag checking.
|
||||
stack = new java.util.Stack<>();
|
||||
writer = new OutputStreamWriter(oStream);
|
||||
writeRowSet(caller);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
private void writeRowSet(WebRowSet caller) throws SQLException {
|
||||
|
||||
try {
|
||||
|
||||
startHeader();
|
||||
|
||||
writeProperties(caller);
|
||||
writeMetaData(caller);
|
||||
writeData(caller);
|
||||
|
||||
endHeader();
|
||||
|
||||
} catch (java.io.IOException ex) {
|
||||
throw new SQLException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.ioex").toString(), ex.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
private void startHeader() throws java.io.IOException {
|
||||
|
||||
setTag("webRowSet");
|
||||
writer.write("<?xml version=\"1.0\"?>\n");
|
||||
writer.write("<webRowSet xmlns=\"http://java.sun.com/xml/ns/jdbc\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
|
||||
writer.write("xsi:schemaLocation=\"http://java.sun.com/xml/ns/jdbc http://java.sun.com/xml/ns/jdbc/webrowset.xsd\">\n");
|
||||
}
|
||||
|
||||
private void endHeader() throws java.io.IOException {
|
||||
endTag("webRowSet");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
private void writeProperties(WebRowSet caller) throws java.io.IOException {
|
||||
|
||||
beginSection("properties");
|
||||
|
||||
try {
|
||||
propString("command", processSpecialCharacters(caller.getCommand()));
|
||||
propInteger("concurrency", caller.getConcurrency());
|
||||
propString("datasource", caller.getDataSourceName());
|
||||
propBoolean("escape-processing",
|
||||
caller.getEscapeProcessing());
|
||||
|
||||
try {
|
||||
propInteger("fetch-direction", caller.getFetchDirection());
|
||||
} catch(SQLException sqle) {
|
||||
// it may be the case that fetch direction has not been set
|
||||
// fetchDir == 0
|
||||
// in that case it will throw a SQLException.
|
||||
// To avoid that catch it here
|
||||
}
|
||||
|
||||
propInteger("fetch-size", caller.getFetchSize());
|
||||
propInteger("isolation-level",
|
||||
caller.getTransactionIsolation());
|
||||
|
||||
beginSection("key-columns");
|
||||
|
||||
int[] kc = caller.getKeyColumns();
|
||||
for (int i = 0; kc != null && i < kc.length; i++)
|
||||
propInteger("column", kc[i]);
|
||||
|
||||
endSection("key-columns");
|
||||
|
||||
//Changed to beginSection and endSection for maps for proper indentation
|
||||
beginSection("map");
|
||||
Map<String, Class<?>> typeMap = caller.getTypeMap();
|
||||
if(typeMap != null) {
|
||||
for(Map.Entry<String, Class<?>> mm : typeMap.entrySet()) {
|
||||
propString("type", mm.getKey());
|
||||
propString("class", mm.getValue().getName());
|
||||
}
|
||||
}
|
||||
endSection("map");
|
||||
|
||||
propInteger("max-field-size", caller.getMaxFieldSize());
|
||||
propInteger("max-rows", caller.getMaxRows());
|
||||
propInteger("query-timeout", caller.getQueryTimeout());
|
||||
propBoolean("read-only", caller.isReadOnly());
|
||||
|
||||
int itype = caller.getType();
|
||||
String strType = "";
|
||||
|
||||
if(itype == 1003) {
|
||||
strType = "ResultSet.TYPE_FORWARD_ONLY";
|
||||
} else if(itype == 1004) {
|
||||
strType = "ResultSet.TYPE_SCROLL_INSENSITIVE";
|
||||
} else if(itype == 1005) {
|
||||
strType = "ResultSet.TYPE_SCROLL_SENSITIVE";
|
||||
}
|
||||
|
||||
propString("rowset-type", strType);
|
||||
|
||||
propBoolean("show-deleted", caller.getShowDeleted());
|
||||
propString("table-name", caller.getTableName());
|
||||
propString("url", caller.getUrl());
|
||||
|
||||
beginSection("sync-provider");
|
||||
// Remove the string after "@xxxx"
|
||||
// before writing it to the xml file.
|
||||
String strProviderInstance = (caller.getSyncProvider()).toString();
|
||||
String strProvider = strProviderInstance.substring(0, (caller.getSyncProvider()).toString().indexOf("@"));
|
||||
|
||||
propString("sync-provider-name", strProvider);
|
||||
propString("sync-provider-vendor", "Oracle Corporation");
|
||||
propString("sync-provider-version", "1.0");
|
||||
propInteger("sync-provider-grade", caller.getSyncProvider().getProviderGrade());
|
||||
propInteger("data-source-lock", caller.getSyncProvider().getDataSourceLock());
|
||||
|
||||
endSection("sync-provider");
|
||||
|
||||
} catch (SQLException ex) {
|
||||
throw new java.io.IOException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.sqlex").toString(), ex.getMessage()));
|
||||
}
|
||||
|
||||
endSection("properties");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
private void writeMetaData(WebRowSet caller) throws java.io.IOException {
|
||||
int columnCount;
|
||||
|
||||
beginSection("metadata");
|
||||
|
||||
try {
|
||||
|
||||
ResultSetMetaData rsmd = caller.getMetaData();
|
||||
columnCount = rsmd.getColumnCount();
|
||||
propInteger("column-count", columnCount);
|
||||
|
||||
for (int colIndex = 1; colIndex <= columnCount; colIndex++) {
|
||||
beginSection("column-definition");
|
||||
|
||||
propInteger("column-index", colIndex);
|
||||
propBoolean("auto-increment", rsmd.isAutoIncrement(colIndex));
|
||||
propBoolean("case-sensitive", rsmd.isCaseSensitive(colIndex));
|
||||
propBoolean("currency", rsmd.isCurrency(colIndex));
|
||||
propInteger("nullable", rsmd.isNullable(colIndex));
|
||||
propBoolean("signed", rsmd.isSigned(colIndex));
|
||||
propBoolean("searchable", rsmd.isSearchable(colIndex));
|
||||
propInteger("column-display-size",rsmd.getColumnDisplaySize(colIndex));
|
||||
propString("column-label", rsmd.getColumnLabel(colIndex));
|
||||
propString("column-name", rsmd.getColumnName(colIndex));
|
||||
propString("schema-name", rsmd.getSchemaName(colIndex));
|
||||
propInteger("column-precision", rsmd.getPrecision(colIndex));
|
||||
propInteger("column-scale", rsmd.getScale(colIndex));
|
||||
propString("table-name", rsmd.getTableName(colIndex));
|
||||
propString("catalog-name", rsmd.getCatalogName(colIndex));
|
||||
propInteger("column-type", rsmd.getColumnType(colIndex));
|
||||
propString("column-type-name", rsmd.getColumnTypeName(colIndex));
|
||||
|
||||
endSection("column-definition");
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
throw new java.io.IOException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.sqlex").toString(), ex.getMessage()));
|
||||
}
|
||||
|
||||
endSection("metadata");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @exception SQLException if a database access error occurs
|
||||
*/
|
||||
private void writeData(WebRowSet caller) throws java.io.IOException {
|
||||
ResultSet rs;
|
||||
|
||||
try {
|
||||
ResultSetMetaData rsmd = caller.getMetaData();
|
||||
int columnCount = rsmd.getColumnCount();
|
||||
int i;
|
||||
|
||||
beginSection("data");
|
||||
|
||||
caller.beforeFirst();
|
||||
caller.setShowDeleted(true);
|
||||
while (caller.next()) {
|
||||
if (caller.rowDeleted() && caller.rowInserted()) {
|
||||
beginSection("modifyRow");
|
||||
} else if (caller.rowDeleted()) {
|
||||
beginSection("deleteRow");
|
||||
} else if (caller.rowInserted()) {
|
||||
beginSection("insertRow");
|
||||
} else {
|
||||
beginSection("currentRow");
|
||||
}
|
||||
|
||||
for (i = 1; i <= columnCount; i++) {
|
||||
if (caller.columnUpdated(i)) {
|
||||
rs = caller.getOriginalRow();
|
||||
rs.next();
|
||||
beginTag("columnValue");
|
||||
writeValue(i, (RowSet)rs);
|
||||
endTag("columnValue");
|
||||
beginTag("updateRow");
|
||||
writeValue(i, caller);
|
||||
endTag("updateRow");
|
||||
} else {
|
||||
beginTag("columnValue");
|
||||
writeValue(i, caller);
|
||||
endTag("columnValue");
|
||||
}
|
||||
}
|
||||
|
||||
endSection(); // this is unchecked
|
||||
}
|
||||
endSection("data");
|
||||
} catch (SQLException ex) {
|
||||
throw new java.io.IOException(MessageFormat.format(resBundle.handleGetObject("wrsxmlwriter.sqlex").toString(), ex.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
private void writeValue(int idx, RowSet caller) throws java.io.IOException {
|
||||
try {
|
||||
int type = caller.getMetaData().getColumnType(idx);
|
||||
|
||||
switch (type) {
|
||||
case java.sql.Types.BIT:
|
||||
case java.sql.Types.BOOLEAN:
|
||||
boolean b = caller.getBoolean(idx);
|
||||
if (caller.wasNull())
|
||||
writeNull();
|
||||
else
|
||||
writeBoolean(b);
|
||||
break;
|
||||
case java.sql.Types.TINYINT:
|
||||
case java.sql.Types.SMALLINT:
|
||||
short s = caller.getShort(idx);
|
||||
if (caller.wasNull())
|
||||
writeNull();
|
||||
else
|
||||
writeShort(s);
|
||||
break;
|
||||
case java.sql.Types.INTEGER:
|
||||
int i = caller.getInt(idx);
|
||||
if (caller.wasNull())
|
||||
writeNull();
|
||||
else
|
||||
writeInteger(i);
|
||||
break;
|
||||
case java.sql.Types.BIGINT:
|
||||
long l = caller.getLong(idx);
|
||||
if (caller.wasNull())
|
||||
writeNull();
|
||||
else
|
||||
writeLong(l);
|
||||
break;
|
||||
case java.sql.Types.REAL:
|
||||
case java.sql.Types.FLOAT:
|
||||
float f = caller.getFloat(idx);
|
||||
if (caller.wasNull())
|
||||
writeNull();
|
||||
else
|
||||
writeFloat(f);
|
||||
break;
|
||||
case java.sql.Types.DOUBLE:
|
||||
double d = caller.getDouble(idx);
|
||||
if (caller.wasNull())
|
||||
writeNull();
|
||||
else
|
||||
writeDouble(d);
|
||||
break;
|
||||
case java.sql.Types.NUMERIC:
|
||||
case java.sql.Types.DECIMAL:
|
||||
writeBigDecimal(caller.getBigDecimal(idx));
|
||||
break;
|
||||
case java.sql.Types.BINARY:
|
||||
case java.sql.Types.VARBINARY:
|
||||
case java.sql.Types.LONGVARBINARY:
|
||||
break;
|
||||
case java.sql.Types.DATE:
|
||||
java.sql.Date date = caller.getDate(idx);
|
||||
if (caller.wasNull())
|
||||
writeNull();
|
||||
else
|
||||
writeLong(date.getTime());
|
||||
break;
|
||||
case java.sql.Types.TIME:
|
||||
java.sql.Time time = caller.getTime(idx);
|
||||
if (caller.wasNull())
|
||||
writeNull();
|
||||
else
|
||||
writeLong(time.getTime());
|
||||
break;
|
||||
case java.sql.Types.TIMESTAMP:
|
||||
java.sql.Timestamp ts = caller.getTimestamp(idx);
|
||||
if (caller.wasNull())
|
||||
writeNull();
|
||||
else
|
||||
writeLong(ts.getTime());
|
||||
break;
|
||||
case java.sql.Types.CHAR:
|
||||
case java.sql.Types.VARCHAR:
|
||||
case java.sql.Types.LONGVARCHAR:
|
||||
writeStringData(caller.getString(idx));
|
||||
break;
|
||||
default:
|
||||
System.out.println(resBundle.handleGetObject("wsrxmlwriter.notproper").toString());
|
||||
//Need to take care of BLOB, CLOB, Array, Ref here
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
throw new java.io.IOException(resBundle.handleGetObject("wrsxmlwriter.failedwrite").toString()+ ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This begins a new tag with a indent
|
||||
*
|
||||
*/
|
||||
private void beginSection(String tag) throws java.io.IOException {
|
||||
// store the current tag
|
||||
setTag(tag);
|
||||
|
||||
writeIndent(stack.size());
|
||||
|
||||
// write it out
|
||||
writer.write("<" + tag + ">\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* This closes a tag started by beginTag with a indent
|
||||
*
|
||||
*/
|
||||
private void endSection(String tag) throws java.io.IOException {
|
||||
writeIndent(stack.size());
|
||||
|
||||
String beginTag = getTag();
|
||||
|
||||
if(beginTag.indexOf("webRowSet") != -1) {
|
||||
beginTag ="webRowSet";
|
||||
}
|
||||
|
||||
if (tag.equals(beginTag) ) {
|
||||
// get the current tag and write it out
|
||||
writer.write("</" + beginTag + ">\n");
|
||||
} else {
|
||||
;
|
||||
}
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
private void endSection() throws java.io.IOException {
|
||||
writeIndent(stack.size());
|
||||
|
||||
// get the current tag and write it out
|
||||
String beginTag = getTag();
|
||||
writer.write("</" + beginTag + ">\n");
|
||||
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
private void beginTag(String tag) throws java.io.IOException {
|
||||
// store the current tag
|
||||
setTag(tag);
|
||||
|
||||
writeIndent(stack.size());
|
||||
|
||||
// write tag out
|
||||
writer.write("<" + tag + ">");
|
||||
}
|
||||
|
||||
private void endTag(String tag) throws java.io.IOException {
|
||||
String beginTag = getTag();
|
||||
if (tag.equals(beginTag)) {
|
||||
// get the current tag and write it out
|
||||
writer.write("</" + beginTag + ">\n");
|
||||
} else {
|
||||
;
|
||||
}
|
||||
writer.flush();
|
||||
}
|
||||
|
||||
private void emptyTag(String tag) throws java.io.IOException {
|
||||
// write an emptyTag
|
||||
writer.write("<" + tag + "/>");
|
||||
}
|
||||
|
||||
private void setTag(String tag) {
|
||||
// add the tag to stack
|
||||
stack.push(tag);
|
||||
}
|
||||
|
||||
private String getTag() {
|
||||
return stack.pop();
|
||||
}
|
||||
|
||||
private void writeNull() throws java.io.IOException {
|
||||
emptyTag("null");
|
||||
}
|
||||
|
||||
private void writeStringData(String s) throws java.io.IOException {
|
||||
if (s == null) {
|
||||
writeNull();
|
||||
} else if (s.equals("")) {
|
||||
writeEmptyString();
|
||||
} else {
|
||||
|
||||
s = processSpecialCharacters(s);
|
||||
|
||||
writer.write(s);
|
||||
}
|
||||
}
|
||||
|
||||
private void writeString(String s) throws java.io.IOException {
|
||||
if (s != null) {
|
||||
writer.write(s);
|
||||
} else {
|
||||
writeNull();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void writeShort(short s) throws java.io.IOException {
|
||||
writer.write(Short.toString(s));
|
||||
}
|
||||
|
||||
private void writeLong(long l) throws java.io.IOException {
|
||||
writer.write(Long.toString(l));
|
||||
}
|
||||
|
||||
private void writeInteger(int i) throws java.io.IOException {
|
||||
writer.write(Integer.toString(i));
|
||||
}
|
||||
|
||||
private void writeBoolean(boolean b) throws java.io.IOException {
|
||||
writer.write(Boolean.valueOf(b).toString());
|
||||
}
|
||||
|
||||
private void writeFloat(float f) throws java.io.IOException {
|
||||
writer.write(Float.toString(f));
|
||||
}
|
||||
|
||||
private void writeDouble(double d) throws java.io.IOException {
|
||||
writer.write(Double.toString(d));
|
||||
}
|
||||
|
||||
private void writeBigDecimal(java.math.BigDecimal bd) throws java.io.IOException {
|
||||
if (bd != null)
|
||||
writer.write(bd.toString());
|
||||
else
|
||||
emptyTag("null");
|
||||
}
|
||||
|
||||
private void writeIndent(int tabs) throws java.io.IOException {
|
||||
// indent...
|
||||
for (int i = 1; i < tabs; i++) {
|
||||
writer.write(" ");
|
||||
}
|
||||
}
|
||||
|
||||
private void propString(String tag, String s) throws java.io.IOException {
|
||||
beginTag(tag);
|
||||
writeString(s);
|
||||
endTag(tag);
|
||||
}
|
||||
|
||||
private void propInteger(String tag, int i) throws java.io.IOException {
|
||||
beginTag(tag);
|
||||
writeInteger(i);
|
||||
endTag(tag);
|
||||
}
|
||||
|
||||
private void propBoolean(String tag, boolean b) throws java.io.IOException {
|
||||
beginTag(tag);
|
||||
writeBoolean(b);
|
||||
endTag(tag);
|
||||
}
|
||||
|
||||
private void writeEmptyString() throws java.io.IOException {
|
||||
emptyTag("emptyString");
|
||||
}
|
||||
/**
|
||||
* Purely for code coverage purposes..
|
||||
*/
|
||||
public boolean writeData(RowSetInternal caller) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function has been added for the processing of special characters
|
||||
* lik <,>,'," and & in the data to be serialized. These have to be taken
|
||||
* of specifically or else there will be parsing error while trying to read
|
||||
* the contents of the XML file.
|
||||
**/
|
||||
|
||||
private String processSpecialCharacters(String s) {
|
||||
|
||||
if(s == null) {
|
||||
return null;
|
||||
}
|
||||
char []charStr = s.toCharArray();
|
||||
String specialStr = "";
|
||||
|
||||
for(int i = 0; i < charStr.length; i++) {
|
||||
if(charStr[i] == '&') {
|
||||
specialStr = specialStr.concat("&");
|
||||
} else if(charStr[i] == '<') {
|
||||
specialStr = specialStr.concat("<");
|
||||
} else if(charStr[i] == '>') {
|
||||
specialStr = specialStr.concat(">");
|
||||
} else if(charStr[i] == '\'') {
|
||||
specialStr = specialStr.concat("'");
|
||||
} else if(charStr[i] == '\"') {
|
||||
specialStr = specialStr.concat(""");
|
||||
} else {
|
||||
specialStr = specialStr.concat(String.valueOf(charStr[i]));
|
||||
}
|
||||
}
|
||||
|
||||
s = specialStr;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method re populates the resBundle
|
||||
* during the deserialization process
|
||||
*
|
||||
*/
|
||||
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
|
||||
// Default state initialization happens here
|
||||
ois.defaultReadObject();
|
||||
// Initialization of transient Res Bundle happens here .
|
||||
try {
|
||||
resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
|
||||
} catch(IOException ioe) {
|
||||
throw new RuntimeException(ioe);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static final long serialVersionUID = 7163134986189677641L;
|
||||
}
|
||||
59
jdkSrc/jdk8/com/sun/rowset/internal/XmlErrorHandler.java
Normal file
59
jdkSrc/jdk8/com/sun/rowset/internal/XmlErrorHandler.java
Normal file
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.rowset.internal;
|
||||
|
||||
import org.xml.sax.*;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
import com.sun.rowset.*;
|
||||
import javax.sql.rowset.*;
|
||||
|
||||
|
||||
/**
|
||||
* An implementation of the <code>DefaultHandler</code> interface, which
|
||||
* handles all the errors, fatalerrors and warnings while reading the xml file.
|
||||
* This is the ErrorHandler which helps <code>WebRowSetXmlReader</code>
|
||||
* to handle any errors while reading the xml data.
|
||||
*/
|
||||
|
||||
|
||||
public class XmlErrorHandler extends DefaultHandler {
|
||||
public int errorCounter = 0;
|
||||
|
||||
public void error(SAXParseException e) throws SAXException {
|
||||
errorCounter++;
|
||||
|
||||
}
|
||||
|
||||
public void fatalError(SAXParseException e) throws SAXException {
|
||||
errorCounter++;
|
||||
|
||||
}
|
||||
|
||||
public void warning(SAXParseException exception) throws SAXException {
|
||||
|
||||
}
|
||||
}
|
||||
1454
jdkSrc/jdk8/com/sun/rowset/internal/XmlReaderContentHandler.java
Normal file
1454
jdkSrc/jdk8/com/sun/rowset/internal/XmlReaderContentHandler.java
Normal file
File diff suppressed because it is too large
Load Diff
56
jdkSrc/jdk8/com/sun/rowset/internal/XmlResolver.java
Normal file
56
jdkSrc/jdk8/com/sun/rowset/internal/XmlResolver.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.rowset.internal;
|
||||
|
||||
import org.xml.sax.*;
|
||||
|
||||
import org.xml.sax.EntityResolver;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
/**
|
||||
* An implementation of the <code>EntityResolver</code> interface, which
|
||||
* reads and parses an XML formatted <code>WebRowSet</code> object.
|
||||
* This is an implementation of org.xml.sax
|
||||
*
|
||||
*/
|
||||
public class XmlResolver implements EntityResolver {
|
||||
|
||||
public InputSource resolveEntity(String publicId, String systemId) {
|
||||
String schemaName = systemId.substring(systemId.lastIndexOf("/"));
|
||||
|
||||
if(systemId.startsWith("http://java.sun.com/xml/ns/jdbc")) {
|
||||
return new InputSource(this.getClass().getResourceAsStream(schemaName));
|
||||
|
||||
} else {
|
||||
// use the default behaviour
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user