Removing dependency for Cache module in MMDB build
[csql.git] / src / sql / SqlFactory.cxx
blob6c9ff332c3400b2705df9cc6cfa6dca7d344cf3f
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 #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>
27 Config Conf::config;
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) );
36 switch(implFlag)
38 case CSql:
39 if (!Conf::config.useDurability()) {
40 conn = new SqlConnection();
41 }else {
42 AbsSqlConnection *sqlCon = new SqlConnection();
43 conn = new SqlLogConnection();
44 SqlLogConnection *logCon = (SqlLogConnection *)conn;
45 logCon->setNoMsgLog(true);
46 conn->setInnerConnection(sqlCon);
48 break;
49 case CSqlLog:
51 //generates sql logs
52 AbsSqlConnection *sqlCon = new SqlConnection();
53 conn = new SqlLogConnection();
54 conn->setInnerConnection(sqlCon);
55 break;
57 #ifndef MMDB
58 case CSqlAdapter:
60 conn = new SqlOdbcConnection();
61 conn->setInnerConnection(NULL);
62 break;
64 case CSqlGateway:
66 AbsSqlConnection *sqlCon = new SqlConnection();
67 SqlGwConnection *gwconn = new SqlGwConnection();
68 if (isSqlLogNeeded) {
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);
76 conn = gwconn;
77 break;
79 #endif
80 case CSqlNetwork:
82 SqlNwConnection *sqlNwCon = new SqlNwConnection(CSqlNetwork);
83 sqlNwCon->setInnerConnection(NULL);
84 conn = sqlNwCon;
85 break;
87 case CSqlNetworkAdapter:
89 SqlNwConnection *sqlNwCon = new SqlNwConnection(CSqlNetworkAdapter);
90 sqlNwCon->setInnerConnection(NULL);
91 conn = sqlNwCon;
92 break;
94 case CSqlNetworkGateway:
96 SqlNwConnection *sqlNwCon = new SqlNwConnection(CSqlNetworkGateway);
97 sqlNwCon->setInnerConnection(NULL);
98 conn = sqlNwCon;
99 break;
101 case CSqlDirect:
102 conn = new SqlConnection();
103 break;
104 default:
105 printf("Todo");
106 break;
108 return conn;
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 ));
117 switch(implFlag)
119 case CSql:
120 if (!Conf::config.useDurability()) {
121 stmt = new SqlStatement();
122 }else {
123 AbsSqlStatement *sqlStmt = new SqlStatement();
124 stmt = new SqlLogStatement();
125 stmt->setInnerStatement(sqlStmt);
127 break;
128 case CSqlLog:
130 //generates sql logs
131 AbsSqlStatement *sqlStmt = new SqlStatement();
132 stmt = new SqlLogStatement();
133 stmt->setInnerStatement(sqlStmt);
134 break;
136 #ifndef MMDB
137 case CSqlAdapter:
139 stmt = new SqlOdbcStatement();
140 stmt->setInnerStatement(NULL);
141 break;
143 case CSqlGateway:
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);
155 stmt = gwstmt;
156 break;
158 #endif
159 case CSqlNetwork:
161 SqlNwStatement *sqlNwStmt = new SqlNwStatement();
162 sqlNwStmt->setInnerStatement(NULL);
163 stmt = sqlNwStmt;
164 break;
166 case CSqlNetworkAdapter:
168 SqlNwStatement *sqlNwStmt = new SqlNwStatement();
169 sqlNwStmt->setInnerStatement(NULL);
170 stmt=sqlNwStmt;
171 break;
173 case CSqlNetworkGateway:
175 SqlNwStatement *sqlNwStmt = new SqlNwStatement();
176 sqlNwStmt->setInnerStatement(NULL);
177 stmt = sqlNwStmt;
178 break;
180 case CSqlDirect:
181 stmt = new SqlStatement();
182 break;
183 default:
184 printf("Todo");
185 break;
187 return stmt;