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.metadata;
012:
013: import com.versant.core.metadata.parser.JdoExtension;
014: import com.versant.core.common.Debug;
015:
016: import java.io.Serializable;
017: import java.io.PrintStream;
018:
019: /**
020: * A field in a fetch group. This holds the field and assorted store
021: * specific options.
022: */
023: public class FetchGroupField implements Serializable {
024:
025: /**
026: * The field.
027: */
028: public FieldMetaData fmd;
029: /**
030: * The parsed meta data for this field (null if none i.e. automatically
031: * generated default fetch group).
032: */
033: public JdoExtension extension;
034: /**
035: * If a store does read ahead (e.g. a JDBC store using a join) and this
036: * field is a reference to another PC class then get the fields in this
037: * fetch group of that class. This will never be null as it is set to
038: * the default fetch group if not specified.
039: */
040: public FetchGroup nextFetchGroup;
041: /**
042: * If a store does read ahead (e.g. a JDBC store using a join) and this
043: * field is a map and the keys reference another PC class then get the
044: * fields in this fetch group of that class. This will never be null as
045: * it is set to the default fetch group if not specified.
046: */
047: public FetchGroup nextKeyFetchGroup;
048:
049: /**
050: * This flag is used to include reference fields in a fetch group
051: * and to fetch only the OID of the reference and not the referenced
052: * object as well.
053: */
054: public boolean doNotFetchObject;
055:
056: /**
057: * If this is a ref or a collection then this is the useJoin option
058: * to use when this group is fetched. The fields picked up by the join
059: * will be those in the nextFetchGroup of the referenced class.
060: * Values are from JdbcField: USE_JOIN_NO USE_JOIN_INNER USE_JOIN_OUTER.
061: * @see #nextFetchGroup
062: */
063: public int jdbcUseJoin;
064: /**
065: * If this is a map and the keys are a PC class then this is the useJoin
066: * option to use when this group is fetched. The fields picked up by the
067: * join will be those in the nextKeyFetchGroup of the referenced class.
068: * Values are from JdbcField: USE_JOIN_NO USE_JOIN_INNER USE_JOIN_OUTER.
069: * @see #nextKeyFetchGroup
070: */
071: public int jdbcUseKeyJoin;
072: /**
073: * Cache for SQL required to fetch this field. This is normally only
074: * used for pass 2 fields e.g. collections and so on.
075: */
076: public String jdbcSelectSql;
077: /**
078: * Cache for SQL required to fetch this field when selectForUpdate is on.
079: * This is normally only used for pass 2 fields e.g. collections and so on.
080: */
081: public String jdbcSelectSqlForUpdate;
082:
083: public FetchGroupField(FieldMetaData field) {
084: this .fmd = field;
085: }
086:
087: private static String toUseJoinString(int useJoin) {
088: // dont use constants from JdbcRefField to avoid engine depending
089: // on jdbc
090: switch (useJoin) {
091: case 1:
092: return "NO";
093: case 3:
094: return "INNER";
095: case 2:
096: return "OUTER";
097: }
098: return "unknown(" + useJoin + ")";
099: }
100:
101: public String toString() {
102: return String.valueOf(fmd)
103: + " jdbcUseJoin "
104: + toUseJoinString(jdbcUseJoin)
105: + " nextFetchGroup "
106: + nextFetchGroup
107: + (fmd.category == MDStatics.CATEGORY_MAP ? " jdbcUseKeyJoin "
108: + toUseJoinString(jdbcUseKeyJoin)
109: + " nextKeyFetchGroup " + nextKeyFetchGroup
110: : "");
111: }
112:
113: public void dump() {
114: dump(Debug.OUT, "");
115: }
116:
117: public void dump(PrintStream out, String indent) {
118: out.println(indent + this);
119: }
120: }
|