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.metadata.AbstractMemberMetaData;
021: import org.jpox.metadata.MetaData;
022: import org.jpox.store.mapping.JavaTypeMapping;
023: import org.jpox.store.mapping.DatastoreMapping;
024:
025: /**
026: * Representation of a Java field in a datastore.
027: * In the case of RDBMS this will be a column.
028: * In the case of a file-based structure this may be a file.
029: * In the case of an XML-based structure this may be an node.
030: *
031: * @version $Revision: 1.12 $
032: **/
033: public interface DatastoreField extends DatastoreObject {
034: public static final int ROLE_CUSTOM = -1;
035: public static final int ROLE_NONE = 0;
036: public static final int ROLE_OWNER = 1;
037: public static final int ROLE_FIELD = 2;
038: public static final int ROLE_COLLECTION_ELEMENT = 3;
039: public static final int ROLE_ARRAY_ELEMENT = 4;
040: public static final int ROLE_MAP_KEY = 5;
041: public static final int ROLE_MAP_VALUE = 6;
042: public static final int ROLE_INDEX = 7;
043:
044: /**
045: * Accessor for the type of data stored in this field.
046: * @return The type of data in the field.
047: */
048: String getStoredJavaType();
049:
050: /**
051: * Mutator to make the field the primary key.
052: */
053: void setAsPrimaryKey();
054:
055: /**
056: * Accessor for whether the field is the primary key in the datastore.
057: * @return whether the field is (part of) the primary key
058: */
059: boolean isPrimaryKey();
060:
061: /**
062: * Accessor for whether the field is nullable in the datastore.
063: * @return whether the field is nullable
064: */
065: boolean isNullable();
066:
067: /**
068: * Accessor for the datastore mapping that this datastore field relates to.
069: * @return The datastore mapping
070: */
071: DatastoreMapping getDatastoreMapping();
072:
073: /**
074: * Method to associate this datastore field with its mapping.
075: * @param mapping The mapping for this datastore field
076: */
077: void setDatastoreMapping(DatastoreMapping mapping);
078:
079: /**
080: * Accessor for the Mapping for this field.
081: * TODO Change this to DatastoreMapping since a DatastoreField maps via that and not JavaTypeMapping.
082: * @return The Mapping
083: */
084: JavaTypeMapping getMapping();
085:
086: /**
087: * Accessor for the DatastoreContainerObject container of this field
088: * @return The DatastoreContainerObject
089: */
090: DatastoreContainerObject getDatastoreContainerObject();
091:
092: /**
093: * Wraps the column name with a FUNCTION.
094: * <PRE>example: SQRT(?) generates: SQRT(columnName)</PRE>
095: * @param replacementValue the replacement to ?. Probably it's a column name, that may be fully qualified name or not
096: * @return a String with function taking as parameter the replacementValue
097: */
098: String applySelectFunction(String replacementValue);
099:
100: /**
101: * Copy the configuration of this field to another field
102: * @param col the datastore field
103: */
104: void copyConfigurationTo(DatastoreField col);
105:
106: /**
107: * Mutator for the nullability of the datastore field.
108: * @return The datastore field with the updated info
109: */
110: DatastoreField setNullable();
111:
112: /**
113: * Mutator for the defaultability of the datastore field.
114: * @return The datastore field with the updated info
115: */
116: DatastoreField setDefaultable();
117:
118: /**
119: * Mutator for the identifier of the column.
120: * @param identifier The identifier
121: */
122: void setIdentifier(DatastoreIdentifier identifier);
123:
124: /**
125: * Access the metadata definition defining this DatastoreField.
126: * @return the MetaData
127: */
128: MetaData getMetaData();
129:
130: /**
131: * Method to set the MetaData for this datastore field.
132: * Should only be called before completion of initialisation.
133: * @param md The MetaData
134: */
135: void setMetaData(MetaData md);
136:
137: /**
138: * Accessor for the MetaData of the field that this is the datastore field for.
139: * @return MetaData of the field (if representing a field of a class).
140: */
141: AbstractMemberMetaData getFieldMetaData();
142: }
|