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
)
31 AbsSqlConnection
*conn
= NULL
;
32 Conf::config
.readAllValues(os::getenv("CSQL_CONFIG_FILE"));
33 bool isSqlLogNeeded
= ( Conf::config
.useDurability() ||
34 ( Conf::config
.useCache() &&
35 Conf::config
.getCacheMode() == ASYNC_MODE
) );
39 if (!Conf::config
.useDurability()) {
40 conn
= new SqlConnection();
42 AbsSqlConnection
*sqlCon
= new SqlConnection();
43 conn
= new SqlLogConnection();
44 SqlLogConnection
*logCon
= (SqlLogConnection
*)conn
;
45 logCon
->setNoMsgLog(true);
46 conn
->setInnerConnection(sqlCon
);
52 AbsSqlConnection
*sqlCon
= new SqlConnection();
53 conn
= new SqlLogConnection();
54 conn
->setInnerConnection(sqlCon
);
60 conn
= new SqlOdbcConnection();
61 conn
->setInnerConnection(NULL
);
66 AbsSqlConnection
*sqlCon
= new SqlConnection();
67 SqlGwConnection
*gwconn
= new SqlGwConnection();
69 AbsSqlConnection
*sqllogconn
= new SqlLogConnection();
70 sqllogconn
->setInnerConnection(sqlCon
);
71 gwconn
->setInnerConnection(sqllogconn
);
72 } else gwconn
->setInnerConnection(sqlCon
);
74 //createAdapters for MultiDSN
75 gwconn
->createAdapters(gwconn
);
82 SqlNwConnection
*sqlNwCon
= new SqlNwConnection(CSqlNetwork
);
83 sqlNwCon
->setInnerConnection(NULL
);
87 case CSqlNetworkAdapter
:
89 SqlNwConnection
*sqlNwCon
= new SqlNwConnection(CSqlNetworkAdapter
);
90 sqlNwCon
->setInnerConnection(NULL
);
94 case CSqlNetworkGateway
:
96 SqlNwConnection
*sqlNwCon
= new SqlNwConnection(CSqlNetworkGateway
);
97 sqlNwCon
->setInnerConnection(NULL
);
102 conn
= new SqlConnection();
111 AbsSqlStatement
* SqlFactory::createStatement(SqlApiImplType implFlag
)
113 AbsSqlStatement
*stmt
= NULL
;
114 bool isSqlLogNeeded
= ( Conf::config
.useDurability() ||
115 ( Conf::config
.useCache() &&
116 Conf::config
.getCacheMode() == ASYNC_MODE
));
120 if (!Conf::config
.useDurability()) {
121 stmt
= new SqlStatement();
123 AbsSqlStatement
*sqlStmt
= new SqlStatement();
124 stmt
= new SqlLogStatement();
125 stmt
->setInnerStatement(sqlStmt
);
131 AbsSqlStatement
*sqlStmt
= new SqlStatement();
132 stmt
= new SqlLogStatement();
133 stmt
->setInnerStatement(sqlStmt
);
139 stmt
= new SqlOdbcStatement();
140 stmt
->setInnerStatement(NULL
);
145 SqlGwStatement
*gwstmt
= new SqlGwStatement();
146 AbsSqlStatement
*sqlstmt
= new SqlStatement();
148 if (isSqlLogNeeded
) {
149 AbsSqlStatement
*sqllogstmt
= new SqlLogStatement();
150 sqllogstmt
->setInnerStatement(sqlstmt
);
151 gwstmt
->setInnerStatement(sqllogstmt
);
152 } else gwstmt
->setInnerStatement(sqlstmt
);
153 AbsSqlStatement
*adapterstmt
= new SqlOdbcStatement();
154 gwstmt
->setAdapter(adapterstmt
);
161 SqlNwStatement
*sqlNwStmt
= new SqlNwStatement();
162 sqlNwStmt
->setInnerStatement(NULL
);
166 case CSqlNetworkAdapter
:
168 SqlNwStatement
*sqlNwStmt
= new SqlNwStatement();
169 sqlNwStmt
->setInnerStatement(NULL
);
173 case CSqlNetworkGateway
:
175 SqlNwStatement
*sqlNwStmt
= new SqlNwStatement();
176 sqlNwStmt
->setInnerStatement(NULL
);
181 stmt
= new SqlStatement();