001: /**********************************************************************
002: Copyright (c) 2004 Andy Jefferson and others. All rights reserved.
003: Licensed under the Apache License, Version 2.0 (the "License");
004: you may not use this file except in compliance with the License.
005: You may obtain a copy of the License at
006:
007: http://www.apache.org/licenses/LICENSE-2.0
008:
009: Unless required by applicable law or agreed to in writing, software
010: distributed under the License is distributed on an "AS IS" BASIS,
011: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: See the License for the specific language governing permissions and
013: limitations under the License.
014:
015:
016: Contributors:
017: ...
018: **********************************************************************/package org.jpox.store;
019:
020: import org.jpox.StateManager;
021: import org.jpox.exceptions.JPOXObjectNotFoundException;
022: import org.jpox.metadata.AbstractMemberMetaData;
023: import org.jpox.metadata.IdentityType;
024: import org.jpox.store.mapping.JavaTypeMapping;
025: import org.jpox.store.mapping.MappingConsumer;
026:
027: /**
028: * Representation of a Java class in a datastore.
029: * In the case of RDBMS this will be a table (primary or secondary).
030: * In the case of a file-based structure this may be a directory.
031: * In the case of an XML-based structure this may be an element.
032: *
033: * @version $Revision: 1.37 $
034: **/
035: public interface DatastoreClass extends DatastoreContainerObject {
036: /**
037: * Accessor for the primary class represented.
038: * @return Name of the class
039: **/
040: String getType();
041:
042: /**
043: * Accessor for the identity-type used by this table.
044: * @return identity-type tag value
045: */
046: public IdentityType getIdentityType();
047:
048: /**
049: * Accessor for whether the object id will be attributed by the datastore
050: * directly, or whether values have to be supplied.
051: * @return Whether it is attributed in the datastore
052: */
053: boolean isObjectIDDatastoreAttributed();
054:
055: /**
056: * Accessor for whether this datastore class is the base datastore class
057: * for this inheritance hierarchy.
058: * @return Whether it is the base.
059: */
060: boolean isBaseDatastoreClass();
061:
062: /**
063: * Method to return the base DatastoreClass that persists the
064: * specified field. This navigates up through the superclass
065: * tables to find a table that manages the field.
066: * @param fmd MetaData for the field required
067: * @return The DatastoreClass managing that field
068: */
069: public DatastoreClass getBaseDatastoreClassWithField(
070: AbstractMemberMetaData fmd);
071:
072: /**
073: * Accessor for the supertable for this table.
074: * This is only relevant if the DatastoreClass in use supports supertables.
075: * If supertables arent supported by the datastore then null is returned.
076: * @return The supertable (if any)
077: **/
078: public DatastoreClass getSuperDatastoreClass();
079:
080: /**
081: * Accessor for whether this table manages the specified class
082: * @param className Name of the class
083: * @return Whether it is managed by this table
084: */
085: public boolean managesClass(String className);
086:
087: /**
088: * Method to insert an object for this class.
089: * Will insert any superclass records as well (recursive).
090: * @param sm StateManager for the object to insert.
091: **/
092: void insert(StateManager sm);
093:
094: /**
095: * Method to fetch an object for this class.
096: * Will fetch any superclass records as well (recursive).
097: * @param sm StateManager for the object to fetch.
098: * @param fieldMetaData MetaData for the fields to be fetched
099: */
100: void fetch(StateManager sm, AbstractMemberMetaData[] fieldMetaData);
101:
102: /**
103: * Method to update an object for this class.
104: * Will update any superclass records as well (recursive).
105: * @param sm StateManager for the object to update.
106: * @param fieldMetaData MetaData for the fields to be updated
107: */
108: void update(StateManager sm, AbstractMemberMetaData[] fieldMetaData);
109:
110: /**
111: * Method to delete an object for this class.
112: * Will delete any superclass records as well (recursive).
113: * @param sm StateManager for the object to delete.
114: **/
115: void delete(StateManager sm);
116:
117: /**
118: * Locates this object in the datastore.
119: * @param sm The StateManager for the object to be found
120: * @throws JPOXObjectNotFoundException If the instance does not exist in the datastore
121: */
122: void locate(StateManager sm);
123:
124: /**
125: * Accessor for the name of the datastore class (table).
126: * @return The name
127: */
128: String toString();
129:
130: // --------------------------- Mapping Access ------------------------------
131:
132: /**
133: * Accessor for a mapping for the datastore ID (OID) for this object.
134: * @return The (OID) mapping.
135: **/
136: JavaTypeMapping getDataStoreObjectIdMapping();
137:
138: /**
139: * Accessor for the mapping for the specified field name.
140: * Doesn't cope with fields of the same name in different subclasses - you
141: * should call the equivalent method passing FieldMetaData for those.
142: * @param fieldName Name of field
143: * @return The Mapping for the field.
144: */
145: JavaTypeMapping getFieldMapping(String fieldName);
146:
147: /**
148: * Accessor for the mapping for the specified field.
149: * @param mmd Metadata of the field/property
150: * @return The Mapping for the field.
151: */
152: JavaTypeMapping getFieldMapping(AbstractMemberMetaData mmd);
153:
154: /**
155: * Accessor for the mapping for the specified field only in this datastore class.
156: * @param mmd Metadata of the field/property
157: * @return The Mapping for the field (or null if not present here)
158: */
159: JavaTypeMapping getFieldMappingInDatastoreClass(
160: AbstractMemberMetaData mmd);
161:
162: /**
163: * Accessor for a mapping for the datastore ID (OID) for this table.
164: * @param consumer Consumer for the mappings
165: **/
166: void provideDatastoreIdMappings(MappingConsumer consumer);
167:
168: /**
169: * Provide the mappings to the consumer for all primary-key fields mapped to
170: * this table (for application identity).
171: * @param consumer Consumer for the mappings
172: */
173: void providePrimaryKeyMappings(MappingConsumer consumer);
174:
175: /**
176: * Provide the mappings to the consumer for all non primary-key fields
177: * mapped to this table.
178: * @param consumer Consumer for the mappings
179: */
180: void provideNonPrimaryKeyMappings(MappingConsumer consumer);
181:
182: /**
183: * Provide the mappings to the consumer for all absolute field Numbers in this table
184: * that are container in the fieldNumbers parameter.
185: * @param consumer Consumer for the mappings
186: * @param fieldMetaData MetaData of the fields to provide mappings for
187: * @param includeSecondaryTables Whether to supply fields in secondary tables
188: */
189: void provideMappingsForFields(MappingConsumer consumer,
190: AbstractMemberMetaData[] fieldMetaData,
191: boolean includeSecondaryTables);
192:
193: /**
194: * Provide the mappings to version mappings
195: * @param consumer Consumer for the version mappings
196: */
197: void provideVersionMappings(MappingConsumer consumer);
198:
199: /**
200: * Provide the mappings to discriminator mappings
201: * @param consumer Consumer for the mappings
202: */
203: void provideDiscriminatorMappings(MappingConsumer consumer);
204:
205: /**
206: * Instruction to provide all datastore fields without mappings.
207: * @param consumer The consumer for the datastore fields
208: */
209: void provideUnmappedDatastoreFields(MappingConsumer consumer);
210:
211: /**
212: * Instruction to provide all external mappings to the passed consumer.
213: * @param consumer The consumer for the mappings
214: * @param mappingType Type of external mapping to provide
215: */
216: void provideExternalMappings(MappingConsumer consumer,
217: int mappingType);
218:
219: /**
220: * Accessor for the external mapping for the specified field of the specified type.
221: * An external mapping is a mapping for which there is no field in the actual class
222: * to represent it (part of a relation).
223: * The type can be FK, FK discriminator, order, etc
224: * @param fmd MetaData for the (external) field
225: * @param mappingType The type of mapping
226: * @return The external mapping
227: */
228: JavaTypeMapping getExternalMapping(AbstractMemberMetaData fmd,
229: int mappingType);
230:
231: /**
232: * Accessor for the owner field metadata for the specified external mapping of the
233: * specified type
234: * @param mapping The external mapping
235: * @param mappingType The type of mapping
236: * @return Field MetaData in the owner class
237: */
238: AbstractMemberMetaData getMetaDataForExternalMapping(
239: JavaTypeMapping mapping, int mappingType);
240: }
|