ResourcePool includes currently implementations to access mysql and oracle databases.
To get the idea, please have a look at the fully functional 24 line example: selectrow.cc
Most of the fun stuff is done, it's up to do the nasty stuff. This includes documentation, portability and adding some more features and database drivers.
This software does heavily use C++ features, especially templates. I believe it should compile with gcc 3.3 up-wards. I got it working with icc 9 and 10 as well. It is for sure working with gcc 3.4.3.
You should also make sure to have recent versions of autoconf, automake, libtool and flex++.
And of course you need the headers and libraries of the database you want to use.
As this is a 'proof of concept' project, there has not been much time invested to the installation procedures. However it's using the standard GNU utilities like autoconf and automake, this should make life easier.
Have a look at the INSTALL file for details.
After compiling the library (see INSTALL) you should try to get the selectrow.cc example running. I think thats the most important thing in the first place. When you got that one running, you can expect the fun to start ;)
I guess you should play a little bit around to get the feeling. You will notice that it is handy to make a typedef like this:
typedef fatalmind::ResourcePool<fatalmind::ResourceType::SQL> RP;
typedef fatalmind::ResourcePool<fatalmind::ResourceType::mysql> RP; typedef fatalmind::ResourcePool<fatalmind::ResourceType::oracle> RP;
Try to do something with the commonly available commands:
There are some more commands, but they are a little bit more complicated to use, so skip them for now. Just try to have fun with SQLExecute and SQLSelectRow.
After this there must but a little bit theory, most importantly to understand how the abstraction layer works.
If you are done with playing around, read the documentation. I hope this order makes sense:
The other useful commands are
Of course you should also have a look at those classes:
The ResourcePool package supports logging to stderr per default. Programatically logging can be changed completley, however per default logging can be enabled via the environment variable FATALMIND_DEFAULT_LOGEVENTS. The variable can be set to any number of event names to be logged, seperated by the pipe (|) character (think of bitwise or). Setting FATALMIND_DEFAULT_LOGEVENTS to ALL will cause all possible events to be logged and will result in output like this:
1226246794;PREPARE;;NOT CACHED;oracle::SQLSelectRow[SELECT userenv('SESSIONID') FROM DUAL|Bind[]] 1226246794;EXECUTE;;;oracle::SQLSelectRow[SELECT userenv('SESSIONID') FROM DUAL|Bind[]] 1226246794;FETCH;; 1226246794;PREPARE;;NOT CACHED;oracle::SQLSelectRow[SELECT SID, SERIAL# FROM V$SESSION where AUDSID = userenv('SESSIONID')|Bind[]] 1226246794;EXECUTE;;ORA-00942;oracle::SQLSelectRow[SELECT SID, SERIAL# FROM V$SESSION where AUDSID = userenv('SESSIONID')|Bind[]] 1226246794;INCREMENT_POOL;836276;0
Where the columns have the following meaning:
This package supports multi threading environments with POSIX threads.
On default, ResourcePool will use the SingleThreadedModel which means that the classes of this package do not take any protective actions for concurrent access from multiple threads. At configure time you can specify to compile with the MultiThreadedModel which will add code to protect against un-coordinated access of internal data structures from multiple threads.
This is the only choice (configure time selection) which is currently supported.
However, in principle the ResourcePool framework uses class level selection with Policy classes. This means that the user (programmer) can declare every class to be thread safe or not. The same class can be used with and without thread safety within the same program.
This is not yet 'supported' as it requires a little bit more effort to instantiate all required classes. The mechanisms and documentation to accomplish this is currently not available, therefore it is recommended to use the simple configure-time approach.
Have a look at the INSTALL file for details.
ResourcePool has originally been developed in perl with the gain to have something like Apache::DBI for other resources like Net::LDAP. This perl module is out now for a while and is working fine (at least for me). After a while I had the idea to implement the Command design pattern to make it easier to use. While implementing this I figured out that such a command interface could be used to implement an abstraction layer. Of course this didn't make sense for perl, since the DBI library is already an abstraction layer. Of course there are also abstraction layers for C/C++, but non of them does it the way I would like it ;) So I took the challenge to proof that this concept can be used to build and fully functionally, very easy to use database abstraction layer which provides advanced possibilities for optimizations.
And here we are, all of the included tests work with mysql and with oracle. I took mysql and oracle since i believe their interfaces are different enough to make it obvious that every SQL database can be accessed with this technique.