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() && Conf::config
.getCacheMode() == ASYNC_MODE
);
39 isSqlLogNeeded
= Conf::config
.useDurability();
44 if (!isSqlLogNeeded
) conn
= new SqlConnection();
46 AbsSqlConnection
*sqlCon
= new SqlConnection();
47 #if (defined MMDB && defined EMBED)
48 ((SqlConnection
*)sqlCon
)->UID
.create();
50 conn
= new SqlLogConnection();
51 SqlLogConnection
*logCon
= (SqlLogConnection
*)conn
;
52 logCon
->setNoMsgLog(true);
53 conn
->setInnerConnection(sqlCon
);
58 SqlNwConnection
*sqlNwCon
= new SqlNwConnection(CSqlNetwork
);
59 sqlNwCon
->setInnerConnection(NULL
);
64 conn
= new SqlConnection();
69 AbsSqlConnection
*sqlCon
= new SqlConnection();
70 conn
= new SqlLogConnection();
71 conn
->setInnerConnection(sqlCon
);
77 conn
= new SqlOdbcConnection();
78 conn
->setInnerConnection(NULL
);
83 SqlLogConnection
*sqllogconn
=NULL
;
84 AbsSqlConnection
*sqlCon
= new SqlConnection();
85 SqlGwConnection
*gwconn
= new SqlGwConnection();
87 sqllogconn
= new SqlLogConnection();
88 sqllogconn
->setInnerConnection(sqlCon
);
89 gwconn
->setInnerConnection(sqllogconn
);
90 } else gwconn
->setInnerConnection(sqlCon
);
92 //createAdapters for MultiDSN
93 rv
=gwconn
->createAdapters(gwconn
);
97 if(isSqlLogNeeded
) delete sqllogconn
;
103 case CSqlNetworkAdapter
:
105 SqlNwConnection
*sqlNwCon
= new SqlNwConnection(CSqlNetworkAdapter
);
106 sqlNwCon
->setInnerConnection(NULL
);
110 case CSqlNetworkGateway
:
112 SqlNwConnection
*sqlNwCon
= new SqlNwConnection(CSqlNetworkGateway
);
113 sqlNwCon
->setInnerConnection(NULL
);
125 AbsSqlStatement
* SqlFactory::createStatement(SqlApiImplType implFlag
)
127 AbsSqlStatement
*stmt
= NULL
;
128 bool isSqlLogNeeded
= false;
129 #if !(defined MMDB && defined EMBED)
130 isSqlLogNeeded
= Conf::config
.useDurability() ||
131 (Conf::config
.useCache() && Conf::config
.getCacheMode() == ASYNC_MODE
);
133 isSqlLogNeeded
= Conf::config
.useDurability();
138 if (!isSqlLogNeeded
) stmt
= new SqlStatement();
140 AbsSqlStatement
*sqlStmt
= new SqlStatement();
141 stmt
= new SqlLogStatement();
142 stmt
->setInnerStatement(sqlStmt
);
147 SqlNwStatement
*sqlNwStmt
= new SqlNwStatement();
148 sqlNwStmt
->setInnerStatement(NULL
);
153 stmt
= new SqlStatement();
158 AbsSqlStatement
*sqlStmt
= new SqlStatement();
159 stmt
= new SqlLogStatement();
160 stmt
->setInnerStatement(sqlStmt
);
166 stmt
= new SqlOdbcStatement();
167 stmt
->setInnerStatement(NULL
);
172 SqlGwStatement
*gwstmt
= new SqlGwStatement();
173 AbsSqlStatement
*sqlstmt
= new SqlStatement();
175 if (isSqlLogNeeded
) {
176 AbsSqlStatement
*sqllogstmt
= new SqlLogStatement();
177 sqllogstmt
->setInnerStatement(sqlstmt
);
178 gwstmt
->setInnerStatement(sqllogstmt
);
179 } else gwstmt
->setInnerStatement(sqlstmt
);
180 AbsSqlStatement
*adapterstmt
= new SqlOdbcStatement();
181 gwstmt
->setAdapter(adapterstmt
);
185 case CSqlNetworkAdapter
:
187 SqlNwStatement
*sqlNwStmt
= new SqlNwStatement();
188 sqlNwStmt
->setInnerStatement(NULL
);
192 case CSqlNetworkGateway
:
194 SqlNwStatement
*sqlNwStmt
= new SqlNwStatement();
195 sqlNwStmt
->setInnerStatement(NULL
);