1 | /* |
2 | * The contents of this file are subject to the Initial |
3 | * Developer's Public License Version 1.0 (the "License"); |
4 | * you may not use this file except in compliance with the |
5 | * License. You may obtain a copy of the License at |
6 | * http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl. |
7 | * |
8 | * Software distributed under the License is distributed AS IS, |
9 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. |
10 | * See the License for the specific language governing rights |
11 | * and limitations under the License. |
12 | * |
13 | * The Original Code was created by Vlad Khorsun |
14 | * for the Firebird Open Source RDBMS project. |
15 | * |
16 | * Copyright (c) 2008 Vlad Khorsun <hvlad@users.sourceforge.net> |
17 | * and all contributors signed below. |
18 | * |
19 | * All Rights Reserved. |
20 | * Contributor(s): ______________________________________. |
21 | */ |
22 | |
23 | #ifndef EXTDS_INTERNAL_H |
24 | #define EXTDS_INTERNAL_H |
25 | |
26 | |
27 | #include "ExtDS.h" |
28 | |
29 | namespace EDS { |
30 | |
31 | class InternalProvider : public Provider |
32 | { |
33 | public: |
34 | explicit InternalProvider(const char* prvName) : |
35 | Provider(prvName) |
36 | { |
37 | m_flags = (prvMultyStmts | prvMultyTrans); |
38 | } |
39 | |
40 | ~InternalProvider() |
41 | {} |
42 | |
43 | virtual void initialize() {} |
44 | virtual void jrdAttachmentEnd(Jrd::thread_db* tdbb, Jrd::Attachment* att); |
45 | virtual void getRemoteError(const ISC_STATUS* status, Firebird::string& err) const; |
46 | |
47 | protected: |
48 | virtual Connection* doCreateConnection(); |
49 | }; |
50 | |
51 | |
52 | class InternalConnection : public Connection |
53 | { |
54 | protected: |
55 | friend class InternalProvider; |
56 | |
57 | explicit InternalConnection(InternalProvider& prov) : |
58 | Connection(prov), |
59 | m_attachment(0), |
60 | m_isCurrent(false) |
61 | {} |
62 | |
63 | virtual ~InternalConnection(); |
64 | |
65 | public: |
66 | virtual void attach(Jrd::thread_db* tdbb, const Firebird::string& dbName, |
67 | const Firebird::string& user, const Firebird::string& pwd, |
68 | const Firebird::string& role); |
69 | |
70 | virtual bool cancelExecution(); |
71 | |
72 | virtual bool isAvailable(Jrd::thread_db* tdbb, TraScope traScope) const; |
73 | |
74 | virtual bool isConnected() const { return (m_attachment != 0); } |
75 | |
76 | virtual bool isSameDatabase(Jrd::thread_db* tdbb, const Firebird::string& dbName, |
77 | const Firebird::string& user, const Firebird::string& pwd, |
78 | const Firebird::string& role) const; |
79 | |
80 | bool isCurrent() const { return m_isCurrent; } |
81 | |
82 | Jrd::JAttachment* getJrdAtt() { return m_attachment; } |
83 | |
84 | virtual Blob* createBlob(); |
85 | |
86 | protected: |
87 | virtual Transaction* doCreateTransaction(); |
88 | virtual Statement* doCreateStatement(); |
89 | virtual void doDetach(Jrd::thread_db* tdbb); |
90 | |
91 | Jrd::JAttachment* m_attachment; |
92 | bool m_isCurrent; |
93 | }; |
94 | |
95 | |
96 | class InternalTransaction : public Transaction |
97 | { |
98 | protected: |
99 | friend class InternalConnection; |
100 | |
101 | explicit InternalTransaction(InternalConnection& conn) : |
102 | Transaction(conn), |
103 | m_IntConnection(conn), |
104 | m_transaction(0) |
105 | {} |
106 | |
107 | virtual ~InternalTransaction() {} |
108 | |
109 | public: |
110 | Jrd::JTransaction* getJrdTran() { return m_transaction; } |
111 | |
112 | protected: |
113 | virtual void doStart(ISC_STATUS* status, Jrd::thread_db* tdbb, Firebird::ClumpletWriter& tpb); |
114 | virtual void doPrepare(ISC_STATUS* status, Jrd::thread_db* tdbb, int info_len, const char* info); |
115 | virtual void doCommit(ISC_STATUS* status, Jrd::thread_db* tdbb, bool retain); |
116 | virtual void doRollback(ISC_STATUS* status, Jrd::thread_db* tdbb, bool retain); |
117 | |
118 | InternalConnection& m_IntConnection; |
119 | Jrd::JTransaction* m_transaction; |
120 | }; |
121 | |
122 | |
123 | class InternalStatement : public Statement |
124 | { |
125 | protected: |
126 | friend class InternalConnection; |
127 | |
128 | explicit InternalStatement(InternalConnection& conn); |
129 | ~InternalStatement(); |
130 | |
131 | protected: |
132 | virtual void doPrepare(Jrd::thread_db* tdbb, const Firebird::string& sql); |
133 | virtual void doExecute(Jrd::thread_db* tdbb); |
134 | virtual void doOpen(Jrd::thread_db* tdbb); |
135 | virtual bool doFetch(Jrd::thread_db* tdbb); |
136 | virtual void doClose(Jrd::thread_db* tdbb, bool drop); |
137 | |
138 | virtual void putExtBlob(Jrd::thread_db* tdbb, dsc& src, dsc& dst); |
139 | virtual void getExtBlob(Jrd::thread_db* tdbb, const dsc& src, dsc& dst); |
140 | |
141 | InternalTransaction* getIntTransaction() |
142 | { |
143 | return (InternalTransaction*) m_transaction; |
144 | } |
145 | |
146 | InternalConnection& m_intConnection; |
147 | InternalTransaction* m_intTransaction; |
148 | |
149 | Jrd::JStatement* m_request; |
150 | Jrd::JResultSet* m_cursor; |
151 | Firebird::RefPtr<Firebird::MsgMetadata> m_inMetadata, m_outMetadata; |
152 | }; |
153 | |
154 | |
155 | class InternalBlob : public Blob |
156 | { |
157 | friend class InternalConnection; |
158 | protected: |
159 | explicit InternalBlob(InternalConnection& conn); |
160 | |
161 | public: |
162 | ~InternalBlob(); |
163 | |
164 | public: |
165 | virtual void open(Jrd::thread_db* tdbb, Transaction& tran, const dsc& desc, const Firebird::UCharBuffer* bpb); |
166 | virtual void create(Jrd::thread_db* tdbb, Transaction& tran, dsc& desc, const Firebird::UCharBuffer* bpb); |
167 | virtual USHORT read(Jrd::thread_db* tdbb, UCHAR* buff, USHORT len); |
168 | virtual void write(Jrd::thread_db* tdbb, const UCHAR* buff, USHORT len); |
169 | virtual void close(Jrd::thread_db* tdbb); |
170 | virtual void cancel(Jrd::thread_db* tdbb); |
171 | |
172 | private: |
173 | InternalConnection& m_connection; |
174 | Jrd::JBlob* m_blob; |
175 | ISC_QUAD m_blob_id; |
176 | }; |
177 | |
178 | } // namespace EDS |
179 | |
180 | #endif // EXTDS_INTERNAL_H |
181 | |