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 collection of related objects through an association table.
41: *
42: * @author Abe White
43: */
44: public class RelationCollectionTableFieldStrategy extends
45: RelationToManyTableFieldStrategy implements
46: LRSCollectionFieldStrategy {
47:
48: private static final Localizer _loc = Localizer
49: .forPackage(RelationCollectionTableFieldStrategy.class);
50:
51: public FieldMapping getFieldMapping() {
52: return field;
53: }
54:
55: public ClassMapping[] getIndependentElementMappings(boolean traverse) {
56: return super .getIndependentElementMappings(traverse);
57: }
58:
59: public Column[] getElementColumns(ClassMapping elem) {
60: return field.getElementMapping().getColumns();
61: }
62:
63: public ForeignKey getJoinForeignKey(ClassMapping elem) {
64: return super .getJoinForeignKey(elem);
65: }
66:
67: public void selectElement(Select sel, ClassMapping elem,
68: JDBCStore store, JDBCFetchConfiguration fetch,
69: int eagerMode, Joins joins) {
70: super .selectElement(sel, elem, store, fetch, eagerMode, joins);
71: }
72:
73: public Object loadElement(OpenJPAStateManager sm, JDBCStore store,
74: JDBCFetchConfiguration fetch, Result res, Joins joins)
75: throws SQLException {
76: return super .loadElement(sm, store, fetch, res, joins);
77: }
78:
79: public Joins join(Joins joins, ClassMapping elem) {
80: return super .join(joins, elem);
81: }
82:
83: public Joins joinElementRelation(Joins joins, ClassMapping elem) {
84: return super .joinElementRelation(joins, elem);
85: }
86:
87: protected Proxy newLRSProxy() {
88: return new LRSProxyCollection(this );
89: }
90:
91: public void map(boolean adapt) {
92: if (field.getTypeCode() != JavaTypes.COLLECTION
93: && field.getTypeCode() != JavaTypes.ARRAY)
94: throw new MetaDataException(_loc.get("not-coll", field));
95: super.map(adapt);
96: }
97: }
|