changes for windows jdbc driverw
[csql.git] / src / sql / SqlFactory.cxx
blob158bfe2461f7ad9d52371357954d574c7e17fd7a
1 /***************************************************************************
2 * Copyright (C) 2007 by Prabakaran Thirumalai *
3 * praba_tuty@yahoo.com *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 ***************************************************************************/
16 #include <SqlFactory.h>
17 #ifndef CSQL_CLIENT_LIB
18 #include <SqlStatement.h>
19 #include <SqlConnection.h>
20 #include <SqlLogConnection.h>
21 #include <SqlLogStatement.h>
22 #include <SqlOdbcConnection.h>
23 #include <SqlOdbcStatement.h>
24 #include <SqlGwStatement.h>
25 #endif
26 #include <SqlNwConnection.h>
27 #include <SqlNwStatement.h>
28 #ifndef CSQL_CLIENT_LIB
29 Config Conf::config;
30 #endif
32 AbsSqlConnection* SqlFactory::createConnection(SqlApiImplType implFlag)
34 DbRetVal rv=OK;
35 AbsSqlConnection *conn = NULL ;
36 Conf::config.readAllValues(os::getenv("CSQL_CONFIG_FILE"));
37 bool isSqlLogNeeded = false;
38 #if !(defined MMDB && defined EMBED)
39 isSqlLogNeeded = Conf::config.useDurability() ||
40 (Conf::config.useCache() &&
41 (Conf::config.getCacheMode()==ASYNC_MODE ||
42 Conf::config.getCacheMode() == OFFLINE_MODE));
43 #else
44 isSqlLogNeeded = Conf::config.useDurability();
45 #endif
46 switch(implFlag)
48 #ifndef CSQL_CLIENT_LIB
49 case CSql:
50 if (!isSqlLogNeeded) conn = new SqlConnection();
51 else {
52 AbsSqlConnection *sqlCon = new SqlConnection();
53 #if (defined MMDB && defined EMBED)
54 ((SqlConnection *)sqlCon)->UID.create();
55 #endif
56 conn = new SqlLogConnection();
57 SqlLogConnection *logCon = (SqlLogConnection *)conn;
58 logCon->setNoMsgLog(true);
59 conn->setInnerConnection(sqlCon);
61 break;
62 #endif
63 case CSqlNetwork:
65 SqlNwConnection *sqlNwCon = new SqlNwConnection(CSqlNetwork);
66 sqlNwCon->setInnerConnection(NULL);
67 conn = sqlNwCon;
68 break;
70 #ifndef CSQL_CLIENT_LIB
71 case CSqlDirect:
72 conn = new SqlConnection();
73 break;
74 case CSqlLog:
76 //generates sql logs
77 AbsSqlConnection *sqlCon = new SqlConnection();
78 conn = new SqlLogConnection();
79 conn->setInnerConnection(sqlCon);
80 break;
82 #endif
83 #ifndef MMDB
84 #ifndef CSQL_CLIENT_LIB
85 case CSqlAdapter:
87 conn = new SqlOdbcConnection();
88 conn->setInnerConnection(NULL);
89 break;
91 case CSqlGateway:
93 SqlLogConnection *sqllogconn=NULL;
94 AbsSqlConnection *sqlCon = new SqlConnection();
95 SqlGwConnection *gwconn = new SqlGwConnection();
96 if (isSqlLogNeeded) {
97 sqllogconn = new SqlLogConnection();
98 sqllogconn->setInnerConnection(sqlCon);
99 bool isNoMsgLog = Conf::config.useDurability() &&
100 !(Conf::config.useCache() &&
101 Conf::config.getCacheMode()==ASYNC_MODE);
102 if (isNoMsgLog) sqllogconn->setNoMsgLog(true);
103 gwconn->setInnerConnection(sqllogconn);
104 } else gwconn->setInnerConnection(sqlCon);
106 //createAdapters for MultiDSN
107 rv=gwconn->createAdapters(gwconn);
108 if(rv != OK){
109 delete sqlCon;
110 delete gwconn;
111 if(isSqlLogNeeded) delete sqllogconn;
112 return NULL;
114 conn = gwconn;
115 break;
117 #endif
118 case CSqlNetworkAdapter:
120 SqlNwConnection *sqlNwCon = new SqlNwConnection(CSqlNetworkAdapter);
121 sqlNwCon->setInnerConnection(NULL);
122 conn = sqlNwCon;
123 break;
125 case CSqlNetworkGateway:
127 SqlNwConnection *sqlNwCon = new SqlNwConnection(CSqlNetworkGateway);
128 sqlNwCon->setInnerConnection(NULL);
129 conn = sqlNwCon;
130 break;
132 #endif
133 default:
134 printf("Todo");
135 break;
137 return conn;
140 AbsSqlStatement* SqlFactory::createStatement(SqlApiImplType implFlag)
142 AbsSqlStatement *stmt = NULL;
143 bool isSqlLogNeeded = false;
144 #if !(defined MMDB && defined EMBED)
145 isSqlLogNeeded = Conf::config.useDurability() ||
146 (Conf::config.useCache() &&
147 (Conf::config.getCacheMode()==ASYNC_MODE ||
148 Conf::config.getCacheMode() == OFFLINE_MODE));
149 #else
150 isSqlLogNeeded = Conf::config.useDurability();
151 #endif
152 switch(implFlag)
154 #ifndef CSQL_CLIENT_LIB
155 case CSql:
156 if (!isSqlLogNeeded) stmt = new SqlStatement();
157 else {
158 AbsSqlStatement *sqlStmt = new SqlStatement();
159 stmt = new SqlLogStatement();
160 stmt->setInnerStatement(sqlStmt);
162 break;
163 #endif
164 case CSqlNetwork:
166 SqlNwStatement *sqlNwStmt = new SqlNwStatement();
167 sqlNwStmt->setInnerStatement(NULL);
168 stmt = sqlNwStmt;
169 break;
171 #ifndef CSQL_CLIENT_LIB
173 case CSqlDirect:
174 stmt = new SqlStatement();
175 break;
176 case CSqlLog:
178 //generates sql logs
179 AbsSqlStatement *sqlStmt = new SqlStatement();
180 stmt = new SqlLogStatement();
181 stmt->setInnerStatement(sqlStmt);
182 break;
184 #endif
185 #ifndef MMDB
186 #ifndef CSQL_CLIENT_LIB
188 case CSqlAdapter:
190 stmt = new SqlOdbcStatement();
191 stmt->setInnerStatement(NULL);
192 break;
194 case CSqlGateway:
196 SqlGwStatement *gwstmt = new SqlGwStatement();
197 AbsSqlStatement *sqlstmt = new SqlStatement();
199 if (isSqlLogNeeded) {
200 AbsSqlStatement *sqllogstmt = new SqlLogStatement();
201 sqllogstmt->setInnerStatement(sqlstmt);
202 gwstmt->setInnerStatement(sqllogstmt);
203 } else gwstmt->setInnerStatement(sqlstmt);
204 AbsSqlStatement *adapterstmt = new SqlOdbcStatement();
205 gwstmt->setAdapter(adapterstmt);
206 stmt = gwstmt;
207 break;
209 #endif
210 case CSqlNetworkAdapter:
212 SqlNwStatement *sqlNwStmt = new SqlNwStatement();
213 sqlNwStmt->setInnerStatement(NULL);
214 stmt=sqlNwStmt;
215 break;
217 case CSqlNetworkGateway:
219 SqlNwStatement *sqlNwStmt = new SqlNwStatement();
220 sqlNwStmt->setInnerStatement(NULL);
221 stmt = sqlNwStmt;
222 break;
224 #endif
225 default:
226 printf("Todo");
227 break;
229 return stmt;