KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > versant > core > jdbc > JoinStructure


1
2 /*
3  * Copyright (c) 1998 - 2005 Versant Corporation
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * Versant Corporation - initial API and implementation
11  */

12 package com.versant.core.jdbc;
13
14 import com.versant.core.metadata.FetchGroupField;
15 import com.versant.core.metadata.MDStatics;
16 import com.versant.core.metadata.FetchGroup;
17
18 import java.util.List JavaDoc;
19 import java.util.ArrayList JavaDoc;
20
21 /**
22  * This is a dataStructure that is used to remember join conditions.
23  * This is a composite structure where by a child knows its parent, but not
24  * the other way round.
25  */

26 public class JoinStructure implements Comparable JavaDoc {
27     public FetchGroupField fgField;
28     public JoinStructure parent;
29     public boolean refField;
30     public int level = 1;
31
32     public FetchGroupField[] fgFields;
33     /**
34      * If this is the root of the joinStructTree
35      */

36     public boolean rootJoinStructure;
37     /**
38      * This is a collection of all the JoinStructure end points that is a
39      * collection.
40      */

41     public List JavaDoc colJoinStructs;
42     public FetchGroup fetchGroup;
43     private boolean finished;
44
45     public JoinStructure(FetchGroup fg) {
46         rootJoinStructure = true;
47         colJoinStructs = new ArrayList JavaDoc();
48         this.fetchGroup = fg;
49     }
50
51     public JoinStructure(JoinStructure parent, FetchGroupField field) {
52         this.fgField = field;
53         this.setParent(parent);
54         this.refField = (field.fmd.category == MDStatics.CATEGORY_REF);
55         if (!refField) {
56             addColJoinStruct(this);
57         }
58     }
59
60     public boolean isRefField() {
61         return refField;
62     }
63
64     /**
65      * Called to finalize the structure.
66      */

67     public void finish() {
68         if (finished) return;
69         finished = true;
70         List JavaDoc structs = colJoinStructs;
71         if (structs == null) return;
72         for (int i = 0; i < structs.size(); i++) {
73             JoinStructure js = (JoinStructure) structs.get(i);
74             js.finishImp();
75         }
76     }
77
78     private void finishImp() {
79         fgFields = new FetchGroupField[level - 1];
80         appendTo(fgFields);
81     }
82
83     private void appendTo(FetchGroupField[] fgFArray) {
84         if (rootJoinStructure) return;
85         fgFArray[level - 2] = fgField;
86         parent.appendTo(fgFArray);
87     }
88
89     private void addColJoinStruct(JoinStructure js) {
90         if (rootJoinStructure) {
91             colJoinStructs.add(js);
92         } else {
93             parent.addColJoinStruct(js);
94         }
95     }
96
97     private void setParent(JoinStructure joinStructure) {
98         if (joinStructure != null) {
99             parent = joinStructure;
100             level = parent.level + 1;
101         }
102     }
103
104     public int compareTo(Object JavaDoc o) {
105         JoinStructure other = (JoinStructure) o;
106         return level - other.level;
107     }
108
109     public String JavaDoc toString() {
110         if (rootJoinStructure) {
111             return "JoinStructure2@" + System.identityHashCode(this) + " for ROOT";
112         } else {
113             return "JoinStructure2@" + System.identityHashCode(this) + " for " + fgField.fmd.name + " ref " + isRefField();
114         }
115     }
116
117     public void dump(String JavaDoc indent) {
118         System.out.println(indent + "this = " + this + " finished " + finished);
119         if (colJoinStructs == null) return;
120         for (int i = 0; i < colJoinStructs.size(); i++) {
121             JoinStructure joinStructure = (JoinStructure) colJoinStructs.get(i);
122             joinStructure.dump(indent + " ");
123         }
124     }
125 }
126
Popular Tags