1 /***************************************************************************
2 * Copyright (C) 2007 by Prabakaran Thirumalai *
3 * praba_tuty@yahoo.com *
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. *
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. *
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>
26 #include <SqlNwConnection.h>
27 #include <SqlNwStatement.h>
28 #ifndef CSQL_CLIENT_LIB
32 AbsSqlConnection
* SqlFactory::createConnection(SqlApiImplType implFlag
)
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
));
44 isSqlLogNeeded
= Conf::config
.useDurability();
48 #ifndef CSQL_CLIENT_LIB
50 if (!isSqlLogNeeded
) conn
= new SqlConnection();
52 AbsSqlConnection
*sqlCon
= new SqlConnection();
53 #if (defined MMDB && defined EMBED)
54 ((SqlConnection
*)sqlCon
)->UID
.create();
56 conn
= new SqlLogConnection();
57 SqlLogConnection
*logCon
= (SqlLogConnection
*)conn
;
58 logCon
->setNoMsgLog(true);
59 conn
->setInnerConnection(sqlCon
);
65 SqlNwConnection
*sqlNwCon
= new SqlNwConnection(CSqlNetwork
);
66 sqlNwCon
->setInnerConnection(NULL
);
70 #ifndef CSQL_CLIENT_LIB
72 conn
= new SqlConnection();
77 AbsSqlConnection
*sqlCon
= new SqlConnection();
78 conn
= new SqlLogConnection();
79 conn
->setInnerConnection(sqlCon
);
84 #ifndef CSQL_CLIENT_LIB
87 conn
= new SqlOdbcConnection();
88 conn
->setInnerConnection(NULL
);
93 SqlLogConnection
*sqllogconn
=NULL
;
94 AbsSqlConnection
*sqlCon
= new SqlConnection();
95 SqlGwConnection
*gwconn
= new SqlGwConnection();
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
);
111 if(isSqlLogNeeded
) delete sqllogconn
;
118 case CSqlNetworkAdapter
:
120 SqlNwConnection
*sqlNwCon
= new SqlNwConnection(CSqlNetworkAdapter
);
121 sqlNwCon
->setInnerConnection(NULL
);
125 case CSqlNetworkGateway
:
127 SqlNwConnection
*sqlNwCon
= new SqlNwConnection(CSqlNetworkGateway
);
128 sqlNwCon
->setInnerConnection(NULL
);
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
));
150 isSqlLogNeeded
= Conf::config
.useDurability();
154 #ifndef CSQL_CLIENT_LIB
156 if (!isSqlLogNeeded
) stmt
= new SqlStatement();
158 AbsSqlStatement
*sqlStmt
= new SqlStatement();
159 stmt
= new SqlLogStatement();
160 stmt
->setInnerStatement(sqlStmt
);
166 SqlNwStatement
*sqlNwStmt
= new SqlNwStatement();
167 sqlNwStmt
->setInnerStatement(NULL
);
171 #ifndef CSQL_CLIENT_LIB
174 stmt
= new SqlStatement();
179 AbsSqlStatement
*sqlStmt
= new SqlStatement();
180 stmt
= new SqlLogStatement();
181 stmt
->setInnerStatement(sqlStmt
);
186 #ifndef CSQL_CLIENT_LIB
190 stmt
= new SqlOdbcStatement();
191 stmt
->setInnerStatement(NULL
);
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
);
210 case CSqlNetworkAdapter
:
212 SqlNwStatement
*sqlNwStmt
= new SqlNwStatement();
213 sqlNwStmt
->setInnerStatement(NULL
);
217 case CSqlNetworkGateway
:
219 SqlNwStatement
*sqlNwStmt
= new SqlNwStatement();
220 sqlNwStmt
->setInnerStatement(NULL
);