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: 2004 Erik Bengtson - added datastore mapping accessors
018: ...
019: *****************************************************************/package org.jpox.store.mapping;
020:
021: import org.jpox.ClassLoaderResolver;
022: import org.jpox.metadata.AbstractMemberMetaData;
023: import org.jpox.metadata.ColumnMetaData;
024: import org.jpox.plugin.PluginManager;
025: import org.jpox.store.DatastoreAdapter;
026: import org.jpox.store.DatastoreContainerObject;
027: import org.jpox.store.DatastoreField;
028: import org.jpox.store.StoreManager;
029:
030: /**
031: * Representation of a MappingManager, mapping a java mapping type to a datastore mapping type.
032: * Allows a java mapping type to map to multiple datastore mapping types.
033: * Allows a default datastore mapping type be assigned to each java mapping type.
034: *
035: * @version $Revision: 1.29 $
036: */
037: public interface MappingManager {
038: /**
039: * Initialise the datastore mapping.
040: * @param mgr the PlyginManager
041: * @param clr the ClassLoaderResolver
042: * @param vendorId the datastore vendor id
043: */
044: void loadDatastoreMapping(PluginManager mgr,
045: ClassLoaderResolver clr, String vendorId);
046:
047: // --------------------------------------------- Java Types ---------------------------------------------
048:
049: /**
050: * Accessor for a mapping, for a java type.
051: * @param c The java type
052: * @param serialised Whether the type is serialised
053: * @param embedded Whether the type is embedded
054: * @param storeMgr Manager for the datastore
055: * @param fieldName Name of the field (for logging only)
056: * @return The mapping
057: */
058: JavaTypeMapping getMapping(Class c, boolean serialised,
059: boolean embedded, StoreManager storeMgr, String fieldName);
060:
061: /**
062: * Accessor for a mapping, for a java type.
063: * @param c The java type
064: * @param serialised Whether the type is serialised
065: * @param embedded Whether the type is embedded
066: * @param storeMgr Manager of the store
067: * @param clr ClassLoader resolver
068: * @return The mapping
069: */
070: JavaTypeMapping getMapping(Class c, boolean serialised,
071: boolean embedded, StoreManager storeMgr,
072: ClassLoaderResolver clr);
073:
074: /**
075: * Accessor for a mapping for a field, mapped to a table
076: * @param table The table
077: * @param fmd MetaData for the field
078: * @param dba Datastore adapter
079: * @param clr ClassLoader resolver
080: * @param mappingFieldType Field type for the mapping
081: * @return The mapping
082: */
083: JavaTypeMapping getMapping(DatastoreContainerObject table,
084: AbstractMemberMetaData fmd, DatastoreAdapter dba,
085: ClassLoaderResolver clr, int mappingFieldType);
086:
087: // ----------------------------------------- Datastore Types ---------------------------------------------
088:
089: /**
090: * Method to create the datastore mapping for a java type mapping at a particular index.
091: * @param mapping The java mapping
092: * @param fmd MetaData for the field
093: * @param index Index of the datastore field
094: * @param srm Store Manager
095: * @param column The column
096: * @return The datastore mapping
097: */
098: DatastoreMapping createDatastoreMapping(JavaTypeMapping mapping,
099: AbstractMemberMetaData fmd, int index, StoreManager srm,
100: DatastoreField column);
101:
102: /**
103: * Method to create the datastore mapping for a particular column and java type.
104: * @param mapping The java mapping
105: * @param storeMgr Store Manager
106: * @param column The column
107: * @param javaType The java type (isnt this stored in the java mapping ?)
108: * @return The datastore mapping
109: */
110: DatastoreMapping createDatastoreMapping(JavaTypeMapping mapping,
111: StoreManager storeMgr, DatastoreField column,
112: String javaType);
113:
114: /**
115: * Method to create a datastore field (column) in a container (table).
116: * @param mapping The java mapping
117: * @param javaType The java type
118: * @param datastoreFieldIndex The index of the datastore field to create
119: * @return The datastore field
120: */
121: DatastoreField createDatastoreField(JavaTypeMapping mapping,
122: String javaType, int datastoreFieldIndex);
123:
124: /**
125: * Method to create a datastore field (column) in a container (table).
126: * To be used for serialised PC element/key/value in a join table.
127: * @param mapping The java mapping
128: * @param javaType The java type
129: * @param colmd MetaData for the column to create
130: * @return The datastore field
131: */
132: DatastoreField createDatastoreField(JavaTypeMapping mapping,
133: String javaType, ColumnMetaData colmd);
134:
135: /**
136: * Method to create a datastore field for a PersistenceCapable mapping.
137: * @param fmd MetaData for the field
138: * @param datastoreContainer The container in the datastore
139: * @param mapping The java mapping
140: * @param colmd MetaData for the column to create
141: * @param reference The field to reference
142: * @param clr ClassLoader resolver
143: * @return The datastore field
144: */
145: DatastoreField createDatastoreField(AbstractMemberMetaData fmd,
146: DatastoreContainerObject datastoreContainer,
147: JavaTypeMapping mapping, ColumnMetaData colmd,
148: DatastoreField reference, ClassLoaderResolver clr);
149:
150: /**
151: * Utility to register a datastore mapping for a java type, and the SQL/JDBC types it can be mapped to.
152: * This can also be called to change the default setting of a mapping - just supply the same
153: * values of java/JDBC/SQL types and a different default value
154: * @param javaTypeName Name of the java type
155: * @param datastoreMappingType The datastore mapping
156: * @param jdbcType The JDBC type that can be used
157: * @param sqlType The SQL type that can be used
158: * @param dflt Whether this type should be used as the default mapping for this Java type
159: */
160: void registerDatastoreMapping(String javaTypeName,
161: Class datastoreMappingType, String jdbcType,
162: String sqlType, boolean dflt);
163: }
|