001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.openjpa.meta;
020:
021: import java.io.Serializable;
022:
023: /**
024: * Holds metadata on a value; this could be a field value, key value, or
025: * element value.
026: *
027: * @since 0.4.0
028: * @author Abe White
029: */
030: public interface ValueMetaData extends MetaDataContext, MetaDataModes,
031: Serializable {
032:
033: /**
034: * The operation is not cascaded to this field.
035: */
036: public int CASCADE_NONE = 0;
037:
038: /**
039: * The operation is immediately cascaded to this field.
040: */
041: public int CASCADE_IMMEDIATE = 1;
042:
043: /**
044: * Use automatic cascade behavior. Persistence-by-reachability,
045: * delete-dependent, attach-if-detached, etc.
046: */
047: public int CASCADE_AUTO = 2;
048:
049: /**
050: * Marker to set on {@link #setValueMappedBy} to denote that the map key
051: * is mapped by the primary key field of the value.
052: */
053: public static final String MAPPED_BY_PK = "`pk`";
054:
055: /**
056: * Return the owning field for this value.
057: */
058: public FieldMetaData getFieldMetaData();
059:
060: /**
061: * The value class.
062: */
063: public Class getType();
064:
065: /**
066: * The value class.
067: */
068: public void setType(Class type);
069:
070: /**
071: * The type code of the value class.
072: */
073: public int getTypeCode();
074:
075: /**
076: * The type code of the value class.
077: */
078: public void setTypeCode(int code);
079:
080: /**
081: * Whether the type is a persistence capable instance.
082: */
083: public boolean isTypePC();
084:
085: /**
086: * The metadata for the value class, if the type is persistent.
087: */
088: public ClassMetaData getTypeMetaData();
089:
090: /**
091: * Return the declared class of the value. This can differ
092: * from the return value of {@link #getType} if the user indicates
093: * a different type or the value has an externalizer.
094: */
095: public Class getDeclaredType();
096:
097: /**
098: * Set the declared class of the value.
099: */
100: public void setDeclaredType(Class type);
101:
102: /**
103: * Return the declared type code of the value. This can differ
104: * from the return value of {@link #getTypeCode} if the user indicates
105: * a different type or the value has an externalizer.
106: */
107: public int getDeclaredTypeCode();
108:
109: /**
110: * Set the type code for the value. The type code is usually
111: * computed automatically, but it can be useful to set it explicitly
112: * when creating metadatas from scratch.
113: */
114: public void setDeclaredTypeCode(int type);
115:
116: /**
117: * Whether the type is a persistence capable instance.
118: */
119: public boolean isDeclaredTypePC();
120:
121: /**
122: * Return metadata for the value's class, if the type is persistent.
123: */
124: public ClassMetaData getDeclaredTypeMetaData();
125:
126: /**
127: * This attribute is a hint to the implementation to store this value
128: * in the same structure as the class, rather than as a separate datastore
129: * structure. Defaults to true if the field is not a collection or map
130: * or persistence-capable object; defaults to false otherwise.
131: * Implementations are permitted to ignore this attribute.
132: */
133: public boolean isEmbedded();
134:
135: /**
136: * This attribute is a hint to the implementation to store this value
137: * in the same structure as the class, rather than as a separate datastore
138: * structure. Defaults to true if the field is not a collection or map
139: * or persistence-capable objects; defaults to false otherwise.
140: * Implementations are permitted to ignore this attribute.
141: */
142: public void setEmbedded(boolean embedded);
143:
144: /**
145: * Whether this is an embedded persistence capable value.
146: */
147: public boolean isEmbeddedPC();
148:
149: /**
150: * The embedded class metadata for the value.
151: */
152: public ClassMetaData getEmbeddedMetaData();
153:
154: /**
155: * Add embedded metadata for this value.
156: */
157: public ClassMetaData addEmbeddedMetaData();
158:
159: /**
160: * Cascade behavior for delete operation. Only applies to
161: * persistence-capable values. Options are:<br />
162: * <ul>
163: * <li><code>CASCADE_NONE</code>: No cascades.</li>
164: * <li><code>CASCADE_IMMEDIATE</code>: Value is deleted immediately when
165: * the owning object is deleted.</li>
166: * <li><code>CASCADE_AUTO</code>: Value will be deleted on flush
167: * if the owning object is deleted or if the value is removed from the
168: * owning object, and if the value is not assigned to another relation in
169: * the same transaction.</li>
170: * </ul>
171: */
172: public int getCascadeDelete();
173:
174: /**
175: * Cascade behavior for deletion.
176: *
177: * @see #getCascadeDelete
178: */
179: public void setCascadeDelete(int cascade);
180:
181: /**
182: * Cascade behavior for persist operation. Only applies to
183: * persistence-capable values. Options are:<br />
184: * <ul>
185: * <li><code>CASCADE_NONE</code>: No cascades. If a transient relation
186: * is held at flush, an error is thrown.</li>
187: * <li><code>CASCADE_IMMEDIATE</code>: Value is persisted immediately when
188: * the owning object is persisted.</li>
189: * <li><code>CASCADE_AUTO</code>: Value will be persisted on flush.</li>
190: * </ul>
191: */
192: public int getCascadePersist();
193:
194: /**
195: * Cascade behavior for persist operation.
196: *
197: * @see #getCascadePersist
198: */
199: public void setCascadePersist(int cascade);
200:
201: /**
202: * Cascade behavior for attach operation. Only applies to
203: * persistence-capable values. Options are:<br />
204: * <ul>
205: * <li><code>CASCADE_NONE</code>: No cascades of attach. Relation
206: * remains detached.</li>
207: * <li><code>CASCADE_IMMEDIATE</code>: Value is attached immediately.</li>
208: * </ul>
209: */
210: public int getCascadeAttach();
211:
212: /**
213: * Cascade behavior for attach operation.
214: *
215: * @see #getCascadeAttach
216: */
217: public void setCascadeAttach(int cascade);
218:
219: /**
220: * Cascade behavior for refresh operation. Only applies to
221: * persistence-capable values. Options are:<br />
222: * <ul>
223: * <li><code>CASCADE_NONE</code>: No cascades of refresh.</li>
224: * <li><code>CASCADE_IMMEDIATE</code>: Persistent value object is also
225: * refreshed.</li>
226: * <li><code>CASCADE_AUTO</code>: Value will be refreshed if it is
227: * in the current fetch groups.</li>
228: * </ul>
229: */
230: public int getCascadeRefresh();
231:
232: /**
233: * Cascade behavior for refresh operation.
234: *
235: * @see #getCascadeRefresh
236: */
237: public void setCascadeRefresh(int cascade);
238:
239: /**
240: * Whether this value is serialized when stored.
241: */
242: public boolean isSerialized();
243:
244: /**
245: * Whether this value is serialized when stored.
246: */
247: public void setSerialized(boolean serialized);
248:
249: /**
250: * The field that this value shares a mapping with. Currently the only
251: * supported use for a mapped-by value is when a map field key is
252: * determined by a field of the persistence-capable map value.
253: */
254: public String getValueMappedBy();
255:
256: /**
257: * The field that this value shares a mapping with. Currently the only
258: * supported use for a mapped-by value is when a map field key is
259: * determined by a field of the persistence-capable map value.
260: */
261: public void setValueMappedBy(String mapped);
262:
263: /**
264: * The field that this value shares a mapping with. Currently the only
265: * supported use for a mapped-by value is when a map field key is
266: * determined by a field of the persistence-capable map value.
267: */
268: public FieldMetaData getValueMappedByMetaData();
269:
270: /**
271: * User-supplied type overriding assumed type based on field.
272: */
273: public Class getTypeOverride();
274:
275: /**
276: * User-supplied type overriding assumed type based on field.
277: */
278: public void setTypeOverride(Class type);
279:
280: /**
281: * Resolve mode for metadata.
282: */
283: public int getResolve();
284:
285: /**
286: * Resolve mode for metadata.
287: */
288: public void setResolve(int mode);
289:
290: /**
291: * Resolve mode for metadata.
292: */
293: public void setResolve(int mode, boolean on);
294:
295: /**
296: * Resolve and validate metadata. Return true if already resolved.
297: */
298: public boolean resolve(int mode);
299:
300: /**
301: * Copy state from the given value to this one. Do not copy mapping
302: * information.
303: */
304: public void copy(ValueMetaData vmd);
305: }
|