01: /**********************************************************************
02: Copyright (c) 2006 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.mapping;
19:
20: import org.jpox.ClassLoaderResolver;
21: import org.jpox.metadata.AbstractMemberMetaData;
22: import org.jpox.store.DatastoreAdapter;
23: import org.jpox.store.DatastoreContainerObject;
24: import org.jpox.store.expression.ObjectExpression;
25: import org.jpox.store.expression.ObjectLiteral;
26: import org.jpox.store.expression.QueryExpression;
27: import org.jpox.store.expression.ScalarExpression;
28: import org.jpox.store.expression.LogicSetExpression;
29:
30: /**
31: * Mapping for a field that stores a PC object that uses "subclass-table" inheritance
32: * and where this is mapped in the datastore as a separate FK for each subclass.
33: *
34: * @version $Revision: 1.9 $
35: */
36: public class SubclassPCMapping extends MultiMapping {
37: /**
38: * Initialize this JavaTypeMapping with the given DatastoreAdapter for
39: * the given FieldMetaData.
40: *
41: * @param dba The Datastore Adapter that this Mapping should use.
42: * @param fmd FieldMetaData for the field to be mapped (if any)
43: * @param container The datastore container storing this mapping (if any)
44: * @param clr the ClassLoaderResolver
45: */
46: public void initialize(DatastoreAdapter dba,
47: AbstractMemberMetaData fmd,
48: DatastoreContainerObject container, ClassLoaderResolver clr) {
49: super .initialize(dba, fmd, container, clr);
50: createColumns(datastoreContainer, fmd, clr);
51: }
52:
53: /**
54: * Convenience method to create a column for each implementation type of this reference.
55: * @param datastoreContainer Table to use
56: * @param fmd MetaData for the field
57: * @param clr The ClassLoaderResolver
58: */
59: protected void createColumns(
60: DatastoreContainerObject datastoreContainer,
61: AbstractMemberMetaData fmd, ClassLoaderResolver clr) {
62: // Create columns for each possible implementation type of the reference field
63: datastoreContainer.getStoreManager()
64: .createDatastoreColumnsForFieldUsingSubclassTable(this ,
65: datastoreContainer, fmd, clr);
66: }
67:
68: /* (non-Javadoc)
69: * @see org.jpox.store.mapping.JavaTypeMapping#getJavaType()
70: */
71: public Class getJavaType() {
72: return null;
73: }
74:
75: /* (non-Javadoc)
76: * @see org.jpox.store.mapping.Mapping#getSampleValue()
77: */
78: public Object getSampleValue(ClassLoaderResolver clr) {
79: throw new UnsupportedOperationException("Not yet implemented");
80: }
81:
82: // ---------------------------------- JDOQL Query Methods -------------------------------------
83:
84: /* (non-Javadoc)
85: * @see org.jpox.store.mapping.Mapping#newLiteral(org.jpox.store.QueryStatement, java.lang.Object)
86: */
87: public ScalarExpression newLiteral(QueryExpression qs, Object value) {
88: ScalarExpression expr = new ObjectLiteral(qs, this , value,
89: value.getClass().getName());
90: return expr;
91: }
92:
93: public ScalarExpression newScalarExpression(QueryExpression qs,
94: LogicSetExpression te) {
95: ScalarExpression expr = new ObjectExpression(qs, this, te);
96: return expr;
97: }
98: }
|