KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.sql99.ddl.schemadefinition;
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.common.*;
10 import com.daffodilwoods.daffodildb.server.sql99.dcl.sqlcontrolstatement.*;
11 import com.daffodilwoods.daffodildb.server.sql99.ddl.descriptors.*;
12 import com.daffodilwoods.daffodildb.server.sql99.ddl.utility.*;
13 import com.daffodilwoods.daffodildb.server.sql99.dml.*;
14 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*;
15 import com.daffodilwoods.daffodildb.server.sql99.expression.booleanvalueexpression.*;
16 import com.daffodilwoods.daffodildb.server.sql99.token.*;
17 import com.daffodilwoods.daffodildb.server.sql99.utils.*;
18 import com.daffodilwoods.database.resource.*;
19 import com.daffodilwoods.database.utility.*;
20
21 public class functionspecification implements com.daffodilwoods.daffodildb.utils.parser.StatementExecuter, functionspecificationdummyrule {
22    public dispatchclause _Optdispatchclause0;
23    public routinecharacteristics _routinecharacteristics1;
24    public returnsclause _returnsclause2;
25    public SQLparameterdeclarationlist _SQLparameterdeclarationlist3;
26    public schemaqualifiedroutinename _schemaqualifiedroutinename4;
27    public SRESERVEDWORD1206543922 _SRESERVEDWORD12065439225;
28
29    private SchemaDescriptor schemaDescriptor;
30    private DataTypeDescriptor[] dtd = null;
31    private RoutineDescriptor routineDescriptor;
32    public void setSchemaDescriptor(SchemaDescriptor schemaDes) {
33       schemaDescriptor = schemaDes;
34    }
35
36    private Object JavaDoc[] routineCharacteristics;
37
38    public Object JavaDoc run(Object JavaDoc object) throws DException {
39       _ServerSession currentSession = (_ServerSession) object;
40       boolean isIndependentStt = schemaDescriptor == null;
41       routineDescriptor = new RoutineDescriptor();
42       setQualifiedRotuineName(currentSession, routineDescriptor);
43       if (isIndependentStt) {
44          validateUserPrivilege(currentSession);
45       }
46       checkNoOfParameters(currentSession, routineDescriptor);
47       setRoutineCharacterstics(currentSession, routineDescriptor);
48       setDataTypeForReturnsClause(currentSession, routineDescriptor);
49       setParametersAndDtdDescriptor(currentSession, routineDescriptor);
50       checkForParameterMode();
51       return null;
52    }
53
54    private void setDataTypeForReturnsClause(_ServerSession currentSession, RoutineDescriptor routineDescriptor0) throws DException {
55       if (_returnsclause2 != null) {
56          DataTypeDescriptor dt = new DataTypeDescriptor();
57          dt.object_catalog = routineDescriptor0.SPECIFIC_CATALOG;
58          dt.object_schema = routineDescriptor0.SPECIFIC_SCHEMA;
59          dt.object_name = routineDescriptor0.SPECIFIC_NAME;
60          dt.object_type = SqlKeywords.ROUTINE;
61          dt.dtd_identifier = "dummy";
62          _returnsclause2.setDescriptor(dt);
63          _returnsclause2.run(currentSession);
64          routineDescriptor0.DTD_IDENTIFIER = dt.dtd_identifier;
65
66          try {
67             dt.save(currentSession);
68          } catch (PrimaryConstraintException de) {
69             DException tde = new DException("DSE1135", new Object JavaDoc[] {routineDescriptor.SPECIFIC_NAME});
70             throw tde;
71          } catch (DException de) {
72             if (de.getDseCode().equals("DSE1255")) {
73                DException tde = new DException("DSE1135", new Object JavaDoc[] {routineDescriptor.SPECIFIC_NAME});
74                throw tde;
75             }
76             throw de;
77          }
78       }
79    }
80
81    private void checkForParameterMode() throws DException {
82       int noOfParameters = _SQLparameterdeclarationlist3.getNumberOfParameters();
83       if (noOfParameters > 0) {
84          String JavaDoc parameterMode[] = _SQLparameterdeclarationlist3.getModeOfParameters();
85          if (parameterMode != null) {
86             for (int i = 0; i < parameterMode.length; i++) {
87                if (parameterMode[i] != null && ! (parameterMode[i].equalsIgnoreCase(SqlKeywords.IN))) {
88                   throw new DException("DSE8191", null);
89                }
90             }
91          }
92       }
93    }
94
95    public void setExternalJavaMethodProperties(externaljavareference dataStt, _ServerSession currentSession) throws DException {
96       dataStt.setRoutineDescriptor(routineDescriptor);
97       dataStt.run(currentSession);
98       checkForParameters(dataStt, routineDescriptor);
99    }
100
101    public void checkSatements(routinebody _routinebody, _ServerSession currentSession) throws DException {
102       SQLprocedurestatement[] sqlstatements = _routinebody.getStatements();
103       String JavaDoc[] parameterNames = _SQLparameterdeclarationlist3.getNameOfParameters();
104
105       int noOfParameters = _SQLparameterdeclarationlist3.getNumberOfParameters();
106       Object JavaDoc[] parameterTypes = _SQLparameterdeclarationlist3.getDataTypeOfParameters();
107       RoutineServerSession routineServerSession = new RoutineServerSession(SqlKeywords.FUNCTION, routineDescriptor.ROUTINE_CATALOG,
108           routineDescriptor.ROUTINE_SCHEMA, routineDescriptor.ROUTINE_NAME, noOfParameters, parameterTypes, currentSession, true);
109
110       ColumnDetails[] statementCD = null;
111       ArrayList statementsCD = new ArrayList();
112       for (int i = 0; i < sqlstatements.length; i++) {
113          SQLprocedurestatement sqlp = (SQLprocedurestatement) sqlstatements[i];
114          SQLexecutablestatement sqlexe = sqlp.getExecutableStatement();
115          if (sqlexe instanceof SQLcontrolstatement) {
116             SQLcontrolstatement contStt = (SQLcontrolstatement) sqlexe;
117             if (contStt instanceof compoundstatement)
118                ( (compoundstatement) contStt).setServerSession(currentSession);
119             statementCD = contStt.getColumnDetails();
120             if (statementCD != null) {
121                statementsCD.addAll(Arrays.asList(statementCD));
122             }
123          }
124       }
125
126       for (int i = 0; i < sqlstatements.length; i++) {
127          SQLexecutablestatement sql_exec = sqlstatements[i].getExecutableStatement();
128          if (sql_exec instanceof SQLdatastatement) {
129             SQLdatastatement dataStt = (SQLdatastatement) sql_exec;
130             _Reference[] refs = dataStt.checkSemantic(currentSession);
131
132             Object JavaDoc[] parameterRefs = dataStt.getParameters(currentSession);
133             if (parameterRefs != null && parameterRefs.length != 0) {
134                throw new DException("DSE8164", null);
135             }
136
137             boolean refMatchWithParameter;
138             if (refs != null && refs.length != 0) {
139                for (int j = 0; j < refs.length; j++) {
140                   refMatchWithParameter = false;
141                   if (parameterNames != null) {
142                      for (int k = 0; k < parameterNames.length; k++) {
143                         if ( (refs[j].getColumn().equalsIgnoreCase(parameterNames[k]))) {
144                            refMatchWithParameter = true;
145                            break;
146                         }
147                      }
148                   }
149                   if (!refMatchWithParameter) {
150                      throw new DException("DSE8175", new Object JavaDoc[] {refs[j].getQualifiedColumnName()});
151                   }
152                }
153             }
154          } else if (sql_exec instanceof SQLcontrolstatement) {
155             if (_Server.ISONEDOLLARDB)
156                throw new DException("DSE2054", new Object JavaDoc[] {"Psm in procedure"});
157             SQLcontrolstatement dataStt = (SQLcontrolstatement) sql_exec;
158             int functionReturnType = TypeConverter.getDataBaseType(getFunctionReturnType(currentSession));
159             ArrayList refList = new ArrayList();
160             ColumnDetails[] statementCDs = (ColumnDetails[]) statementsCD.toArray(new ColumnDetails[0]);
161             if (statementCDs != null) {
162                for (int j = 0; j < statementCDs.length; j++) {
163                   if (! (statementCDs[j].getColumnName()[0].equalsIgnoreCase(SqlKeywords.NULL)) &&
164                       statementCDs[j].isReturnStatementCD() && statementCDs[j].getType() == TypeConstants.CONSTANT) {
165                      checkDatatype(functionReturnType, statementCDs[j].getDatatype());
166                   }
167                }
168             }
169             boolean found = false;
170             GeneralPurposeStaticClass.addRecursively(statementCDs, refList);
171             for (int k = 0; k < refList.size(); k++) {
172                ColumnDetails cd = (ColumnDetails) refList.get(k);
173                if (parameterNames != null) {
174                   for (int j = 0; j < parameterNames.length; j++) {
175                      if (cd.getQualifiedColumnName().equalsIgnoreCase(parameterNames[j])) {
176                         found = true;
177                         cd.setDatatype(dtd[j].getType());
178                         cd.setSize(dtd[j].getPrecision());
179                         if (cd.isReturnStatementCD()) {
180                            if (! (cd.getColumnName()[0].equalsIgnoreCase(SqlKeywords.NULL)) &&
181                                functionReturnType != TypeConverter.getDataBaseType(parameterTypes[j].toString().trim())) {
182                               throw new DException("DSE8195", null);
183                            }
184                         }
185                         break;
186                      }
187                   }
188                   if (!found) {
189                      if (! (cd.getColumnName()[0].equalsIgnoreCase(SqlKeywords.NULL)) &&
190                          cd.isReturnStatementCD()) {
191                         if (functionReturnType != cd.getDatatype()) {
192                            throw new DException("DSE8195", null);
193                         }
194                      }
195                   }
196                } else if (! (cd.getColumnName()[0].equalsIgnoreCase(SqlKeywords.NULL)) &&
197                           cd.isReturnStatementCD()) {
198                   if (functionReturnType != cd.getDatatype()) {
199                      throw new DException("DSE8195", null);
200                   }
201                }
202             }
203
204             if (dataStt instanceof compoundstatement) {
205                if (noOfParameters != 0) {
206                   ArrayList parameterList = new ArrayList();
207                   for (int j = 0; j < parameterNames.length; j++) {
208                      parameterList.add(parameterNames[j]);
209                   }
210                   compoundstatement compStatement = (compoundstatement) dataStt;
211                   compStatement.setParameterInDeclarationList(parameterList);
212                }
213             }
214
215             _Reference[] refs = dataStt.checkSemantic(routineServerSession);
216             if (refs != null) {
217                for (int k = 0; k < refs.length; k++) {
218                   boolean flag = false;
219                   if (parameterNames != null) {
220                      for (int j = 0; j < parameterNames.length; j++) {
221                         if (refs[k].getQualifiedColumnName().equalsIgnoreCase(parameterNames[j])) {
222                            refs[k].setDatatype(dtd[j].getType());
223                            refs[k].setSize(dtd[j].getPrecision());
224                            flag = true;
225                         }
226                         if (flag)
227                            break;
228                      }
229                   }
230                }
231             }
232
233             boolean refMatchWithParameter;
234             if (refs != null && refs.length != 0) {
235                for (int j = 0; j < refs.length; j++) {
236                   refMatchWithParameter = false;
237                   if (parameterNames != null) {
238                      for (int k = 0; k < parameterNames.length; k++) {
239                         if ( (refs[j].getColumn().equalsIgnoreCase(parameterNames[k]))) {
240                            refMatchWithParameter = true;
241                            break;
242                         }
243                      }
244                   }
245                   if (!refMatchWithParameter) {
246                      throw new DException("DSE8175", new Object JavaDoc[] {refs[j].getColumn()});
247                   }
248                }
249             }
250
251             Object JavaDoc[] parameterRefs = dataStt.getParameters(currentSession);
252             if (parameterRefs != null && parameterRefs.length != 0) {
253                throw new DException("DSE8164", null);
254             }
255
256          } else {
257             throw new DException("DSE8189", new Object JavaDoc[] {sql_exec.toString()});
258          }
259       }
260    }
261
262    private void checkForParameters(externaljavareference dataStt, RoutineDescriptor routineDescriptor) throws DException {
263       int noOfParameters = _SQLparameterdeclarationlist3.getNumberOfParameters();
264       int noOfJavaParameters = dataStt.getJavaParameters();
265
266       if (noOfParameters != noOfJavaParameters)
267          throw new DException("DSE8123", null);
268
269       String JavaDoc[] parameterModes = _SQLparameterdeclarationlist3.getModeOfParameters();
270
271       if (noOfJavaParameters > 0) {
272          Class JavaDoc[] param = dataStt.getJavaParametersClass();
273          if (param != null) {
274             String JavaDoc external = routineDescriptor.EXTERNAL_NAME;
275             String JavaDoc methodIdentifier = external.substring(external.indexOf("(") + 1, external.indexOf(")"));
276             StringTokenizer token = new StringTokenizer(methodIdentifier, ",");
277             String JavaDoc str[] = new String JavaDoc[param.length];
278             int k = 0;
279             while (token.hasMoreTokens()) {
280                str[k++] = token.nextToken();
281             }
282
283             for (int i = 0; i < param.length; i++) {
284                if (parameterModes[i].equalsIgnoreCase("IN")) {
285                   Object JavaDoc javaMethodParametersType = (Object JavaDoc) param[i];
286                   Object JavaDoc parametersTyp = null;
287                   if ( (dtd[i].data_Type.equalsIgnoreCase("char") && dtd[i].getPrecision() > 1) ||
288                       (dtd[i].data_Type.equalsIgnoreCase("character") && dtd[i].getPrecision() > 1)) {
289                      parametersTyp = String JavaDoc.class;
290                   } else {
291                      parametersTyp = GeneralUtility.getJavaDataType(dtd[i].data_Type);
292                   }
293                   if (! (javaMethodParametersType.equals(parametersTyp)))
294                      throw new DException("DSE8124", new Object JavaDoc[] {new Integer JavaDoc(i + 1)});
295                }
296             }
297          }
298       }
299    }
300
301    private void setQualifiedRotuineName(_ServerSession currentSession,
302                                         RoutineDescriptor routineDescriptor) throws DException {
303       routineDescriptor.ROUTINE_CATALOG = _schemaqualifiedroutinename4.getCatalogName();
304       routineDescriptor.ROUTINE_SCHEMA = _schemaqualifiedroutinename4.getSchemaName();
305       routineDescriptor.ROUTINE_NAME = _schemaqualifiedroutinename4.getIdentifierName();
306
307       /**
308        * if ROUTINE definition is part of schema definition
309        */

310       if (schemaDescriptor != null) {
311          if (routineDescriptor.ROUTINE_SCHEMA == null) {
312             routineDescriptor.ROUTINE_SCHEMA = schemaDescriptor.schema_name;
313          } else
314          if (! (routineDescriptor.ROUTINE_SCHEMA.equalsIgnoreCase(schemaDescriptor.schema_name))) {
315             throw new DException("DSE895", null);
316          }
317          if (routineDescriptor.ROUTINE_CATALOG == null) {
318             routineDescriptor.ROUTINE_CATALOG = schemaDescriptor.catalog_name;
319          } else
320          if (! (routineDescriptor.ROUTINE_CATALOG.equalsIgnoreCase(schemaDescriptor.catalog_name))) {
321             throw new DException("DSE895", null);
322          }
323       } else {
324          if (routineDescriptor.ROUTINE_CATALOG == null) {
325             routineDescriptor.ROUTINE_CATALOG = currentSession.getCurrentCatalog();
326          }
327          if (routineDescriptor.ROUTINE_SCHEMA == null) {
328             routineDescriptor.ROUTINE_SCHEMA = currentSession.getCurrentSchema();
329          }
330          schemaDescriptor = new SchemaDescriptor();
331          schemaDescriptor.catalog_name = routineDescriptor.ROUTINE_CATALOG;
332          schemaDescriptor.schema_name = routineDescriptor.ROUTINE_SCHEMA;
333          schemaDescriptor.load(currentSession);
334       }
335    }
336
337    private void validateUserPrivilege(_ServerSession currentSession) throws DException {
338       String JavaDoc schemaOwner = schemaDescriptor.schema_owner;
339       if (!currentSession.isEnabledAuthorizationIdentifier(schemaOwner, true)) {
340          throw new DException("DSE12", null);
341       }
342    }
343
344    private void checkNoOfParameters(_ServerSession serverSession,
345                                     RoutineDescriptor routineDescriptor) throws DException {
346       int noOfParameters = _SQLparameterdeclarationlist3.getNumberOfParameters();
347       ArrayList list = QueryMaker.getSpecificCorrespondingToProcedureName(
348           serverSession, routineDescriptor.ROUTINE_CATALOG,
349           routineDescriptor.ROUTINE_SCHEMA, routineDescriptor.ROUTINE_NAME);
350       _Executer executer = SqlSchemaConstants.getExecuter(serverSession,
351           QueryMaker.getParameterCountQuery());
352       if (list != null) {
353          for (int i = 0, size = list.size(); i < size; i++) {
354             Object JavaDoc[] obj = (Object JavaDoc[]) list.get(i);
355             _SelectQueryIterator iter = (_SelectQueryIterator) executer.executeForFresh(obj);
356             if (iter.first()) {
357                if ( ( ( (Object JavaDoc[]) iter.getObject())[0]).hashCode() ==
358                    noOfParameters) {
359                   throw new DException("DSE8190",
360                                        new Object JavaDoc[] {routineDescriptor.ROUTINE_CATALOG +
361                                        "." + routineDescriptor.ROUTINE_SCHEMA + "." +
362                                        routineDescriptor.ROUTINE_NAME});
363                }
364             } else {
365                if (noOfParameters == 0) {
366                   throw new DException("DSE8190",
367                                        new Object JavaDoc[] {routineDescriptor.ROUTINE_CATALOG +
368                                        "." + routineDescriptor.ROUTINE_SCHEMA + "." +
369                                        routineDescriptor.ROUTINE_NAME});
370                }
371             }
372          }
373       }
374    }
375
376    private void setRoutineCharacterstics(_ServerSession serverSession,
377                                          RoutineDescriptor routineDescriptor) throws DException {
378       routineCharacteristics = _routinecharacteristics1.getAllRoutineCharacteristics();
379       if (routineCharacteristics[2] == null) {
380          routineDescriptor.SPECIFIC_NAME = serverSession.getDataDictionary().generateSpecificName();
381          routineDescriptor.SPECIFIC_CATALOG = routineDescriptor.ROUTINE_CATALOG;
382          routineDescriptor.SPECIFIC_SCHEMA = routineDescriptor.ROUTINE_SCHEMA;
383       } else {
384          SRESERVEDWORD1206543922specificname temp = (SRESERVEDWORD1206543922specificname) routineCharacteristics[2];
385          String JavaDoc tempSchema = temp.getSchemaName();
386          String JavaDoc tempCatalog = temp.getCatalogName();
387          routineDescriptor.SPECIFIC_CATALOG = tempCatalog == null ?
388              routineDescriptor.ROUTINE_CATALOG : tempCatalog;
389          routineDescriptor.SPECIFIC_SCHEMA = tempSchema == null ?
390              routineDescriptor.ROUTINE_SCHEMA : tempSchema;
391          routineDescriptor.SPECIFIC_NAME = temp.getIdentifierName();
392          checkCatalogSchemaOfRoutineAndSpecificName(routineDescriptor);
393       }
394    }
395
396    private void checkCatalogSchemaOfRoutineAndSpecificName(RoutineDescriptor routDes) throws DException {
397       if (!routDes.SPECIFIC_CATALOG.equalsIgnoreCase(routDes.ROUTINE_CATALOG)) {
398          throw new DException("DSE5025", null);
399       }
400       if (!routDes.SPECIFIC_SCHEMA.equalsIgnoreCase(routDes.ROUTINE_SCHEMA)) {
401          throw new DException("DSE5025", null);
402       }
403    }
404
405    private void setParametersAndDtdDescriptor(_ServerSession serverSession, RoutineDescriptor routineDescriptor) throws
406        DException {
407       dtd = _SQLparameterdeclarationlist3.storeParameteresForProcedure(
408           new Object JavaDoc[] {routineDescriptor.SPECIFIC_CATALOG,
409           routineDescriptor.SPECIFIC_SCHEMA,
410           routineDescriptor.SPECIFIC_NAME}
411           , serverSession);
412    }
413
414    public void setRoutineDescriptor(routinebody _routinebody, _ServerSession currentSession, String JavaDoc toString) throws DException {
415       routineDescriptor.ROUTINE_NAME = _schemaqualifiedroutinename4.getIdentifierName();
416       routineDescriptor.ROUTINE_TYPE = SqlKeywords.FUNCTION;
417       routineDescriptor.ROUTINE_DEFINITION = "CREATE " + toString;
418       routineDescriptor.SCHEMA_LEVEL_ROUTINE = SqlSchemaConstants.YES;
419       routineDescriptor.IS_USER_DEFINED_CAST = SqlKeywords.NO;
420       routineDescriptor.SECURITY_TYPE = SqlKeywords.IMPLEMENTATION + " " + SqlKeywords.DEFINED;
421       routineDescriptor.AS_LOCATOR = SqlSchemaConstants.NO;
422       if (dtd != null) {
423          for (int i = 0; i < dtd.length; i++) {
424             routineDescriptor.DTD_IDENTIFIER = dtd[i].dtd_identifier;
425          }
426       }
427       java.sql.Timestamp JavaDoc time = new java.sql.Timestamp JavaDoc(System.currentTimeMillis());
428       routineDescriptor.CREATED = time;
429       routineDescriptor.LAST_ALTERED = time;
430       if (routineCharacteristics != null) {
431          if (! (_routinebody instanceof SQLroutinebody)) {
432             routineDescriptor.PARAMETER_STYLE = routineCharacteristics[1].toString();
433          }
434          routineDescriptor.IS_DETERMINISTIC = routineCharacteristics[3].toString();
435          routineDescriptor.SQL_DATA_ACCESS = routineCharacteristics[4].toString();
436       }
437       if (_routinebody instanceof SQLroutinebody)
438          routineDescriptor.ROUTINE_BODY = SqlKeywords.SQL;
439       else if (_routinebody instanceof externaljavareference)
440          routineDescriptor.ROUTINE_BODY = SqlKeywords.EXTERNAL;
441       routineDescriptor.save(currentSession);
442    }
443
444    public void createPrivileges(_ServerSession currentSession) throws DException {
445       String JavaDoc grantee = schemaDescriptor.schema_owner;
446       String JavaDoc grantQuery = QueryMaker.getRoutineDefinitionGrantQueryForFunction(
447           routineDescriptor.getQualifiedSpecificName(),
448           grantee, isPrivilegeGrantable(currentSession));
449       grantprivilegestatement _grantprivilegestatement = (grantprivilegestatement)
450           com.daffodilwoods.daffodildb.utils.parser.Parser.parseQuery(grantQuery);
451       _grantprivilegestatement.setObjectDescriptor(routineDescriptor);
452       _grantprivilegestatement.run(currentSession.getSystemServerSession());
453    }
454
455    private boolean isPrivilegeGrantable(_ServerSession user_session) throws DException {
456       return true;
457    }
458
459    public String JavaDoc toString() {
460       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
461       sb.append(" ");
462       sb.append(_SRESERVEDWORD12065439225);
463       sb.append(" ");
464       sb.append(_schemaqualifiedroutinename4);
465       sb.append(" ");
466       sb.append(_SQLparameterdeclarationlist3);
467       sb.append(" ");
468       sb.append(_returnsclause2);
469       sb.append(" ");
470       sb.append(_routinecharacteristics1);
471       sb.append(" ");
472       if (_Optdispatchclause0 != null) {
473          sb.append(_Optdispatchclause0);
474       }
475       return sb.toString();
476    }
477
478    /**
479     * clone
480     * @return Object
481     */

482    public Object JavaDoc clone() {
483       throw new UnsupportedOperationException JavaDoc(" clone() method not implemented ");
484    }
485
486    private void checkDatatype(int returnClauseDataType, int returnStatementDataType) throws DException {
487       try {
488          Check.checkForDatatype(returnClauseDataType, returnStatementDataType);
489       } catch (DException ex) {
490          if (ex.getDseCode().equalsIgnoreCase("DSE87")) {
491             throw new DException("DSE8195", null);
492          }
493          throw ex;
494       }
495    }
496
497    public String JavaDoc getFunctionReturnType(_ServerSession currentSession) throws DException {
498       String JavaDoc queryClause = " SELECT data_type from " +
499           SystemTables.dataTypeDescriptor_TableName + " where dtd_identifier='dummy' and object_catalog= '" +
500           routineDescriptor.SPECIFIC_CATALOG + "' and object_schema= '" + routineDescriptor.SPECIFIC_SCHEMA
501           + "' and object_name= '" + routineDescriptor.SPECIFIC_NAME + "'";
502       _SelectQueryIterator retIter = SqlSchemaConstants.getIterator(currentSession, queryClause, null);
503       if (retIter.first()) {
504          Object JavaDoc[] obj = (Object JavaDoc[]) retIter.getColumnValues();
505          return obj[0].toString();
506       }
507       return null;
508    }
509
510    public void storeTableIncludedColumnIncluded(routinebody _routinebody0) throws DException {
511       SQLprocedurestatement[] sqlstatements = _routinebody0.getStatements();
512       storeTablesIncluded(sqlstatements);
513       storeColumnsIncluded(sqlstatements);
514    }
515
516    private void storeTablesIncluded(SQLprocedurestatement[] sqlstatements) throws DException {
517       ArrayList tablesIncluded = new ArrayList();
518       if (sqlstatements != null && sqlstatements.length > 0) {
519          for (int i = 0; i < sqlstatements.length; i++) {
520             SQLexecutablestatement sql_exec = sqlstatements[i].getExecutableStatement();
521             if (sql_exec instanceof SQLdatastatement || sql_exec instanceof SQLcontrolstatement) {
522
523             }
524          }
525       }
526       ArrayList tablesList = GeneralUtility.removeRedundentTables(routineDescriptor.SPECIFIC_CATALOG,
527           routineDescriptor.SPECIFIC_SCHEMA, tablesIncluded);
528       routineDescriptor.tablesUsed = tablesList;
529    }
530
531    private void storeColumnsIncluded(SQLprocedurestatement[] sqlstatements) throws DException {
532       ArrayList columnsIncluded = new ArrayList();
533       if (sqlstatements != null && sqlstatements.length > 0) {
534          for (int i = 0; i < sqlstatements.length; i++) {
535             SQLexecutablestatement sql_exec = sqlstatements[i].getExecutableStatement();
536             if (sql_exec instanceof SQLdatastatement || sql_exec instanceof SQLcontrolstatement) {
537
538             }
539          }
540       }
541       ArrayList columnsList = GeneralUtility.removeRedundentColumns(
542           routineDescriptor.SPECIFIC_CATALOG, routineDescriptor.SPECIFIC_SCHEMA, null,
543           columnsIncluded);
544       routineDescriptor.columnsUsed = columnsList;
545    }
546 }
547
Popular Tags