01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.openjpa.jdbc.meta.strats;
20:
21: import java.sql.SQLException;
22:
23: import org.apache.openjpa.conf.OpenJPAConfiguration;
24: import org.apache.openjpa.jdbc.kernel.JDBCFetchConfiguration;
25: import org.apache.openjpa.jdbc.kernel.JDBCStore;
26: import org.apache.openjpa.jdbc.meta.ClassMapping;
27: import org.apache.openjpa.jdbc.meta.FieldMapping;
28: import org.apache.openjpa.jdbc.schema.Column;
29: import org.apache.openjpa.jdbc.schema.ForeignKey;
30: import org.apache.openjpa.jdbc.sql.Joins;
31: import org.apache.openjpa.jdbc.sql.Result;
32: import org.apache.openjpa.jdbc.sql.Select;
33: import org.apache.openjpa.kernel.OpenJPAStateManager;
34: import org.apache.openjpa.lib.util.Localizer;
35: import org.apache.openjpa.meta.JavaTypes;
36: import org.apache.openjpa.util.MetaDataException;
37: import org.apache.openjpa.util.Proxy;
38:
39: /**
40: * Maps a relation to a collection of other objects using an inverse
41: * foreign key in the related object table.
42: *
43: * @author Abe White
44: */
45: public class RelationCollectionInverseKeyFieldStrategy extends
46: RelationToManyInverseKeyFieldStrategy implements
47: LRSCollectionFieldStrategy {
48:
49: private static final Localizer _loc = Localizer
50: .forPackage(RelationCollectionInverseKeyFieldStrategy.class);
51:
52: public FieldMapping getFieldMapping() {
53: return field;
54: }
55:
56: public ClassMapping[] getIndependentElementMappings(boolean traverse) {
57: return super .getIndependentElementMappings(traverse);
58: }
59:
60: public Column[] getElementColumns(ClassMapping elem) {
61: return elem.getPrimaryKeyColumns();
62: }
63:
64: public ForeignKey getJoinForeignKey(ClassMapping elem) {
65: return super .getJoinForeignKey(elem);
66: }
67:
68: public void selectElement(Select sel, ClassMapping elem,
69: JDBCStore store, JDBCFetchConfiguration fetch,
70: int eagerMode, Joins joins) {
71: super .selectElement(sel, elem, store, fetch, eagerMode, joins);
72: }
73:
74: public Object loadElement(OpenJPAStateManager sm, JDBCStore store,
75: JDBCFetchConfiguration fetch, Result res, Joins joins)
76: throws SQLException {
77: return super .loadElement(sm, store, fetch, res, joins);
78: }
79:
80: public Joins join(Joins joins, ClassMapping elem) {
81: return super .join(joins, elem);
82: }
83:
84: public Joins joinElementRelation(Joins joins, ClassMapping elem) {
85: return super .joinElementRelation(joins, elem);
86: }
87:
88: protected Proxy newLRSProxy() {
89: return new LRSProxyCollection(this );
90: }
91:
92: public void map(boolean adapt) {
93: if (field.getTypeCode() != JavaTypes.COLLECTION
94: && field.getTypeCode() != JavaTypes.ARRAY)
95: throw new MetaDataException(_loc.get("not-coll", field));
96: super.map(adapt);
97: }
98: }
|