ffead.server.doc
CibernateConnPools.h
1 /*
2  Copyright 2009-2012, Sumeet Chhetri
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 /*
17  * CibernateConnPools.h
18  *
19  * Created on: Mar 16, 2010
20  * Author: sumeet
21  */
22 
23 #ifndef CIBERNATECONNPOOLS_H_
24 #define CIBERNATECONNPOOLS_H_
25 #include "CibernateConnectionPool.h"
26 #include "map"
27 #include "Logger.h"
28 typedef map<string,string> strMap;
29 typedef map<string,strMap> smstrMap;
30 
31 class DBRel
32 {
33 public:
34  int type;//1->1-1 2->1-N 3->N-N
35  string fk;
36  string pk;
37  string clsName;
38  string field;
39 };
40 typedef map<string,vector<DBRel> > relMap;
41 class Mapping
42 {
43  smstrMap appTableColMapping;
44  smstrMap tableAppColMapping;
45  strMap appTableClassMapping;
46  relMap appTableRelMapping;
47 public:
48  string getAppTableColMapping(string table,string propertyName)
49  {
50  if(this->appTableColMapping.find(table)!=this->appTableColMapping.end())
51  {
52  if(this->appTableColMapping[table].find(propertyName)!=this->appTableColMapping[table].end())
53  return this->appTableColMapping[table][propertyName];
54  else
55  return "";
56  }
57  return "";
58  }
59 
60  string getTableAppColMapping(string table,string columnName)
61  {
62  if(this->tableAppColMapping.find(table)!=this->tableAppColMapping.end())
63  {
64  if(this->tableAppColMapping[table].find(columnName)!=this->tableAppColMapping[table].end())
65  return this->tableAppColMapping[table][columnName];
66  else
67  return "";
68  }
69  return "";
70  }
71 
72  strMap getAppTableColMapping(string table)
73  {
74  if(this->appTableColMapping.find(table)!=this->appTableColMapping.end())
75  {
76  return this->appTableColMapping[table];
77  }
78  strMap tem;
79  return tem;
80  }
81 
82  strMap getTableAppColMapping(string table)
83  {
84  if(this->tableAppColMapping.find(table)!=this->tableAppColMapping.end())
85  {
86  return this->tableAppColMapping[table];
87  }
88  strMap tem;
89  return tem;
90  }
91 
92  void setAppTableColMapping(smstrMap appTableColMapping)
93  {
94  this->appTableColMapping = appTableColMapping;
95  smstrMap::iterator it;
96  for(it=appTableColMapping.begin();it!=appTableColMapping.end();it++) {
97  strMap tempo;
98  strMap::iterator ite;
99  for(ite=it->second.begin();ite!=it->second.end();ite++) {
100  tempo[ite->second] = ite->first;
101  }
102  this->tableAppColMapping[appTableClassMapping[it->first]] = tempo;
103  }
104  }
105 
106  string getAppTableClassMapping(string claz)
107  {
108  if(this->appTableClassMapping.find(claz)!=this->appTableClassMapping.end())
109  return this->appTableClassMapping[claz];
110  else
111  return "";
112  }
113 
114  void setAppTableClassMapping(strMap appTableClassMapping)
115  {
116  this->appTableClassMapping = appTableClassMapping;
117  smstrMap::iterator it;
118  for(it=appTableColMapping.begin();it!=appTableColMapping.end();it++) {
119  strMap tempo;
120  strMap::iterator ite;
121  for(ite=it->second.begin();ite!=it->second.end();ite++) {
122  tempo[ite->second] = ite->first;
123  }
124  this->tableAppColMapping[appTableClassMapping[it->first]] = tempo;
125  }
126  }
127 
128  vector<DBRel> getAppTablerelMapping(string claz)
129  {
130  if(this->appTableRelMapping.find(claz)!=this->appTableRelMapping.end())
131  return this->appTableRelMapping[claz];
132  else
133  {
134  vector<DBRel> rel;
135  return rel;
136  }
137  }
138 
139  void setAppTableRelMapping(relMap appTableRelMapping)
140  {
141  this->appTableRelMapping = appTableRelMapping;
142  }
143 
144 };
146  Logger logger;
147  map<string,CibernateConnectionPool*> cpools;
148  map<string,Mapping*> mappings;
149  static CibernateConnPools* get();
150  bool initialized;
151 public:
153  virtual ~CibernateConnPools();
154  static void addPool(int,string,string,string,string);
155  static void addMapping(string,Mapping*);
156  static bool isInitialized();
157  static CibernateConnectionPool* getPool(string);
158  static Mapping* getMapping(string);
159  static map<string,Mapping*> getMappings()
160  {
161  map<string,Mapping*> temp;
162  if(get()!=NULL)
163  return get()->mappings;
164  return temp;
165  }
166  static void destroy();
167 };
168 
169 #endif /* CIBERNATECONNPOOLS_H_ */