KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > sql99 > ddl > schemadefinition > indexdefinition


1 package com.daffodilwoods.daffodildb.server.sql99.ddl.schemadefinition;
2
3 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*;
4 import com.daffodilwoods.daffodildb.server.serversystem.*;
5 import com.daffodilwoods.daffodildb.server.sql99.common.*;
6 import com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors.*;
7 import com.daffodilwoods.daffodildb.server.sql99.dql.tableexpression.fromclause.*;
8 import com.daffodilwoods.daffodildb.server.sql99.token.*;
9 import com.daffodilwoods.database.general.*;
10 import com.daffodilwoods.database.resource.*;
11
12 public class indexdefinition implements SQLschemadefinitionstatement {
13    public oncolumns _oncolumns0;
14    public tablename _tablename1;
15    public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439222;
16    public indexname _indexname3;
17    public SNONRESERVEDWORD136444255 _SNONRESERVEDWORD1364442554;
18    public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439225;
19
20    private TableDescriptor tableDescriptor;
21    public String JavaDoc indexTableName;
22    private boolean selfInitiated = true;
23
24    /** @todo algo
25     * 1. initialise currentUserSession and globalSession
26     * 2. get table name and column names
27     * 3. check existence of table
28     * 4. check access rules
29     * 5. check for each column whether is of fixed type or not
30     * if not of fixed type than give error message
31     * 6. save descriptors
32     * 7. if statement is self initiated give call to data system to make index*/

33    /** @todo
34     * 1. since create table also create default index and curretly we are
35     * making that call directlly. so duplicacy of code,
36     * one solution is call this class method from create table
37     * and in case of call from create table some checking need not to
38     * be done*/

39
40    public Object JavaDoc run(Object JavaDoc object) throws DException {
41       _ServerSession currentSession = (_ServerSession) object;
42       boolean isIndependentStt = tableDescriptor == null && selfInitiated;
43
44       IndexDescriptor indexDescriptor = new IndexDescriptor();
45       setIndexName(object, indexDescriptor);
46       checkTableExistance(currentSession);
47       if (isIndependentStt) {
48          checkAccessRules(currentSession);
49       }
50       setTable(indexDescriptor);
51       executeOnColumns(object, indexDescriptor);
52       QualifiedIdentifier sourceTable = tableDescriptor.getQualifiedTableName();
53       indexDescriptor.is_system_generated = new Boolean JavaDoc(!isIndependentStt);
54       setIndexTableName(currentSession, indexDescriptor);
55       indexDescriptor.save(currentSession);
56       if (isIndependentStt) {
57          /** @todo there should be only one method in serversession as createIndex
58           if any check required it should be in their class
59           */

60          if (SystemTables.isSystemTable(sourceTable.getIdentifier())) {
61             currentSession.createIndexForSystemTable(sourceTable,
62                 indexDescriptor.indexname);
63          } else {
64             currentSession.createIndex(sourceTable, indexDescriptor.indexname, true);
65          }
66       } else {
67          tableDescriptor.addIndexName(indexDescriptor.indexname);
68       }
69       return new Integer JavaDoc(0);
70    }
71
72    private void setIndexName(Object JavaDoc object, IndexDescriptor indexDescriptor) throws
73        DException {
74       indexDescriptor.indexname = (String JavaDoc) _indexname3.run(object);
75    }
76
77    private void checkTableExistance(_ServerSession currentSession) throws
78        DException {
79       if (tableDescriptor == null) {
80          tableDescriptor = new TableDescriptor();
81          tableDescriptor.table_catalog = _tablename1.getCatalogName();
82          tableDescriptor.table_schema = _tablename1.getSchemaName();
83          tableDescriptor.table_name = _tablename1.getTableName();
84          if (tableDescriptor.table_catalog == null) {
85             tableDescriptor.table_catalog = currentSession.getCurrentCatalog();
86          }
87          if (tableDescriptor.table_schema == null) {
88             tableDescriptor.table_schema = currentSession.getCurrentSchema();
89          }
90          try {
91             tableDescriptor.load(currentSession);
92          } catch (DException ex) {
93             throw new DException("DSE7060",
94                                  new Object JavaDoc[] {tableDescriptor.getQualifiedTableName().
95                                  getIdentifier()});
96          }
97          if (tableDescriptor.table_type.equalsIgnoreCase(SqlKeywords.VIEW)) {
98             throw new DException("DSE8102", null);
99          }
100       }
101       if (tableDescriptor.schemaDescriptor == null) {
102          tableDescriptor.loadSchemaDescriptor(currentSession);
103       }
104    }
105
106    private void checkAccessRules(_ServerSession serverSystem) throws DException {
107       String JavaDoc authorizationIdentifier = tableDescriptor.schemaDescriptor.
108           schema_owner;
109       if (!serverSystem.isEnabledAuthorizationIdentifier(authorizationIdentifier, true)) {
110          throw new DException("DSE12", null);
111       }
112    }
113
114    private void setTable(IndexDescriptor indexDescriptor) {
115       indexDescriptor.table_catalog = tableDescriptor.table_catalog;
116       indexDescriptor.table_schema = tableDescriptor.table_schema;
117       indexDescriptor.table_name = tableDescriptor.table_name;
118    }
119
120    private void executeOnColumns(Object JavaDoc object, IndexDescriptor indexDescriptor) throws
121        DException {
122       _oncolumns0.setIndexDescriptor(indexDescriptor);
123       _oncolumns0.setTableDescriptor(tableDescriptor);
124       _oncolumns0.run(object);
125    }
126
127    /** @todo
128     * see for the way of generating IndexTableName it is required or not
129     * index table name is to be made by datasystem ???
130     * */

131    private void setIndexTableName(_ServerSession currentSession,
132                                   IndexDescriptor indexDescriptor) throws
133        DException {
134       if (indexTableName == null) {
135          indexTableName = indexDescriptor.indexname + "_Index";
136       }
137       indexDescriptor.indextablename = indexTableName;
138    }
139
140    public void setIsSelfInitiated(boolean self) {
141       selfInitiated = self;
142    }
143
144    public void setTableDescriptor(_Descriptor tableDes0) throws DException {
145       tableDescriptor = (TableDescriptor) tableDes0;
146    }
147
148    public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
149       return this;
150    }
151
152    public String JavaDoc toString() {
153       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
154       sb.append(" ");
155       sb.append(_SRESERVEDWORD12065439225);
156       sb.append(" ");
157       sb.append(_SNONRESERVEDWORD1364442554);
158       sb.append(" ");
159       sb.append(_indexname3);
160       sb.append(" ");
161       sb.append(_SRESERVEDWORD12065439222);
162       sb.append(" ");
163       sb.append(_tablename1);
164       sb.append(" ");
165       sb.append(_oncolumns0);
166       return sb.toString();
167    }
168
169 }
170
Popular Tags