001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package com.sun.sql.rowset;
042:
043: import javax.sql.rowset.*;
044: import java.sql.*;
045: import javax.sql.*;
046: import javax.naming.*;
047: import java.io.*;
048: import java.math.*;
049: import java.util.*;
050:
051: import com.sun.rowset.internal.Row;
052:
053: import com.sun.sql.rowset.internal.CachedRowSetXReader;
054: import com.sun.sql.rowset.internal.CachedRowSetXWriter;
055:
056: import com.sun.sql.rowset.providers.RIOptimisticProvider;
057:
058: /**
059: * The reference implementation of the <code>CachedRowSetX</code> interface. See the interface
060: * defintion for full behavior and implementation requirements.
061: *
062: * Note: This implemenation is based on the Sun Microsystems Reference Implemenation of
063: * <code>CachedRowSet</code>
064: */
065:
066: // public class CachedRowSetXImpl extends BaseRowSetX implements CachedRowSetX, RowSetInternal, Serializable, Cloneable {
067: public class CachedRowSetXImpl extends CachedRowSetXImpl5 {
068:
069: /**
070: * Constructs a default <code>CachedRowSetXImpl</code> object instance.
071: *
072: * Constructs a new default <code>CachedRowSetXImpl</code> object with
073: * the capacity to hold 100 rows. This new object has no metadata
074: * and has the following default values:
075: * <pre>
076: * cursorPos = 0
077: * numRows = 0
078: * showDeleted = false
079: * queryTimeout = 0
080: * maxRows = 0
081: * maxFieldSize = 0
082: * rowSetType = ResultSet.TYPE_SCROLL_INSENSITIVE
083: * concurrency = ResultSet.CONCUR_UPDATABLE
084: * readOnly = false
085: * isolation = Connection.TRANSACTION_READ_COMMITTED
086: * escapeProcessing = true
087: * cursorPos = 0
088: * absolutePos = 0
089: * numRows = 0
090: * </pre>
091: * A <code>CachedRowSetXImpl</code> object is configured to use the default
092: * <code>RIOptimisticProvider</code> implementation to provide connectivity
093: * and synchronization capabilities to the set data source.
094: */
095: public CachedRowSetXImpl() {
096:
097: /*
098: try {
099: // set the Reader, this maybe overridden latter
100: provider = (SyncProvider)SyncFactory.getInstance(DEFAULT_SYNC_PROVIDER);
101: } catch (SQLException e) {
102: throw new RuntimeException(e);
103: }
104: */
105: provider = new RIOptimisticProvider();
106:
107: if (!(provider instanceof RIOptimisticProvider)) {
108: throw new RuntimeException(new SQLException(rb
109: .getString("INVALID_PERSISTENCE_PROV_GEN"))); //NOI18N
110: }
111:
112: rowSetReader = (CachedRowSetXReader) provider.getRowSetReader();
113: rowSetWriter = (CachedRowSetXWriter) provider.getRowSetWriter();
114:
115: // allocate the parameters collection
116: initParams();
117:
118: initContainer();
119:
120: // set up some default values
121: try {
122: initProperties();
123: } catch (SQLException e) {
124: throw new RuntimeException(e);
125: }
126:
127: // set the warninings
128: sqlwarn = new SQLWarning();
129: rowsetWarning = new RowSetWarning();
130: }
131:
132: /*
133: * used internally by readers and writer
134: */
135: static public CachedRowSetXImpl createInternalUseInstance() {
136: CachedRowSetXImpl iucrs = new CachedRowSetXImpl();
137: iucrs.internalUseInstance = true;
138: return iucrs;
139: }
140:
141: /**
142: * Provides a <code>CachedRowSetXImpl</code> instance with the same default properties as
143: * as the zero parameter constructor.
144: * <pre>
145: * cursorPos = 0
146: * numRows = 0
147: * showDeleted = false
148: * queryTimeout = 0
149: * maxRows = 0
150: * maxFieldSize = 0
151: * rowSetType = ResultSet.TYPE_SCROLL_INSENSITIVE
152: * concurrency = ResultSet.CONCUR_UPDATABLE
153: * readOnly = false
154: * isolation = Connection.TRANSACTION_READ_COMMITTED
155: * escapeProcessing = true
156: * onInsertRow = false
157: * cursorPos = 0
158: * absolutePos = 0
159: * numRows = 0
160: * </pre>
161: *
162: * However, applications will have the means to specify at runtime the
163: * desired <code>SyncProvider</code> object.
164: * <p>
165: * For example, creating a <code>CachedRowSetXImpl</code> object as follows ensures
166: * that a it is established with the <code>com.foo.provider.Impl</code> synchronization
167: * implementation providing the synchronization mechanism for this disconnected
168: * <code>RowSet</code> object.
169: * <pre>
170: * Hashtable env = new Hashtable();
171: * env.put(javax.sql.rowset.spi.SyncFactory.ROWSET_PROVIDER_NAME,
172: * "com.foo.provider.Impl");
173: * CachedRowSetXImpl crs = new CachedRowSet(env);
174: * </pre>
175: * <p>
176: * Calling this constructor with a <code>null</code> parameter will
177: * cause the <code>SyncFactory</code> to provide the reference
178: * optimistic provider <code>com.sun.rowset.providers.RIOptimisticProvider</code>.
179: * <p>
180: * In addition, the following properties can be associated with the
181: * provider to assist in determining the choice of the synchronizaton
182: * provider such as:
183: * <ul>
184: * <li><code>ROWSET_SYNC_PROVIDER</code> - the property specifying the the
185: * <code>SyncProvider</code> class name to be instantiated by the
186: * <code>SyncFacttory</code>
187: * <li><code>ROWSET_SYNC_VENDOR</code> - the property specifying the software
188: * vendor associated with a <code>SyncProvider</code> implementation.
189: * <li><code>ROWSET_SYNC_PROVIDER_VER</code> - the property specifying the
190: * version of the <code>SyncProvider</code> implementation provided by the
191: * software vendor.
192: * </ul>
193: * More specific detailes are available in the <code>SyncFactory</code>
194: * and <code>SyncProvider</code> specificiations later in this document.
195: * <p>
196: * @param env a <code>Hashtable</code> object with a list of desired
197: * synchronization providers
198: * @throws SQLException if the requested provider cannot be found by the
199: * synchonization factory
200: * @see SyncProvider
201: */
202: public CachedRowSetXImpl(Hashtable env) throws SQLException {
203:
204: if (env == null) {
205: throw new SQLException(rb.getString("NULL_HASHTABLE")); //NOI18N
206: }
207:
208: /*
209: String providerName = (String)env.get(
210: javax.sql.rowset.spi.SyncFactory.ROWSET_SYNC_PROVIDER);
211:
212: // set the Reader, this maybe overridden latter
213: provider =
214: (SyncProvider)SyncFactory.getInstance(providerName);
215: */
216: provider = new RIOptimisticProvider();
217:
218: rowSetReader = provider.getRowSetReader();
219: rowSetWriter = provider.getRowSetWriter();
220:
221: initParams(); // allocate the parameters collection
222: initContainer();
223: initProperties(); // set up some default values
224: }
225:
226: //-----------------------------------------------------------------------
227: // Properties
228: //-----------------------------------------------------------------------
229:
230: /**
231: * {@inheritDoc}
232: */
233: public void setCommand(String command) throws SQLException {
234:
235: String oldValue = getCommand();
236: super .setCommand(command);
237: release();
238: propertyChangeSupport.firePropertyChange("command", oldValue,
239: command); // NOI18N
240: }
241:
242: //--------------------------JDBC 2.0-----------------------------------
243:
244: /*
245: * RowSetInternal Interface
246: */
247:
248: public ResultSet getOriginal() throws SQLException {
249: checkExecuted();
250: CachedRowSetXImpl crs = CachedRowSetXImpl
251: .createInternalUseInstance();
252: crs.rowSetMD = rowSetMD;
253: crs.numRows = numRows;
254: crs.cursorPos = 0;
255:
256: // make sure we don't get someone playing with these
257: // %%% is this now necessary ???
258: //crs.setReader(null);
259: //crs.setWriter(null);
260: int colCount = rowSetMD.getColumnCount();
261: Row orig;
262:
263: for (Iterator i = rvh.iterator(); i.hasNext();) {
264: orig = new Row(colCount, ((Row) i.next()).getOrigRow());
265: crs.rvh.add(orig);
266: }
267: return (ResultSet) crs;
268: }
269:
270: public ResultSet getOriginalRow() throws SQLException {
271: checkExecuted();
272: CachedRowSetXImpl crs = CachedRowSetXImpl
273: .createInternalUseInstance();
274: crs.rowSetMD = rowSetMD;
275: crs.numRows = 1;
276: crs.cursorPos = 0;
277:
278: // make sure we don't get someone playing with these
279: // %%% is this now necessary ???
280: //crs.setReader(null);
281: //crs.setWriter(null);
282:
283: Row orig = new Row(rowSetMD.getColumnCount(), getCurrentRow()
284: .getOrigRow());
285:
286: crs.rvh.add(orig);
287:
288: return (ResultSet) crs;
289:
290: }
291:
292: //--------------------------------------------------------------------------------
293: // Methods added in JDBC 4.0 (JDK6)
294: //--------------------------------------------------------------------------------
295:
296: public int getHoldability() throws SQLException {
297: throw new UnsupportedOperationException(
298: "Operation not yet supported.");
299: }
300:
301: public Reader getNCharacterStream(int arg0) throws SQLException {
302: throw new UnsupportedOperationException(
303: "Operation not yet supported.");
304: }
305:
306: public Reader getNCharacterStream(String arg0) throws SQLException {
307: throw new UnsupportedOperationException(
308: "Operation not yet supported.");
309: }
310:
311: public NClob getNClob(int arg0) throws SQLException {
312: throw new UnsupportedOperationException(
313: "Operation not yet supported.");
314: }
315:
316: public NClob getNClob(String arg0) throws SQLException {
317: throw new UnsupportedOperationException(
318: "Operation not yet supported.");
319: }
320:
321: public String getNString(int arg0) throws SQLException {
322: throw new UnsupportedOperationException(
323: "Operation not yet supported.");
324: }
325:
326: public String getNString(String arg0) throws SQLException {
327: throw new UnsupportedOperationException(
328: "Operation not yet supported.");
329: }
330:
331: public RowId getRowId(int arg0) throws SQLException {
332: throw new UnsupportedOperationException(
333: "Operation not yet supported.");
334: }
335:
336: public RowId getRowId(String arg0) throws SQLException {
337: throw new UnsupportedOperationException(
338: "Operation not yet supported.");
339: }
340:
341: public SQLXML getSQLXML(int arg0) throws SQLException {
342: throw new UnsupportedOperationException(
343: "Operation not yet supported.");
344: }
345:
346: public SQLXML getSQLXML(String arg0) throws SQLException {
347: throw new UnsupportedOperationException(
348: "Operation not yet supported.");
349: }
350:
351: public boolean isClosed() throws SQLException {
352: throw new UnsupportedOperationException(
353: "Operation not yet supported.");
354: }
355:
356: public void updateAsciiStream(int arg0, InputStream arg1, long arg2)
357: throws SQLException {
358: throw new UnsupportedOperationException(
359: "Operation not yet supported.");
360: }
361:
362: public void updateAsciiStream(String arg0, InputStream arg1,
363: long arg2) throws SQLException {
364: throw new UnsupportedOperationException(
365: "Operation not yet supported.");
366: }
367:
368: public void updateAsciiStream(int arg0, InputStream arg1)
369: throws SQLException {
370: throw new UnsupportedOperationException(
371: "Operation not yet supported.");
372: }
373:
374: public void updateAsciiStream(String arg0, InputStream arg1)
375: throws SQLException {
376: throw new UnsupportedOperationException(
377: "Operation not yet supported.");
378: }
379:
380: public void updateBinaryStream(int arg0, InputStream arg1, long arg2)
381: throws SQLException {
382: throw new UnsupportedOperationException(
383: "Operation not yet supported.");
384: }
385:
386: public void updateBinaryStream(String arg0, InputStream arg1,
387: long arg2) throws SQLException {
388: throw new UnsupportedOperationException(
389: "Operation not yet supported.");
390: }
391:
392: public void updateBinaryStream(int arg0, InputStream arg1)
393: throws SQLException {
394: throw new UnsupportedOperationException(
395: "Operation not yet supported.");
396: }
397:
398: public void updateBinaryStream(String arg0, InputStream arg1)
399: throws SQLException {
400: throw new UnsupportedOperationException(
401: "Operation not yet supported.");
402: }
403:
404: public void updateBlob(int arg0, InputStream arg1, long arg2)
405: throws SQLException {
406: throw new UnsupportedOperationException(
407: "Operation not yet supported.");
408: }
409:
410: public void updateBlob(String arg0, InputStream arg1, long arg2)
411: throws SQLException {
412: throw new UnsupportedOperationException(
413: "Operation not yet supported.");
414: }
415:
416: public void updateBlob(int arg0, InputStream arg1)
417: throws SQLException {
418: throw new UnsupportedOperationException(
419: "Operation not yet supported.");
420: }
421:
422: public void updateBlob(String arg0, InputStream arg1)
423: throws SQLException {
424: throw new UnsupportedOperationException(
425: "Operation not yet supported.");
426: }
427:
428: public void updateCharacterStream(int arg0, Reader arg1, long arg2)
429: throws SQLException {
430: throw new UnsupportedOperationException(
431: "Operation not yet supported.");
432: }
433:
434: public void updateCharacterStream(String arg0, Reader arg1,
435: long arg2) throws SQLException {
436: throw new UnsupportedOperationException(
437: "Operation not yet supported.");
438: }
439:
440: public void updateCharacterStream(int arg0, Reader arg1)
441: throws SQLException {
442: throw new UnsupportedOperationException(
443: "Operation not yet supported.");
444: }
445:
446: public void updateCharacterStream(String arg0, Reader arg1)
447: throws SQLException {
448: throw new UnsupportedOperationException(
449: "Operation not yet supported.");
450: }
451:
452: public void updateClob(int arg0, Reader arg1, long arg2)
453: throws SQLException {
454: throw new UnsupportedOperationException(
455: "Operation not yet supported.");
456: }
457:
458: public void updateClob(String arg0, Reader arg1, long arg2)
459: throws SQLException {
460: throw new UnsupportedOperationException(
461: "Operation not yet supported.");
462: }
463:
464: public void updateClob(int arg0, Reader arg1) throws SQLException {
465: throw new UnsupportedOperationException(
466: "Operation not yet supported.");
467: }
468:
469: public void updateClob(String arg0, Reader arg1)
470: throws SQLException {
471: throw new UnsupportedOperationException(
472: "Operation not yet supported.");
473: }
474:
475: public void updateNCharacterStream(int arg0, Reader arg1, long arg2)
476: throws SQLException {
477: throw new UnsupportedOperationException(
478: "Operation not yet supported.");
479: }
480:
481: public void updateNCharacterStream(String arg0, Reader arg1,
482: long arg2) throws SQLException {
483: throw new UnsupportedOperationException(
484: "Operation not yet supported.");
485: }
486:
487: public void updateNCharacterStream(int arg0, Reader arg1)
488: throws SQLException {
489: throw new UnsupportedOperationException(
490: "Operation not yet supported.");
491: }
492:
493: public void updateNCharacterStream(String arg0, Reader arg1)
494: throws SQLException {
495: throw new UnsupportedOperationException(
496: "Operation not yet supported.");
497: }
498:
499: public void updateNClob(int arg0, NClob arg1) throws SQLException {
500: throw new UnsupportedOperationException(
501: "Operation not yet supported.");
502: }
503:
504: public void updateNClob(String arg0, NClob arg1)
505: throws SQLException {
506: throw new UnsupportedOperationException(
507: "Operation not yet supported.");
508: }
509:
510: public void updateNClob(int arg0, Reader arg1, long arg2)
511: throws SQLException {
512: throw new UnsupportedOperationException(
513: "Operation not yet supported.");
514: }
515:
516: public void updateNClob(String arg0, Reader arg1, long arg2)
517: throws SQLException {
518: throw new UnsupportedOperationException(
519: "Operation not yet supported.");
520: }
521:
522: public void updateNClob(int arg0, Reader arg1) throws SQLException {
523: throw new UnsupportedOperationException(
524: "Operation not yet supported.");
525: }
526:
527: public void updateNClob(String arg0, Reader arg1)
528: throws SQLException {
529: throw new UnsupportedOperationException(
530: "Operation not yet supported.");
531: }
532:
533: public void updateNString(int arg0, String arg1)
534: throws SQLException {
535: throw new UnsupportedOperationException(
536: "Operation not yet supported.");
537: }
538:
539: public void updateNString(String arg0, String arg1)
540: throws SQLException {
541: throw new UnsupportedOperationException(
542: "Operation not yet supported.");
543: }
544:
545: public void updateRowId(int arg0, RowId arg1) throws SQLException {
546: throw new UnsupportedOperationException(
547: "Operation not yet supported.");
548: }
549:
550: public void updateRowId(String arg0, RowId arg1)
551: throws SQLException {
552: throw new UnsupportedOperationException(
553: "Operation not yet supported.");
554: }
555:
556: public void updateSQLXML(int arg0, SQLXML arg1) throws SQLException {
557: throw new UnsupportedOperationException(
558: "Operation not yet supported.");
559: }
560:
561: public void updateSQLXML(String arg0, SQLXML arg1)
562: throws SQLException {
563: throw new UnsupportedOperationException(
564: "Operation not yet supported.");
565: }
566:
567: public boolean isWrapperFor(Class arg0) throws SQLException {
568: return false;
569: }
570:
571: public Object unwrap(Class arg0) throws SQLException {
572: return null;
573: }
574:
575: } //end class
|