KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > dql > common > QueryColumns


1 package com.daffodilwoods.daffodildb.server.sql99.dql.common;
2
3 import java.util.*;
4
5 import com.daffodilwoods.daffodildb.server.sql99.common.*;
6 import com.daffodilwoods.database.resource.*;
7 import com.daffodilwoods.database.utility.*;
8
9 /**
10  * It is used to represent all the columns involved in select query.
11  * <p>Title: </p>
12  * <p>Description: </p>
13  * <p>Copyright: Copyright (c) 2003</p>
14  * <p>Company: </p>
15  * @author unascribed
16  * @version 1.0
17  */

18
19 public class QueryColumns implements _QueryColumns {
20
21    /**
22     * Represents the map of tables and all of its columns present in select
23     * query.
24     */

25
26    HashMap queryColumns;
27
28    /**
29     * Represents the mapping of table and hasRecord columns present in select
30     * query.
31     */

32
33    Object JavaDoc[][] mapping;
34
35    public QueryColumns(HashMap queryColumns0) {
36       queryColumns = queryColumns0;
37    }
38
39    /**
40     * Returns the map of table and its columns present in select query.
41     * @return
42     * @throws DException
43     */

44
45    public HashMap getQueryColsHashMap() throws DException {
46       return queryColumns;
47    }
48
49    /**
50     * It allows user to retrieve the hasRecord columns for the passed table.
51     * @param tableDetails
52     * @return array of columns
53     * @throws DException
54     */

55
56    public ColumnDetails[] getHasRecordColumns(TableDetails tableDetails) throws DException {
57       if (mapping == null) {
58          return null;
59       }
60       for (int i = 0; i < mapping.length; i++) {
61          if ( ( (TableDetails) mapping[i][0]) == tableDetails) {
62             return (ColumnDetails[]) ( (ArrayList) mapping[i][1]).toArray(new ColumnDetails[0]);
63          }
64       }
65       return null;
66    }
67
68    /**
69     * Sets the mapping of tables and its hasRecord columns.
70     * @param mapping0
71     * @throws DException
72     */

73
74    public void setHasRecordMapping(Object JavaDoc[][] mapping0) throws DException {
75       mapping = mapping0;
76    }
77
78    public String JavaDoc toString() {
79       return "Mapping " + P.print(mapping) + "QueryColumns " + queryColumns;
80    }
81
82    /**
83     * Sets the map of tables and all of its columns present in select query.
84     * @param queryColumns0
85     * @throws DException
86     */

87
88    public void setQueryColumns(HashMap queryColumns0) throws DException {
89       queryColumns = queryColumns0;
90    }
91
92    /**
93     * It allows user to add the columns in existing map of tables and all of its
94     * columns.
95     * @param cd
96     * @throws DException
97     */

98
99    public void addColumnDetails(ColumnDetails[] cd) throws DException {
100       for (int i = 0; i < cd.length; i++) {
101          TableDetails td = cd[i].getTableDetails();
102          ColumnDetails[] columns = (ColumnDetails[]) queryColumns.get(td);
103          ColumnDetails[] newColumns = null;
104          if (columns == null) {
105             newColumns = new ColumnDetails[] {cd[i]};
106          } else {
107             int length = columns.length;
108             newColumns = new ColumnDetails[length + 1];
109             System.arraycopy(columns, 0, newColumns, 0, length);
110             newColumns[length] = cd[i];
111          }
112          queryColumns.put(td, newColumns);
113       }
114    }
115
116 }
117
Popular Tags