001: /*
002: * Copyright 2004-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.compass.gps.device.jdbc.mapping;
018:
019: /**
020: * Maps an id column to <code>Resource Property</code>. The id column is the column that identifies
021: * or is part of columns that identifies the <code>ResultSet</code>. In a
022: * table, it is the table primary keys.
023: * <p>
024: * The <code>PropertyIndex</code> is <code>Property.Index.UN_TOKENIZED</code>.
025: * the <code>PropertyStore</code> is <code>Property.Store.YES</code>, the
026: * <code>PropertyTermVector</code> is <code>Property.TermVector.NO</code>
027: * and the <code>Boost</code> is <code>1.0f</code>.
028: * <p>
029: * The id mapping also holds an additional mapping, the
030: * <code>columnNameForVersion</code> mapping. When performing the mirror
031: * operation (if enabled), it is the id column name that is added to the select
032: * query in order to filter by the specified ids. For example, if the select
033: * query is (for a PARENT and CHILD table relationship):
034: * <code>select p.id as parent_id, p.first_name as parent_first_name, p.last_name as parent_last_name, p.version as parent_version, COALESCE(c.id, 0) as child_id, c.first_name as child_first_name, c.last_name child_last_name, COALESCE(c.version, 0) as child_version from parent p left join child c on p.id = c.parent_id</code>
035: * than when performing the query to get the values for certain values of ids
036: * (the parent and child ids), the column names that will be used are:
037: * <code>p.id</code> and <code>COALESCE(c.id, 0)</code>. And the actual
038: * where clause will be: <code>where p.id = ? and COALESCE(c.id, 0) = ?</code>.
039: * <p>
040: * Note, that the id column name is <code>parent_id</code>, and
041: * <code>child_id</code>. They are used for reading the id values, not
042: * constructing queries.
043: *
044: * @author kimchy
045: */
046: public class IdColumnToPropertyMapping extends
047: AbstractConstantColumnToPropertyMapping {
048:
049: private String columnNameForVersion;
050:
051: /**
052: * Creates an empty id column to property mapping. Must set at least the
053: * colum index or colum name, and the property name. If using mirroring,
054: * must set the column name for version as well.
055: */
056: public IdColumnToPropertyMapping() {
057:
058: }
059:
060: /**
061: * Creates a new Id column to propery mapping given the column name and the
062: * property name. The column name will also be used as the
063: * <code>columnNameForVersion</code> value.
064: *
065: * @param columnName
066: * The id column name that will be used to look up the id value
067: * (also acts as the columnNameForVersion).
068: * @param propertyName
069: * The Compass <code>Resource Property</code> name.
070: */
071: public IdColumnToPropertyMapping(String columnName,
072: String propertyName) {
073: this (columnName, propertyName, columnName);
074: }
075:
076: /**
077: * Creates a new Id column to property mapping given the column name, the
078: * property name, and the column name for the versioning (the mirror
079: * operation).
080: *
081: * @param columnName
082: * The id column name that will be used to look up the id value.
083: * @param propertyName
084: * The Compass <code>Resource Property</code> name.
085: * @param columnNameForVersion
086: * The id column name that will be used in the dynamically
087: * created where clause with the original select query.
088: */
089: public IdColumnToPropertyMapping(String columnName,
090: String propertyName, String columnNameForVersion) {
091: super (columnName, propertyName);
092: this .columnNameForVersion = columnNameForVersion;
093: }
094:
095: /**
096: * Creates a new Id Column to property mapping given the column index and
097: * the property name. Note that the column name for versioning will be null,
098: * so if mirroring will be enabled, it must be set.
099: *
100: * @param columnIndex
101: * The id column index that will be used to look up the id value.
102: * @param propertyName
103: * The Compass <code>Resource Property</code> name.
104: */
105: public IdColumnToPropertyMapping(int columnIndex,
106: String propertyName) {
107: this (columnIndex, propertyName, null);
108: }
109:
110: /**
111: * Creates a new Id Column to property mapping given the column index, the
112: * property name, and the column name for the versioning (the mirror
113: * operation).
114: *
115: * @param columnIndex
116: * The id column index that will be used to look up the id value.
117: * @param propertyName
118: * The Compass <code>Resource Property</code> name.
119: * @param columnNameForVersion
120: * The id column name that will be used in the dynamically
121: * created where clause with the original select query.
122: */
123: public IdColumnToPropertyMapping(int columnIndex,
124: String propertyName, String columnNameForVersion) {
125: super (columnIndex, propertyName);
126: this .columnNameForVersion = columnNameForVersion;
127: }
128:
129: /**
130: * Returns the id column name that will be used in the dynamically created
131: * where clause with the original select query.
132: */
133: public String getColumnNameForVersion() {
134: return columnNameForVersion;
135: }
136:
137: /**
138: * Sets the id column name that will be used in the dynamically created
139: * where clause with the original select query.
140: *
141: * @param columnNameForVersion
142: * The id column name that will be used in the dynamically
143: * created where clause with the original select query.
144: */
145: public void setColumnNameForVersion(String columnNameForVersion) {
146: this.columnNameForVersion = columnNameForVersion;
147: }
148:
149: }
|