01: /**********************************************************************
02: Copyright (c) 2005 Andy Jefferson and others. All rights reserved.
03: Licensed under the Apache License, Version 2.0 (the "License");
04: you may not use this file except in compliance with the License.
05: You may obtain a copy of the License at
06:
07: http://www.apache.org/licenses/LICENSE-2.0
08:
09: Unless required by applicable law or agreed to in writing, software
10: distributed under the License is distributed on an "AS IS" BASIS,
11: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: See the License for the specific language governing permissions and
13: limitations under the License.
14:
15:
16: Contributors:
17: ...
18: **********************************************************************/package org.jpox.store.query;
19:
20: import org.jpox.ClassLoaderResolver;
21: import org.jpox.metadata.AbstractClassMetaData;
22: import org.jpox.store.DatastoreAdapter;
23: import org.jpox.store.DatastoreClass;
24: import org.jpox.store.DatastoreIdentifier;
25: import org.jpox.store.StoreManager;
26: import org.jpox.store.expression.QueryExpression;
27: import org.jpox.util.Localiser;
28:
29: /**
30: * Abstract representation of a statement that is used for iterating through a list of
31: * objects of a class, possibly including subclasses.
32: *
33: * @version $Revision: 1.13 $
34: */
35: public abstract class AbstractIteratorStatement {
36: /** Localisation or messages. */
37: protected static final Localiser LOCALISER = Localiser
38: .getInstance("org.jpox.store.Localisation");
39:
40: /** Whether to include iteration through subclasses of the candidate. */
41: protected final boolean includeSubclasses;
42:
43: /** Manager for the Store. */
44: protected final StoreManager storeMgr;
45:
46: /** Datastore adapter */
47: protected final DatastoreAdapter dba;
48:
49: /** full class name for the candidate class **/
50: protected String candidateFullClassName;
51:
52: /** Table where the candidate objects are stored. */
53: protected DatastoreClass candidateTable;
54:
55: /** ClassLoader resolver. */
56: protected final ClassLoaderResolver clr;
57:
58: /**
59: * Constructor.
60: * @param type Class that we are querying for as our base.
61: * @param clr ClassLoaderResolver
62: * @param subclasses Whether to include subclasses in the iteration.
63: * @param storeMgr Manager for the store
64: */
65: public AbstractIteratorStatement(Class type,
66: ClassLoaderResolver clr, boolean subclasses,
67: StoreManager storeMgr) {
68: this .includeSubclasses = subclasses;
69: this .storeMgr = storeMgr;
70: this .dba = storeMgr.getDatastoreAdapter();
71: this .clr = clr;
72: AbstractClassMetaData cmd = storeMgr.getMetaDataManager()
73: .getMetaDataForClass(type, clr);
74: if (cmd == null) {
75: candidateFullClassName = type.getName();
76: } else {
77: candidateFullClassName = cmd.getFullClassName();
78: }
79:
80: if (!storeMgr.getOMFContext().getTypeManager().isSupportedType(
81: candidateFullClassName)) {
82: candidateTable = storeMgr.getDatastoreClass(
83: candidateFullClassName, clr);
84: }
85: }
86:
87: /**
88: * Accessor for the QueryStatement that will return the objects of the candidate
89: * type and its subclasses (if required).
90: * @param candidateAlias Alias for the candidate
91: * @return The QueryExpression
92: */
93: public abstract QueryExpression getQueryStatement(
94: DatastoreIdentifier candidateAlias);
95: }
|