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 #include <SqlStatement.h>
18 #include <SqlConnection.h>
19 #include <SqlLogConnection.h>
20 #include <SqlLogStatement.h>
21 #include <SqlOdbcConnection.h>
22 #include <SqlOdbcStatement.h>
23 #include <SqlGwStatement.h>
24 #include <SqlNwConnection.h>
25 #include <SqlNwStatement.h>
29 AbsSqlConnection
* SqlFactory::createConnection(SqlApiImplType implFlag
)
32 AbsSqlConnection
*conn
= NULL
;
33 Conf::config
.readAllValues(os::getenv("CSQL_CONFIG_FILE"));
34 bool isSqlLogNeeded
= false;
35 #if !(defined MMDB && defined EMBED)
36 isSqlLogNeeded
= Conf::config
.useDurability() ||
37 (Conf::config
.useCache() &&
38 (Conf::config
.getCacheMode()==ASYNC_MODE
||
39 Conf::config
.getCacheMode() == OFFLINE_MODE
));
41 isSqlLogNeeded
= Conf::config
.useDurability();
46 if (!isSqlLogNeeded
) conn
= new SqlConnection();
48 AbsSqlConnection
*sqlCon
= new SqlConnection();
49 #if (defined MMDB && defined EMBED)
50 ((SqlConnection
*)sqlCon
)->UID
.create();
52 conn
= new SqlLogConnection();
53 SqlLogConnection
*logCon
= (SqlLogConnection
*)conn
;
54 logCon
->setNoMsgLog(true);
55 conn
->setInnerConnection(sqlCon
);
60 SqlNwConnection
*sqlNwCon
= new SqlNwConnection(CSqlNetwork
);
61 sqlNwCon
->setInnerConnection(NULL
);
66 conn
= new SqlConnection();
71 AbsSqlConnection
*sqlCon
= new SqlConnection();
72 conn
= new SqlLogConnection();
73 conn
->setInnerConnection(sqlCon
);
79 conn
= new SqlOdbcConnection();
80 conn
->setInnerConnection(NULL
);
85 SqlLogConnection
*sqllogconn
=NULL
;
86 AbsSqlConnection
*sqlCon
= new SqlConnection();
87 SqlGwConnection
*gwconn
= new SqlGwConnection();
89 sqllogconn
= new SqlLogConnection();
90 sqllogconn
->setInnerConnection(sqlCon
);
91 bool isNoMsgLog
= Conf::config
.useDurability() &&
92 !(Conf::config
.useCache() &&
93 Conf::config
.getCacheMode()==ASYNC_MODE
);
94 if (isNoMsgLog
) sqllogconn
->setNoMsgLog(true);
95 gwconn
->setInnerConnection(sqllogconn
);
96 } else gwconn
->setInnerConnection(sqlCon
);
98 //createAdapters for MultiDSN
99 rv
=gwconn
->createAdapters(gwconn
);
103 if(isSqlLogNeeded
) delete sqllogconn
;
109 case CSqlNetworkAdapter
:
111 SqlNwConnection
*sqlNwCon
= new SqlNwConnection(CSqlNetworkAdapter
);
112 sqlNwCon
->setInnerConnection(NULL
);
116 case CSqlNetworkGateway
:
118 SqlNwConnection
*sqlNwCon
= new SqlNwConnection(CSqlNetworkGateway
);
119 sqlNwCon
->setInnerConnection(NULL
);
131 AbsSqlStatement
* SqlFactory::createStatement(SqlApiImplType implFlag
)
133 AbsSqlStatement
*stmt
= NULL
;
134 bool isSqlLogNeeded
= false;
135 #if !(defined MMDB && defined EMBED)
136 isSqlLogNeeded
= Conf::config
.useDurability() ||
137 (Conf::config
.useCache() &&
138 (Conf::config
.getCacheMode()==ASYNC_MODE
||
139 Conf::config
.getCacheMode() == OFFLINE_MODE
));
141 isSqlLogNeeded
= Conf::config
.useDurability();
146 if (!isSqlLogNeeded
) stmt
= new SqlStatement();
148 AbsSqlStatement
*sqlStmt
= new SqlStatement();
149 stmt
= new SqlLogStatement();
150 stmt
->setInnerStatement(sqlStmt
);
155 SqlNwStatement
*sqlNwStmt
= new SqlNwStatement();
156 sqlNwStmt
->setInnerStatement(NULL
);
161 stmt
= new SqlStatement();
166 AbsSqlStatement
*sqlStmt
= new SqlStatement();
167 stmt
= new SqlLogStatement();
168 stmt
->setInnerStatement(sqlStmt
);
174 stmt
= new SqlOdbcStatement();
175 stmt
->setInnerStatement(NULL
);
180 SqlGwStatement
*gwstmt
= new SqlGwStatement();
181 AbsSqlStatement
*sqlstmt
= new SqlStatement();
183 if (isSqlLogNeeded
) {
184 AbsSqlStatement
*sqllogstmt
= new SqlLogStatement();
185 sqllogstmt
->setInnerStatement(sqlstmt
);
186 gwstmt
->setInnerStatement(sqllogstmt
);
187 } else gwstmt
->setInnerStatement(sqlstmt
);
188 AbsSqlStatement
*adapterstmt
= new SqlOdbcStatement();
189 gwstmt
->setAdapter(adapterstmt
);
193 case CSqlNetworkAdapter
:
195 SqlNwStatement
*sqlNwStmt
= new SqlNwStatement();
196 sqlNwStmt
->setInnerStatement(NULL
);
200 case CSqlNetworkGateway
:
202 SqlNwStatement
*sqlNwStmt
= new SqlNwStatement();
203 sqlNwStmt
->setInnerStatement(NULL
);