KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > dql > resultsetmetadata > SelectKeyColumnInformation


1 package com.daffodilwoods.daffodildb.server.sql99.dql.resultsetmetadata;
2
3 import java.io.*;
4
5 import com.daffodilwoods.daffodildb.server.sql99.common.*;
6 import com.daffodilwoods.daffodildb.utils.comparator.*;
7 import com.daffodilwoods.database.resource.*;
8 import com.daffodilwoods.database.utility.*;
9
10 /**
11  * It represents the key column information of select query. It provides the
12  * functionality of providing key and the comparator for comparing the key.
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 SelectKeyColumnInformation implements Serializable {
22
23    /**
24     * Represents the position of key columns in row returned by resultset.
25     */

26
27    private int[] mapping;
28
29    /**
30     * Represents the orderspecification(asc/desc) of key columns.
31     */

32
33    private boolean[] orderSpecifications;
34
35    /**
36     * Represents the comparator for comparing the keys.
37     */

38
39    private SuperComparator comparator;
40
41    public SelectKeyColumnInformation(_KeyColumnInformation[] keyColumns, int[] mapping1, boolean isAggregateAndNoGroup) throws DException {
42       mapping = mapping1;
43       orderSpecifications = getOrderSpecification(keyColumns);
44       comparator = isAggregateAndNoGroup
45           ? (SuperComparator)new DefaultKeyComparator() : new KeyComparator(orderSpecifications);
46    }
47
48    /**
49     * Returns the comparator for comparing the keys based on its
50     * orderspecifications.
51     * @param keyColumns
52     * @return
53     * @throws DException
54     */

55
56    private SuperComparator getKeyComparator(_KeyColumnInformation[] keyColumns) throws DException {
57       ColumnDetails[] columns = getColumnDetails(keyColumns);
58       return GeneralPurposeStaticClass.getOrderComparator(columns, orderSpecifications);
59    }
60
61    /**
62     * Returns the orderspecifications of key columns.
63     * @param keyColumnInformation
64     * @return
65     * @throws DException
66     */

67
68    private boolean[] getOrderSpecification(_KeyColumnInformation[] keyColumnInformation) throws DException {
69       int length = keyColumnInformation.length;
70       boolean[] result = new boolean[length];
71       for (int i = 0; i < length; i++) {
72          result[i] = keyColumnInformation[i].getOrderSpecification();
73       }
74       return result;
75    }
76
77    /**
78     * Returns the columns involved in key.
79     * @param keyColumnInformation
80     * @return
81     * @throws DException
82     */

83
84    private ColumnDetails[] getColumnDetails(_KeyColumnInformation[] keyColumnInformation) throws DException {
85       int length = keyColumnInformation.length;
86       ColumnDetails[] result = new ColumnDetails[length];
87       for (int i = 0; i < length; i++) {
88          result[i] = keyColumnInformation[i].getColumnDetails();
89       }
90       return result;
91    }
92
93    /**
94     * Returns the key of passed row. A key represents a row uniquely.
95     * @param row
96     * @return
97     * @throws DException
98     */

99
100    public Object JavaDoc getKey(Object JavaDoc row) throws DException {
101       try {
102          int length = mapping.length;
103          Object JavaDoc[] result = new Object JavaDoc[length];
104          for (int i = 0; i < length; i++) {
105             result[i] = ( (Object JavaDoc[]) row)[mapping[i] - 1];
106          }
107          return result;
108       } catch (ArrayIndexOutOfBoundsException JavaDoc ex) {
109          throw ex;
110       }
111    }
112
113    /**
114     * Returns the comparator to compare the keys of rows.
115     * @return
116     * @throws DException
117     */

118
119    public SuperComparator getComparator() throws DException {
120       return comparator;
121    }
122
123    /**
124     * Returns the orderspecifications of key columns.
125     * @return
126     */

127
128    public boolean[] getOrder() {
129       return orderSpecifications;
130    }
131 }
132
Popular Tags