1 | /* |
2 | * The contents of this file are subject to the Interbase Public |
3 | * License Version 1.0 (the "License"); you may not use this file |
4 | * except in compliance with the License. You may obtain a copy |
5 | * of the License at http://www.Inprise.com/IPL.html |
6 | * |
7 | * Software distributed under the License is distributed on an |
8 | * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express |
9 | * or implied. See the License for the specific language governing |
10 | * rights and limitations under the License. |
11 | * |
12 | * The Original Code was created by Inprise Corporation |
13 | * and its predecessors. Portions created by Inprise Corporation are |
14 | * Copyright (C) Inprise Corporation. |
15 | * |
16 | * All Rights Reserved. |
17 | * Contributor(s): ______________________________________. |
18 | * Adriano dos Santos Fernandes |
19 | */ |
20 | |
21 | #ifndef JRD_ROUTINE_H |
22 | #define JRD_ROUTINE_H |
23 | |
24 | #include "../common/classes/array.h" |
25 | #include "../common/classes/alloc.h" |
26 | #include "../common/classes/BlrReader.h" |
27 | #include "../common/classes/MetaName.h" |
28 | #include "../common/classes/QualifiedName.h" |
29 | #include "../common/classes/NestConst.h" |
30 | #include "../common/MsgMetadata.h" |
31 | |
32 | namespace Jrd |
33 | { |
34 | class thread_db; |
35 | class CompilerScratch; |
36 | class JrdStatement; |
37 | class Lock; |
38 | class Format; |
39 | class Parameter; |
40 | |
41 | class Routine : public Firebird::PermanentStorage |
42 | { |
43 | protected: |
44 | explicit Routine(MemoryPool& p) |
45 | : PermanentStorage(p), |
46 | id(0), |
47 | name(p), |
48 | securityName(p), |
49 | statement(NULL), |
50 | subRoutine(false), |
51 | implemented(true), |
52 | defined(true), |
53 | defaultCount(0), |
54 | inputFormat(NULL), |
55 | outputFormat(NULL), |
56 | inputFields(p), |
57 | outputFields(p), |
58 | flags(0), |
59 | useCount(0), |
60 | intUseCount(0), |
61 | alterCount(0), |
62 | existenceLock(NULL) |
63 | { |
64 | } |
65 | |
66 | public: |
67 | virtual ~Routine() |
68 | { |
69 | } |
70 | |
71 | public: |
72 | static const USHORT FLAG_SCANNED = 1; // Field expressions scanned |
73 | static const USHORT FLAG_OBSOLETE = 2; // Procedure known gonzo |
74 | static const USHORT FLAG_BEING_SCANNED = 4; // New procedure needs dependencies during scan |
75 | static const USHORT FLAG_BEING_ALTERED = 8; // Procedure is getting altered |
76 | // This flag is used to make sure that MET_remove_routine |
77 | // does not delete and remove procedure block from cache |
78 | // so dfw.epp:modify_procedure() can flip procedure body without |
79 | // invalidating procedure pointers from other parts of metadata cache |
80 | static const USHORT FLAG_CHECK_EXISTENCE = 16; // Existence lock released |
81 | |
82 | static const USHORT MAX_ALTER_COUNT = 64; // Number of times an in-cache routine can be altered |
83 | |
84 | static Firebird::MsgMetadata* createMetadata( |
85 | const Firebird::Array<NestConst<Parameter> >& parameters); |
86 | static Format* createFormat(MemoryPool& pool, Firebird::IMessageMetadata* params, bool addEof); |
87 | |
88 | public: |
89 | USHORT getId() const |
90 | { |
91 | fb_assert(!subRoutine); |
92 | return id; |
93 | } |
94 | |
95 | void setId(USHORT value) { id = value; } |
96 | |
97 | const Firebird::QualifiedName& getName() const { return name; } |
98 | void setName(const Firebird::QualifiedName& value) { name = value; } |
99 | |
100 | const Firebird::MetaName& getSecurityName() const { return securityName; } |
101 | void setSecurityName(const Firebird::MetaName& value) { securityName = value; } |
102 | |
103 | /*const*/ JrdStatement* getStatement() const { return statement; } |
104 | void setStatement(JrdStatement* value) { statement = value; } |
105 | |
106 | bool isSubRoutine() const { return subRoutine; } |
107 | void setSubRoutine(bool value) { subRoutine = value; } |
108 | |
109 | bool isImplemented() const { return implemented; } |
110 | void setImplemented(bool value) { implemented = value; } |
111 | |
112 | bool isDefined() const { return defined; } |
113 | void setDefined(bool value) { defined = value; } |
114 | |
115 | USHORT getDefaultCount() const { return defaultCount; } |
116 | void setDefaultCount(USHORT value) { defaultCount = value; } |
117 | |
118 | const Format* getInputFormat() const { return inputFormat; } |
119 | void setInputFormat(const Format* value) { inputFormat = value; } |
120 | |
121 | const Format* getOutputFormat() const { return outputFormat; } |
122 | void setOutputFormat(const Format* value) { outputFormat = value; } |
123 | |
124 | const Firebird::Array<NestConst<Parameter> >& getInputFields() const { return inputFields; } |
125 | Firebird::Array<NestConst<Parameter> >& getInputFields() { return inputFields; } |
126 | |
127 | const Firebird::Array<NestConst<Parameter> >& getOutputFields() const { return outputFields; } |
128 | Firebird::Array<NestConst<Parameter> >& getOutputFields() { return outputFields; } |
129 | |
130 | void parseBlr(thread_db* tdbb, CompilerScratch* csb, bid* blob_id); |
131 | void parseMessages(thread_db* tdbb, CompilerScratch* csb, Firebird::BlrReader blrReader); |
132 | |
133 | bool isUsed() const |
134 | { |
135 | return useCount != 0; |
136 | } |
137 | |
138 | void addRef() |
139 | { |
140 | ++useCount; |
141 | } |
142 | |
143 | virtual void releaseFormat() |
144 | { |
145 | } |
146 | |
147 | void release(thread_db* tdbb); |
148 | void releaseStatement(thread_db* tdbb); |
149 | void remove(thread_db* tdbb); |
150 | |
151 | public: |
152 | virtual int getObjectType() const = 0; |
153 | virtual SLONG getSclType() const = 0; |
154 | virtual bool checkCache(thread_db* tdbb) const = 0; |
155 | virtual void clearCache(thread_db* tdbb) = 0; |
156 | |
157 | private: |
158 | USHORT id; // routine ID |
159 | Firebird::QualifiedName name; // routine name |
160 | Firebird::MetaName securityName; // security class name |
161 | JrdStatement* statement; // compiled routine statement |
162 | bool subRoutine; // Is this a subroutine? |
163 | bool implemented; // Is the packaged routine missing the body/entrypoint? |
164 | bool defined; // UDF has its implementation module available |
165 | USHORT defaultCount; // default input arguments |
166 | const Format* inputFormat; // input format |
167 | const Format* outputFormat; // output format |
168 | Firebird::Array<NestConst<Parameter> > inputFields; // array of field blocks |
169 | Firebird::Array<NestConst<Parameter> > outputFields; // array of field blocks |
170 | |
171 | public: |
172 | USHORT flags; |
173 | USHORT useCount; // requests compiled with routine |
174 | SSHORT intUseCount; // number of routines compiled with routine, set and |
175 | // used internally in the MET_clear_cache routine |
176 | // no code should rely on value of this field |
177 | // (it will usually be 0) |
178 | USHORT alterCount; // No. of times the routine was altered |
179 | Lock* existenceLock; // existence lock, if any |
180 | }; |
181 | } |
182 | |
183 | #endif // JRD_ROUTINE_H |
184 | |