01: package org.apache.ojb.broker.accesslayer;
02:
03: /* Copyright 2002-2005 The Apache Software Foundation
04: *
05: * Licensed under the Apache License, Version 2.0 (the "License");
06: * you may not use this file except in compliance with the License.
07: * You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: import org.apache.ojb.broker.Identity;
19: import org.apache.ojb.broker.PersistenceBrokerException;
20: import org.apache.ojb.broker.core.PersistenceBrokerImpl;
21:
22: /**
23: * RsIterator based on SQL-Statement
24: *
25: * @author <a href="mailto:jbraeuchi@hotmail.com">Jakob Braeuchi</a>
26: * @version $Id: SqlBasedRsIterator.java,v 1.23.2.1 2005/12/21 22:22:58 tomdz Exp $
27: */
28: public class SqlBasedRsIterator extends RsIterator {
29: /**
30: * SqlBasedRsIterator constructor.
31: */
32: public SqlBasedRsIterator(RsQueryObject queryObject,
33: PersistenceBrokerImpl broker)
34: throws PersistenceBrokerException {
35: super (queryObject, broker);
36: if (!queryObject.isSQLBased()) {
37: throw new PersistenceBrokerException(
38: "Given query is not a QueryBySQL object");
39: }
40: }
41:
42: /**
43: * returns a proxy or a fully materialized Object from the current row of the
44: * underlying resultset.
45: */
46: protected Object getObjectFromResultSet()
47: throws PersistenceBrokerException {
48:
49: try {
50: // if all primitive attributes of the object are contained in the ResultSet
51: // the fast direct mapping can be used
52: return super .getObjectFromResultSet();
53: }
54: // if the full loading failed we assume that at least PK attributes are contained
55: // in the ResultSet and perform a slower Identity based loading...
56: // This may of course also fail and can throw another PersistenceBrokerException
57: catch (PersistenceBrokerException e) {
58: Identity oid = getIdentityFromResultSet();
59: return getBroker().getObjectByIdentity(oid);
60: }
61:
62: }
63: }
|