KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors;
2
3 import com.daffodilwoods.daffodildb.server.datadictionarysystem.*;
4 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*;
5 /**
6  * Title:
7  * Description:
8  * Copyright: Copyright (c) 2002
9  * Company:
10  * @author
11  * @version 1.0
12  */

13 import com.daffodilwoods.daffodildb.server.sql99.utils.parser.*;
14 /**
15  * Title:
16  * Description:
17  * Copyright: Copyright (c) 2002
18  * Company:
19  * @author
20  * @version 1.0
21  */

22 import com.daffodilwoods.database.resource.*;
23
24 /**
25  * Title:
26  * Description:
27  * Copyright: Copyright (c) 2002
28  * Company:
29  * @author
30  * @version 1.0
31  */

32 public class QueryGetter {
33
34    public QueryGetter() {
35    }
36
37    /* public static String tableDescriptorQueryForCheckConstraints = "select * from "+SystemTables.table_constraints_TableName+" where table_catalog = ? and table_schema = ? and table_name = ? and constraint_type = '"+SqlKeywords.CHECK +"' and is_deferrable = ?";
38        public static String domainConstraintsQuery = "select * from "+SystemTables.domain_constraints_TableName+" where domain_catalog = ? and domain_schema = ? and domain_name = ? ";
39        public static String tablesForeignConstriaintQuery = " Select "
40          +SystemTables.key_column_usage_TableName+".constraint_catalog, "
41          +SystemTables.key_column_usage_TableName+".constraint_schema , "
42          +SystemTables.key_column_usage_TableName+".constraint_name, "
43              +SystemTables.key_column_usage_TableName+".ordinal_position "
44              +" from "+SystemTables.key_column_usage_TableName
45              +","+SystemTables.table_constraints_TableName
46              +" where "
47              +SystemTables.key_column_usage_TableName+".table_catalog = ? and "
48              +SystemTables.key_column_usage_TableName+".table_schema = ? and "
49              +SystemTables.key_column_usage_TableName+".table_name = ? and "
50              +SystemTables.key_column_usage_TableName+".column_name = ?"
51              +" and ("
52              +SystemTables.table_constraints_TableName+".constraint_catalog = "+SystemTables.key_column_usage_TableName+".constraint_catalog and "
53              +SystemTables.table_constraints_TableName+".constraint_schema = "+SystemTables.key_column_usage_TableName+".constraint_schema and "
54              +SystemTables.table_constraints_TableName+".constraint_name = "+SystemTables.key_column_usage_TableName+".constraint_name "
55              +" ) "
56              +" and "+SystemTables.table_constraints_TableName+".constraint_type = '"+SqlKeywords.FOREIGN+" "+SqlKeywords.KEY
57              +"\'";
58         public static String relatedTableAndColumnQuery123 = " Select "
59              + SystemTables.key_column_usage_TableName + ".table_catalog,"
60              + SystemTables.key_column_usage_TableName+".table_schema ,"
61              + SystemTables.key_column_usage_TableName+".table_name ,"
62              + SystemTables.key_column_usage_TableName+".column_name"
63              +" from "+SystemTables.key_column_usage_TableName
64              +" where ("
65              +SystemTables.key_column_usage_TableName+".constraint_catalog, "
66              +SystemTables.key_column_usage_TableName+".constraint_schema, "
67              +SystemTables.key_column_usage_TableName+".constraint_name )"
68              +" in ("
69              +" Select "
70              +"unique_constraint_catalog, "
71              +"unique_constraint_schema , "
72              +"unique_constraint_name "
73              +" from "+SystemTables.referential_constraints_TableName
74              +" where "
75              +"constraint_catalog = ? and "
76              +"constraint_schema = ? and "
77              +"constraint_name = ? )" ;
78         public static String relatedTableAndColumnQuery = " Select "
79              + SystemTables.key_column_usage_TableName + ".table_catalog,"
80              + SystemTables.key_column_usage_TableName+".table_schema ,"
81              + SystemTables.key_column_usage_TableName+".table_name ,"
82              + SystemTables.key_column_usage_TableName+".column_name"
83              +" from "+SystemTables.key_column_usage_TableName
84              +","+SystemTables.referential_constraints_TableName
85              +" where "
86              +SystemTables.key_column_usage_TableName+".constraint_catalog = "
87             +SystemTables.referential_constraints_TableName+".unique_constraint_catalog and "
88              +SystemTables.key_column_usage_TableName+".constraint_schema = "
89             +SystemTables.referential_constraints_TableName+".unique_constraint_schema and "
90              +SystemTables.key_column_usage_TableName+".constraint_name ="
91             +SystemTables.referential_constraints_TableName + ".unique_constraint_name and "
92              +SystemTables.referential_constraints_TableName +".constraint_catalog = ? and "
93              +SystemTables.referential_constraints_TableName +".constraint_schema = ? and "
94              +SystemTables.referential_constraints_TableName +".constraint_name = ? " ;
95        public static String columnDetailsQuery = "select "
96              +SystemTables.columns_TableName+".table_catalog,"
97              +SystemTables.columns_TableName+".table_schema ,"
98              +SystemTables.columns_TableName+".table_name,"
99              +SystemTables.columns_TableName+".column_name,"
100              +SystemTables.dataTypeDescriptor_TableName+".data_type,"
101              +SystemTables.columns_TableName+".column_default,"
102              +SystemTables.dataTypeDescriptor_TableName+".numeric_scale,"
103              +SystemTables.dataTypeDescriptor_TableName+".numeric_precision,"
104              +SystemTables.dataTypeDescriptor_TableName+".character_maximum_length,"
105              +SystemTables.dataTypeDescriptor_TableName+".datetime_precision,"
106              +SystemTables.dataTypeDescriptor_TableName+".interval_precision,"
107              +SystemTables.columns_TableName+".is_Nullable,"
108              +SystemTables.columns_TableName+".domain_catalog,"
109              +SystemTables.columns_TableName+".domain_schema,"
110              +SystemTables.columns_TableName+".domain_name"
111              +" from "+SystemTables.columns_TableName
112              +","+SystemTables.dataTypeDescriptor_TableName
113             +" where ("
114              + SystemTables.columns_TableName+".table_catalog = ? and "
115              + SystemTables.columns_TableName+".table_schema = ? and "
116              + SystemTables.columns_TableName+".table_name = ? and "
117              + SystemTables.dataTypeDescriptor_TableName+".object_catalog = ? and "
118              +SystemTables.dataTypeDescriptor_TableName+".object_schema = ? and "
119              +SystemTables.dataTypeDescriptor_TableName+".object_name = ? )"
120              + " and "+SystemTables.dataTypeDescriptor_TableName+".object_type = 'TABLE' "
121              +"and ("+SystemTables.columns_TableName+".table_catalog = "+SystemTables.dataTypeDescriptor_TableName+".object_catalog and "
122              +SystemTables.columns_TableName+".table_schema = "+SystemTables.dataTypeDescriptor_TableName+".object_schema and "
123              +SystemTables.columns_TableName+".table_name = "+SystemTables.dataTypeDescriptor_TableName+".object_name and "
124              +SystemTables.columns_TableName+".dtd_identifier = "+SystemTables.dataTypeDescriptor_TableName+".dtd_identifier )"
125              +" order by " +SystemTables.columns_TableName+".ordinal_position ";
126        public static String tableTypesQuery = "select table_type from "+SystemTables.tables_TableName + " where table_catalog = ? and table_schema = ? and table_name = ?";
127        public static String primaryKeysQuery123 = " Select "
128              + SystemTables.key_column_usage_TableName+".column_name"
129              +" from "+SystemTables.key_column_usage_TableName
130              +" where ("
131              +SystemTables.key_column_usage_TableName+".constraint_catalog, "
132              +SystemTables.key_column_usage_TableName+".constraint_schema, "
133              +SystemTables.key_column_usage_TableName+".constraint_name )"
134              +" in ("
135              +" Select "
136              +SystemTables.table_constraints_TableName+".constraint_catalog, "
137              +SystemTables.table_constraints_TableName+".constraint_schema , "
138              +SystemTables.table_constraints_TableName+".constraint_name "
139              +" from "
140              +SystemTables.table_constraints_TableName
141              +" where "
142              +SystemTables.table_constraints_TableName+".table_catalog = ? and "
143              +SystemTables.table_constraints_TableName+".table_schema = ? and "
144              +SystemTables.table_constraints_TableName+".table_name = ? and "
145              +SystemTables.table_constraints_TableName+".constraint_type = '" + SqlKeywords.PRIMARY +" " +SqlKeywords.KEY
146              +"' ) " ;
147        public static String primaryKeysQuery = " Select "
148              + SystemTables.key_column_usage_TableName+".column_name"
149              +" from "+SystemTables.key_column_usage_TableName + ", "
150              +SystemTables.table_constraints_TableName
151              +" where "
152              +SystemTables.key_column_usage_TableName+".constraint_catalog = "
153              +SystemTables.table_constraints_TableName+".constraint_catalog And "
154              +SystemTables.key_column_usage_TableName+".constraint_schema = "
155              +SystemTables.table_constraints_TableName+".constraint_schema And "
156              +SystemTables.key_column_usage_TableName+".constraint_name = "
157              +SystemTables.table_constraints_TableName+".constraint_name And "
158              +SystemTables.table_constraints_TableName+".table_catalog = ? and "
159              +SystemTables.table_constraints_TableName+".table_schema = ? and "
160              +SystemTables.table_constraints_TableName+".table_name = ? and "
161              +SystemTables.table_constraints_TableName+".constraint_type = '" + SqlKeywords.PRIMARY +" " +SqlKeywords.KEY
162              +"'" ;
163        public static String columnQuery = "Select * from "+SystemTables.columns_TableName + " where table_catalog = ? and table_schema = ? and table_name = ? order by ordinal_position";
164        public static String dataTypeQuery = "Select * from "+SystemTables.dataTypeDescriptor_TableName + " where object_catalog = ? and object_schema = ? and object_name = ?";
165        public static String checkIsIndexTableQuery = "select table_catalog,table_schema,table_name,indexname from "+ SystemTables.INDEXINFO
166                       + " where indextablename = ? ";
167        public static String defalutClauseQuery = "select column_default,is_autoIncrement from " + SystemTables.columns_TableName
168                                          +" where table_catalog = ? and table_schema = ? and table_name = ? and column_name != '"+SystemFields.systemFields[SystemFields.rowId]+ "' order by ordinal_position ";
169        public static String indexInfoQuery = "Select * from "
170                         + SystemTables.INDEXINFO + " where table_catalog = ? and table_schema = ? and table_name = ? ";
171        public static String indexColumnsQuery = "Select * from "
172                     + SystemTables.INDEXCOLUMNS + " where table_catalog = ? and table_schema = ? and table_name = ? and indexname = ? order by ordinal_position";
173        public static String allIndexColumnsQuery = "Select column_name,ordertype,indexname "
174                     +"from "
175                     + SystemTables.INDEXCOLUMNS + " where table_catalog = ? and table_schema = ? and table_name = ? order by ordinal_position";
176        public static String tableDescriptorQueryForPrimaryAndUniqueConstraint = "select * from "+SystemTables.table_constraints_TableName+" where table_catalog = ? and table_schema = ? and table_name = ? and constraint_type in ('"+SqlKeywords.PRIMARY+" "+SqlKeywords.KEY+"','"+SqlKeywords.UNIQUE+"') and is_deferrable = ?";
177        public static String tablePrivilegesQuery = "select * from "+ SystemTables.table_privileges_TableName +" where grantee in ( ? , ?) or grantee ='"+SqlKeywords.PUBLIC+"'";
178        public static String tablePrivilegesForTableQuery = "select privilege_type from " + SystemTables.table_privileges_TableName
179            + " where table_catalog = ? and table_schema = ? and table_name = ? and grantee in ( ? , ?,'"+SqlKeywords.PUBLIC+"')";//,'"+com.daffodilwoods.database.sql.SqlKeywords.PUBLIC+"') ";
180        public static String columnPrivilegesForColumnQuery = "select privilege_type from " + SystemTables.column_privileges_TableName
181            + " where table_catalog = ? and table_schema = ? and table_name = ? and column_name = ? and grantee in ( ? , ?,'"+SqlKeywords.PUBLIC+"')";//,'"+com.daffodilwoods.database.sql.SqlKeywords.PUBLIC+"')";
182        public static String referencedConstraintsJoinQuery = " Select * from "+SystemTables.referential_constraints_TableName
183          +" , "+SystemTables.table_constraints_TableName
184          + " where ("
185          + SystemTables.referential_constraints_TableName +".constraint_catalog = " +SystemTables.table_constraints_TableName +".constraint_catalog and "
186          + SystemTables.referential_constraints_TableName+".constraint_schema = " + SystemTables.table_constraints_TableName +".constraint_schema and "
187          + SystemTables.referential_constraints_TableName+".constraint_name = " +SystemTables.table_constraints_TableName +".constraint_name and "
188              + SystemTables.table_constraints_TableName+".constraint_type = '"+SqlKeywords.FOREIGN+" "+SqlKeywords.KEY +"' )"
189          +" and ("
190          +SystemTables.referential_constraints_TableName+".unique_constraint_catalog, "
191          +SystemTables.referential_constraints_TableName+".unique_constraint_schema, "
192          +SystemTables.referential_constraints_TableName+".unique_constraint_name) "
193          +" in ("
194          +" Select "
195          +SystemTables.table_constraints_TableName+".constraint_catalog, "
196          +SystemTables.table_constraints_TableName+".constraint_schema , "
197          +SystemTables.table_constraints_TableName+".constraint_name "
198          +" from "+SystemTables.table_constraints_TableName
199          +" where "
200          +SystemTables.table_constraints_TableName+".table_catalog = ? and "
201          +SystemTables.table_constraints_TableName+".table_schema = ? and "
202          +SystemTables.table_constraints_TableName+".table_name = ? "
203          +" and ("+SystemTables.table_constraints_TableName+".constraint_type = '"+SqlKeywords.PRIMARY+" "+SqlKeywords.KEY
204          +"' or "+SystemTables.table_constraints_TableName+".constraint_type = '"+SqlKeywords.UNIQUE
205          +"' ) ) and "
206          +SystemTables.table_constraints_TableName+".is_deferrable = ? ";
207        public static String referencingConstraintsJoinQuery = " Select * from "+SystemTables.referential_constraints_TableName
208          +" , "+SystemTables.table_constraints_TableName
209          + " where ("
210          + SystemTables.referential_constraints_TableName +".constraint_catalog = " +SystemTables.table_constraints_TableName +".constraint_catalog and "
211          + SystemTables.referential_constraints_TableName+".constraint_schema = " + SystemTables.table_constraints_TableName +".constraint_schema and "
212          + SystemTables.referential_constraints_TableName+".constraint_name = " +SystemTables.table_constraints_TableName +".constraint_name) "
213          +" and "
214          +SystemTables.table_constraints_TableName+".table_catalog = ? and "
215          +SystemTables.table_constraints_TableName+".table_schema = ? and "
216          +SystemTables.table_constraints_TableName+".table_name = ? and "
217          +SystemTables.table_constraints_TableName+".constraint_type = '"+ SqlKeywords.FOREIGN +" "+SqlKeywords.KEY+"' and "
218          +SystemTables.table_constraints_TableName+".is_deferrable = ?";
219        public static String trigersQueryWithEventCondition = "select * from "+SystemTables.triggers_TableName+" where event_object_catalog = ? and event_object_schema = ? and event_object_table = ? and event_manipulation = ? and action_orientation = ? and condition_timing = ? ";
220        public static String trigersQueryWithTriggerNameCondition = "select * from "+SystemTables.triggers_TableName+" where trigger_catalog = ? and trigger_schema = ? and trigger_name = ? and event_manipulation = ? and action_orientation = ? and condition_timing = ? ";
221        public static String triggeredUpdatedQuery = "select * from "+ SystemTables.triggered_update_columns_TableName + " where event_object_catalog = ? and event_object_schema = ? and event_object_table = ? and event_object_column in (?) ";
222        public static String triggeredUpdatedQueryForAllColumns = "select * from "+ SystemTables.triggered_update_columns_TableName + " where event_object_catalog = ? and event_object_schema = ? and event_object_table = ? ";
223        public static String triggerQueryForUpdateType = "select * from "+SystemTables.triggers_TableName+" where (event_object_catalog = ? and event_object_schema = ? and event_object_table = ? and event_manipulation = '"+SqlKeywords.UPDATE+"' and action_orientation = ? and condition_timing = ? ) "
224                                                     +" and (trigger_catalog,trigger_schema,trigger_name) NOT IN (?)";
225        public static String viewsQueryWithNameCondition = "select view_definition, check_option, is_updatable, is_insertable_into from " + SystemTables.views_TableName
226                                    + " where table_catalog = ? and table_schema = ? and table_name = ? ";
227        public static String deferredChecking = "select * from "+SystemTables.table_constraints_TableName +" where table_catalog = ? and table_schema = ? and table_name = ? and is_deferrable ='yes'";
228     */

229    public static String JavaDoc tableConstraintQuery = "select * from "
230        + SystemTables.table_constraints_TableName
231        + " where constraint_catalog = ? and constraint_schema = ? "
232        + " and constraint_name = ? ";
233
234    public static String JavaDoc keyColumnUsageQuery = "select * from "
235        + SystemTables.key_column_usage_TableName
236        + " where constraint_catalog = ? and constraint_schema = ? "
237        + " and constraint_name = ? order by ordinal_position ";
238
239    public static String JavaDoc checkConstraintQuery = "select check_clause from "
240        + SystemTables.check_constraints_TableName
241        + " where constraint_catalog = ? and constraint_schema = ? "
242        + " and constraint_name = ? ";
243
244    public static String JavaDoc tablePrivilegeDescriptorDependent_A = "select * from " + SystemTables.table_privileges_TableName
245        + " where table_name = ? and table_schema = ? and table_catalog = ? and privilege_type = ?";
246    public static String JavaDoc tablePrivilegeDescriptorDependent_B = "select * from " + SystemTables.table_privileges_TableName
247        + " as one where grantor='_SYSTEM'"
248        + " and privilege_type = ? "
249        + " and (? or ? = (select grantee from " + SystemTables.table_privileges_TableName
250        + " as two where two.grantor='_SYSTEM' and one.table_name = two.table_name"
251        + " and one.table_schema = two.table_schema and one.table_catalog = two.table_catalog))"
252        + " and ";
253
254    public static String JavaDoc columnPrivilegeDescriptorDependent_A = "select * from " + SystemTables.column_privileges_TableName
255        + " where table_name = ? and table_schema = ? and table_catalog = ? and column_name = ? and privilege_type = ?";
256    public static String JavaDoc columnPrivilegeDescriptorDependent_B = "select * from " + SystemTables.column_privileges_TableName
257        + " as one where grantor='_SYSTEM'"
258        + " and privilege_type = ? "
259        + " and (? or ? = (select grantee from " + SystemTables.table_privileges_TableName
260        + " as two where two.grantor='_SYSTEM' and one.table_name = two.table_name"
261        + " and one.table_schema = two.table_schema and one.table_catalog = two.table_catalog))"
262        + " and ";
263
264    public static String JavaDoc routinePrivilegeDescriptorDependent_A = "select * from " + SystemTables.routine_privileges_TableName
265        + " where specific_name = ? and specific_schema = ? and specific_catalog = ? and privilege_type = ?";
266    public static String JavaDoc routinePrivilegeDescriptorDependent_B;
267
268    public static String JavaDoc usagePrivilegeDescriptorDependent_A = "select * from " + SystemTables.usage_privileges_TableName
269        + " where object_name = ? and object_schema = ? and object_catalog = ? and object_type = ?";
270    public static String JavaDoc usagePrivilegeDescriptorDependent_B;
271
272    public static String JavaDoc privilegeDescriptorDependents_C = "select * from " + SystemTables.usage_privileges_TableName
273        + " as A, " + SystemTables.usage_privileges_TableName + " as B "
274        + " where A.grantor='_SYSTEM' and A.object_type='DOMAIN' "
275        + " and ('PUBLIC' = ? or "
276        + " (? = B.grantee and B.grantor='_SYSTEM'"
277        + " and A.object_name=B.object_name "
278        + " and A.object_schema=B.object_schema "
279        + " and A.object_catalog=B.object_catalog "
280        + " and B.object_type='DOMAIN'))";
281
282    public static String JavaDoc domainCheckConstraints = "select"
283        + " C.constraint_catalog, C.constraint_schema, C.constraint_name, C.check_clause"
284        + " from " + SystemTables.domain_constraints_TableName
285        + " as B, " + SystemTables.check_constraints_TableName + " as C "
286        + " where B.domain_name=? and B.domain_schema=? and B.domain_catalog=?"
287        + " and B.constraint_catalog=C.constraint_catalog and B.constraint_schema=C.constraint_schema and B.constraint_name=C.constraint_name";
288
289    public static String JavaDoc usagePrivilegeDescriptorAncestor_C_Column = "select * from " + SystemTables.column_privileges_TableName
290        + " where (grantee = ? or grantee = 'PUBLIC') and privilege_type='REFERENCES'";
291    public static String JavaDoc usagePrivilegeDescriptorAncestor_C_Usage = "select * from " + SystemTables.usage_privileges_TableName
292        + " where (grantee = ? or grantee = 'PUBLIC')";
293
294    public static String JavaDoc checkViews = "select * from " + SystemTables.views_TableName
295        + " where table_name = ? and table_schema = ? and table_catalog = ?";
296    public static String JavaDoc tableOwner = "select distinct grantee from " + SystemTables.table_privileges_TableName
297        + " where table_name = ? and table_schema = ? and table_catalog = ? and grantor = '_SYSTEM'";
298    public static String JavaDoc routineOwner = "select distinct grantee from " + SystemTables.routine_privileges_TableName
299        + " where specific_name = ? and specific_schema = ? and specific_catalog = ? and grantor = '_SYSTEM'";
300    public static String JavaDoc usageObjectOwner = "select distinct grantee from " + SystemTables.usage_privileges_TableName
301        + " where object_type = ? and object_name = ? and object_schema = ? and object_catalog = ?"
302        + " and grantor = '_SYSTEM'";
303    public static String JavaDoc dependentRoles = "select * from " + SystemTables.role_authorization_TableName + " where role_name = ?";
304    public static String JavaDoc userPasswordQuery = " Select * from " + SystemTables.users_TableName + " where user_name = ? and user_password = ? ";
305
306    public static String JavaDoc recordCondition;
307
308    public static booleanvalueexpression privilegeCondition;
309    public static String JavaDoc privilegeConditionString;
310
311    public static booleanvalueexpression getPrivilegeCondition() throws DException {
312       if (privilegeCondition == null) {
313          privilegeCondition = (booleanvalueexpression) SessionConditionParser.parseCondition(" true ");
314          privilegeConditionString = privilegeCondition.toString();
315       }
316       return privilegeCondition;
317    }
318
319    public static booleanvalueexpression sequenceCondition;
320
321    public static booleanvalueexpression getSequenceCondition() throws DException {
322       if (sequenceCondition == null) {
323          sequenceCondition = (booleanvalueexpression) ConditionParser.parseCondition("sequence_catalog = ? and sequence_schema = ? and sequence_name = ?");
324       }
325       return sequenceCondition;
326    }
327 }
328
Popular Tags