1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
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.meta;
20
21 import java.io.ObjectOutput;
22 import java.util.Calendar;
23 import java.util.SortedMap;
24 import java.util.SortedSet;
25
26 import org.apache.openjpa.enhance.PersistenceCapable;
27 import org.apache.openjpa.enhance.StateManager;
28 import org.apache.openjpa.util.InternalException;
29
30 /**
31 * Mostly-unimplemented state manager type whose sole purpose is to
32 * check the initial value of all SCO container fields for their initialized
33 * types and comparators.
34 *
35 * @author Abe White
36 */
37 class ProxySetupStateManager
38 implements StateManager {
39
40 private Object _object = null;
41
42 public void setProxyData(PersistenceCapable pc, ClassMetaData meta) {
43 FieldMetaData[] fmds = meta.getFields();
44 for (int i = 0; i < fmds.length; i++) {
45 if (fmds[i].getDefiningMetaData() != meta)
46 continue;
47
48 switch (fmds[i].getDeclaredTypeCode()) {
49 case JavaTypes.CALENDAR:
50 pc.pcProvideField(fmds[i].getIndex());
51 if (_object != null) {
52 // specified timezone
53 fmds[i]
54 .setInitializer(((Calendar) _object).getTimeZone());
55 }
56 break;
57 case JavaTypes.COLLECTION:
58 pc.pcProvideField(fmds[i].getIndex());
59 if (_object != null) {
60 // more specific type?
61 if (_object.getClass() != fmds[i].getDeclaredType())
62 fmds[i].setProxyType(_object.getClass());
63
64 // custom comparator?
65 if (_object instanceof SortedSet)
66 fmds[i].setInitializer(((SortedSet) _object).
67 comparator());
68 }
69 break;
70 case JavaTypes.MAP:
71 pc.pcProvideField(fmds[i].getIndex());
72 if (_object != null) {
73 // more specific type?
74 if (_object.getClass() != fmds[i].getDeclaredType())
75 fmds[i].setProxyType(_object.getClass());
76
77 // custom comparator?
78 if (_object instanceof SortedMap)
79 fmds[i].setInitializer(((SortedMap) _object).
80 comparator());
81 }
82 break;
83 }
84 }
85 }
86
87 public Object getPCPrimaryKey(Object oid, int field) {
88 throw new UnsupportedOperationException();
89 }
90
91 public StateManager replaceStateManager(StateManager sm) {
92 throw new InternalException();
93 }
94
95 public boolean isDirty() {
96 throw new InternalException();
97 }
98
99 public boolean isTransactional() {
100 throw new InternalException();
101 }
102
103 public boolean isPersistent() {
104 throw new InternalException();
105 }
106
107 public boolean isNew() {
108 throw new InternalException();
109 }
110
111 public boolean isDeleted() {
112 throw new InternalException();
113 }
114
115 public boolean isDetached() {
116 throw new InternalException();
117 }
118
119 public Object getGenericContext() {
120 throw new InternalException();
121 }
122
123 public void dirty(String s) {
124 throw new InternalException();
125 }
126
127 public Object fetchObjectId() {
128 throw new InternalException();
129 }
130
131 public Object getVersion() {
132 throw new InternalException();
133 }
134
135 public void accessingField(int i) {
136 throw new InternalException();
137 }
138
139 public boolean serializing() {
140 throw new InternalException();
141 }
142
143 public boolean writeDetached(ObjectOutput out) {
144 throw new InternalException();
145 }
146
147 public void proxyDetachedDeserialized(int idx) {
148 throw new InternalException();
149 }
150
151 public void settingBooleanField(PersistenceCapable pc, int i, boolean b,
152 boolean b2, int set) {
153 throw new InternalException();
154 }
155
156 public void settingCharField(PersistenceCapable pc, int i, char c, char c2,
157 int set) {
158 throw new InternalException();
159 }
160
161 public void settingByteField(PersistenceCapable pc, int i, byte b, byte b2,
162 int set) {
163 throw new InternalException();
164 }
165
166 public void settingShortField(PersistenceCapable pc, int i, short s,
167 short s2, int set) {
168 throw new InternalException();
169 }
170
171 public void settingIntField(PersistenceCapable pc, int i, int i2, int i3,
172 int set) {
173 throw new InternalException();
174 }
175
176 public void settingLongField(PersistenceCapable pc, int i, long l, long l2,
177 int set) {
178 throw new InternalException();
179 }
180
181 public void settingFloatField(PersistenceCapable pc, int i, float f,
182 float f2, int set) {
183 throw new InternalException();
184 }
185
186 public void settingDoubleField(PersistenceCapable pc, int i, double d,
187 double d2, int set) {
188 throw new InternalException();
189 }
190
191 public void settingStringField(PersistenceCapable pc, int i, String s,
192 String s2, int set) {
193 throw new InternalException();
194 }
195
196 public void settingObjectField(PersistenceCapable pc, int i, Object o,
197 Object o2, int set) {
198 throw new InternalException();
199 }
200
201 public void providedBooleanField(PersistenceCapable pc, int i, boolean b) {
202 throw new InternalException();
203 }
204
205 public void providedCharField(PersistenceCapable pc, int i, char c) {
206 throw new InternalException();
207 }
208
209 public void providedByteField(PersistenceCapable pc, int i, byte b) {
210 throw new InternalException();
211 }
212
213 public void providedShortField(PersistenceCapable pc, int i, short s) {
214 throw new InternalException();
215 }
216
217 public void providedIntField(PersistenceCapable pc, int i, int i2) {
218 throw new InternalException();
219 }
220
221 public void providedLongField(PersistenceCapable pc, int i, long l) {
222 throw new InternalException();
223 }
224
225 public void providedFloatField(PersistenceCapable pc, int i, float f) {
226 throw new InternalException();
227 }
228
229 public void providedDoubleField(PersistenceCapable pc, int i, double d) {
230 throw new InternalException();
231 }
232
233 public void providedStringField(PersistenceCapable pc, int i, String s) {
234 throw new InternalException();
235 }
236
237 public void providedObjectField(PersistenceCapable pc, int i, Object o) {
238 _object = o;
239 }
240
241 public boolean replaceBooleanField(PersistenceCapable pc, int i) {
242 throw new InternalException();
243 }
244
245 public char replaceCharField(PersistenceCapable pc, int i) {
246 throw new InternalException();
247 }
248
249 public byte replaceByteField(PersistenceCapable pc, int i) {
250 throw new InternalException();
251 }
252
253 public short replaceShortField(PersistenceCapable pc, int i) {
254 throw new InternalException();
255 }
256
257 public int replaceIntField(PersistenceCapable pc, int i) {
258 throw new InternalException();
259 }
260
261 public long replaceLongField(PersistenceCapable pc, int i) {
262 throw new InternalException();
263 }
264
265 public float replaceFloatField(PersistenceCapable pc, int i) {
266 throw new InternalException();
267 }
268
269 public double replaceDoubleField(PersistenceCapable pc, int i) {
270 throw new InternalException();
271 }
272
273 public String replaceStringField(PersistenceCapable pc, int i) {
274 throw new InternalException();
275 }
276
277 public Object replaceObjectField(PersistenceCapable pc, int i) {
278 throw new InternalException();
279 }
280 }