KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > dql > plan > table > TableReferenceMerger


1 package com.daffodilwoods.daffodildb.server.sql99.dql.plan.table;
2
3 import com.daffodilwoods.daffodildb.server.datasystem.indexsystem.*;
4 import com.daffodilwoods.daffodildb.server.sql99.common.*;
5 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.predicates.*;
6 import com.daffodilwoods.database.resource.*;
7 import com.daffodilwoods.database.sqlinitiator.*;
8
9 /**
10  * It provides functionality of checking whether index is able to solve order,
11  * aggregates and all the columns of table present in query. It is a utility
12  * class.
13  * <p>Title: </p>
14  * <p>Description: </p>
15  * <p>Copyright: Copyright (c) 2003</p>
16  * <p>Company: </p>
17  * @author unascribed
18  * @version 1.0
19  */

20
21 public class TableReferenceMerger implements ExecutionPlanConstants {
22
23    /**
24     * Checks whether sorting need of order can be satisfied by passed index.
25     * It also take orderspecifiaction(asc/desc) in to the consideration.
26     * @param order
27     * @param indexInformation
28     * @return -1 when Order can't be solved by index, 0 when Order can be solved
29     * using index, 1 when Order is used but the orderspecification(asc/desc) of
30     * index and order doesn't match.
31     * @throws DException
32     */

33    public static int checkForOrderColumns(_Order order, _IndexInformation indexInformation) throws DException {
34       if (order == null) {
35          return 0;
36       }
37       String JavaDoc[] indexColumns = indexInformation.getColumns();
38       ColumnDetails cd[] = order.getColumnDetails();
39       int length1 = cd.length, length2 = indexColumns.length;
40       if (length1 > length2) {
41          return -1;
42       }
43       boolean[] indexColumnsOrder = indexInformation.getOrderOfColumns();
44       boolean[] orderColumnsOrder = order.getOrderOfColumns();
45       int sameOrder = -1; // -1 initial, 0 same ,1 Reverse
46
for (int i = 0, j = 0; i < length1 && j < length2; i++, j++) {
47          if (! (cd[i].getColumn().equalsIgnoreCase(indexColumns[j]))) {
48             return -1;
49          }
50          if (orderColumnsOrder[i] == indexColumnsOrder[j]) {
51             if (sameOrder == 1) {
52                return -1;
53             }
54             sameOrder = 0;
55          } else {
56             if (sameOrder == 0) {
57                return -1;
58             }
59             sameOrder = 1;
60          }
61       }
62       return sameOrder;
63    }
64
65    /**
66     * This method is used to check whether aggregate column can be solved with
67     * the help of index.
68     * @param aggColumn
69     * @param indexInformation
70     * @return
71     * @throws DException
72     */

73
74    public static boolean checkForAggregateColumn(ColumnDetails aggColumn, _IndexInformation indexInformation) throws DException {
75       if (aggColumn == null) {
76          return true;
77       }
78       String JavaDoc indexColumnName = indexInformation.getColumns()[0];
79       boolean indexColumnOrder = indexInformation.getOrderOfColumns()[0];
80       return!aggColumn.checkNegativeValueFlag() && aggColumn.getColumn().equalsIgnoreCase(indexColumnName) && indexColumnOrder;
81    }
82
83    /**
84     * This method is used to check whether all the columns of table present in
85     * query are involved in the index or not.
86     * @param indexColumns
87     * @param queryColumns
88     * @return
89     * @throws DException
90     */

91    public static boolean checkForQueryColumns(String JavaDoc[] indexColumns, String JavaDoc[] queryColumns) throws DException {
92       if (queryColumns == null || indexColumns == null) {
93          return false;
94       }
95       int length1 = indexColumns.length;
96       outerloop:for (int i = 0, length = queryColumns.length; i < length; ++i) {
97          int j = 0;
98          for (; j < length1; ++j) {
99             if (indexColumns[j].equalsIgnoreCase(queryColumns[i])) {
100                continue outerloop;
101             }
102          }
103          if (j == length1) {
104             return false;
105          }
106       }
107       return true;
108    }
109
110 }
111
Popular Tags