001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.sql.internal.rowset;
019:
020: import java.io.InputStream;
021: import java.io.Reader;
022: import java.math.BigDecimal;
023: import java.sql.Array;
024: import java.sql.Blob;
025: import java.sql.Clob;
026: import java.sql.Date;
027: import java.sql.Ref;
028: import java.sql.ResultSetMetaData;
029: import java.sql.SQLException;
030: import java.sql.SQLWarning;
031: import java.sql.Statement;
032: import java.sql.Time;
033: import java.sql.Timestamp;
034: import java.util.ArrayList;
035: import java.util.Calendar;
036: import java.util.List;
037: import java.util.Map;
038:
039: import javax.sql.RowSetMetaData;
040: import javax.sql.rowset.BaseRowSet;
041: import javax.sql.rowset.spi.SyncResolver;
042:
043: import org.apache.harmony.luni.util.NotImplementedException;
044: import org.apache.harmony.sql.internal.nls.Messages;
045:
046: /**
047: * TODO seems RI's implementation is not complete, now we follow RI throw
048: * <code>UnsupportedOperationException</code>. To complete implementation of
049: * this class may need extends
050: * org.apache.harmony.sql.internal.rowset.CachedRowSetImpl class
051: *
052: */
053: public class SyncResolverImpl extends BaseRowSet implements
054: SyncResolver {
055:
056: private static final long serialVersionUID = 4964648528867743289L;
057:
058: private List<ConflictedRow> conflictRows;
059:
060: private int currentIndex;
061:
062: private RowSetMetaData metadata;
063:
064: private static class ConflictedRow {
065: CachedRow row;
066:
067: int index;
068:
069: int status;
070:
071: public ConflictedRow(CachedRow row, int index, int status) {
072: this .row = row;
073: this .index = index;
074: this .status = status;
075: }
076: }
077:
078: public SyncResolverImpl(RowSetMetaData metadata) {
079: super ();
080: this .metadata = metadata;
081: conflictRows = new ArrayList<ConflictedRow>();
082: currentIndex = -1;
083: }
084:
085: public void addConflictRow(CachedRow row, int rowIndex, int status) {
086: conflictRows.add(new ConflictedRow(row, rowIndex, status));
087: }
088:
089: public Object getConflictValue(int index) throws SQLException {
090: if (index <= 0 || index > metadata.getColumnCount()) {
091: // sql.27=Invalid column index :{0}
092: throw new SQLException(Messages.getString("sql.27", Integer //$NON-NLS-1$
093: .valueOf(index)));
094: }
095:
096: if (currentIndex < 0 || currentIndex >= conflictRows.size()) {
097: // rowset.7=Not a valid cursor
098: throw new SQLException(Messages.getString("rowset.7")); //$NON-NLS-1$
099: }
100:
101: return conflictRows.get(currentIndex).row.getObject(index);
102: }
103:
104: public Object getConflictValue(String columnName)
105: throws SQLException {
106: return getConflictValue(getIndexByName(columnName));
107: }
108:
109: public int getStatus() {
110: if (currentIndex < 0 || currentIndex >= conflictRows.size()) {
111: /*
112: * invalid cursor, can't throw SQLException, we throw
113: * NullPointerException instead
114: */
115: // rowset.7=Not a valid cursor
116: throw new NullPointerException(Messages
117: .getString("rowset.7")); //$NON-NLS-1$
118: }
119:
120: return conflictRows.get(currentIndex).status;
121: }
122:
123: /**
124: * TODO close input stream and clear warning chain as spec say
125: */
126: public boolean nextConflict() throws SQLException {
127: if (currentIndex == conflictRows.size()) {
128: return false;
129: }
130:
131: currentIndex++;
132: return currentIndex >= 0 && currentIndex < conflictRows.size();
133: }
134:
135: public boolean previousConflict() throws SQLException {
136: if (currentIndex == -1) {
137: return false;
138: }
139:
140: currentIndex--;
141: return currentIndex >= 0 && currentIndex < conflictRows.size();
142: }
143:
144: public void setResolvedValue(int index, Object obj)
145: throws SQLException {
146: // TODO not yet implemented
147: throw new NotImplementedException();
148:
149: }
150:
151: public void setResolvedValue(String columnName, Object obj)
152: throws SQLException {
153: setResolvedValue(getIndexByName(columnName), obj);
154: }
155:
156: public int getRow() throws SQLException {
157: if (currentIndex < 0 || currentIndex >= conflictRows.size()) {
158: return 0;
159: }
160: return conflictRows.get(currentIndex).index;
161: }
162:
163: private int getIndexByName(String columnName) throws SQLException {
164: for (int i = 1; i <= metadata.getColumnCount(); i++) {
165: if (columnName.equalsIgnoreCase(metadata.getColumnName(i))) {
166: return i;
167: }
168: }
169: // rowset.1=Not a valid column name
170: throw new SQLException(Messages.getString("rowset.1"));
171: }
172:
173: public void execute() throws SQLException {
174: throw new UnsupportedOperationException();
175: }
176:
177: public boolean absolute(int row) throws SQLException {
178: throw new UnsupportedOperationException();
179: }
180:
181: public void afterLast() throws SQLException {
182: throw new UnsupportedOperationException();
183: }
184:
185: public void beforeFirst() throws SQLException {
186: throw new UnsupportedOperationException();
187: }
188:
189: public void cancelRowUpdates() throws SQLException {
190: throw new UnsupportedOperationException();
191: }
192:
193: public void clearWarnings() throws SQLException {
194: throw new UnsupportedOperationException();
195: }
196:
197: public void close() throws SQLException {
198: throw new UnsupportedOperationException();
199: }
200:
201: public void deleteRow() throws SQLException {
202: throw new UnsupportedOperationException();
203: }
204:
205: public int findColumn(String columnName) throws SQLException {
206: throw new UnsupportedOperationException();
207: }
208:
209: public boolean first() throws SQLException {
210: throw new UnsupportedOperationException();
211: }
212:
213: public Array getArray(int columnIndex) throws SQLException {
214: throw new UnsupportedOperationException();
215: }
216:
217: public Array getArray(String colName) throws SQLException {
218: throw new UnsupportedOperationException();
219: }
220:
221: public InputStream getAsciiStream(int columnIndex)
222: throws SQLException {
223: throw new UnsupportedOperationException();
224: }
225:
226: public InputStream getAsciiStream(String columnName)
227: throws SQLException {
228: throw new UnsupportedOperationException();
229: }
230:
231: public BigDecimal getBigDecimal(int columnIndex)
232: throws SQLException {
233: throw new UnsupportedOperationException();
234: }
235:
236: public BigDecimal getBigDecimal(int columnIndex, int scale)
237: throws SQLException {
238: throw new UnsupportedOperationException();
239: }
240:
241: public BigDecimal getBigDecimal(String columnName)
242: throws SQLException {
243: throw new UnsupportedOperationException();
244: }
245:
246: public BigDecimal getBigDecimal(String columnName, int scale)
247: throws SQLException {
248: throw new UnsupportedOperationException();
249: }
250:
251: public InputStream getBinaryStream(int columnIndex)
252: throws SQLException {
253: throw new UnsupportedOperationException();
254: }
255:
256: public InputStream getBinaryStream(String columnName)
257: throws SQLException {
258: throw new UnsupportedOperationException();
259: }
260:
261: public Blob getBlob(int columnIndex) throws SQLException {
262: throw new UnsupportedOperationException();
263: }
264:
265: public Blob getBlob(String columnName) throws SQLException {
266: throw new UnsupportedOperationException();
267: }
268:
269: public boolean getBoolean(int columnIndex) throws SQLException {
270: throw new UnsupportedOperationException();
271: }
272:
273: public boolean getBoolean(String columnName) throws SQLException {
274: throw new UnsupportedOperationException();
275: }
276:
277: public byte getByte(int columnIndex) throws SQLException {
278: throw new UnsupportedOperationException();
279: }
280:
281: public byte getByte(String columnName) throws SQLException {
282: throw new UnsupportedOperationException();
283: }
284:
285: public byte[] getBytes(int columnIndex) throws SQLException {
286: throw new UnsupportedOperationException();
287: }
288:
289: public byte[] getBytes(String columnName) throws SQLException {
290: throw new UnsupportedOperationException();
291: }
292:
293: public Reader getCharacterStream(int columnIndex)
294: throws SQLException {
295: throw new UnsupportedOperationException();
296: }
297:
298: public Reader getCharacterStream(String columnName)
299: throws SQLException {
300: throw new UnsupportedOperationException();
301: }
302:
303: public Clob getClob(int columnIndex) throws SQLException {
304: throw new UnsupportedOperationException();
305: }
306:
307: public Clob getClob(String colName) throws SQLException {
308: throw new UnsupportedOperationException();
309: }
310:
311: public String getCursorName() throws SQLException {
312: throw new UnsupportedOperationException();
313: }
314:
315: public Date getDate(int columnIndex) throws SQLException {
316: throw new UnsupportedOperationException();
317: }
318:
319: public Date getDate(int columnIndex, Calendar cal)
320: throws SQLException {
321: throw new UnsupportedOperationException();
322: }
323:
324: public Date getDate(String columnName) throws SQLException {
325: throw new UnsupportedOperationException();
326: }
327:
328: public Date getDate(String columnName, Calendar cal)
329: throws SQLException {
330: throw new UnsupportedOperationException();
331: }
332:
333: public double getDouble(int columnIndex) throws SQLException {
334: throw new UnsupportedOperationException();
335: }
336:
337: public double getDouble(String columnName) throws SQLException {
338: throw new UnsupportedOperationException();
339: }
340:
341: public float getFloat(int columnIndex) throws SQLException {
342: throw new UnsupportedOperationException();
343: }
344:
345: public float getFloat(String columnName) throws SQLException {
346: throw new UnsupportedOperationException();
347: }
348:
349: public int getInt(int columnIndex) throws SQLException {
350: throw new UnsupportedOperationException();
351: }
352:
353: public int getInt(String columnName) throws SQLException {
354: throw new UnsupportedOperationException();
355: }
356:
357: public long getLong(int columnIndex) throws SQLException {
358: throw new UnsupportedOperationException();
359: }
360:
361: public long getLong(String columnName) throws SQLException {
362: throw new UnsupportedOperationException();
363: }
364:
365: public ResultSetMetaData getMetaData() throws SQLException {
366: throw new UnsupportedOperationException();
367: }
368:
369: public Object getObject(int columnIndex) throws SQLException {
370: throw new UnsupportedOperationException();
371: }
372:
373: public Object getObject(int columnIndex, Map<String, Class<?>> map)
374: throws SQLException {
375: throw new UnsupportedOperationException();
376: }
377:
378: public Object getObject(String columnName) throws SQLException {
379: throw new UnsupportedOperationException();
380: }
381:
382: public Object getObject(String columnName, Map<String, Class<?>> map)
383: throws SQLException {
384: throw new UnsupportedOperationException();
385: }
386:
387: public Ref getRef(int columnIndex) throws SQLException {
388: throw new UnsupportedOperationException();
389: }
390:
391: public Ref getRef(String colName) throws SQLException {
392: throw new UnsupportedOperationException();
393: }
394:
395: public short getShort(int columnIndex) throws SQLException {
396: throw new UnsupportedOperationException();
397: }
398:
399: public short getShort(String columnName) throws SQLException {
400: throw new UnsupportedOperationException();
401: }
402:
403: public Statement getStatement() throws SQLException {
404: throw new UnsupportedOperationException();
405: }
406:
407: public String getString(int columnIndex) throws SQLException {
408: throw new UnsupportedOperationException();
409: }
410:
411: public String getString(String columnName) throws SQLException {
412: throw new UnsupportedOperationException();
413: }
414:
415: public Time getTime(int columnIndex) throws SQLException {
416: throw new UnsupportedOperationException();
417: }
418:
419: public Time getTime(int columnIndex, Calendar cal)
420: throws SQLException {
421: throw new UnsupportedOperationException();
422: }
423:
424: public Time getTime(String columnName) throws SQLException {
425: throw new UnsupportedOperationException();
426: }
427:
428: public Time getTime(String columnName, Calendar cal)
429: throws SQLException {
430: throw new UnsupportedOperationException();
431: }
432:
433: public Timestamp getTimestamp(int columnIndex) throws SQLException {
434: throw new UnsupportedOperationException();
435: }
436:
437: public Timestamp getTimestamp(int columnIndex, Calendar cal)
438: throws SQLException {
439: throw new UnsupportedOperationException();
440: }
441:
442: public Timestamp getTimestamp(String columnName)
443: throws SQLException {
444: throw new UnsupportedOperationException();
445: }
446:
447: public Timestamp getTimestamp(String columnName, Calendar cal)
448: throws SQLException {
449: throw new UnsupportedOperationException();
450: }
451:
452: public java.net.URL getURL(int columnIndex) throws SQLException {
453: throw new UnsupportedOperationException();
454: }
455:
456: public java.net.URL getURL(String columnName) throws SQLException {
457: throw new UnsupportedOperationException();
458: }
459:
460: public InputStream getUnicodeStream(int columnIndex)
461: throws SQLException {
462: throw new UnsupportedOperationException();
463: }
464:
465: public InputStream getUnicodeStream(String columnName)
466: throws SQLException {
467: throw new UnsupportedOperationException();
468: }
469:
470: public SQLWarning getWarnings() throws SQLException {
471: throw new UnsupportedOperationException();
472: }
473:
474: public void insertRow() throws SQLException {
475: throw new UnsupportedOperationException();
476: }
477:
478: public boolean isAfterLast() throws SQLException {
479: throw new UnsupportedOperationException();
480: }
481:
482: public boolean isBeforeFirst() throws SQLException {
483: throw new UnsupportedOperationException();
484: }
485:
486: public boolean isFirst() throws SQLException {
487: throw new UnsupportedOperationException();
488: }
489:
490: public boolean isLast() throws SQLException {
491: throw new UnsupportedOperationException();
492: }
493:
494: public boolean last() throws SQLException {
495: throw new UnsupportedOperationException();
496: }
497:
498: public void moveToCurrentRow() throws SQLException {
499: throw new UnsupportedOperationException();
500: }
501:
502: public void moveToInsertRow() throws SQLException {
503: throw new UnsupportedOperationException();
504: }
505:
506: public boolean next() throws SQLException {
507: throw new UnsupportedOperationException();
508: }
509:
510: public boolean previous() throws SQLException {
511: throw new UnsupportedOperationException();
512: }
513:
514: public void refreshRow() throws SQLException {
515: throw new UnsupportedOperationException();
516: }
517:
518: public boolean relative(int rows) throws SQLException {
519: throw new UnsupportedOperationException();
520: }
521:
522: public boolean rowDeleted() throws SQLException {
523: throw new UnsupportedOperationException();
524: }
525:
526: public boolean rowInserted() throws SQLException {
527: throw new UnsupportedOperationException();
528: }
529:
530: public boolean rowUpdated() throws SQLException {
531: throw new UnsupportedOperationException();
532: }
533:
534: public void updateArray(int columnIndex, Array x)
535: throws SQLException {
536: throw new UnsupportedOperationException();
537: }
538:
539: public void updateArray(String columnName, Array x)
540: throws SQLException {
541: throw new UnsupportedOperationException();
542: }
543:
544: public void updateAsciiStream(int columnIndex, InputStream x,
545: int length) throws SQLException {
546: throw new UnsupportedOperationException();
547: }
548:
549: public void updateAsciiStream(String columnName, InputStream x,
550: int length) throws SQLException {
551: throw new UnsupportedOperationException();
552: }
553:
554: public void updateBigDecimal(int columnIndex, BigDecimal x)
555: throws SQLException {
556: throw new UnsupportedOperationException();
557: }
558:
559: public void updateBigDecimal(String columnName, BigDecimal x)
560: throws SQLException {
561: throw new UnsupportedOperationException();
562: }
563:
564: public void updateBinaryStream(int columnIndex, InputStream x,
565: int length) throws SQLException {
566: throw new UnsupportedOperationException();
567: }
568:
569: public void updateBinaryStream(String columnName, InputStream x,
570: int length) throws SQLException {
571: throw new UnsupportedOperationException();
572: }
573:
574: public void updateBlob(int columnIndex, Blob x) throws SQLException {
575: throw new UnsupportedOperationException();
576: }
577:
578: public void updateBlob(String columnName, Blob x)
579: throws SQLException {
580: throw new UnsupportedOperationException();
581: }
582:
583: public void updateBoolean(int columnIndex, boolean x)
584: throws SQLException {
585: throw new UnsupportedOperationException();
586: }
587:
588: public void updateBoolean(String columnName, boolean x)
589: throws SQLException {
590: throw new UnsupportedOperationException();
591: }
592:
593: public void updateByte(int columnIndex, byte x) throws SQLException {
594: throw new UnsupportedOperationException();
595: }
596:
597: public void updateByte(String columnName, byte x)
598: throws SQLException {
599: throw new UnsupportedOperationException();
600: }
601:
602: public void updateBytes(int columnIndex, byte[] x)
603: throws SQLException {
604: throw new UnsupportedOperationException();
605: }
606:
607: public void updateBytes(String columnName, byte[] x)
608: throws SQLException {
609: throw new UnsupportedOperationException();
610: }
611:
612: public void updateCharacterStream(int columnIndex, Reader x,
613: int length) throws SQLException {
614: throw new UnsupportedOperationException();
615: }
616:
617: public void updateCharacterStream(String columnName, Reader reader,
618: int length) throws SQLException {
619: throw new UnsupportedOperationException();
620: }
621:
622: public void updateClob(int columnIndex, Clob x) throws SQLException {
623: throw new UnsupportedOperationException();
624: }
625:
626: public void updateClob(String columnName, Clob x)
627: throws SQLException {
628: throw new UnsupportedOperationException();
629: }
630:
631: public void updateDate(int columnIndex, Date x) throws SQLException {
632: throw new UnsupportedOperationException();
633: }
634:
635: public void updateDate(String columnName, Date x)
636: throws SQLException {
637: throw new UnsupportedOperationException();
638: }
639:
640: public void updateDouble(int columnIndex, double x)
641: throws SQLException {
642: throw new UnsupportedOperationException();
643: }
644:
645: public void updateDouble(String columnName, double x)
646: throws SQLException {
647: throw new UnsupportedOperationException();
648: }
649:
650: public void updateFloat(int columnIndex, float x)
651: throws SQLException {
652: throw new UnsupportedOperationException();
653: }
654:
655: public void updateFloat(String columnName, float x)
656: throws SQLException {
657: throw new UnsupportedOperationException();
658: }
659:
660: public void updateInt(int columnIndex, int x) throws SQLException {
661: throw new UnsupportedOperationException();
662: }
663:
664: public void updateInt(String columnName, int x) throws SQLException {
665: throw new UnsupportedOperationException();
666: }
667:
668: public void updateLong(int columnIndex, long x) throws SQLException {
669: throw new UnsupportedOperationException();
670: }
671:
672: public void updateLong(String columnName, long x)
673: throws SQLException {
674: throw new UnsupportedOperationException();
675: }
676:
677: public void updateNull(int columnIndex) throws SQLException {
678: throw new UnsupportedOperationException();
679: }
680:
681: public void updateNull(String columnName) throws SQLException {
682: throw new UnsupportedOperationException();
683: }
684:
685: public void updateObject(int columnIndex, Object x)
686: throws SQLException {
687: throw new UnsupportedOperationException();
688: }
689:
690: public void updateObject(int columnIndex, Object x, int scale)
691: throws SQLException {
692: throw new UnsupportedOperationException();
693: }
694:
695: public void updateObject(String columnName, Object x)
696: throws SQLException {
697: throw new UnsupportedOperationException();
698: }
699:
700: public void updateObject(String columnName, Object x, int scale)
701: throws SQLException {
702: throw new UnsupportedOperationException();
703: }
704:
705: public void updateRef(int columnIndex, Ref x) throws SQLException {
706: throw new UnsupportedOperationException();
707: }
708:
709: public void updateRef(String columnName, Ref x) throws SQLException {
710: throw new UnsupportedOperationException();
711: }
712:
713: public void updateRow() throws SQLException {
714: throw new UnsupportedOperationException();
715: }
716:
717: public void updateShort(int columnIndex, short x)
718: throws SQLException {
719: throw new UnsupportedOperationException();
720: }
721:
722: public void updateShort(String columnName, short x)
723: throws SQLException {
724: throw new UnsupportedOperationException();
725: }
726:
727: public void updateString(int columnIndex, String x)
728: throws SQLException {
729: throw new UnsupportedOperationException();
730: }
731:
732: public void updateString(String columnName, String x)
733: throws SQLException {
734: throw new UnsupportedOperationException();
735: }
736:
737: public void updateTime(int columnIndex, Time x) throws SQLException {
738: throw new UnsupportedOperationException();
739: }
740:
741: public void updateTime(String columnName, Time x)
742: throws SQLException {
743: throw new UnsupportedOperationException();
744: }
745:
746: public void updateTimestamp(int columnIndex, Timestamp x)
747: throws SQLException {
748: throw new UnsupportedOperationException();
749: }
750:
751: public void updateTimestamp(String columnName, Timestamp x)
752: throws SQLException {
753: throw new UnsupportedOperationException();
754: }
755:
756: public boolean wasNull() throws SQLException {
757: throw new UnsupportedOperationException();
758: }
759:
760: }
|