KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > dql > plan > condition > SimpleRelation


1 package com.daffodilwoods.daffodildb.server.sql99.dql.plan.condition;
2
3 import com.daffodilwoods.daffodildb.server.datasystem.indexsystem.*;
4 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
5 import com.daffodilwoods.daffodildb.server.serversystem.*;
6 import com.daffodilwoods.daffodildb.server.sql99.common.*;
7 import com.daffodilwoods.daffodildb.server.sql99.dql.plan.table.*;
8 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*;
9 import com.daffodilwoods.database.resource.*;
10 import com.daffodilwoods.database.utility.P;
11 import java.util.ArrayList JavaDoc;
12
13 /**
14  * It represents inner join condition. It provides the functionality for
15  * checking whether this join condition can be solved with the help of index or
16  * not.
17  * <p>Title: </p>
18  * <p>Description: </p>
19  * <p>Copyright: Copyright (c) 2004</p>
20  * <p>Company: </p>
21  * @author not attributable
22  * @version 1.0
23  */

24 public class SimpleRelation implements _JoinRelation {
25   /**
26    * It represents inner join condition
27    */

28   public booleanvalueexpression joinCondition;
29   /**
30    * It represents list of tablename on which join condition solved.
31    */

32   public String JavaDoc[] relationTables;
33
34    public SimpleRelation(TableDetails[] relationTables0, booleanvalueexpression joinCondition0) throws DException {
35       joinCondition = joinCondition0;
36       /** @todo correction required, in case of view tabledetails will be null of the view */
37       relationTables = new String JavaDoc[relationTables0.length];
38       for (int i = 0; i < relationTables0.length; i++) {
39          relationTables[i] = relationTables0[i].getNameOfTable();
40       }
41
42    }
43    /**
44     * Note:-For documentation of following method please refers to _JoinRelation
45     * @param condition
46     * @throws DException
47     */

48    public void setCondition(booleanvalueexpression condition) throws DException {
49       this.joinCondition = condition;
50    }
51
52    public booleanvalueexpression getCondition() throws DException {
53       return joinCondition;
54    }
55
56    public TableDetails[] getTableDetails() throws DException {
57      ArrayList JavaDoc aList = new ArrayList JavaDoc(5);
58       ColumnDetails columnDetails[] = joinCondition.getColumnDetails();
59       return GeneralPurposeStaticClass.getTableDetailsOfRefernceType(columnDetails,aList);
60    }
61
62    public String JavaDoc toString() {
63       return joinCondition.toString();
64    }
65
66    /**
67     * It is required to check whether index present on any column of the join
68     * condition. It helps in sorting of join conditions present in query.
69     * @param session
70     * @return
71     * @throws DException
72     */

73    public boolean isIndexPossible(_ServerSession session) throws DException {
74       ColumnDetails[] cds = joinCondition.getColumnDetails();
75       if (cds.length > 2) {
76          return false;
77       }
78       TableDetails[] td = getTableDetails();
79       for (int i = 0; i < td.length; i++) {
80          if (td[i] == null) {
81             return false;
82          }
83          if (td[i].getTableType() == TypeConstants.VIEW) {
84             continue;
85          }
86          _IndexTable indexTable = session.getIndexTable(td[i].getQualifiedIdentifier());
87          _IndexInformation[] indexInformations = indexTable.getIndexInformations();
88          if (checkifIndexPossible(indexInformations, cds[i])) {
89             return true;
90          }
91       }
92       return false;
93    }
94    /**
95     * This method allows user to check whether passed index is possible on
96     * passed column .
97     * @param indexInformations
98     * @param cd
99     * @return
100     * @throws DException
101     */

102    private boolean checkifIndexPossible(_IndexInformation[] indexInformations, ColumnDetails cd) throws DException {
103       String JavaDoc colName = cd.getColumn();
104       for (int i = 0; i < indexInformations.length; i++) {
105          String JavaDoc[] colNames = indexInformations[i].getColumns();
106          if (colName.equalsIgnoreCase(colNames[0])) {
107             return true;
108          }
109       }
110       return false;
111    }
112 }
113
Popular Tags