Enterprise to opensource. 40 files including Makefil.am and .in from storage, sqllog...
[csql.git] / src / sql / SqlFactory.cxx
blobcba86d9521536017737f6a52b22567007f8e34ce
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();
35 switch(implFlag)
37 case CSql:
38 if (!Conf::config.useDurability()) {
39 conn = new SqlConnection();
40 }else {
41 AbsSqlConnection *sqlCon = new SqlConnection();
42 conn = new SqlLogConnection();
43 conn->setInnerConnection(sqlCon);
45 break;
46 case CSqlLog:
48 //generates sql logs
49 AbsSqlConnection *sqlCon = new SqlConnection();
50 conn = new SqlLogConnection();
51 conn->setInnerConnection(sqlCon);
52 break;
54 #ifndef MMDB
55 case CSqlAdapter:
57 conn = new SqlOdbcConnection();
58 conn->setInnerConnection(NULL);
59 break;
61 case CSqlGateway:
63 AbsSqlConnection *sqlCon = new SqlConnection();
64 SqlGwConnection *gwconn = new SqlGwConnection();
65 if (isSqlLogNeeded) {
66 AbsSqlConnection *sqllogconn = new SqlLogConnection();
67 sqllogconn->setInnerConnection(sqlCon);
68 gwconn->setInnerConnection(sqllogconn);
69 } else gwconn->setInnerConnection(sqlCon);
70 AbsSqlConnection *adapterCon = new SqlOdbcConnection();
71 gwconn->setAdapter(adapterCon);
72 conn = gwconn;
73 break;
75 #endif
76 case CSqlNetwork:
78 SqlNwConnection *sqlNwCon = new SqlNwConnection(CSqlNetwork);
79 sqlNwCon->setInnerConnection(NULL);
80 conn = sqlNwCon;
81 break;
83 case CSqlNetworkAdapter:
85 SqlNwConnection *sqlNwCon = new SqlNwConnection(CSqlNetworkAdapter);
86 sqlNwCon->setInnerConnection(NULL);
87 conn = sqlNwCon;
88 break;
90 case CSqlNetworkGateway:
92 SqlNwConnection *sqlNwCon = new SqlNwConnection(CSqlNetworkGateway);
93 sqlNwCon->setInnerConnection(NULL);
94 conn = sqlNwCon;
95 break;
97 case CSqlDirect:
98 conn = new SqlConnection();
99 break;
100 default:
101 printf("Todo");
102 break;
104 return conn;
107 AbsSqlStatement* SqlFactory::createStatement(SqlApiImplType implFlag)
109 AbsSqlStatement *stmt = NULL;
110 bool isSqlLogNeeded = Conf::config.useDurability();
111 switch(implFlag)
113 case CSql:
114 if (!Conf::config.useDurability()) {
115 stmt = new SqlStatement();
116 }else {
117 AbsSqlStatement *sqlStmt = new SqlStatement();
118 stmt = new SqlLogStatement();
119 stmt->setInnerStatement(sqlStmt);
121 break;
122 case CSqlLog:
124 //generates sql logs
125 AbsSqlStatement *sqlStmt = new SqlStatement();
126 stmt = new SqlLogStatement();
127 stmt->setInnerStatement(sqlStmt);
128 break;
130 #ifndef MMDB
131 case CSqlAdapter:
133 stmt = new SqlOdbcStatement();
134 stmt->setInnerStatement(NULL);
135 break;
137 case CSqlGateway:
139 SqlGwStatement *gwstmt = new SqlGwStatement();
140 AbsSqlStatement *sqlstmt = new SqlStatement();
141 if (isSqlLogNeeded) {
142 AbsSqlStatement *sqllogstmt = new SqlLogStatement();
143 sqllogstmt->setInnerStatement(sqlstmt);
144 gwstmt->setInnerStatement(sqllogstmt);
145 } else gwstmt->setInnerStatement(sqlstmt);
146 AbsSqlStatement *adapterstmt = new SqlOdbcStatement();
147 gwstmt->setAdapter(adapterstmt);
148 stmt = gwstmt;
149 break;
151 #endif
152 case CSqlNetwork:
154 SqlNwStatement *sqlNwStmt = new SqlNwStatement();
155 sqlNwStmt->setInnerStatement(NULL);
156 stmt = sqlNwStmt;
157 break;
159 case CSqlNetworkAdapter:
161 SqlNwStatement *sqlNwStmt = new SqlNwStatement();
162 sqlNwStmt->setInnerStatement(NULL);
163 stmt=sqlNwStmt;
164 break;
166 case CSqlNetworkGateway:
168 SqlNwStatement *sqlNwStmt = new SqlNwStatement();
169 sqlNwStmt->setInnerStatement(NULL);
170 stmt = sqlNwStmt;
171 break;
173 case CSqlDirect:
174 stmt = new SqlStatement();
175 break;
176 default:
177 printf("Todo");
178 break;
180 return stmt;