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 org.apache.openjpa.jdbc.meta.ClassMapping;
22: import org.apache.openjpa.jdbc.meta.ClassMappingInfo;
23: import org.apache.openjpa.jdbc.schema.Table;
24: import org.apache.openjpa.lib.util.Localizer;
25: import org.apache.openjpa.util.MetaDataException;
26:
27: /**
28: * Mapping for classes mapped to their superclass table.
29: *
30: * @author Abe White
31: */
32: public class FlatClassStrategy extends AbstractClassStrategy {
33:
34: public static final String ALIAS = "flat";
35:
36: private static final Localizer _loc = Localizer
37: .forPackage(FlatClassStrategy.class);
38:
39: public String getAlias() {
40: return ALIAS;
41: }
42:
43: public void map(boolean adapt) {
44: ClassMapping sup = cls.getMappedPCSuperclassMapping();
45: if (sup == null || cls.getEmbeddingMetaData() != null)
46: throw new MetaDataException(_loc.get("not-sub", cls));
47:
48: ClassMappingInfo info = cls.getMappingInfo();
49: info.assertNoSchemaComponents(cls, true);
50:
51: if (info.getTableName() != null) {
52: Table table = info.createTable(cls, null, info
53: .getSchemaName(), info.getTableName(), false);
54: if (table != sup.getTable())
55: throw new MetaDataException(_loc.get("flat-table", cls,
56: table.getFullName(), sup.getTable()
57: .getFullName()));
58: }
59:
60: cls.setTable(sup.getTable());
61: cls.setPrimaryKeyColumns(sup.getPrimaryKeyColumns());
62: cls.setColumnIO(sup.getColumnIO());
63: }
64:
65: public boolean isPrimaryKeyObjectId(boolean hasAll) {
66: return cls.getMappedPCSuperclassMapping().isPrimaryKeyObjectId(
67: hasAll);
68: }
69: }
|