KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > ddl > descriptors > FullTextIndexDescriptor


1 package com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors;
2
3 import java.util.*;
4
5 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*;
6 import com.daffodilwoods.daffodildb.server.serversystem.*;
7 import com.daffodilwoods.daffodildb.server.serversystem.dmlvalidation.constraintsystem.*;
8 import com.daffodilwoods.daffodildb.server.sql99.*;
9 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*;
10 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*;
11 import com.daffodilwoods.database.general.*;
12 import com.daffodilwoods.database.resource.*;
13
14 public class FullTextIndexDescriptor extends Descriptor {
15    public String JavaDoc table_catalog;
16    public String JavaDoc table_schema;
17    public String JavaDoc table_name;
18    public String JavaDoc indexname;
19    public Object JavaDoc fixedVariable;
20
21    public static final int maxIndexColumnSize = 4192;
22    ArrayList indexColumnDescriptors;
23
24    private int columnCount = 0;
25
26    public FullTextIndexDescriptor() throws DException {
27    }
28
29    public void load(_ServerSession serverSession) throws DException {
30       _Executer fullTextInfoExecuter = ( (DataDictionary) serverSession.getDataDictionary()).getPreparedStatementGetter().getFullTextInfoExecuter();
31       _SelectQueryIterator iter = (_SelectQueryIterator) fullTextInfoExecuter.execute(new Object JavaDoc[] {table_catalog, table_schema, table_name, indexname});
32       if (!iter.first())
33          throw new DException("DSE976", new Object JavaDoc[] {indexname, getQualifiedTable()});
34       loadData(iter);
35       loadColumnDescriptors(serverSession);
36    }
37
38    private void loadData(_SelectQueryIterator iter) throws DException {
39       Object JavaDoc[] values = (Object JavaDoc[]) iter.getObject();
40       fixedVariable = values[0];
41    }
42
43    public void loadDataFromRecord(_SelectQueryIterator iter) throws DException {
44       Object JavaDoc[] values = (Object JavaDoc[]) iter.getObject();
45       table_catalog = (String JavaDoc) values[SystemTablesFields.fulltextindex_table_catalog];
46       table_schema = (String JavaDoc) values[SystemTablesFields.fulltextindex_table_schema];
47       table_name = (String JavaDoc) values[SystemTablesFields.fulltextindex_table_name];
48       indexname = (String JavaDoc) values[SystemTablesFields.fulltextindex_indexname];
49       fixedVariable = values[SystemTablesFields.fulltextindex_fixedVariable];
50    }
51
52    public void loadColumnDescriptors(_ServerSession serverSession) throws DException {
53       _Executer fullTextColumnInfoExecuter = ( (DataDictionary) serverSession.getDataDictionary()).getPreparedStatementGetter().getFullTextColumnInfoExecuter();
54       _SelectQueryIterator iter = (_SelectQueryIterator) fullTextColumnInfoExecuter.execute(new Object JavaDoc[] {table_catalog, table_schema, table_name, indexname});
55       if (!iter.first()) {
56          throw new DException("DSE977", null);
57       }
58       indexColumnDescriptors = new ArrayList();
59       do {
60          IndexColumnDescriptor columnDescriptor = new IndexColumnDescriptor(SystemTables.FULLTEXTCOLUMNINFO);
61          columnDescriptor.table_catalog = table_catalog;
62          columnDescriptor.table_schema = table_schema;
63          columnDescriptor.table_name = table_name;
64          columnDescriptor.indexname = indexname;
65          columnDescriptor.loadDataFromRecord(iter);
66          indexColumnDescriptors.add(columnDescriptor);
67       } while (iter.next());
68    }
69
70    public String JavaDoc[] getColumnDescriptors() throws DException {
71       String JavaDoc[] columns = new String JavaDoc[indexColumnDescriptors.size()];
72       for (int i = 0; i < indexColumnDescriptors.size(); i++) {
73          columns[i] = ( (IndexColumnDescriptor) indexColumnDescriptors.get(i)).columnName;
74       }
75       return columns;
76    }
77
78    public void save(_ServerSession serverSession) throws DException {
79       Object JavaDoc[] columnValues = new Object JavaDoc[] {
80           table_catalog, table_schema,
81           table_name, indexname, fixedVariable};
82       try {
83          SqlSchemaConstants.insert(serverSession, SystemTables.FULLTEXTINFO, null,
84                                    columnValues);
85       } catch (PrimaryConstraintException de) {
86          DException tde = new DException("DSE1142", new Object JavaDoc[] {indexname,
87                                          getTableName()});
88          throw tde;
89       } catch (SizeMisMatchException de) {
90          if (de.getDseCode().equals("DSE773")) {
91             DException tde = new DException("DSE8103", null);
92             throw tde;
93          }
94       } catch (DException de) {
95          if (de.getDseCode().equals("DSE1255")) {
96             DException tde = new DException("DSE1142", new Object JavaDoc[] {indexname,
97                                             getTableName()});
98             throw tde;
99          }
100          if (de.getDseCode().equals("DSE773")) {
101             DException tde = new DException("DSE8103", null);
102             throw tde;
103          }
104          throw de;
105       }
106       saveIndexColumns(serverSession);
107    }
108
109    public void saveIndexColumns(_ServerSession serverSession) throws DException {
110       for (int i = 0, columnCount = indexColumnDescriptors.size();
111            i < columnCount; i++) {
112          IndexColumnDescriptor columnDescriptor = (IndexColumnDescriptor)
113              indexColumnDescriptors.get(i);
114          columnDescriptor.save(serverSession);
115       }
116    }
117
118    public void addIndexColumnDescriptor(IndexColumnDescriptor indexColumnDes) throws
119        DException {
120       if (indexColumnDescriptors == null) {
121          indexColumnDescriptors = new ArrayList();
122       }
123       indexColumnDes.ordinalPosition = new Integer JavaDoc(++columnCount);
124       indexColumnDescriptors.add(indexColumnDes);
125    }
126
127    public void delete(_ServerSession serverSession) throws DException {
128       booleanvalueexpression condition = ( (DataDictionary) serverSession.getDataDictionary()).
129           getPreparedStatementGetter().getFullTextIndexInfoTableCondition();
130       super.delete(serverSession, SqlSchemaConstants.FULLTEXTINFO, condition, new Object JavaDoc[] {table_catalog, table_schema, table_name, indexname});
131       deleteColumns(serverSession);
132    }
133
134    private void deleteColumns(_ServerSession serverSession) throws DException {
135       for (int i = 0, columnCount = indexColumnDescriptors.size();
136            i < columnCount; i++) {
137          IndexColumnDescriptor columnDescriptor = (IndexColumnDescriptor)
138              indexColumnDescriptors.get(i);
139          columnDescriptor.delete(serverSession);
140       }
141    }
142
143
144    public String JavaDoc getTableName() throws DException {
145       return new StringBuffer JavaDoc().append(table_catalog).append(".").append(
146           table_schema).append(".").append(table_name).toString();
147    }
148
149    public QualifiedIdentifier getQualifiedTable() throws DException {
150       return new QualifiedIdentifier(table_catalog, table_schema, table_name);
151    }
152
153    public int getDescriptorType() {
154       return FULLTEXTINDEX_DESCRIPTOR;
155    }
156 }
157
Popular Tags