001: /**********************************************************************
002: Copyright (c) 2003 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:
016: Contributors:
017: ...
018: **********************************************************************/package org.jpox.store;
019:
020: import org.jpox.store.mapping.JavaTypeMapping;
021:
022: /**
023: * Maintain an index for the mapping field vs columns in a JDBC statement.
024: * Each field for a Request (in a Statement) must have one instance of this
025: * containing the field Number + Mapping + the columns
026: * <PRE>
027: * e.g.
028: * CLASS FIELDNUMBER MAPPING TABLE EXPRESSION INDEX (JDBC)
029: * ----------------- ----------- -------------- ---------------- ----------------
030: * class A --> --> --> TABLE_A
031: * {
032: * int fieldA; --> 1 --> IntegerMapping --> COL_FIELDA --> 1
033: * String fieldB; --> 2 --> StringMapping --> COL_FIELDB_PART1 --> 2
034: * --> --> --> COL_FIELDB_PART2 --> 3
035: * ...
036: * }
037: * </PRE>
038: *
039: * @version $Revision: 1.4 $
040: */
041: public class StatementExpressionIndex {
042: /** the mapping to the field **/
043: JavaTypeMapping mapping;
044:
045: /** the index for a column in the statement **/
046: int[] expressionIndex;
047:
048: /** the index for a parameter in the statement **/
049: int[] parameterIndex;
050:
051: /** Any name applied in the field selection (SELECT xxx AS yyy). Only applies for cases with 1 column. */
052: String columnName;
053:
054: /**
055: * Accessor for the expression index(es).
056: * @return The expression index
057: */
058: public int[] getExpressionIndex() {
059: return expressionIndex;
060: }
061:
062: /**
063: * Accessor for the mapping for the field.
064: * @return The mapping
065: */
066: public JavaTypeMapping getMapping() {
067: return mapping;
068: }
069:
070: /**
071: * Accessor for the column name (if any).
072: * @return The column name.
073: */
074: public String getColumnName() {
075: if (columnName != null) {
076: return columnName;
077: } else if (mapping != null
078: && mapping.getFieldMetaData() != null) {
079: return mapping.getFieldMetaData().getName();
080: }
081: return null;
082: }
083:
084: /**
085: * Mutator for the JDBC expression index(es).
086: * This is the position in the JDBC result set.
087: * @param is The expression index
088: */
089: public void setExpressionIndex(int[] is) {
090: expressionIndex = is;
091: }
092:
093: /**
094: * Mutator for the mapping for the field.
095: * @param mapping The mapping
096: */
097: public void setMapping(JavaTypeMapping mapping) {
098: this .mapping = mapping;
099: }
100:
101: /**
102: * Mutator for the column name (alias).
103: * Overrides the name of the field that the mapping refers to.
104: * @param colName The name of the column (alias).
105: */
106: public void setColumnName(String colName) {
107: this .columnName = colName;
108: }
109:
110: /**
111: * Accessor for the parameter index(es).
112: * @return The parameter index
113: */
114: public int[] getParameterIndex() {
115: return parameterIndex;
116: }
117:
118: /**
119: * @param is The parameter index
120: */
121: public void setParameterIndex(int[] is) {
122: parameterIndex = is;
123: }
124:
125: /**
126: * Method to return a string version of this object.
127: * @return String version
128: **/
129: public String toString() {
130: StringBuffer buffer = new StringBuffer();
131: buffer.append("mapping: " + mapping);
132: buffer.append("\n");
133: buffer.append("parameterIndex: " + parameterIndex);
134: buffer.append("\n");
135: buffer.append("expressionIndex: " + expressionIndex);
136: buffer.append("\n");
137: return buffer.toString();
138: }
139: }
|