added module db
This commit is contained in:
parent
64801e12e8
commit
b53bd7753c
|
@ -0,0 +1,87 @@
|
|||
#!/bin/sh
|
||||
#-------------------------------------------------------------------------------
|
||||
# Copyright (c) 2004 Media Development Loan Fund
|
||||
#
|
||||
# This file is part of the LiveSupport project.
|
||||
# http://livesupport.campware.org/
|
||||
# To report bugs, send an e-mail to bugs@campware.org
|
||||
#
|
||||
# LiveSupport 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
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# LiveSupport 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 LiveSupport; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
#
|
||||
# Author : $Author: maroy $
|
||||
# Version : $Revision: 1.1 $
|
||||
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/bin/autogen.sh,v $
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Run this to set up the build system: configure, makefiles, etc.
|
||||
# (based on the version in enlightenment's cvs)
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
package="Db"
|
||||
|
||||
# assume we're in $basedir/bin
|
||||
basedir=`dirname $0`/..
|
||||
test -z "$basedir" && basedir=.
|
||||
|
||||
tmpdir=$basedir/tmp
|
||||
|
||||
cd "$tmpdir"
|
||||
DIE=0
|
||||
|
||||
# look at all other directories as seen from ${basedir}/tmp
|
||||
tmpdir=.
|
||||
bindir=../bin
|
||||
etcdir=../etc
|
||||
|
||||
(autoheader --version) < /dev/null > /dev/null 2>&1 || {
|
||||
echo
|
||||
echo "You must have autoconf installed to compile $package."
|
||||
echo "Download the appropriate package for your distribution,"
|
||||
echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
|
||||
DIE=1
|
||||
}
|
||||
|
||||
(autoconf --version) < /dev/null > /dev/null 2>&1 || {
|
||||
echo
|
||||
echo "You must have autoconf installed to compile $package."
|
||||
echo "Download the appropriate package for your distribution,"
|
||||
echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
|
||||
DIE=1
|
||||
}
|
||||
|
||||
if test "$DIE" -eq 1; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if test -z "$*"; then
|
||||
echo "I am going to run ./configure with no arguments - if you wish "
|
||||
echo "to pass any to it, please specify them on the $0 command line."
|
||||
fi
|
||||
|
||||
echo "Generating configuration files for $package, please wait...."
|
||||
|
||||
configure_ac=${etcdir}/configure.ac
|
||||
configure=${tmpdir}/configure
|
||||
|
||||
#echo " aclocal $ACLOCAL_FLAGS"
|
||||
#aclocal $ACLOCAL_FLAGS
|
||||
echo " autoheader ${configure_ac}"
|
||||
autoheader ${configure_ac}
|
||||
echo " autoconf -o ${configure} ${configure_ac}"
|
||||
autoconf -o ${configure} ${configure_ac}
|
||||
|
||||
${configure} "$@" && echo
|
|
@ -0,0 +1 @@
|
|||
keep me
|
|
@ -0,0 +1,151 @@
|
|||
#-------------------------------------------------------------------------------
|
||||
# Copyright (c) 2004 Media Development Loan Fund
|
||||
#
|
||||
# This file is part of the LiveSupport project.
|
||||
# http://livesupport.campware.org/
|
||||
# To report bugs, send an e-mail to bugs@campware.org
|
||||
#
|
||||
# LiveSupport 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
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# LiveSupport 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 LiveSupport; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
#
|
||||
# Author : $Author: maroy $
|
||||
# Version : $Revision: 1.1 $
|
||||
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/etc/Makefile.in,v $
|
||||
#
|
||||
# @configure_input@
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# General command definitions
|
||||
#-------------------------------------------------------------------------------
|
||||
MKDIR = mkdir -p
|
||||
RM = rm -f
|
||||
RMDIR = rm -rf
|
||||
DOXYGEN = doxygen
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Basic directory and file definitions
|
||||
#-------------------------------------------------------------------------------
|
||||
BASE_DIR = @builddir@
|
||||
DOC_DIR = ${BASE_DIR}/doc
|
||||
DOXYGEN_DIR = ${DOC_DIR}/doxygen
|
||||
ETC_DIR = ${BASE_DIR}/etc
|
||||
INCLUDE_DIR = ${BASE_DIR}/include
|
||||
LIB_DIR = ${BASE_DIR}/lib
|
||||
SRC_DIR = ${BASE_DIR}/src
|
||||
TMP_DIR = ${BASE_DIR}/tmp
|
||||
|
||||
USR_DIR = ${BASE_DIR}/../../usr
|
||||
USR_INCLUDE_DIR = ${USR_DIR}/include
|
||||
USR_LIB_DIR = ${USR_DIR}/lib
|
||||
BOOST_INCLUDE_DIR = ${USR_INCLUDE_DIR}/boost-1_31
|
||||
LIBXMLPP_INCLUDE_DIR = ${USR_INCLUDE_DIR}/libxml++-1.0
|
||||
|
||||
MODULES_DIR = ${BASE_DIR}/..
|
||||
|
||||
CORE_DIR = ${MODULES_DIR}/core
|
||||
CORE_INCLUDE_DIR = ${CORE_DIR}/include
|
||||
CORE_LIB_DIR = ${CORE_DIR}/lib
|
||||
CORE_LIB = livesupport_core
|
||||
CORE_LIB_FILE = ${CORE_LIB_DIR}/lib${CORE_LIB}.a
|
||||
|
||||
VPATH = ${SRC_DIR}
|
||||
|
||||
DB_LIB = livesupport_db
|
||||
DB_LIB_FILE = ${LIB_DIR}/lib${DB_LIB}.a
|
||||
TEST_RUNNER = ${TMP_DIR}/testRunner
|
||||
|
||||
DOXYGEN_CONFIG = ${ETC_DIR}/doxygen.config
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Configuration parameters
|
||||
#-------------------------------------------------------------------------------
|
||||
CPPFLAGS = @CPPFLAGS@
|
||||
CXXFLAGS = @CXXFLAGS@ @DEFS@ -I${USR_INCLUDE_DIR} \
|
||||
-I${BOOST_INCLUDE_DIR} \
|
||||
-I${LIBXMLPP_INCLUDE_DIR} \
|
||||
-I${CORE_INCLUDE_DIR} \
|
||||
-I${INCLUDE_DIR} -I${TMP_DIR} \
|
||||
-pedantic -Wall -Wno-long-long
|
||||
LDFLAGS = @LDFLAGS@ -L${USR_LIB_DIR} -L${CORE_LIB_DIR} -L${LIB_DIR}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Dependencies
|
||||
#-------------------------------------------------------------------------------
|
||||
DB_LIB_OBJS = ${TMP_DIR}/SimpleConnectionManager.o \
|
||||
${TMP_DIR}/ConnectionManagerFactory.o \
|
||||
${TMP_DIR}/Conversion.o
|
||||
TEST_RUNNER_OBJS = ${TMP_DIR}/SimpleConnectionManagerTest.o \
|
||||
${TMP_DIR}/ConnectionManagerFactoryTest.o \
|
||||
${TMP_DIR}/TestRunner.o
|
||||
TEST_RUNNER_LIBS = -l${DB_LIB} -l${CORE_LIB} -lodbc++ -lxml++-1.0 -lcppunit -ldl
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Targets
|
||||
#-------------------------------------------------------------------------------
|
||||
.PHONY: all dir_setup doc clean docclean depclean distclean
|
||||
|
||||
all: dir_setup ${DB_LIB_FILE}
|
||||
|
||||
dir_setup: ${TMP_DIR} ${DOXYGEN_DIR}
|
||||
|
||||
doc:
|
||||
${DOXYGEN} ${DOXYGEN_CONFIG}
|
||||
|
||||
clean:
|
||||
${RM} ${DB_LIB_OBJS} ${DB_LIB_FILE}
|
||||
${RM} ${TEST_RUNNER_OBJS} ${TEST_RUNNER}
|
||||
|
||||
docclean:
|
||||
${RMDIR} ${DOXYGEN_DIR}/html
|
||||
|
||||
depclean: clean
|
||||
|
||||
distclean: clean docclean
|
||||
${RMDIR} ${TMP_DIR}/config* ${TMP_DIR}/autom4te*
|
||||
|
||||
check: all ${TEST_RUNNER}
|
||||
LD_LIBRARY_PATH=${USR_LIB_DIR} ${TEST_RUNNER}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Specific targets
|
||||
#-------------------------------------------------------------------------------
|
||||
${DB_LIB_FILE}: ${DB_LIB_OBJS}
|
||||
${AR} crus $@ $^
|
||||
|
||||
${TMP_DIR}:
|
||||
${MKDIR} ${TMP_DIR}
|
||||
|
||||
${DOXYGEN_DIR}:
|
||||
${MKDIR} ${DOXYGEN_DIR}
|
||||
|
||||
${TEST_RUNNER}: ${CORE_LIB_FILE} ${TEST_RUNNER_OBJS} ${DB_LIB_FILE}
|
||||
${CXX} ${LDFLAGS} -o $@ ${TEST_RUNNER_OBJS} ${TEST_RUNNER_LIBS}
|
||||
|
||||
${CORE_LIB_FILE}:
|
||||
${MAKE} -C ${CORE_DIR}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Pattern rules
|
||||
#-------------------------------------------------------------------------------
|
||||
${TMP_DIR}/%.o : ${SRC_DIR}/%.cxx
|
||||
${CXX} ${CPPFLAGS} ${CXXFLAGS} -c -o $@ $<
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
dnl-----------------------------------------------------------------------------
|
||||
dnl Copyright (c) 2004 Media Development Loan Fund
|
||||
dnl
|
||||
dnl This file is part of the LiveSupport project.
|
||||
dnl http://livesupport.campware.org/
|
||||
dnl To report bugs, send an e-mail to bugs@campware.org
|
||||
dnl
|
||||
dnl LiveSupport is free software; you can redistribute it and/or modify
|
||||
dnl it under the terms of the GNU General Public License as published by
|
||||
dnl the Free Software Foundation; either version 2 of the License, or
|
||||
dnl (at your option) any later version.
|
||||
dnl
|
||||
dnl LiveSupport is distributed in the hope that it will be useful,
|
||||
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
dnl GNU General Public License for more details.
|
||||
dnl
|
||||
dnl You should have received a copy of the GNU General Public License
|
||||
dnl along with LiveSupport; if not, write to the Free Software
|
||||
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
dnl
|
||||
dnl
|
||||
dnl Author : $Author: maroy $
|
||||
dnl Version : $Revision: 1.1 $
|
||||
dnl Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/etc/configure.ac,v $
|
||||
dnl-----------------------------------------------------------------------------
|
||||
|
||||
dnl-----------------------------------------------------------------------------
|
||||
dnl NOTE: Run all configure related scripts from the tmp directory of the
|
||||
dnl project.
|
||||
dnl This is due to the fact that configure spreads a lot of trash around,
|
||||
dnl like atom4te cache directories, config.* files, etc. into the directory
|
||||
dnl it is being run from. We clearly don't want these in our base directory.
|
||||
dnl-----------------------------------------------------------------------------
|
||||
AC_INIT(Db, 1.0, livesupport-dev@campware.org)
|
||||
AC_PREREQ(2.59)
|
||||
AC_COPYRIGHT([Copyright (c) 2004 Media Development Loan Fund under the GNU GPL])
|
||||
AC_REVISION($Revision: 1.1 $)
|
||||
|
||||
AC_CONFIG_SRCDIR(../include/LiveSupport/Db/ConnectionManagerInterface.h)
|
||||
|
||||
AC_CONFIG_HEADERS(configure.h)
|
||||
AC_PROG_CXX()
|
||||
|
||||
AC_CHECK_HEADERS()
|
||||
|
||||
AC_CONFIG_FILES(../Makefile:../etc/Makefile.in)
|
||||
|
||||
AC_OUTPUT()
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE connectionManagerFactory [
|
||||
|
||||
<!ELEMENT connectionManagerFactory (simpleConnectionManager) >
|
||||
|
||||
<!ELEMENT simpleConnectionManager EMPTY >
|
||||
<!ATTLIST simpleConnectionManager dsn CDATA #REQUIRED >
|
||||
<!ATTLIST simpleConnectionManager userName CDATA #REQUIRED >
|
||||
<!ATTLIST simpleConnectionManager password CDATA #REQUIRED >
|
||||
]>
|
||||
<connectionManagerFactory>
|
||||
<simpleConnectionManager dsn = "LiveSupport-test"
|
||||
userName = "test"
|
||||
password = "test"
|
||||
/>
|
||||
</connectionManagerFactory>
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!DOCTYPE simpleConnectionManager [
|
||||
|
||||
<!ELEMENT simpleConnectionManager EMPTY >
|
||||
<!ATTLIST simpleConnectionManager dsn CDATA #REQUIRED >
|
||||
<!ATTLIST simpleConnectionManager userName CDATA #REQUIRED >
|
||||
<!ATTLIST simpleConnectionManager password CDATA #REQUIRED >
|
||||
]>
|
||||
<simpleConnectionManager dsn = "LiveSupport-test"
|
||||
userName = "test"
|
||||
password = "test"
|
||||
/>
|
|
@ -0,0 +1,190 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport 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
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport 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 LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/include/LiveSupport/Db/ConnectionManagerFactory.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
#ifndef LiveSupport_Db_ConnectionManagerFactory_h
|
||||
#define LiveSupport_Db_ConnectionManagerFactory_h
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This is a C++ include file
|
||||
#endif
|
||||
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "LiveSupport/Core/Configurable.h"
|
||||
#include "LiveSupport/Db/ConnectionManagerInterface.h"
|
||||
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace Db {
|
||||
|
||||
using namespace LiveSupport;
|
||||
using namespace LiveSupport::Core;
|
||||
|
||||
/* ================================================================ constants */
|
||||
|
||||
|
||||
/* =================================================================== macros */
|
||||
|
||||
|
||||
/* =============================================================== data types */
|
||||
|
||||
/**
|
||||
* The factory to create appropriate ConnectionManager objects.
|
||||
* This singleton class has to be configured with an XML element,
|
||||
* describing the ConnectionManagerInterface that it should build
|
||||
* and maintain. This is done by including the configuration element
|
||||
* for the desired type of connection manager inside the configuration
|
||||
* element for the factory.
|
||||
*
|
||||
* Currently only the SimpleConnectionManager is supported, thus a
|
||||
* configuration file may look like this:
|
||||
*
|
||||
* <pre><code>
|
||||
* <connectionManagerFactory>
|
||||
* <simpleConnectionManager dsn = "LiveSupport"
|
||||
* userName = "foo"
|
||||
* password = "bar"
|
||||
* />
|
||||
* </connectionManagerFactory>
|
||||
* </code></pre>
|
||||
*
|
||||
* The DTD for the above XML structure is:
|
||||
*
|
||||
* <pre><code>
|
||||
* <!ELEMENT connectionManagerFactory (simpleConnectionManager) >
|
||||
* </code></pre>
|
||||
*
|
||||
* For the DTD and details of the simpleConnectionManager configuration
|
||||
* element, see the SimpleConnectionManager documentation.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.1 $
|
||||
* @see SimpleConnectionManager
|
||||
*/
|
||||
class ConnectionManagerFactory :
|
||||
virtual public Configurable
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* The name of the configuration XML elmenent used by this object.
|
||||
*/
|
||||
static const std::string configElementNameStr;
|
||||
|
||||
/**
|
||||
* The singleton instance of this object.
|
||||
*/
|
||||
static Ptr<ConnectionManagerFactory>::Ref singleton;
|
||||
|
||||
/**
|
||||
* The connection manager created by this factory.
|
||||
*/
|
||||
Ptr<ConnectionManagerInterface>::Ref connectionManager;
|
||||
|
||||
/**
|
||||
* The default constructor.
|
||||
*/
|
||||
ConnectionManagerFactory(void) throw()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* A virtual destructor, as this class has virtual functions.
|
||||
*/
|
||||
virtual
|
||||
~ConnectionManagerFactory(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the XML element this object expects
|
||||
* to be sent to a call to configure().
|
||||
*
|
||||
* @return the name of the expected XML configuration element.
|
||||
*/
|
||||
static const std::string
|
||||
configElementName(void) throw ()
|
||||
{
|
||||
return configElementNameStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the singleton instance of this object.
|
||||
*
|
||||
* @return the singleton instance of this object.
|
||||
*/
|
||||
static Ptr<ConnectionManagerFactory>::Ref
|
||||
getInstance() throw ();
|
||||
|
||||
/**
|
||||
* Configure the object based on the XML element supplied.
|
||||
*
|
||||
* @param element the XML element to configure the object from.
|
||||
* @exception std::invalid_argument if the supplied XML element
|
||||
* contains bad configuraiton information
|
||||
* @exception std::logic_error if the object has already
|
||||
* been configured, and can not be reconfigured.
|
||||
*/
|
||||
virtual void
|
||||
configure(const xmlpp::Element & element)
|
||||
throw (std::invalid_argument,
|
||||
std::logic_error);
|
||||
|
||||
/**
|
||||
* Return a connection manager.
|
||||
*
|
||||
* @return the appropriate connection manager, according to the
|
||||
* configuration of this factory.
|
||||
*/
|
||||
Ptr<ConnectionManagerInterface>::Ref
|
||||
getConnectionManager(void) throw ()
|
||||
{
|
||||
return connectionManager;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* ================================================= external data structures */
|
||||
|
||||
|
||||
/* ====================================================== function prototypes */
|
||||
|
||||
|
||||
} // namespace Db
|
||||
} // namespace LiveSupport
|
||||
|
||||
#endif // LiveSupport_Db_ConnectionManagerFactory_h
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport 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
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport 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 LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/include/LiveSupport/Db/ConnectionManagerInterface.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
#ifndef LiveSupport_Db_ConnectionManagerInterface_h
|
||||
#define LiveSupport_Db_ConnectionManagerInterface_h
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This is a C++ include file
|
||||
#endif
|
||||
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include <odbc++/connection.h>
|
||||
|
||||
|
||||
#include "LiveSupport/Core/Ptr.h"
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace Db {
|
||||
|
||||
using namespace LiveSupport::Core;
|
||||
|
||||
/* ================================================================ constants */
|
||||
|
||||
|
||||
/* =================================================================== macros */
|
||||
|
||||
|
||||
/* =============================================================== data types */
|
||||
|
||||
/**
|
||||
* The interface for handing out and managing database connections.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
class ConnectionManagerInterface
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Get a database connection from the manager.
|
||||
* After use, the connection must be returned by calling
|
||||
* returnConnection().
|
||||
*
|
||||
* @return a database connection to the database this manager
|
||||
* serves.
|
||||
* @see #returnConnection
|
||||
*/
|
||||
virtual Ptr<odbc::Connection>::Ref
|
||||
getConnection(void) throw (std::runtime_error)
|
||||
= 0;
|
||||
|
||||
/**
|
||||
* Return a database connection previously aquired by a call to
|
||||
* getConnection(), after it is not needed anymore.
|
||||
*
|
||||
* @param connection the connection to return.
|
||||
* @see #getConnection
|
||||
*/
|
||||
virtual void
|
||||
returnConnection(Ptr<odbc::Connection>::Ref connection)
|
||||
throw (std::runtime_error)
|
||||
= 0;
|
||||
};
|
||||
|
||||
|
||||
/* ================================================= external data structures */
|
||||
|
||||
|
||||
/* ====================================================== function prototypes */
|
||||
|
||||
|
||||
} // namespace Db
|
||||
} // namespace LiveSupport
|
||||
|
||||
#endif // LiveSupport_Db_ConnectionManagerInterface_h
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport 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
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport 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 LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/include/LiveSupport/Db/Conversion.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
#ifndef LiveSupport_Db_Conversion_h
|
||||
#define LiveSupport_Db_Conversion_h
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This is a C++ include file
|
||||
#endif
|
||||
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <odbc++/types.h>
|
||||
|
||||
#include "LiveSupport/Core/Ptr.h"
|
||||
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace Db {
|
||||
|
||||
using namespace boost;
|
||||
|
||||
using namespace LiveSupport;
|
||||
using namespace LiveSupport::Core;
|
||||
|
||||
|
||||
/* ================================================================ constants */
|
||||
|
||||
|
||||
/* =================================================================== macros */
|
||||
|
||||
|
||||
/* =============================================================== data types */
|
||||
|
||||
/**
|
||||
* A helper object holding static conversion functions, that are
|
||||
* helpful when accessing databases.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
class Conversion
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* The default constructor.
|
||||
*/
|
||||
Conversion(void) throw()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* Convert a boost::ptime to a odbc::Timestamp.
|
||||
*
|
||||
* @param ptime the boost ptime to convert.
|
||||
* @return an odbc::Timestamp, holding the same time.
|
||||
*/
|
||||
static Ptr<odbc::Timestamp>::Ref
|
||||
ptimeToTimestamp(Ptr<const posix_time::ptime>::Ref ptime) throw();
|
||||
};
|
||||
|
||||
|
||||
/* ================================================= external data structures */
|
||||
|
||||
|
||||
/* ====================================================== function prototypes */
|
||||
|
||||
|
||||
} // namespace Db
|
||||
} // namespace LiveSupport
|
||||
|
||||
#endif // LiveSupport_Db_Conversion_h
|
||||
|
|
@ -0,0 +1 @@
|
|||
keep me
|
|
@ -0,0 +1,111 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport 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
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport 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 LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/src/ConnectionManagerFactory.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include "LiveSupport/Db/ConnectionManagerFactory.h"
|
||||
#include "SimpleConnectionManager.h"
|
||||
|
||||
|
||||
using namespace LiveSupport::Core;
|
||||
using namespace LiveSupport::Db;
|
||||
|
||||
/* =================================================== local data structures */
|
||||
|
||||
|
||||
/* ================================================ local constants & macros */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the config element for this class
|
||||
*----------------------------------------------------------------------------*/
|
||||
const std::string ConnectionManagerFactory::configElementNameStr =
|
||||
"connectionManagerFactory";
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The singleton instance of ConnectionManagerFactory
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<ConnectionManagerFactory>::Ref ConnectionManagerFactory::singleton;
|
||||
|
||||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
|
||||
/* ============================================================= module code */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Return the singleton instance to ConnectionManagerFactory
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<ConnectionManagerFactory>::Ref
|
||||
ConnectionManagerFactory :: getInstance(void) throw ()
|
||||
{
|
||||
if (!singleton.get()) {
|
||||
singleton.reset(new ConnectionManagerFactory());
|
||||
}
|
||||
|
||||
return singleton;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Configure the connection manager factory.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ConnectionManagerFactory :: configure(const xmlpp::Element & element)
|
||||
throw (std::invalid_argument,
|
||||
std::logic_error)
|
||||
{
|
||||
if (element.get_name() != configElementNameStr) {
|
||||
std::string eMsg = "Bad configuration element ";
|
||||
eMsg += element.get_name();
|
||||
throw std::invalid_argument(eMsg);
|
||||
}
|
||||
|
||||
connectionManager.reset();
|
||||
|
||||
// try to look for a SimpleConnectionManager configuration element
|
||||
xmlpp::Node::NodeList nodes = element.get_children(
|
||||
SimpleConnectionManager::getConfigElementName());
|
||||
if (nodes.size() >= 1) {
|
||||
const xmlpp::Element * configElement =
|
||||
dynamic_cast<const xmlpp::Element*> (*(nodes.begin()));
|
||||
Ptr<SimpleConnectionManager>::Ref scm(new SimpleConnectionManager());
|
||||
scm->configure(*configElement);
|
||||
connectionManager = scm;
|
||||
}
|
||||
|
||||
if (!connectionManager) {
|
||||
throw std::invalid_argument("no storage client factories to configure");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport 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
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport 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 LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/src/ConnectionManagerFactoryTest.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#error "Need unistd.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <odbc++/resultset.h>
|
||||
|
||||
#include "LiveSupport/Db/ConnectionManagerFactory.h"
|
||||
#include "ConnectionManagerFactoryTest.h"
|
||||
|
||||
|
||||
using namespace odbc;
|
||||
using namespace LiveSupport::Db;
|
||||
|
||||
/* =================================================== local data structures */
|
||||
|
||||
|
||||
/* ================================================ local constants & macros */
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(ConnectionManagerFactoryTest);
|
||||
|
||||
/**
|
||||
* The name of the configuration file for the connection manager factory.
|
||||
*/
|
||||
static const std::string configFileName = "etc/connectionManagerFactory.xml";
|
||||
|
||||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
|
||||
/* ============================================================= module code */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Set up the test environment
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ConnectionManagerFactoryTest :: setUp(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Clean up the test environment
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ConnectionManagerFactoryTest :: tearDown(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Test to see if the singleton Hello object is accessible
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
ConnectionManagerFactoryTest :: firstTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
try {
|
||||
Ptr<xmlpp::DomParser>::Ref parser(
|
||||
new xmlpp::DomParser(configFileName, true));
|
||||
const xmlpp::Document * document = parser->get_document();
|
||||
const xmlpp::Element * root = document->get_root_node();
|
||||
Ptr<ConnectionManagerFactory>::Ref cmf =
|
||||
ConnectionManagerFactory::getInstance();
|
||||
|
||||
cmf->configure(*root);
|
||||
|
||||
Ptr<ConnectionManagerInterface>::Ref cm = cmf->getConnectionManager();
|
||||
CPPUNIT_ASSERT(cm);
|
||||
|
||||
Ptr<Connection>::Ref connection = cm->getConnection();
|
||||
CPPUNIT_ASSERT(connection);
|
||||
|
||||
// so far, so good. now simply execute "SELECT 1", and see if
|
||||
// it works
|
||||
Ptr<Statement>::Ref stmt(connection->createStatement());
|
||||
Ptr<ResultSet>::Ref rs(stmt->executeQuery("SELECT 1"));
|
||||
CPPUNIT_ASSERT(rs->next());
|
||||
CPPUNIT_ASSERT(rs->getInt(1) == 1);
|
||||
|
||||
} catch (std::invalid_argument &e) {
|
||||
CPPUNIT_FAIL("semantic error in configuration file");
|
||||
} catch (xmlpp::exception &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport 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
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport 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 LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/src/ConnectionManagerFactoryTest.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
#ifndef ConnectionManagerFactoryTest_h
|
||||
#define ConnectionManagerFactoryTest_h
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This is a C++ include file
|
||||
#endif
|
||||
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace Db {
|
||||
|
||||
/* ================================================================ constants */
|
||||
|
||||
|
||||
/* =================================================================== macros */
|
||||
|
||||
|
||||
/* =============================================================== data types */
|
||||
|
||||
/**
|
||||
* Unit test for the ConnectionManagerFactory class.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.1 $
|
||||
* @see ConnectionManagerFactory
|
||||
*/
|
||||
class ConnectionManagerFactoryTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(ConnectionManagerFactoryTest);
|
||||
CPPUNIT_TEST(firstTest);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* A simple test.
|
||||
*
|
||||
* @exception CPPUNIT_NS::Exception on test failures.
|
||||
*/
|
||||
void
|
||||
firstTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Set up the environment for the test case.
|
||||
*/
|
||||
void
|
||||
setUp(void) throw ();
|
||||
|
||||
/**
|
||||
* Clean up the environment after the test case.
|
||||
*/
|
||||
void
|
||||
tearDown(void) throw ();
|
||||
};
|
||||
|
||||
|
||||
/* ================================================= external data structures */
|
||||
|
||||
|
||||
/* ====================================================== function prototypes */
|
||||
|
||||
|
||||
} // namespace Db
|
||||
} // namespace LiveSupport
|
||||
|
||||
#endif // ConnectionManagerFactoryTest_h
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport 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
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport 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 LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/src/Conversion.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include "LiveSupport/Db/Conversion.h"
|
||||
|
||||
|
||||
using namespace boost;
|
||||
|
||||
using namespace LiveSupport::Core;
|
||||
using namespace LiveSupport::Db;
|
||||
|
||||
/* =================================================== local data structures */
|
||||
|
||||
|
||||
/* ================================================ local constants & macros */
|
||||
|
||||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
|
||||
/* ============================================================= module code */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Convert a boost::ptime to an odbc::Timestamp
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<odbc::Timestamp>::Ref
|
||||
Conversion :: ptimeToTimestamp(Ptr<const posix_time::ptime>::Ref ptime)
|
||||
throw ()
|
||||
{
|
||||
gregorian::date date = ptime->date();
|
||||
posix_time::time_duration hours = ptime->time_of_day();
|
||||
|
||||
Ptr<odbc::Timestamp>::Ref timestamp(new odbc::Timestamp(date.year(),
|
||||
date.month(),
|
||||
date.day(),
|
||||
hours.hours(),
|
||||
hours.minutes(),
|
||||
hours.seconds()));
|
||||
return timestamp;
|
||||
}
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport 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
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport 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 LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/src/SimpleConnectionManager.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include <odbc++/drivermanager.h>
|
||||
|
||||
#include "SimpleConnectionManager.h"
|
||||
|
||||
|
||||
using namespace LiveSupport::Core;
|
||||
using namespace LiveSupport::Db;
|
||||
|
||||
/* =================================================== local data structures */
|
||||
|
||||
|
||||
/* ================================================ local constants & macros */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* The name of the config element for this class
|
||||
*----------------------------------------------------------------------------*/
|
||||
const std::string SimpleConnectionManager::configElementNameStr =
|
||||
"simpleConnectionManager";
|
||||
|
||||
/**
|
||||
* The name of the attribute to get the dsn for the connection.
|
||||
*/
|
||||
static const std::string dsnAttrName = "dsn";
|
||||
|
||||
/**
|
||||
* The name of the attribute to get the userName for the connection.
|
||||
*/
|
||||
static const std::string userNameAttrName = "userName";
|
||||
|
||||
/**
|
||||
* The name of the attribute to get the password for the connection.
|
||||
*/
|
||||
static const std::string passwordAttrName = "password";
|
||||
|
||||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
|
||||
/* ============================================================= module code */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Configure the connection manager factory.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SimpleConnectionManager :: configure(const xmlpp::Element & element)
|
||||
throw (std::invalid_argument,
|
||||
std::logic_error)
|
||||
{
|
||||
if (element.get_name() != configElementNameStr) {
|
||||
std::string eMsg = "Bad configuration element ";
|
||||
eMsg += element.get_name();
|
||||
throw std::invalid_argument(eMsg);
|
||||
}
|
||||
|
||||
const xmlpp::Attribute * attribute;
|
||||
|
||||
if (!(attribute = element.get_attribute(dsnAttrName))) {
|
||||
std::string eMsg = "Missing attribute ";
|
||||
eMsg += dsnAttrName;
|
||||
throw std::invalid_argument(eMsg);
|
||||
}
|
||||
dsn = attribute->get_value();
|
||||
|
||||
if (!(attribute = element.get_attribute(userNameAttrName))) {
|
||||
std::string eMsg = "Missing attribute ";
|
||||
eMsg += userNameAttrName;
|
||||
throw std::invalid_argument(eMsg);
|
||||
}
|
||||
userName = attribute->get_value();
|
||||
|
||||
if (!(attribute = element.get_attribute(passwordAttrName))) {
|
||||
std::string eMsg = "Missing attribute ";
|
||||
eMsg += passwordAttrName;
|
||||
throw std::invalid_argument(eMsg);
|
||||
}
|
||||
password = attribute->get_value();
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Give out a connection.
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<odbc::Connection>::Ref
|
||||
SimpleConnectionManager :: getConnection(void)
|
||||
throw (std::runtime_error)
|
||||
{
|
||||
odbc::Connection * conn = odbc::DriverManager::getConnection(dsn,
|
||||
userName,
|
||||
password);
|
||||
if (!conn) {
|
||||
std::string eMsg = "unable to option ODBC connection for DSN ";
|
||||
eMsg += dsn;
|
||||
throw std::runtime_error(eMsg);
|
||||
}
|
||||
|
||||
Ptr<odbc::Connection>::Ref connection(conn);
|
||||
return connection;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Receive a connection back.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SimpleConnectionManager :: returnConnection(
|
||||
Ptr<odbc::Connection>::Ref connection)
|
||||
throw (std::runtime_error)
|
||||
{
|
||||
// nothing to do here...
|
||||
// we could save the outgoing connections to a set in getConnection()
|
||||
// and check here to see if the returned one is contained there
|
||||
}
|
||||
|
|
@ -0,0 +1,193 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport 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
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport 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 LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/src/SimpleConnectionManager.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
#ifndef SimpleConnectionManager_h
|
||||
#define SimpleConnectionManager_h
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This is a C++ include file
|
||||
#endif
|
||||
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include <LiveSupport/Core/Configurable.h>
|
||||
#include <LiveSupport/Db/ConnectionManagerInterface.h>
|
||||
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace Db {
|
||||
|
||||
using namespace LiveSupport;
|
||||
using namespace LiveSupport::Core;
|
||||
|
||||
/* ================================================================ constants */
|
||||
|
||||
|
||||
/* =================================================================== macros */
|
||||
|
||||
|
||||
/* =============================================================== data types */
|
||||
|
||||
/**
|
||||
* A simple connection manager, basically a facade to the underlying
|
||||
* odbc::DriverManager class.
|
||||
* This class can be configured with the following XML element, containing
|
||||
* the ODBC Data Source Name (DSN), ODBC user name and ODBC password
|
||||
* the manager will connect with to the ODBC source. The XML element looks
|
||||
* as follows:
|
||||
*
|
||||
* <pre><code>
|
||||
* <simpleConnectionManager dsn = "LiveSupport"
|
||||
* userName = "foo"
|
||||
* password = "bar"
|
||||
* />
|
||||
* </code></pre>
|
||||
*
|
||||
* The DTD for the above XML structure is:
|
||||
*
|
||||
* <pre><code>
|
||||
* <!ELEMENT simpleConnectionManager EMPTY >
|
||||
* <!ATTLIST simpleConnectionManager dsn CDATA #REQUIRED >
|
||||
* <!ATTLIST simpleConnectionManager userName CDATA #REQUIRED >
|
||||
* <!ATTLIST simpleConnectionManager password CDATA #REQUIRED >
|
||||
* </code></pre>
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.1 $
|
||||
*/
|
||||
class SimpleConnectionManager :
|
||||
virtual public Configurable,
|
||||
virtual public ConnectionManagerInterface
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* The name of the configuration XML elmenent used by this object.
|
||||
*/
|
||||
static const std::string configElementNameStr;
|
||||
|
||||
/**
|
||||
* The ODBC Data Source Name this manager connects to.
|
||||
*/
|
||||
std::string dsn;
|
||||
|
||||
/**
|
||||
* The user name to use when connecting to the ODBC DSN.
|
||||
*/
|
||||
std::string userName;
|
||||
|
||||
/**
|
||||
* The password to use when connecting to the ODBC DSN.
|
||||
*/
|
||||
std::string password;
|
||||
|
||||
|
||||
public:
|
||||
/**
|
||||
* The default constructor.
|
||||
*/
|
||||
SimpleConnectionManager(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* A virtual destructor, as this class has virtual functions.
|
||||
*/
|
||||
virtual
|
||||
~SimpleConnectionManager(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the XML element this object expects
|
||||
* to be sent to a call to configure().
|
||||
*
|
||||
* @return the name of the expected XML configuration element.
|
||||
*/
|
||||
static const std::string
|
||||
getConfigElementName(void) throw ()
|
||||
{
|
||||
return configElementNameStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the object based on the XML element supplied.
|
||||
*
|
||||
* @param element the XML element to configure the object from.
|
||||
* @exception std::invalid_argument if the supplied XML element
|
||||
* contains bad configuraiton information
|
||||
* @exception std::logic_error if the object has already
|
||||
* been configured, and can not be reconfigured.
|
||||
*/
|
||||
virtual void
|
||||
configure(const xmlpp::Element & element)
|
||||
throw (std::invalid_argument,
|
||||
std::logic_error);
|
||||
|
||||
/**
|
||||
* Get a database connection from the manager.
|
||||
* After use, the connection must be returned by calling
|
||||
* returnConnection().
|
||||
*
|
||||
* @return a database connection to the database this manager
|
||||
* serves.
|
||||
* @see #returnConnection
|
||||
*/
|
||||
virtual Ptr<odbc::Connection>::Ref
|
||||
getConnection(void) throw (std::runtime_error);
|
||||
|
||||
/**
|
||||
* Return a database connection previously aquired by a call to
|
||||
* getConnection(), after it is not needed anymore.
|
||||
*
|
||||
* @param connection the connection to return.
|
||||
* @see #getConnection
|
||||
*/
|
||||
virtual void
|
||||
returnConnection(Ptr<odbc::Connection>::Ref connection)
|
||||
throw (std::runtime_error);
|
||||
};
|
||||
|
||||
|
||||
/* ================================================= external data structures */
|
||||
|
||||
|
||||
/* ====================================================== function prototypes */
|
||||
|
||||
|
||||
} // namespace Db
|
||||
} // namespace LiveSupport
|
||||
|
||||
#endif // SimpleConnectionManager_h
|
||||
|
|
@ -0,0 +1,122 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport 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
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport 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 LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/src/SimpleConnectionManagerTest.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#if HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#error "Need unistd.h"
|
||||
#endif
|
||||
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <odbc++/resultset.h>
|
||||
|
||||
#include "SimpleConnectionManager.h"
|
||||
#include "SimpleConnectionManagerTest.h"
|
||||
|
||||
|
||||
using namespace odbc;
|
||||
using namespace LiveSupport::Db;
|
||||
|
||||
/* =================================================== local data structures */
|
||||
|
||||
|
||||
/* ================================================ local constants & macros */
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(SimpleConnectionManagerTest);
|
||||
|
||||
/**
|
||||
* The name of the configuration file for the connection manager.
|
||||
*/
|
||||
static const std::string configFileName = "etc/simpleConnectionManager.xml";
|
||||
|
||||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
|
||||
/* ============================================================= module code */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Set up the test environment
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SimpleConnectionManagerTest :: setUp(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Clean up the test environment
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SimpleConnectionManagerTest :: tearDown(void) throw ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Test to see if the singleton Hello object is accessible
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SimpleConnectionManagerTest :: firstTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
try {
|
||||
Ptr<xmlpp::DomParser>::Ref parser(
|
||||
new xmlpp::DomParser(configFileName, true));
|
||||
const xmlpp::Document * document = parser->get_document();
|
||||
const xmlpp::Element * root = document->get_root_node();
|
||||
Ptr<SimpleConnectionManager>::Ref scm(new SimpleConnectionManager());
|
||||
|
||||
scm->configure(*root);
|
||||
|
||||
Ptr<Connection>::Ref connection = scm->getConnection();
|
||||
CPPUNIT_ASSERT(connection);
|
||||
|
||||
// so far, so good. now simply execute "SELECT 1", and see if
|
||||
// it works
|
||||
Ptr<Statement>::Ref stmt(connection->createStatement());
|
||||
Ptr<ResultSet>::Ref rs(stmt->executeQuery("SELECT 1"));
|
||||
CPPUNIT_ASSERT(rs->next());
|
||||
CPPUNIT_ASSERT(rs->getInt(1) == 1);
|
||||
|
||||
} catch (std::invalid_argument &e) {
|
||||
CPPUNIT_FAIL("semantic error in configuration file");
|
||||
} catch (xmlpp::exception &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport 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
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport 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 LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/src/SimpleConnectionManagerTest.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
#ifndef SimpleConnectionManagerTest_h
|
||||
#define SimpleConnectionManagerTest_h
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This is a C++ include file
|
||||
#endif
|
||||
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace Db {
|
||||
|
||||
/* ================================================================ constants */
|
||||
|
||||
|
||||
/* =================================================================== macros */
|
||||
|
||||
|
||||
/* =============================================================== data types */
|
||||
|
||||
/**
|
||||
* Unit test for the SimpleConnectionManager class.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.1 $
|
||||
* @see SimpleConnectionManager
|
||||
*/
|
||||
class SimpleConnectionManagerTest : public CPPUNIT_NS::TestFixture
|
||||
{
|
||||
CPPUNIT_TEST_SUITE(SimpleConnectionManagerTest);
|
||||
CPPUNIT_TEST(firstTest);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* A simple test.
|
||||
*
|
||||
* @exception CPPUNIT_NS::Exception on test failures.
|
||||
*/
|
||||
void
|
||||
firstTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Set up the environment for the test case.
|
||||
*/
|
||||
void
|
||||
setUp(void) throw ();
|
||||
|
||||
/**
|
||||
* Clean up the environment after the test case.
|
||||
*/
|
||||
void
|
||||
tearDown(void) throw ();
|
||||
};
|
||||
|
||||
|
||||
/* ================================================= external data structures */
|
||||
|
||||
|
||||
/* ====================================================== function prototypes */
|
||||
|
||||
|
||||
} // namespace Db
|
||||
} // namespace LiveSupport
|
||||
|
||||
#endif // SimpleConnectionManagerTest_h
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2004 Media Development Loan Fund
|
||||
|
||||
This file is part of the LiveSupport project.
|
||||
http://livesupport.campware.org/
|
||||
To report bugs, send an e-mail to bugs@campware.org
|
||||
|
||||
LiveSupport 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
|
||||
(at your option) any later version.
|
||||
|
||||
LiveSupport 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 LiveSupport; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.1 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/db/src/TestRunner.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "configure.h"
|
||||
#endif
|
||||
|
||||
#include <cppunit/BriefTestProgressListener.h>
|
||||
#include <cppunit/CompilerOutputter.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <cppunit/TestResult.h>
|
||||
#include <cppunit/TestResultCollector.h>
|
||||
#include <cppunit/TestRunner.h>
|
||||
|
||||
|
||||
/* =================================================== local data structures */
|
||||
|
||||
|
||||
/* ================================================ local constants & macros */
|
||||
|
||||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
|
||||
/* ============================================================= module code */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Run all tests
|
||||
*----------------------------------------------------------------------------*/
|
||||
int
|
||||
main( int argc,
|
||||
char * argv[] ) throw ()
|
||||
{
|
||||
// Create the event manager and test controller
|
||||
CPPUNIT_NS::TestResult controller;
|
||||
|
||||
// Add a listener that colllects test result
|
||||
CPPUNIT_NS::TestResultCollector result;
|
||||
controller.addListener( &result );
|
||||
|
||||
// Add a listener that print dots as test run.
|
||||
CPPUNIT_NS::BriefTestProgressListener progress;
|
||||
controller.addListener( &progress );
|
||||
|
||||
// Add the top suite to the test runner
|
||||
CPPUNIT_NS::TestRunner runner;
|
||||
runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
|
||||
runner.run( controller );
|
||||
|
||||
// Print test in a compiler compatible format.
|
||||
CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr );
|
||||
outputter.setLocationFormat("%p:%l:");
|
||||
outputter.write();
|
||||
|
||||
return result.wasSuccessful() ? 0 : 1;
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
keep me
|
Loading…
Reference in New Issue