Click here to Skip to main content
11,720,785 members (83,701 online)
Click here to Skip to main content
Articles » Database » Database » General » Downloads
Add your own
alternative version

PostgreSQL/libpqxx Class Generator

, 18 Aug 2006 54K 1.3K 35
Automated generation of PostgreSQL data transfer classes.
 DataManager.h - Singleton class that manages connection to the database.
                 This file also include the declaration of the dmwork class,
				 which is a custom transaction object, designed to work with
				 the data manager's connection pooling.

 begin     : August 2006
 copyright : (C) 2006 by Phil Cairns
 email     :
 $Id: DataManager.h 2080 2006-08-18 01:53:19Z phil $

 This code may be used in compiled form in any way you desire (including
 commercial use). The code may be redistributed unmodified by any means
 providing it is not sold for profit without the authors written consent,
 and providing that this notice and the authors name and all copyright
 notices remains intact.

 This software is provided "as is" without express or implied warranty. Use
 it at your own risk!

#pragma once

#include "Singleton.h"
#include "SyncColl.h"

class dmwork;

class DataManager
	friend class Pagaros::Singleton<DataManager>;
	friend class dmwork;


	Pagaros::SyncList<pqxx::connection*> _dbConnPool;
	static Pagaros::SyncObject _trxSync;
	std::string _connStr;

	pqxx::connection* checkOutDbConn();
	void checkInDbConn(pqxx::connection* pConn);
	bool processSQLFile(dmwork& trx, const std::string& fName);
	void strToVersion(const std::string& s, __int64& i64v);
	void versionToStr(__int64 i64v, std::string& s);

	pqxx::connection* dbConn() { return checkOutDbConn(); }
	std::string connStr() { return _connStr; }
	void cleanUp();
typedef Pagaros::Singleton<DataManager> DataManagerS;

// Transaction that ensures serialised access to the connection
class dmwork : public pqxx::basic_transaction
	friend class DataManager;
	bool _monitoring;
	pqxx::connection* _myConn;
	typedef pqxx::isolation_traits<pqxx::read_committed> isolation_tag;
	explicit dmwork(pqxx::connection* C, const std::string &TName, bool monitoring=true)	//[t1]
		: basic_transaction(*_myConn, isolation_tag::name(), TName)
		, _myConn(C)
		, _monitoring(monitoring)
	explicit dmwork(pqxx::connection* C, const char* TName, bool monitoring=true)	//[t1]
		: basic_transaction(*C, isolation_tag::name(), std::string(TName))
		, _myConn(C)
		, _monitoring(monitoring)
	explicit dmwork(pqxx::connection* C, bool monitoring=true)				//[t1]
		: basic_transaction(*C, isolation_tag::name(), std::string())
		, _myConn(C)
		, _monitoring(monitoring)
	virtual ~dmwork() throw ()
		pqxx::internal::disable_noticer Quiet(conn());
		if (_monitoring)
	virtual const char *classname() const throw () { return "dm_transaction"; }

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Australia Australia
No Biography provided

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150901.1 | Last Updated 18 Aug 2006
Article Copyright 2005 by _oti
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid