001: /**********************************************************************
002: Copyright (c) 2005 Erik Bengtson 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: Contributors:
016: 2006 Andy Jefferson - changed to interface
017: ...
018: **********************************************************************/package org.jpox.store;
019:
020: import org.jpox.ClassLoaderResolver;
021: import org.jpox.metadata.AbstractClassMetaData;
022: import org.jpox.metadata.AbstractMemberMetaData;
023: import org.jpox.store.DatastoreIdentifier;
024:
025: /**
026: * Factory that creates immutable instances of DatastoreIdentifier.
027: * Identifiers are of a particular type. Each datastore could invent its own particular types
028: * as required, just that the ones here should be the principal types required.
029: *
030: * @version $Revision: 1.16 $
031: */
032: public interface IdentifierFactory {
033: /** Representation of an identifier specified in UPPER CASE */
034: public static final int IDENTIFIER_UPPER_CASE = 0;
035:
036: /** Representation of an identifier specified in "UPPER CASE" */
037: public static final int IDENTIFIER_UPPER_CASE_QUOTED = 1;
038:
039: /** Representation of an identifier specified in lower case. */
040: public static final int IDENTIFIER_LOWER_CASE = 2;
041:
042: /** Representation of an identifier specified in "lower case" */
043: public static final int IDENTIFIER_LOWER_CASE_QUOTED = 3;
044:
045: /** Representation of an identifier specified in Mixed Case. */
046: public static final int IDENTIFIER_MIXED_CASE = 4;
047:
048: /** Representation of an identifier specified in "Mixed Case". */
049: public static final int IDENTIFIER_MIXED_CASE_QUOTED = 5;
050:
051: // TODO Not all of these statics are applicable to all datastores, so maybe trim them down and move some to RDBMS */
052: /** identifier for table names **/
053: public final static int TABLE = 0;
054:
055: /** column **/
056: public final static int COLUMN = 1;
057:
058: /** foreign key **/
059: public final static int FOREIGN_KEY = 2;
060:
061: /** index **/
062: public final static int INDEX = 3;
063:
064: /** candidate key - unique index constraint **/
065: public final static int CANDIDATE_KEY = 4;
066:
067: /** primary key **/
068: public final static int PRIMARY_KEY = 5;
069:
070: /** identifier for datastore sequence. */
071: public final static int SEQUENCE = 6;
072:
073: /**
074: * Accessor for the datastore adapter that we are creating identifiers for.
075: * @return The datastore adapter
076: */
077: DatastoreAdapter getDatastoreAdapter();
078:
079: /**
080: * Accessor for the identifier case being used.
081: * @return The identifier case
082: */
083: int getIdentifierCase();
084:
085: /**
086: * Convenience method to return the name for the identifier case.
087: * @return Identifier case name
088: */
089: String getNameOfIdentifierCase();
090:
091: /**
092: * Accessor for an identifier for use in the datastore adapter
093: * @param identifier The identifier name
094: * @return Identifier name for use with the datastore adapter
095: */
096: String getIdentifierInAdapterCase(String identifier);
097:
098: /**
099: * To be called when we want an identifier name creating based on the
100: * identifier. Creates identifier for COLUMN, FOREIGN KEY, INDEX and TABLE
101: * @param identifierType the type of identifier to be created
102: * @param sqlIdentifier The SQL identifier name
103: * @return The DatastoreIdentifier
104: */
105: DatastoreIdentifier newIdentifier(int identifierType,
106: String sqlIdentifier);
107:
108: /**
109: * Method to use to generate an identifier for a datastore field with the supplied name.
110: * The passed name will not be changed (other than in its case) although it may
111: * be truncated to fit the maximum length permitted for a datastore field identifier.
112: * @param identifierName The identifier name
113: * @return The DatastoreIdentifier for the table
114: */
115: DatastoreIdentifier newDatastoreContainerIdentifier(
116: String identifierName);
117:
118: /**
119: * Method to return a Table identifier for the specified class.
120: * @param clr the ClassLoaderResolver
121: * @param md Meta data for the class
122: * @return The identifier for the table
123: **/
124: DatastoreIdentifier newDatastoreContainerIdentifier(
125: ClassLoaderResolver clr, AbstractClassMetaData md);
126:
127: /**
128: * Method to return a Table identifier for the specified field.
129: * @param clr the ClassLoaderResolver
130: * @param fmd Meta data for the field
131: * @return The identifier for the table
132: **/
133: DatastoreIdentifier newDatastoreContainerIdentifier(
134: ClassLoaderResolver clr, AbstractMemberMetaData fmd);
135:
136: /**
137: * Method to use to generate an identifier for a datastore field with the supplied name.
138: * The passed name will not be changed (other than in its case) although it may
139: * be truncated to fit the maximum length permitted for a datastore field identifier.
140: * @param identifierName The identifier name
141: * @return The DatastoreIdentifier
142: */
143: DatastoreIdentifier newDatastoreFieldIdentifier(
144: String identifierName);
145:
146: /**
147: * Method to create an identifier for a datastore field where we want the
148: * name based on the supplied java name, and the field has a particular
149: * role (and so could have its naming set according to the role).
150: * @param javaName The java field name
151: * @param embedded Whether the identifier is for a field embedded
152: * @param fieldRole The role to be performed by this column e.g FK, Index ?
153: * @return The DatastoreIdentifier
154: */
155: DatastoreIdentifier newDatastoreFieldIdentifier(String javaName,
156: boolean embedded, int fieldRole);
157:
158: /**
159: * Method to generate an identifier name for reference field, based on the metadata for the
160: * field, and the ClassMetaData for the implementation.
161: * @param refMetaData the MetaData for the reference field
162: * @param implMetaData the AbstractClassMetaData for this implementation
163: * @param implIdentifier PK identifier for the implementation
164: * @param embedded Whether the identifier is for a field embedded
165: * @param fieldRole The role to be performed by this column e.g FK, collection element ?
166: * @return The DatastoreIdentifier
167: */
168: DatastoreIdentifier newReferenceFieldIdentifier(
169: AbstractMemberMetaData refMetaData,
170: AbstractClassMetaData implMetaData,
171: DatastoreIdentifier implIdentifier, boolean embedded,
172: int fieldRole);
173:
174: /**
175: * Method to return an identifier for a discriminator datastore field.
176: * @return The discriminator datastore field identifier
177: */
178: DatastoreIdentifier newDiscriminatorFieldIdentifier();
179:
180: /**
181: * Method to return an identifier for a version datastore field.
182: * @return The version datastore field identifier
183: */
184: DatastoreIdentifier newVersionFieldIdentifier();
185:
186: /**
187: * Method to return a new Identifier based on the passed identifier, but adding on the passed suffix
188: * @param identifier The current identifier
189: * @param suffix The suffix
190: * @return The new identifier
191: */
192: DatastoreIdentifier newIdentifier(DatastoreIdentifier identifier,
193: String suffix);
194: }
|