Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SqlBasedRsIterator |
|
| 3.0;3 |
1 | package org.apache.ojb.broker.accesslayer; | |
2 | ||
3 | /* Copyright 2002-2005 The Apache Software Foundation | |
4 | * | |
5 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | * you may not use this file except in compliance with the License. | |
7 | * You may obtain a copy of the License at | |
8 | * | |
9 | * 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.1 2007-08-24 22:17:30 ewestfal Exp $ | |
27 | */ | |
28 | public class SqlBasedRsIterator extends RsIterator | |
29 | { | |
30 | /** | |
31 | * SqlBasedRsIterator constructor. | |
32 | */ | |
33 | public SqlBasedRsIterator(RsQueryObject queryObject, PersistenceBrokerImpl broker) | |
34 | throws PersistenceBrokerException | |
35 | { | |
36 | super(queryObject, broker); | |
37 | if(!queryObject.isSQLBased()) | |
38 | { | |
39 | throw new PersistenceBrokerException("Given query is not a QueryBySQL object"); | |
40 | } | |
41 | } | |
42 | ||
43 | /** | |
44 | * returns a proxy or a fully materialized Object from the current row of the | |
45 | * underlying resultset. | |
46 | */ | |
47 | protected Object getObjectFromResultSet() throws PersistenceBrokerException | |
48 | { | |
49 | ||
50 | try | |
51 | { | |
52 | // if all primitive attributes of the object are contained in the ResultSet | |
53 | // the fast direct mapping can be used | |
54 | return super.getObjectFromResultSet(); | |
55 | } | |
56 | // if the full loading failed we assume that at least PK attributes are contained | |
57 | // in the ResultSet and perform a slower Identity based loading... | |
58 | // This may of course also fail and can throw another PersistenceBrokerException | |
59 | catch (PersistenceBrokerException e) | |
60 | { | |
61 | Identity oid = getIdentityFromResultSet(); | |
62 | return getBroker().getObjectByIdentity(oid); | |
63 | } | |
64 | ||
65 | } | |
66 | } |