feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,157 @@
/*
* Copyright (c) 2005, 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;
import java.io.*;
import java.util.*;
/**
* This class is used to help in localization of resources,
* especially the exception strings.
*
* @author Amit Handa
*/
public class JdbcRowSetResourceBundle implements Serializable {
/**
* This <code>String</code> variable stores the location
* of the resource bundle location.
*/
private static String fileName;
/**
* This variable will hold the <code>PropertyResourceBundle</code>
* of the text to be internationalized.
*/
private transient PropertyResourceBundle propResBundle;
/**
* The constructor initializes to this object
*
*/
private static volatile JdbcRowSetResourceBundle jpResBundle;
/**
* The variable which will represent the properties
* the suffix or extension of the resource bundle.
**/
private static final String PROPERTIES = "properties";
/**
* The variable to represent underscore
**/
private static final String UNDERSCORE = "_";
/**
* The variable which will represent dot
**/
private static final String DOT = ".";
/**
* The variable which will represent the slash.
**/
private static final String SLASH = "/";
/**
* The variable where the default resource bundle will
* be placed.
**/
private static final String PATH = "com/sun/rowset/RowSetResourceBundle";
/**
* The constructor which initializes the resource bundle.
* Note this is a private constructor and follows Singleton
* Design Pattern.
*
* @throws IOException if unable to load the ResourceBundle
* according to locale or the default one.
*/
private JdbcRowSetResourceBundle () throws IOException {
// Try to load the resource bundle according
// to the locale. Else if no bundle found according
// to the locale load the default.
// In default case the default locale resource bundle
// should always be loaded else it
// will be difficult to throw appropriate
// exception string messages.
Locale locale = Locale.getDefault();
// Load appropriate bundle according to locale
propResBundle = (PropertyResourceBundle) ResourceBundle.getBundle(PATH,
locale, Thread.currentThread().getContextClassLoader());
}
/**
* This method is used to get a handle to the
* initialized instance of this class. Note that
* at any time there is only one instance of this
* class initialized which will be returned.
*
* @throws IOException if unable to find the RowSetResourceBundle.properties
*/
public static JdbcRowSetResourceBundle getJdbcRowSetResourceBundle()
throws IOException {
if(jpResBundle == null){
synchronized(JdbcRowSetResourceBundle.class) {
if(jpResBundle == null){
jpResBundle = new JdbcRowSetResourceBundle();
} //end if
} //end synchronized block
} //end if
return jpResBundle;
}
/**
* This method returns an enumerated handle of the keys
* which correspond to values translated to various locales.
*
* @return an enumeration of keys which have messages tranlated to
* corresponding locales.
*/
@SuppressWarnings("rawtypes")
public Enumeration getKeys() {
return propResBundle.getKeys();
}
/**
* This method takes the key as an argument and
* returns the corresponding value reading it
* from the Resource Bundle loaded earlier.
*
* @return value in locale specific language
* according to the key passed.
*/
public Object handleGetObject(String key) {
return propResBundle.handleGetObject(key);
}
static final long serialVersionUID = 436199386225359954L;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,69 @@
/*
* Copyright (c) 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;
import java.sql.SQLException;
import javax.sql.rowset.CachedRowSet;
import javax.sql.rowset.FilteredRowSet;
import javax.sql.rowset.JdbcRowSet;
import javax.sql.rowset.JoinRowSet;
import javax.sql.rowset.WebRowSet;
import javax.sql.rowset.RowSetFactory;
/**
* This is the implementation specific class for the
* <code>javax.sql.rowset.spi.RowSetFactory</code>. This is the platform
* default implementation for the Java SE platform.
*
* @author Lance Andersen
*
*
* @version 1.7
*/
public final class RowSetFactoryImpl implements RowSetFactory {
public CachedRowSet createCachedRowSet() throws SQLException {
return new com.sun.rowset.CachedRowSetImpl();
}
public FilteredRowSet createFilteredRowSet() throws SQLException {
return new com.sun.rowset.FilteredRowSetImpl();
}
public JdbcRowSet createJdbcRowSet() throws SQLException {
return new com.sun.rowset.JdbcRowSetImpl();
}
public JoinRowSet createJoinRowSet() throws SQLException {
return new com.sun.rowset.JoinRowSetImpl();
}
public WebRowSet createWebRowSet() throws SQLException {
return new com.sun.rowset.WebRowSetImpl();
}
}

View File

@@ -0,0 +1,292 @@
/*
* 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;
import java.sql.*;
import javax.sql.*;
import java.io.*;
import java.math.*;
import java.util.*;
import java.text.*;
import org.xml.sax.*;
import javax.sql.rowset.*;
import javax.sql.rowset.spi.*;
import com.sun.rowset.providers.*;
import com.sun.rowset.internal.*;
/**
* The standard implementation of the <code>WebRowSet</code> interface. See the interface
* definition for full behavior and implementation requirements.
*
* @author Jonathan Bruce, Amit Handa
*/
public class WebRowSetImpl extends CachedRowSetImpl implements WebRowSet {
/**
* The <code>WebRowSetXmlReader</code> object that this
* <code>WebRowSet</code> object will call when the method
* <code>WebRowSet.readXml</code> is invoked.
*/
private WebRowSetXmlReader xmlReader;
/**
* The <code>WebRowSetXmlWriter</code> object that this
* <code>WebRowSet</code> object will call when the method
* <code>WebRowSet.writeXml</code> is invoked.
*/
private WebRowSetXmlWriter xmlWriter;
/* This stores the cursor position prior to calling the writeXML.
* This variable is used after the write to restore the position
* to the point where the writeXml was called.
*/
private int curPosBfrWrite;
private SyncProvider provider;
/**
* Constructs a new <code>WebRowSet</code> object initialized with the
* default values for a <code>CachedRowSet</code> object instance. This
* provides the <code>RIOptimistic</code> provider to deliver
* synchronization capabilities to relational datastores and a default
* <code>WebRowSetXmlReader</code> object and a default
* <code>WebRowSetXmlWriter</code> object to enable XML output
* capabilities.
*
* @throws SQLException if an error occurs in configuring the default
* synchronization providers for relational and XML providers.
*/
public WebRowSetImpl() throws SQLException {
super();
// %%%
// Needs to use to SPI XmlReader,XmlWriters
//
xmlReader = new WebRowSetXmlReader();
xmlWriter = new WebRowSetXmlWriter();
}
/**
* Constructs a new <code>WebRowSet</code> object initialized with the the
* synchronization SPI provider properties as specified in the <code>Hashtable</code>. If
* this hashtable is empty or is <code>null</code> the default constructor is invoked.
*
* @throws SQLException if an error occurs in configuring the specified
* synchronization providers for the relational and XML providers; or
* if the Hashtanle is null
*/
@SuppressWarnings("rawtypes")
public WebRowSetImpl(Hashtable env) throws SQLException {
try {
resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
} catch(IOException ioe) {
throw new RuntimeException(ioe);
}
if ( env == null) {
throw new SQLException(resBundle.handleGetObject("webrowsetimpl.nullhash").toString());
}
String providerName =
(String)env.get(javax.sql.rowset.spi.SyncFactory.ROWSET_SYNC_PROVIDER);
// set the Reader, this maybe overridden latter
provider = SyncFactory.getInstance(providerName);
// xmlReader = provider.getRowSetReader();
// xmlWriter = provider.getRowSetWriter();
}
/**
* Populates this <code>WebRowSet</code> object with the
* data in the given <code>ResultSet</code> object and writes itself
* to the given <code>java.io.Writer</code> object in XML format.
* This includes the rowset's data, properties, and metadata.
*
* @throws SQLException if an error occurs writing out the rowset
* contents to XML
*/
public void writeXml(ResultSet rs, java.io.Writer writer)
throws SQLException {
// WebRowSetImpl wrs = new WebRowSetImpl();
this.populate(rs);
// Store the cursor position before writing
curPosBfrWrite = this.getRow();
this.writeXml(writer);
}
/**
* Writes this <code>WebRowSet</code> object to the given
* <code>java.io.Writer</code> object in XML format. This
* includes the rowset's data, properties, and metadata.
*
* @throws SQLException if an error occurs writing out the rowset
* contents to XML
*/
public void writeXml(java.io.Writer writer) throws SQLException {
// %%%
// This will change to a XmlReader, which over-rides the default
// Xml that is used when a WRS is instantiated.
// WebRowSetXmlWriter xmlWriter = getXmlWriter();
if (xmlWriter != null) {
// Store the cursor position before writing
curPosBfrWrite = this.getRow();
xmlWriter.writeXML(this, writer);
} else {
throw new SQLException(resBundle.handleGetObject("webrowsetimpl.invalidwr").toString());
}
}
/**
* Reads this <code>WebRowSet</code> object in its XML format.
*
* @throws SQLException if a database access error occurs
*/
public void readXml(java.io.Reader reader) throws SQLException {
// %%%
// This will change to a XmlReader, which over-rides the default
// Xml that is used when a WRS is instantiated.
//WebRowSetXmlReader xmlReader = getXmlReader();
try {
if (reader != null) {
xmlReader.readXML(this, reader);
// Position is before the first row
// The cursor position is to be stored while serializng
// and deserializing the WebRowSet Object.
if(curPosBfrWrite == 0) {
this.beforeFirst();
}
// Return the position back to place prior to callin writeXml
else {
this.absolute(curPosBfrWrite);
}
} else {
throw new SQLException(resBundle.handleGetObject("webrowsetimpl.invalidrd").toString());
}
} catch (Exception e) {
throw new SQLException(e.getMessage());
}
}
// Stream based methods
/**
* Reads a stream based XML input to populate this <code>WebRowSet</code>
* object.
*
* @throws SQLException if a data source access error occurs
* @throws IOException if a IO exception occurs
*/
public void readXml(java.io.InputStream iStream) throws SQLException, IOException {
if (iStream != null) {
xmlReader.readXML(this, iStream);
// Position is before the first row
// The cursor position is to be stored while serializng
// and deserializing the WebRowSet Object.
if(curPosBfrWrite == 0) {
this.beforeFirst();
}
// Return the position back to place prior to callin writeXml
else {
this.absolute(curPosBfrWrite);
}
} else {
throw new SQLException(resBundle.handleGetObject("webrowsetimpl.invalidrd").toString());
}
}
/**
* Writes this <code>WebRowSet</code> object to the given <code> OutputStream</code>
* object in XML format.
* Creates an an output stream of the internal state and contents of a
* <code>WebRowSet</code> for XML proceessing
*
* @throws SQLException if a datasource access error occurs
* @throws IOException if an IO exception occurs
*/
public void writeXml(java.io.OutputStream oStream) throws SQLException, IOException {
if (xmlWriter != null) {
// Store the cursor position before writing
curPosBfrWrite = this.getRow();
xmlWriter.writeXML(this, oStream);
} else {
throw new SQLException(resBundle.handleGetObject("webrowsetimpl.invalidwr").toString());
}
}
/**
* Populates this <code>WebRowSet</code> object with the
* data in the given <code>ResultSet</code> object and writes itself
* to the given <code>java.io.OutputStream</code> object in XML format.
* This includes the rowset's data, properties, and metadata.
*
* @throws SQLException if a datasource access error occurs
* @throws IOException if an IO exception occurs
*/
public void writeXml(ResultSet rs, java.io.OutputStream oStream) throws SQLException, IOException {
this.populate(rs);
// Store the cursor position before writing
curPosBfrWrite = this.getRow();
this.writeXml(oStream);
}
/**
* 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 = -8771775154092422943L;
}

View 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;
}

View 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;
}

File diff suppressed because it is too large Load Diff

View 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;
}

View 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;
}
}

File diff suppressed because it is too large Load Diff

View 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;
}

View 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("&amp;");
} else if(charStr[i] == '<') {
specialStr = specialStr.concat("&lt;");
} else if(charStr[i] == '>') {
specialStr = specialStr.concat("&gt;");
} else if(charStr[i] == '\'') {
specialStr = specialStr.concat("&apos;");
} else if(charStr[i] == '\"') {
specialStr = specialStr.concat("&quot;");
} 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;
}

View 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 {
}
}

File diff suppressed because it is too large Load Diff

View 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;
}
}
}

View File

@@ -0,0 +1,262 @@
/*
* 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.providers;
import com.sun.rowset.JdbcRowSetResourceBundle;
import javax.sql.*;
import java.io.*;
import javax.sql.rowset.spi.*;
import com.sun.rowset.internal.*;
/**
* The reference implementation of a JDBC Rowset synchronization provider
* providing optimistic synchronization with a relational datastore
* using any JDBC technology-enabled driver.
* <p>
* <h3>1.0 Backgroud</h3>
* This synchronization provider is registered with the
* <code>SyncFactory</code> by default as the
* <code>com.sun.rowset.providers.RIOptimisticProvider</code>.
* As an extension of the <code>SyncProvider</code> abstract
* class, it provides the reader and writer classes required by disconnected
* rowsets as <code>javax.sql.RowSetReader</code> and <code>javax.sql.RowSetWriter</code>
* interface implementations. As a reference implementation,
* <code>RIOptimisticProvider</code> provides a
* fully functional implementation offering a medium grade classification of
* syncrhonization, namely GRADE_CHECK_MODIFIED_AT_COMMIT. A
* disconnected <code>RowSet</code> implementation using the
* <code>RIOptimisticProvider</code> can expect the writer to
* check only rows that have been modified in the <code>RowSet</code> against
* the values in the data source. If there is a conflict, that is, if a value
* in the data source has been changed by another party, the
* <code>RIOptimisticProvider</code> will not write any of the changes to the data
* source and will throw a <code>SyncProviderException</code> object.
*
* <h3>2.0 Usage</h3>
* Standard disconnected <code>RowSet</code> implementations may opt to use this
* <code>SyncProvider</code> implementation in one of two ways:
* <OL>
* <LI>By specifically calling the <code>setSyncProvider</code> method
defined in the <code>CachedRowSet</code> interface
* <pre>
* CachedRowset crs = new FooCachedRowSetImpl();
* crs.setSyncProvider("com.sun.rowset.providers.RIOptimisticProvider");
* </pre>
* <LI>By specifying it in the constructor of the <code>RowSet</code>
* implementation
* <pre>
* CachedRowset crs = new FooCachedRowSetImpl(
* "com.sun.rowset.providers.RIOptimisticProvider");
* </pre>
* </OL>
* Note that because the <code>RIOptimisticProvider</code> implementation is
* the default provider, it will always be the provider when no provider ID is
* specified to the constructor.
* <P>
* See the standard <code>RowSet</code> reference implementations in the
* <code>com.sun.rowset</code> package for more details.
*
* @author Jonathan Bruce
* @see javax.sql.rowset.spi.SyncProvider
* @see javax.sql.rowset.spi.SyncProviderException
* @see javax.sql.rowset.spi.SyncFactory
* @see javax.sql.rowset.spi.SyncFactoryException
*
*/
public final class RIOptimisticProvider extends SyncProvider implements Serializable {
private CachedRowSetReader reader;
private CachedRowSetWriter writer;
/**
* The unique provider identifier.
*/
private String providerID = "com.sun.rowset.providers.RIOptimisticProvider";
/**
* The vendor name of this SyncProvider implementation
*/
private String vendorName = "Oracle Corporation";
/**
* The version number of this SyncProvider implementation
*/
private String versionNumber = "1.0";
/**
* ResourceBundle
*/
private JdbcRowSetResourceBundle resBundle;
/**
* Creates an <code>RIOptimisticProvider</code> object initialized with the
* fully qualified class name of this <code>SyncProvider</code> implementation
* and a default reader and writer.
* <P>
* This provider is available to all disconnected <code>RowSet</code> implementations
* as the default persistence provider.
*/
public RIOptimisticProvider() {
providerID = this.getClass().getName();
reader = new CachedRowSetReader();
writer = new CachedRowSetWriter();
try {
resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
} catch(IOException ioe) {
throw new RuntimeException(ioe);
}
}
/**
* Returns the <code>'javax.sql.rowset.providers.RIOptimisticProvider'</code>
* provider identification string.
*
* @return String Provider ID of this persistence provider
*/
public String getProviderID() {
return providerID;
}
/**
* Returns the <code>javax.sql.RowSetWriter</code> object for this
* <code>RIOptimisticProvider</code> object. This is the writer that will
* write changes made to the <code>Rowset</code> object back to the data source.
*
* @return the <code>javax.sql.RowSetWriter</code> object for this
* <code>RIOptimisticProvider</code> object
*/
public RowSetWriter getRowSetWriter() {
try {
writer.setReader(reader);
} catch (java.sql.SQLException e) {}
return writer;
}
/**
* Returns the <code>javax.sql.RowSetReader</code> object for this
* <code>RIOptimisticProvider</code> object. This is the reader that will
* populate a <code>RowSet</code> object using this <code>RIOptimisticProvider</code>.
*
* @return the <code>javax.sql.RowSetReader</code> object for this
* <code>RIOptimisticProvider</code> object
*/
public RowSetReader getRowSetReader() {
return reader;
}
/**
* Returns the <code>SyncProvider</code> grade of synchronization that
* <code>RowSet</code> objects can expect when using this
* implementation. As an optimisic synchonization provider, the writer
* will only check rows that have been modified in the <code>RowSet</code>
* object.
*/
public int getProviderGrade() {
return SyncProvider.GRADE_CHECK_MODIFIED_AT_COMMIT;
}
/**
* Modifies the data source lock severity according to the standard
* <code>SyncProvider</code> classifications.
*
* @param datasource_lock An <code>int</code> indicating the level of locking to be
* set; must be one of the following constants:
* <PRE>
* SyncProvider.DATASOURCE_NO_LOCK,
* SyncProvider.DATASOURCE_ROW_LOCK,
* SyncProvider.DATASOURCE_TABLE_LOCK,
* SyncProvider.DATASOURCE_DB_LOCk
* </PRE>
* @throws SyncProviderException if the parameter specified is not
* <code>SyncProvider.DATASOURCE_NO_LOCK</code>
*/
public void setDataSourceLock(int datasource_lock) throws SyncProviderException {
if(datasource_lock != SyncProvider.DATASOURCE_NO_LOCK ) {
throw new SyncProviderException(resBundle.handleGetObject("riop.locking").toString());
}
}
/**
* Returns the active data source lock severity in this
* reference implementation of the <code>SyncProvider</code>
* abstract class.
*
* @return <code>SyncProvider.DATASOURCE_NO_LOCK</code>.
* The reference implementation does not support data source locks.
*/
public int getDataSourceLock() throws SyncProviderException {
return SyncProvider.DATASOURCE_NO_LOCK;
}
/**
* Returns the supported updatable view abilities of the
* reference implementation of the <code>SyncProvider</code>
* abstract class.
*
* @return <code>SyncProvider.NONUPDATABLE_VIEW_SYNC</code>. The
* the reference implementation does not support updating tables
* that are the source of a view.
*/
public int supportsUpdatableView() {
return SyncProvider.NONUPDATABLE_VIEW_SYNC;
}
/**
* Returns the release version ID of the Reference Implementation Optimistic
* Synchronization Provider.
*
* @return the <code>String</code> detailing the version number of this SyncProvider
*/
public String getVersion() {
return this.versionNumber;
}
/**
* Returns the vendor name of the Reference Implementation Optimistic
* Synchronization Provider
*
* @return the <code>String</code> detailing the vendor name of this
* SyncProvider
*/
public String getVendor() {
return this.vendorName;
}
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 =-3143367176751761936L;
}

View File

@@ -0,0 +1,248 @@
/*
* 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.providers;
import com.sun.rowset.JdbcRowSetResourceBundle;
import java.io.IOException;
import java.sql.*;
import javax.sql.*;
import javax.sql.rowset.spi.*;
/**
* A reference implementation of a JDBC RowSet synchronization provider
* with the ability to read and write rowsets in well formed XML using the
* standard WebRowSet schema.
*
* <h3>1.0 Background</h3>
* This synchronization provider is registered with the
* <code>SyncFactory</code> by default as the
* <code>com.sun.rowset.providers.RIXMLProvider</code>.
* <P>
* A <code>WebRowSet</code> object uses an <code>RIXMLProvider</code> implementation
* to read an XML data source or to write itself in XML format using the
* <code>WebRowSet</code> XML schema definition available at
* <pre>
* <a href="http://java.sun.com/xml/ns/jdbc/webrowset.xsd">http://java.sun.com/xml/ns/jdbc/webrowset.xsd</a>
* </pre>
* The <code>RIXMLProvider</code> implementation has a synchronization level of
* GRADE_NONE, which means that it does no checking at all for conflicts. It
* simply writes a <code>WebRowSet</code> object to a file.
* <h3>2.0 Usage</h3>
* A <code>WebRowSet</code> implementation is created with an <code>RIXMLProvider</code>
* by default.
* <pre>
* WebRowSet wrs = new FooWebRowSetImpl();
* </pre>
* The <code>SyncFactory</code> always provides an instance of
* <code>RIOptimisticProvider</code> when no provider is specified,
* but the implementation of the default constructor for <code>WebRowSet</code> sets the
* provider to be the <code>RIXMLProvider</code> implementation. Therefore,
* the following line of code is executed behind the scenes as part of the
* implementation of the default constructor.
* <pre>
* wrs.setSyncProvider("com.sun.rowset.providers.RIXMLProvider");
* </pre>
* See the standard <code>RowSet</code> reference implementations in the
* <code>com.sun.rowset</code> package for more details.
*
* @author Jonathan Bruce
* @see javax.sql.rowset.spi.SyncProvider
* @see javax.sql.rowset.spi.SyncProviderException
* @see javax.sql.rowset.spi.SyncFactory
* @see javax.sql.rowset.spi.SyncFactoryException
*/
public final class RIXMLProvider extends SyncProvider {
/**
* The unique provider identifier.
*/
private String providerID = "com.sun.rowset.providers.RIXMLProvider";
/**
* The vendor name of this SyncProvider implementation.
*/
private String vendorName = "Oracle Corporation";
/**
* The version number of this SyncProvider implementation.
*/
private String versionNumber = "1.0";
private JdbcRowSetResourceBundle resBundle;
private XmlReader xmlReader;
private XmlWriter xmlWriter;
/**
* This provider is available to all JDBC <code>RowSet</code> implementations as the
* default persistence provider.
*/
public RIXMLProvider() {
providerID = this.getClass().getName();
try {
resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle();
} catch(IOException ioe) {
throw new RuntimeException(ioe);
}
}
/**
* Returns <code>"javax.sql.rowset.providers.RIXMLProvider"</code>, which is
* the fully qualified class name of this provider implementation.
*
* @return a <code>String</code> object with the fully specified class name of
* this <code>RIOptimisticProvider</code> implementation
*/
public String getProviderID() {
return providerID;
}
// additional methods that sit on top of reader/writer methods back to
// original datasource. Allow XML state to be written out and in
/**
* Sets this <code>WebRowSet</code> object's reader to the given
* <code>XmlReader</code> object.
*
* @throws SQLException if a database access error occurs
*/
public void setXmlReader(XmlReader reader) throws SQLException {
xmlReader = reader;
}
/**
* Sets this <code>WebRowSet</code> object's writer to the given
* <code>XmlWriter</code> object.
*
* @throws SQLException if a database access error occurs
*/
public void setXmlWriter(XmlWriter writer) throws SQLException {
xmlWriter = writer;
}
/**
* Retrieves the reader that this <code>WebRowSet</code> object
* will call when its <code>readXml</code> method is called.
*
* @return the <code>XmlReader</code> object for this SyncProvider
* @throws SQLException if a database access error occurs
*/
public XmlReader getXmlReader() throws SQLException {
return xmlReader;
}
/**
* Retrieves the writer that this <code>WebRowSet</code> object
* will call when its <code>writeXml</code> method is called.
*
* @return the <code>XmlWriter</code> for this SyncProvider
* @throws SQLException if a database access error occurs
*/
public XmlWriter getXmlWriter() throws SQLException {
return xmlWriter;
}
/**
* Returns the <code>SyncProvider</code> grade of syncrhonization that
* <code>RowSet</code> object instances can expect when using this
* implementation. As this implementation provides no synchonization
* facilities to the XML data source, the lowest grade is returned.
*
* @return the <code>SyncProvider</code> syncronization grade of this
* provider; must be one of the following constants:
* <PRE>
* SyncProvider.GRADE_NONE,
* SyncProvider.GRADE_MODIFIED_AT_COMMIT,
* SyncProvider.GRADE_CHECK_ALL_AT_COMMIT,
* SyncProvider.GRADE_LOCK_WHEN_MODIFIED,
* SyncProvider.GRADE_LOCK_WHEN_LOADED
* </PRE>
*
*/
public int getProviderGrade() {
return SyncProvider.GRADE_NONE;
}
/**
* Returns the default UPDATABLE_VIEW behavior of this reader
*
*/
public int supportsUpdatableView() {
return SyncProvider.NONUPDATABLE_VIEW_SYNC;
}
/**
* Returns the default DATASOURCE_LOCK behavior of this reader
*/
public int getDataSourceLock() throws SyncProviderException {
return SyncProvider.DATASOURCE_NO_LOCK;
}
/**
* Throws an unsupported operation exception as this method does
* function with non-locking XML data sources.
*/
public void setDataSourceLock(int lock) throws SyncProviderException {
throw new UnsupportedOperationException(resBundle.handleGetObject("rixml.unsupp").toString());
}
/**
* Returns a null object as RowSetWriters are not returned by this SyncProvider
*/
public RowSetWriter getRowSetWriter() {
return null;
}
/**
* Returns a null object as RowSetWriter objects are not returned by this
* SyncProvider
*/
public RowSetReader getRowSetReader() {
return null;
}
/**
* Returns the release version ID of the Reference Implementation Optimistic
* Synchronization Provider.
*
* @return the <code>String</code> detailing the version number of this SyncProvider
*/
public String getVersion() {
return this.versionNumber;
}
/**
* Returns the vendor name of the Reference Implemntation Optimistic
* Syncchronication Provider
*
* @return the <code>String</code> detailing the vendor name of this
* SyncProvider
*/
public String getVendor() {
return this.vendorName;
}
}