001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.jdo;
012:
013: import com.versant.core.common.OID;
014:
015: import java.util.Collection;
016: import java.util.Iterator;
017: import java.util.List;
018: import java.util.ListIterator;
019:
020: import com.versant.core.common.BindingSupportImpl;
021:
022: import javax.jdo.PersistenceManager;
023:
024: /**
025: * Base class for QueryResult implementations that throws an exception for
026: * all mutating methods. It also manages the next and prev pointers. All
027: * methods from the interface have abstract methods here to avoid problems
028: * with the IBM VMs.
029: *
030: * @see QueryResult
031: * @see ForwardQueryResult
032: * @see RandomAccessQueryResult
033: * @see MemoryQueryResult
034: */
035: public abstract class QueryResultBase implements QueryResult {
036:
037: private QueryResult next;
038: private QueryResult prev;
039:
040: public final QueryResult getNext() {
041: return next;
042: }
043:
044: public final void setNext(QueryResult next) {
045: this .next = next;
046: }
047:
048: public final QueryResult getPrev() {
049: return prev;
050: }
051:
052: public final void setPrev(QueryResult prev) {
053: this .prev = prev;
054: }
055:
056: public abstract void close();
057:
058: public abstract void setParams(Object[] params);
059:
060: public abstract Iterator createInternalIterNoFlush();
061:
062: public boolean add(Object o) {
063: throw BindingSupportImpl.getInstance().unsupportedOperation(
064: "Modification not allowed");
065: }
066:
067: public boolean remove(Object o) {
068: throw BindingSupportImpl.getInstance().unsupportedOperation(
069: "Modification not allowed");
070: }
071:
072: public boolean addAll(Collection c) {
073: throw BindingSupportImpl.getInstance().unsupportedOperation(
074: "Modification not allowed");
075: }
076:
077: public boolean addAll(int index, Collection c) {
078: throw BindingSupportImpl.getInstance().unsupportedOperation(
079: "Modification not allowed");
080: }
081:
082: public boolean removeAll(Collection c) {
083: throw BindingSupportImpl.getInstance().unsupportedOperation(
084: "Modification not allowed");
085: }
086:
087: public boolean retainAll(Collection c) {
088: throw BindingSupportImpl.getInstance().unsupportedOperation(
089: "Modification not allowed");
090: }
091:
092: public void clear() {
093: throw BindingSupportImpl.getInstance().unsupportedOperation(
094: "Modification not allowed");
095: }
096:
097: public Object set(int index, Object element) {
098: throw BindingSupportImpl.getInstance().unsupportedOperation(
099: "Modification not allowed");
100: }
101:
102: public void add(int index, Object element) {
103: throw BindingSupportImpl.getInstance().unsupportedOperation(
104: "Modification not allowed");
105: }
106:
107: public Object remove(int index) {
108: throw BindingSupportImpl.getInstance().unsupportedOperation(
109: "Modification not allowed");
110: }
111:
112: public abstract int size();
113:
114: public abstract boolean isEmpty();
115:
116: public abstract boolean contains(Object o);
117:
118: public abstract Iterator iterator();
119:
120: public abstract Object[] toArray();
121:
122: public abstract Object[] toArray(Object a[]);
123:
124: public abstract boolean containsAll(Collection c);
125:
126: public abstract Object get(int index);
127:
128: public abstract int indexOf(Object o);
129:
130: public abstract int lastIndexOf(Object o);
131:
132: public abstract ListIterator listIterator();
133:
134: public abstract ListIterator listIterator(int index);
135:
136: public abstract List subList(int fromIndex, int toIndex);
137:
138: public static Object resolveRow(Object row, PersistenceManager pm) {
139: if (row == null)
140: return null;
141: if (row instanceof OID) {
142: return pm.getObjectById(row, false);
143: } else if (row instanceof Object[]) {
144: Object[] data = (Object[]) row;
145: for (int i = 0; i < data.length; i++) {
146: Object o = data[i];
147: if (o instanceof OID) {
148: data[i] = pm.getObjectById(o, false);
149: }
150: }
151: }
152: return row;
153: }
154: }
|