Permalink
Browse files

initial import

  • Loading branch information...
0 parents commit ebcdd3cf90736330c05d7876c07a0a79200a5ad8 @artemp artemp committed Jun 14, 2005
@@ -0,0 +1,18 @@
+#postgis datasource plugin
+
+project
+ : usage-requirements
+ <include>/opt/postgresql8/include
+ ;
+lib pq
+ :
+ : <file>/opt/postgresql8/lib/libpq.so
+ ;
+
+lib postgis
+ :
+ postgis.cc
+ postgisfs.cc
+ pq
+ ;
+
@@ -0,0 +1,24 @@
+#mapnik
+
+Import ('env')
+
+prefix = env['PREFIX']
+boost_root = env['BOOST_ROOT']
+postgresql_root = env['POSTGRESQL_ROOT']
+agg_root = env['AGG_ROOT']
+agg_headers = agg_root + '/include'
+
+postgresql_headers=postgresql_root+"/include"
+postgresql_libs=postgresql_root+"/lib"
+
+postgis_src = Split(
+ """
+ postgis.cpp
+ postgisfs.cpp
+ """
+ )
+
+headers = ['#include',boost_root,agg_headers,postgresql_headers]
+postgis_datasource = env.SharedLibrary('postgis',source=postgis_src,SHLIBPREFIX='',CPPPATH=headers,LIBS="pq",LIBPATH=postgresql_libs)
+env.Install(prefix + '/datasources',postgis_datasource)
+env.Alias("install",prefix + '/datasources')
@@ -0,0 +1,85 @@
+/* This file is part of Mapnik (c++ mapping toolkit)
+ * Copyright (C) 2005 Artem Pavlenko
+ *
+ * Mapnik is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+//$Id: connection.hpp 17 2005-03-08 23:58:43Z pavlenko $
+
+#ifndef CONNECTION_HPP
+#define CONNECTION_HPP
+
+
+#include "libpq-fe.h"
+#include "mapnik.hpp"
+#include "resultset.hpp"
+
+using namespace mapnik;
+
+class ResultSet;
+
+class Connection
+{
+private:
+ PGconn *conn_;
+public:
+ Connection(const std::string& uri,const std::string& dbname,
+ const std::string& username,const std::string& password)
+ {
+ std::string connStr="host="+uri+" dbname="+dbname+" user="+username+" password="+password;
+ conn_=PQconnectdb(connStr.c_str());
+ if (PQstatus(conn_) == CONNECTION_BAD)
+ {
+ std::cerr << "connection to "<< connStr << " failed\n"
+ << PQerrorMessage(conn_)<< std::endl;
+ }
+ else
+ {
+ std::cout <<"connected ok "<<std::endl;
+ }
+ }
+ bool execute(const std::string& sql) const
+ {
+ PGresult *result=PQexec(conn_,sql.c_str());
+ bool ok=(result && PQresultStatus(result)==PGRES_COMMAND_OK);
+ PQclear(result);
+ return ok;
+ }
+ ref_ptr<ResultSet> executeQuery(const std::string& sql,int type=0) const
+ {
+ PGresult *result=0;
+ if (type==1)
+ {
+ result=PQexecParams(conn_,sql.c_str(),0,0,0,0,0,1);
+ return ref_ptr<ResultSet>(new ResultSet(result));
+ }
+ result=PQexec(conn_,sql.c_str());
+ return ref_ptr<ResultSet>(new ResultSet(result));
+ }
+ bool isOK() const
+ {
+ return (PQstatus(conn_)!=CONNECTION_BAD);
+ }
+ void close()
+ {
+ PQfinish(conn_);
+ }
+ ~Connection()
+ {
+ PQfinish(conn_);
+ }
+};
+
+#endif //CONNECTION_HPP
@@ -0,0 +1,111 @@
+/* This file is part of Mapnik (c++ mapping toolkit)
+ * Copyright (C) 2005 Artem Pavlenko
+ *
+ * Mapnik is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+//$Id: connection_manager.hpp 17 2005-03-08 23:58:43Z pavlenko $
+
+#ifndef CONNECTION_MANAGER_HPP
+#define CONNECTION_MANAGER_HPP
+
+#include <string>
+#include "pool.hpp"
+#include "utils.hpp"
+#include "connection.hpp"
+
+using namespace mapnik;
+using std::string;
+
+template <typename T>
+class ConnectionCreator
+{
+ string url_;
+ string dbname_;
+ string user_;
+ string pass_;
+public:
+ ConnectionCreator(const string& url,const string& dbname,
+ const string& user,const string& pass)
+ : url_(url),
+ dbname_(dbname),
+ user_(user),
+ pass_(pass) {}
+
+ T* operator()() const
+ {
+ return new T(url_,dbname_,user_,pass_);
+ }
+ std::string id() const
+ {
+ return url_+":"+dbname_+":"+user_+":"+pass_;
+ }
+};
+
+class ConnectionManager : public singleton <ConnectionManager,CreateStatic>
+{
+
+ friend class CreateStatic<ConnectionManager>;
+ typedef Pool<Connection,ConnectionCreator> PoolType;
+ typedef std::map<std::string,ref_ptr<PoolType> > ContType;
+ typedef ref_ptr<Connection> HolderType;
+ ContType pools_;
+
+public:
+
+ bool registerPool(const ConnectionCreator<Connection>& creator,int initialSize,int maxSize)
+ {
+ Lock lock(&mutex_);
+ if (pools_.find(creator.id())==pools_.end())
+ {
+ return pools_.insert(std::make_pair(creator.id(),
+ ref_ptr<PoolType>(new PoolType(creator,initialSize,maxSize)))).second;
+ }
+
+ return false;
+
+ }
+ const ref_ptr<PoolType>& getPool(const std::string& key)
+ {
+ Lock lock(&mutex_);
+ ContType::const_iterator itr=pools_.find(key);
+ if (itr!=pools_.end())
+ {
+ return itr->second;
+ }
+ static const ref_ptr<PoolType> emptyPool(0);
+ return emptyPool;
+ }
+
+ const HolderType& get(const std::string& key)
+ {
+ Lock lock(&mutex_);
+ ContType::const_iterator itr=pools_.find(key);
+ if (itr!=pools_.end())
+ {
+ ref_ptr<PoolType> pool=itr->second;
+ return pool->borrowObject();
+ }
+ static const HolderType EmptyConn(0);
+ return EmptyConn;
+ }
+
+private:
+ ConnectionManager() {}
+ ConnectionManager(const ConnectionManager&);
+ ConnectionManager& operator=(const ConnectionManager);
+};
+
+#endif //CONNECTION_MANAGER_HPP
Oops, something went wrong.

0 comments on commit ebcdd3c

Please sign in to comment.