KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sql99.ddl.schemadefinition;
2
3 import com.daffodilwoods.daffodildb.server.serversystem.*;
4 import com.daffodilwoods.daffodildb.server.sql99.*;
5 import com.daffodilwoods.daffodildb.server.sql99.common.*;
6 import com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors.*;
7 import com.daffodilwoods.daffodildb.server.sql99.ddl.utility.*;
8 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*;
9 import com.daffodilwoods.daffodildb.server.sql99.token.*;
10 import com.daffodilwoods.daffodildb.utils.parser.*;
11 import com.daffodilwoods.database.resource.*;
12
13 public class domaindefinition implements SQLschemadefinitionstatement, schemaelement {
14    public dummyrule _Optdummyrule0;
15    public domainconstraint[] _OptRepdomainconstraint1;
16    public defaultclause _Optdefaultclause2;
17    public datatype _datatype3;
18    public SRESERVEDWORD1206543922 _OptSRESERVEDWORD12065439224;
19    public domainname _domainname5;
20    public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439226;
21    public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439227;
22
23    private SchemaDescriptor schemaDescriptor;
24
25    public domaindefinition() {
26    }
27
28    /*
29       - Check for schema name in domain defn.; ---> implicit
30       - Check for schema name in Constraint name defn.; ----> implicit
31       - Check whether the schema already contains the domain name specified;
32       - if data type is character and collate clause is not defined;
33          - get the character set and from it the collate clause;
34          - this collate is the explicit or implicit collate clause;
35       - datatype should not be of three specified types;
36       - Check for inUsage ??;
37       - if collate clause is not null then data type should be Character type;
38       - for every domain constraint if constraint char is not null
39          INITIALLY IMMEDIATE NOT DEFERRABLE is implicit;
40       - Check for Authorization identifier;
41       - Privelage is created;
42       - Check for search condition ( General Rule 5 & 6 );
43     */

44
45    /*
46       Required :-
47          Current Session for Authorization Identifier
48     */

49
50    /** @todo algo
51     * 1. intialise currentSession and globalSession, DomainDescriptor, nestedStatement
52     * 1-1 commit the currentSession
53     * 2. setDomainName
54     * 1. set name
55     * 2. identify the schema/catalog of the domain implicit/explicit
56     * 3. ensure Schema
57     * 3. validate user rights
58     * 4. set Domain properties
59     * 0. set Data type
60     * 1. set default value -- if given
61     * 2. set collate clause -- if given
62     * 5. save domain descriptor
63     * 6. process domain constraint if any present
64     * 7. create default owner privilges of domain */

65    public Object JavaDoc run(Object JavaDoc obj) throws DException {
66       _ServerSession currentSession = (_ServerSession) obj;
67       if(!(_datatype3 instanceof predefinedtype)){
68          throw new DException("DSE8178",new Object JavaDoc[]{_datatype3.toString()});
69       }
70       boolean isIndependentStt = schemaDescriptor == null;
71       DomainDescriptor domainDescriptor = new DomainDescriptor();
72       setDomainName(currentSession, domainDescriptor);
73       if (isIndependentStt) {
74          checkAccessRules(currentSession);
75       }
76       setDomainProperties(currentSession, domainDescriptor);
77       domainDescriptor.save(currentSession);
78       if (_OptRepdomainconstraint1 != null) {
79          setDomainConstraints(currentSession, domainDescriptor);
80       }
81       createPrivileges(currentSession, domainDescriptor);
82       return null;
83    }
84
85    private void setDomainProperties(_ServerSession currentSession,
86                                     DomainDescriptor domainDescriptor) throws
87        DException {
88       /** @todo
89        * change the way of initializing dtd itentifier sunita
90        * */

91       domainDescriptor.dtd_Idenifier = domainDescriptor.catalog_name + "."
92           + domainDescriptor.schema_name + "." + domainDescriptor.domain_name;
93       setDataTypeDescriptor(currentSession, domainDescriptor);
94       if (_Optdefaultclause2 != null) {
95          _Optdefaultclause2.setDataTypeDescriptor(domainDescriptor.
96                                                   dataTypeDescriptor);
97          domainDescriptor.default_clause = (String JavaDoc) _Optdefaultclause2.run(
98              currentSession);
99       }
100    }
101
102    /** @todo this type of method is written in each ddl statement so why not we
103     * move this code in some utility class */

104    private void setDomainName(_ServerSession currentSession,
105                               DomainDescriptor domainDescriptor) throws DException {
106       domainDescriptor.catalog_name = _domainname5.getCatalogName();
107       domainDescriptor.schema_name = _domainname5.getSchemaName();
108       domainDescriptor.domain_name = _domainname5.getDomainName();
109       if (schemaDescriptor != null) {
110          if (domainDescriptor.schema_name != null &&
111              !domainDescriptor.schema_name.equalsIgnoreCase(schemaDescriptor.
112              schema_name)) {
113             throw new DException("DSE906",
114                                  new Object JavaDoc[] {domainDescriptor.domain_name});
115          }
116          if (domainDescriptor.catalog_name != null &&
117              !domainDescriptor.catalog_name.equalsIgnoreCase(schemaDescriptor.
118              catalog_name)) {
119             throw new DException("DSE226",
120                                  new Object JavaDoc[] {domainDescriptor.domain_name});
121          }
122          domainDescriptor.schema_name = schemaDescriptor.schema_name;
123          domainDescriptor.catalog_name = schemaDescriptor.catalog_name;
124       } else {
125          if (domainDescriptor.catalog_name == null) {
126             domainDescriptor.catalog_name = currentSession.getCurrentCatalog();
127          }
128          if (domainDescriptor.schema_name == null) {
129             domainDescriptor.schema_name = currentSession.getCurrentSchema();
130          }
131          schemaDescriptor = new SchemaDescriptor();
132          schemaDescriptor.catalog_name = domainDescriptor.catalog_name;
133          schemaDescriptor.schema_name = domainDescriptor.schema_name;
134          schemaDescriptor.load(currentSession);
135       }
136    }
137
138    private void setDataTypeDescriptor(_ServerSession currentSession,
139                                       DomainDescriptor domainDescriptor) throws
140        DException {
141       DataTypeDescriptor dataTypeDescriptor = new DataTypeDescriptor();
142       dataTypeDescriptor.object_catalog = domainDescriptor.catalog_name;
143       dataTypeDescriptor.object_schema = domainDescriptor.schema_name;
144       dataTypeDescriptor.object_name = domainDescriptor.domain_name;
145       dataTypeDescriptor.object_type = SqlKeywords.DOMAIN;
146       _datatype3.setDescriptor(dataTypeDescriptor);
147       _datatype3.run(null);
148       domainDescriptor.dataTypeDescriptor = dataTypeDescriptor;
149       dataTypeDescriptor.dtd_identifier = domainDescriptor.dtd_Idenifier;
150    }
151
152    public void setSchemaDescriptor(_Descriptor schemaDes0) throws
153        DException {
154       schemaDescriptor = (SchemaDescriptor) schemaDes0;
155    }
156
157    private void setDomainConstraints(_ServerSession currentSession, DomainDescriptor domainDes) throws
158        DException {
159       for (int i = 0, size = _OptRepdomainconstraint1.length; i < size; i++) {
160          _OptRepdomainconstraint1[i].setDomainDescriptor(domainDes);
161          _OptRepdomainconstraint1[i].run(currentSession);
162       }
163    }
164
165    /** @todo get query from a utility class*/
166    private void createPrivileges(_ServerSession currentSession, DomainDescriptor domainDescriptor) throws DException {
167       String JavaDoc user = schemaDescriptor.schema_owner;
168       boolean isGrantable = domainDescriptor.hasGrantableRefRightsForColumnsIncluded(currentSession, user);
169       String JavaDoc query = QueryMaker.getDomainDefinitionGrantQuery(domainDescriptor.
170           getQualifiedIdentifier(), user, isGrantable);
171       grantprivilegestatement _grantprivilegestatement = (grantprivilegestatement)
172           Parser.parseQuery(query.toString());
173       _grantprivilegestatement.setObjectDescriptor(domainDescriptor);
174       _grantprivilegestatement.run(currentSession.getSystemServerSession());
175    }
176
177    /** @todo this checking should not be done here use DataDictionary */
178    private void checkAccessRules(_ServerSession currentSession) throws DException {
179       String JavaDoc authorizationIdentifier = schemaDescriptor.schema_owner;
180       if (!currentSession.isEnabledAuthorizationIdentifier(authorizationIdentifier, true)) {
181          ;//// Removed By Program ** System.out.println("authorizationIdentifier " + authorizationIdentifier);
182
throw new DException("DSE12", null);
183       }
184    }
185
186    public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
187       return this;
188    }
189
190    public String JavaDoc toString() {
191       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
192       sb.append(" ");
193       sb.append(_SRESERVEDWORD12065439227);
194       sb.append(" ");
195       sb.append(_SRESERVEDWORD12065439226);
196       sb.append(" ");
197       sb.append(_domainname5);
198       sb.append(" ");
199       if (_OptSRESERVEDWORD12065439224 != null) {
200          sb.append(_OptSRESERVEDWORD12065439224);
201       }
202       sb.append(" ");
203       sb.append(_datatype3);
204       sb.append(" ");
205       if (_Optdefaultclause2 != null) {
206          sb.append(_Optdefaultclause2);
207       }
208       sb.append(" ");
209       if (_OptRepdomainconstraint1 != null) {
210          for (int i = 0; i < _OptRepdomainconstraint1.length; i++) {
211             sb.append("").append(_OptRepdomainconstraint1[i]);
212          }
213       }
214       sb.append(" ");
215       if (_Optdummyrule0 != null) {
216          sb.append(_Optdummyrule0);
217       }
218       return sb.toString();
219    }
220 }
221
Popular Tags