001: /*
002: * Copyright (c) 1998 - 2005 Versant Corporation
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * Versant Corporation - initial API and implementation
010: */
011: package com.versant.core.jdbc.sql.exp;
012:
013: import com.versant.core.jdbc.metadata.JdbcField;
014: import com.versant.core.jdbc.metadata.JdbcColumn;
015: import com.versant.core.jdo.query.ParamNode;
016:
017: import java.util.Map;
018:
019: /**
020: * This tracks usage of this parameter in an SqlExp tree.
021: * A parameter may be used several times in the same tree if it is
022: * used more than once in the original filter expression. This will be
023: * null if the param is not used.<p>
024: *
025: * A parameter may also have to be split into more than one SqlExp
026: * if it is compared to a field with multiple columns. The first
027: * expression is expList. The expcount field specifies how far down
028: * the list to go as expList may be part of a larger list.
029: *
030: * @see com.versant.core.jdo.query.ParamNode#usageList
031: */
032: public class ParamNodeUsage {
033:
034: /**
035: * Add us to the end of the usage list for n.
036: */
037: public void addToParamNode(ParamNode n) {
038: if (n.usageList == null) {
039: n.usageList = this ;
040: } else {
041: ParamNodeUsage p = (ParamNodeUsage) n.usageList;
042: for (; p.next != null; p = p.next)
043: ;
044: p.next = this ;
045: }
046: }
047:
048: /**
049: * The field for this parameter or null if it is not being compared
050: * to a field.
051: * @see #javaTypeCode
052: * @see #jdbcType
053: */
054: public JdbcField jdbcField;
055:
056: public JdbcColumn col;
057: /**
058: * The java type code of this usage of the parameter. This is not
059: * set if jdbcField is not null.
060: * @see #jdbcField
061: */
062: public int javaTypeCode;
063: /**
064: * The JDBC type of this usage of the parameter. This is not
065: * set if jdbcField is not null.
066: * @see java.sql.Types
067: * @see #jdbcField
068: */
069: public int jdbcType;
070: /**
071: * The class index of the class for this parameter (-1 if unknown).
072: * This is used for OID parameters compared to columns that are
073: * not associated with a field e.g. in a link table.
074: */
075: public int classIndex;
076: /**
077: * The first expression for this usage of the parameter. This is
078: * the parent of the first ParamExp instance for this usage.
079: */
080: public SqlExp expList;
081: /**
082: * The number of expressions in expList for this usage of the
083: * parameter. If a param is used with a field split over multiple
084: * columns then this will be more than 1. This will be zero if
085: * the parameter never has to be converted into a 'is null' or
086: * 'is not null' expression.
087: */
088: public int expCount;
089: /**
090: * How must the parameter value be modified before being set? This is
091: * used for startsWith and endsWith for databases that do not allow
092: * expressions on the right hand side of a LIKE (e.g. Informix).
093: * @see com.versant.core.jdbc.query.SqlStruct.Param#MOD_APPEND_PERCENT
094: */
095: public int mod;
096: /**
097: * The next usage in the list.
098: */
099: public ParamNodeUsage next;
100:
101: public ParamNodeUsage getClone(Map cloneMap) {
102: ParamNodeUsage sqlUsage = new ParamNodeUsage();
103: sqlUsage.jdbcField = jdbcField;
104: sqlUsage.javaTypeCode = javaTypeCode;
105: sqlUsage.jdbcType = jdbcType;
106: sqlUsage.classIndex = classIndex;
107: sqlUsage.expCount = expCount;
108: sqlUsage.mod = mod;
109: sqlUsage.expList = SqlExp.createClone(expList, cloneMap);
110: if (next != null) {
111: sqlUsage.next = next.getClone(cloneMap);
112: }
113: return sqlUsage;
114: }
115: }
|