Showing the changes to java/pkg/com/sun/rowset/WebRowSetImpl.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,291 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. | |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
| 4 | + * | |
| 5 | + * This code is free software; you can redistribute it and/or modify it | |
| 6 | + * under the terms of the GNU General Public License version 2 only, as | |
| 7 | + * published by the Free Software Foundation. Oracle designates this | |
| 8 | + * particular file as subject to the "Classpath" exception as provided | |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. | |
| 10 | + * | |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT | |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that | |
| 15 | + * accompanied this code). | |
| 16 | + * | |
| 17 | + * You should have received a copy of the GNU General Public License version | |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, | |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 20 | + * | |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
| 22 | + * or visit www.oracle.com if you need additional information or have any | |
| 23 | + * questions. | |
| 24 | + */ | |
| 25 | + | |
| 26 | +package com.sun.rowset; | |
| 27 | + | |
| 28 | +import java.sql.*; | |
| 29 | +import javax.sql.*; | |
| 30 | +import java.io.*; | |
| 31 | +import java.math.*; | |
| 32 | +import java.util.*; | |
| 33 | +import java.text.*; | |
| 34 | + | |
| 35 | +import org.xml.sax.*; | |
| 36 | + | |
| 37 | +import javax.sql.rowset.*; | |
| 38 | +import javax.sql.rowset.spi.*; | |
| 39 | + | |
| 40 | +import com.sun.rowset.providers.*; | |
| 41 | +import com.sun.rowset.internal.*; | |
| 42 | + | |
| 43 | +/** | |
| 44 | + * The standard implementation of the <code>WebRowSet</code> interface. See the interface | |
| 45 | + * defintion for full behaviour and implementation requirements. | |
| 46 | + * | |
| 47 | + * @author Jonathan Bruce, Amit Handa | |
| 48 | + */ | |
| 49 | +public class WebRowSetImpl extends CachedRowSetImpl implements WebRowSet { | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * The <code>WebRowSetXmlReader</code> object that this | |
| 53 | + * <code>WebRowSet</code> object will call when the method | |
| 54 | + * <code>WebRowSet.readXml</code> is invoked. | |
| 55 | + */ | |
| 56 | + private WebRowSetXmlReader xmlReader; | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * The <code>WebRowSetXmlWriter</code> object that this | |
| 60 | + * <code>WebRowSet</code> object will call when the method | |
| 61 | + * <code>WebRowSet.writeXml</code> is invoked. | |
| 62 | + */ | |
| 63 | + private WebRowSetXmlWriter xmlWriter; | |
| 64 | + | |
| 65 | + /* This stores the cursor position prior to calling the writeXML. | |
| 66 | + * This variable is used after the write to restore the position | |
| 67 | + * to the point where the writeXml was called. | |
| 68 | + */ | |
| 69 | + private int curPosBfrWrite; | |
| 70 | + | |
| 71 | + private SyncProvider provider; | |
| 72 | + | |
| 73 | + /** | |
| 74 | + * Constructs a new <code>WebRowSet</code> object initialized with the | |
| 75 | + * default values for a <code>CachedRowSet</code> object instance. This | |
| 76 | + * provides the <code>RIOptimistic</code> provider to deliver | |
| 77 | + * synchronization capabilities to relational datastores and a default | |
| 78 | + * <code>WebRowSetXmlReader</code> object and a default | |
| 79 | + * <code>WebRowSetXmlWriter</code> object to enable XML output | |
| 80 | + * capabilities. | |
| 81 | + * | |
| 82 | + * @throws SQLException if an error occurs in configuring the default | |
| 83 | + * synchronization providers for relational and XML providers. | |
| 84 | + */ | |
| 85 | + public WebRowSetImpl() throws SQLException { | |
| 86 | + super(); | |
| 87 | + | |
| 88 | + // %%% | |
| 89 | + // Needs to use to SPI XmlReader,XmlWriters | |
| 90 | + // | |
| 91 | + xmlReader = new WebRowSetXmlReader(); | |
| 92 | + xmlWriter = new WebRowSetXmlWriter(); | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * Constructs a new <code>WebRowSet</code> object initialized with the the | |
| 97 | + * synchronization SPI provider properties as specified in the <code>Hashtable</code>. If | |
| 98 | + * this hashtable is empty or is <code>null</code> the default constructor is invoked. | |
| 99 | + * | |
| 100 | + * @throws SQLException if an error occurs in configuring the specified | |
| 101 | + * synchronization providers for the relational and XML providers; or | |
| 102 | + * if the Hashtanle is null | |
| 103 | + */ | |
| 104 | + public WebRowSetImpl(Hashtable env) throws SQLException { | |
| 105 | + | |
| 106 | + try { | |
| 107 | + resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle(); | |
| 108 | + } catch(IOException ioe) { | |
| 109 | + throw new RuntimeException(ioe); | |
| 110 | + } | |
| 111 | + | |
| 112 | + if ( env == null) { | |
| 113 | + throw new SQLException(resBundle.handleGetObject("webrowsetimpl.nullhash").toString()); | |
| 114 | + } | |
| 115 | + | |
| 116 | + String providerName = | |
| 117 | + (String)env.get(javax.sql.rowset.spi.SyncFactory.ROWSET_SYNC_PROVIDER); | |
| 118 | + | |
| 119 | + // set the Reader, this maybe overridden latter | |
| 120 | + provider = (SyncProvider)SyncFactory.getInstance(providerName); | |
| 121 | + | |
| 122 | + // xmlReader = provider.getRowSetReader(); | |
| 123 | + // xmlWriter = provider.getRowSetWriter(); | |
| 124 | + } | |
| 125 | + | |
| 126 | + /** | |
| 127 | + * Populates this <code>WebRowSet</code> object with the | |
| 128 | + * data in the given <code>ResultSet</code> object and writes itself | |
| 129 | + * to the given <code>java.io.Writer</code> object in XML format. | |
| 130 | + * This includes the rowset's data, properties, and metadata. | |
| 131 | + * | |
| 132 | + * @throws SQLException if an error occurs writing out the rowset | |
| 133 | + * contents to XML | |
| 134 | + */ | |
| 135 | + public void writeXml(ResultSet rs, java.io.Writer writer) | |
| 136 | + throws SQLException { | |
| 137 | + // WebRowSetImpl wrs = new WebRowSetImpl(); | |
| 138 | + this.populate(rs); | |
| 139 | + | |
| 140 | + // Store the cursor position before writing | |
| 141 | + curPosBfrWrite = this.getRow(); | |
| 142 | + | |
| 143 | + this.writeXml(writer); | |
| 144 | + } | |
| 145 | + | |
| 146 | + /** | |
| 147 | + * Writes this <code>WebRowSet</code> object to the given | |
| 148 | + * <code>java.io.Writer</code> object in XML format. This | |
| 149 | + * includes the rowset's data, properties, and metadata. | |
| 150 | + * | |
| 151 | + * @throws SQLException if an error occurs writing out the rowset | |
| 152 | + * contents to XML | |
| 153 | + */ | |
| 154 | + public void writeXml(java.io.Writer writer) throws SQLException { | |
| 155 | + // %%% | |
| 156 | + // This will change to a XmlReader, which over-rides the default | |
| 157 | + // Xml that is used when a WRS is instantiated. | |
| 158 | + // WebRowSetXmlWriter xmlWriter = getXmlWriter(); | |
| 159 | + if (xmlWriter != null) { | |
| 160 | + | |
| 161 | + // Store the cursor position before writing | |
| 162 | + curPosBfrWrite = this.getRow(); | |
| 163 | + | |
| 164 | + xmlWriter.writeXML(this, writer); | |
| 165 | + } else { | |
| 166 | + throw new SQLException(resBundle.handleGetObject("webrowsetimpl.invalidwr").toString()); | |
| 167 | + } | |
| 168 | + } | |
| 169 | + | |
| 170 | + /** | |
| 171 | + * Reads this <code>WebRowSet</code> object in its XML format. | |
| 172 | + * | |
| 173 | + * @throws SQLException if a database access error occurs | |
| 174 | + */ | |
| 175 | + public void readXml(java.io.Reader reader) throws SQLException { | |
| 176 | + // %%% | |
| 177 | + // This will change to a XmlReader, which over-rides the default | |
| 178 | + // Xml that is used when a WRS is instantiated. | |
| 179 | + //WebRowSetXmlReader xmlReader = getXmlReader(); | |
| 180 | + try { | |
| 181 | + if (reader != null) { | |
| 182 | + xmlReader.readXML(this, reader); | |
| 183 | + | |
| 184 | + // Position is before the first row | |
| 185 | + // The cursor position is to be stored while serializng | |
| 186 | + // and deserializing the WebRowSet Object. | |
| 187 | + if(curPosBfrWrite == 0) { | |
| 188 | + this.beforeFirst(); | |
| 189 | + } | |
| 190 | + | |
| 191 | + // Return the position back to place prior to callin writeXml | |
| 192 | + else { | |
| 193 | + this.absolute(curPosBfrWrite); | |
| 194 | + } | |
| 195 | + | |
| 196 | + } else { | |
| 197 | + throw new SQLException(resBundle.handleGetObject("webrowsetimpl.invalidrd").toString()); | |
| 198 | + } | |
| 199 | + } catch (Exception e) { | |
| 200 | + throw new SQLException(e.getMessage()); | |
| 201 | + } | |
| 202 | + } | |
| 203 | + | |
| 204 | + // Stream based methods | |
| 205 | + /** | |
| 206 | + * Reads a stream based XML input to populate this <code>WebRowSet</code> | |
| 207 | + * object. | |
| 208 | + * | |
| 209 | + * @throws SQLException if a data source access error occurs | |
| 210 | + * @throws IOException if a IO exception occurs | |
| 211 | + */ | |
| 212 | + public void readXml(java.io.InputStream iStream) throws SQLException, IOException { | |
| 213 | + if (iStream != null) { | |
| 214 | + xmlReader.readXML(this, iStream); | |
| 215 | + | |
| 216 | + // Position is before the first row | |
| 217 | + // The cursor position is to be stored while serializng | |
| 218 | + // and deserializing the WebRowSet Object. | |
| 219 | + if(curPosBfrWrite == 0) { | |
| 220 | + this.beforeFirst(); | |
| 221 | + } | |
| 222 | + | |
| 223 | + // Return the position back to place prior to callin writeXml | |
| 224 | + else { | |
| 225 | + this.absolute(curPosBfrWrite); | |
| 226 | + } | |
| 227 | + | |
| 228 | + } else { | |
| 229 | + throw new SQLException(resBundle.handleGetObject("webrowsetimpl.invalidrd").toString()); | |
| 230 | + } | |
| 231 | + } | |
| 232 | + | |
| 233 | + /** | |
| 234 | + * Writes this <code>WebRowSet</code> object to the given <code> OutputStream</code> | |
| 235 | + * object in XML format. | |
| 236 | + * Creates an an output stream of the internal state and contents of a | |
| 237 | + * <code>WebRowSet</code> for XML proceessing | |
| 238 | + * | |
| 239 | + * @throws SQLException if a datasource access error occurs | |
| 240 | + * @throws IOException if an IO exception occurs | |
| 241 | + */ | |
| 242 | + public void writeXml(java.io.OutputStream oStream) throws SQLException, IOException { | |
| 243 | + if (xmlWriter != null) { | |
| 244 | + | |
| 245 | + // Store the cursor position before writing | |
| 246 | + curPosBfrWrite = this.getRow(); | |
| 247 | + | |
| 248 | + xmlWriter.writeXML(this, oStream); | |
| 249 | + } else { | |
| 250 | + throw new SQLException(resBundle.handleGetObject("webrowsetimpl.invalidwr").toString()); | |
| 251 | + } | |
| 252 | + | |
| 253 | + } | |
| 254 | + | |
| 255 | + /** | |
| 256 | + * Populates this <code>WebRowSet</code> object with the | |
| 257 | + * data in the given <code>ResultSet</code> object and writes itself | |
| 258 | + * to the given <code>java.io.OutputStream</code> object in XML format. | |
| 259 | + * This includes the rowset's data, properties, and metadata. | |
| 260 | + * | |
| 261 | + * @throws SQLException if a datasource access error occurs | |
| 262 | + * @throws IOException if an IO exception occurs | |
| 263 | + */ | |
| 264 | + public void writeXml(ResultSet rs, java.io.OutputStream oStream) throws SQLException, IOException { | |
| 265 | + this.populate(rs); | |
| 266 | + | |
| 267 | + // Store the cursor position before writing | |
| 268 | + curPosBfrWrite = this.getRow(); | |
| 269 | + | |
| 270 | + this.writeXml(oStream); | |
| 271 | + } | |
| 272 | + | |
| 273 | + /** | |
| 274 | + * This method re populates the resBundle | |
| 275 | + * during the deserialization process | |
| 276 | + * | |
| 277 | + */ | |
| 278 | + private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { | |
| 279 | + // Default state initialization happens here | |
| 280 | + ois.defaultReadObject(); | |
| 281 | + // Initialization of transient Res Bundle happens here . | |
| 282 | + try { | |
| 283 | + resBundle = JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle(); | |
| 284 | + } catch(IOException ioe) { | |
| 285 | + throw new RuntimeException(ioe); | |
| 286 | + } | |
| 287 | + | |
| 288 | + } | |
| 289 | + | |
| 290 | + static final long serialVersionUID = -8771775154092422943L; | |
| 291 | +} | |