committed Data

This commit is contained in:
Guenter Obiltschnig
2007-05-12 14:41:03 +00:00
parent cf80f255be
commit 01bcb63000
177 changed files with 100448 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
//
// AbstractBinder.cpp
//
// $Id: //poco/Main/Data/src/AbstractBinder.cpp#2 $
//
// Library: Data
// Package: DataCore
// Module: AbstractBinder
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/AbstractBinder.h"
namespace Poco {
namespace Data {
AbstractBinder::AbstractBinder()
{
}
AbstractBinder::~AbstractBinder()
{
}
} } // namespace Poco::Data

View File

@@ -0,0 +1,55 @@
//
// AbstractBinding.cpp
//
// $Id: //poco/Main/Data/src/AbstractBinding.cpp#3 $
//
// Library: Data
// Package: DataCore
// Module: AbstractBinding
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/AbstractBinding.h"
namespace Poco {
namespace Data {
AbstractBinding::AbstractBinding():
_pBinder(0)
{
}
AbstractBinding::~AbstractBinding()
{
}
} } // namespace Poco::Data

View File

@@ -0,0 +1,56 @@
//
// AbstractExtraction.cpp
//
// $Id: //poco/Main/Data/src/AbstractExtraction.cpp#2 $
//
// Library: Data
// Package: DataCore
// Module: AbstractExtraction
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/AbstractExtraction.h"
namespace Poco {
namespace Data {
AbstractExtraction::AbstractExtraction(Poco::UInt32 limit):
_pExtractor(0),
_limit(limit)
{
}
AbstractExtraction::~AbstractExtraction()
{
}
} } // namespace Poco::Data

View File

@@ -0,0 +1,54 @@
//
// AbstractExtractor.cpp
//
// $Id: //poco/Main/Data/src/AbstractExtractor.cpp#2 $
//
// Library: Data
// Package: DataCore
// Module: AbstractExtractor
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/AbstractExtractor.h"
namespace Poco {
namespace Data {
AbstractExtractor::AbstractExtractor()
{
}
AbstractExtractor::~AbstractExtractor()
{
}
} } // namespace Poco::Data

View File

@@ -0,0 +1,54 @@
//
// AbstractPreparation.cpp
//
// $Id: //poco/Main/Data/src/AbstractPreparation.cpp#1 $
//
// Library: Data
// Package: DataCore
// Module: AbstractPreparation
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/AbstractPreparation.h"
namespace Poco {
namespace Data {
AbstractPreparation::AbstractPreparation()
{
}
AbstractPreparation::~AbstractPreparation()
{
}
} } // namespace Poco::Data

View File

@@ -0,0 +1,56 @@
//
// AbstractPrepare.cpp
//
// $Id: //poco/Main/Data/src/AbstractPrepare.cpp#2 $
//
// Library: Data
// Package: DataCore
// Module: AbstractPrepare
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/AbstractPrepare.h"
namespace Poco {
namespace Data {
AbstractPrepare::AbstractPrepare(AbstractPreparation* pPrepare):
_pPrepare(pPrepare)
{
poco_assert_dbg (_pPrepare);
}
AbstractPrepare::~AbstractPrepare()
{
}
} } // namespace Poco::Data

87
Data/src/BLOB.cpp Normal file
View File

@@ -0,0 +1,87 @@
//
// BLOB.cpp
//
// $Id: //poco/Main/Data/src/BLOB.cpp#7 $
//
// Library: Data
// Package: DataCore
// Module: BLOB
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/BLOB.h"
namespace Poco {
namespace Data {
BLOB::BLOB():
_pContent(new std::vector<char>())
{
}
BLOB::BLOB(const std::vector<char>& content):
_pContent(new std::vector<char>(content))
{
}
BLOB::BLOB(const char* const pContent, std::size_t size):
_pContent(new std::vector<char>(pContent, pContent + size))
{
}
BLOB::BLOB(const std::string& content):
_pContent(new std::vector<char>(content.begin(), content.end()))
{
}
BLOB::BLOB(const BLOB& other):
_pContent(other._pContent)
{
}
BLOB::~BLOB()
{
}
BLOB& BLOB::operator = (const BLOB& other)
{
BLOB tmp(other);
swap(tmp);
return *this;
}
} } // namespace Poco::Data

131
Data/src/BLOBStream.cpp Normal file
View File

@@ -0,0 +1,131 @@
//
// BLOBStream.cpp
//
// $Id: //poco/Main/Data/src/BLOBStream.cpp#2 $
//
// Library: Data
// Package: DataCore
// Module: BLOBStream
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/BLOBStream.h"
namespace Poco {
namespace Data {
//
// BLOBStreamBuf
//
BLOBStreamBuf::BLOBStreamBuf(BLOB& blob):
_blob(blob),
_it(_blob.begin())
{
}
BLOBStreamBuf::~BLOBStreamBuf()
{
}
UnbufferedStreamBuf::int_type BLOBStreamBuf::readFromDevice()
{
if (_it != _blob.end())
return charToInt(*_it++);
else
return -1;
}
UnbufferedStreamBuf::int_type BLOBStreamBuf::writeToDevice(char c)
{
_blob._pContent->push_back(c);
return 1;
}
//
// BLOBIOS
//
BLOBIOS::BLOBIOS(BLOB& blob, openmode mode) :_buf(blob)
{
poco_ios_init(&_buf);
}
BLOBIOS::~BLOBIOS()
{
}
BLOBStreamBuf* BLOBIOS::rdbuf()
{
return &_buf;
}
//
// BLOBOutputStream
//
BLOBOutputStream::BLOBOutputStream(BLOB& blob):
BLOBIOS(blob, std::ios::out),
std::ostream(&_buf)
{
}
BLOBOutputStream::~BLOBOutputStream()
{
}
//
// BLOBInputStream
//
BLOBInputStream::BLOBInputStream(BLOB& blob):
BLOBIOS(blob, std::ios::in),
std::istream(&_buf)
{
}
BLOBInputStream::~BLOBInputStream()
{
}
} } // namespace Poco::Data

View File

@@ -0,0 +1,59 @@
//
// DataException.cpp
//
// $Id: //poco/Main/Data/src/DataException.cpp#7 $
//
// Library: Data
// Package: DataCore
// Module: DataException
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/DataException.h"
#include <typeinfo>
namespace Poco {
namespace Data {
POCO_IMPLEMENT_EXCEPTION(DataException, Poco::IOException, "Database Exception")
POCO_IMPLEMENT_EXCEPTION(RowDataMissingException, DataException, "Data for row missing")
POCO_IMPLEMENT_EXCEPTION(UnknownDataBaseException, DataException, "Type of data base unknown")
POCO_IMPLEMENT_EXCEPTION(UnknownTypeException, DataException, "Type of data unknown")
POCO_IMPLEMENT_EXCEPTION(ExecutionException, DataException, "Execution error")
POCO_IMPLEMENT_EXCEPTION(BindingException, DataException, "Binding error")
POCO_IMPLEMENT_EXCEPTION(ExtractException, DataException, "Extraction error")
POCO_IMPLEMENT_EXCEPTION(LimitException, DataException, "Limit error")
POCO_IMPLEMENT_EXCEPTION(NotSupportedException, DataException, "Feature or property not supported")
POCO_IMPLEMENT_EXCEPTION(NotImplementedException, DataException, "Feature or property not implemented")
POCO_IMPLEMENT_EXCEPTION(SessionUnavailableException, DataException, "Session is unavailable")
POCO_IMPLEMENT_EXCEPTION(SessionPoolExhaustedException, DataException, "No more sessions available from the session pool")
} } // namespace Poco::Data

57
Data/src/Limit.cpp Normal file
View File

@@ -0,0 +1,57 @@
//
// Limit.cpp
//
// $Id: //poco/Main/Data/src/Limit.cpp#5 $
//
// Library: Data
// Package: DataCore
// Module: Limit
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/Limit.h"
namespace Poco {
namespace Data {
Limit::Limit(Poco::UInt32 value, bool hardLimit, bool isLowerLimit):
_value(value),
_hardLimit(hardLimit),
_isLowerLimit(isLowerLimit)
{
}
Limit::~Limit()
{
}
} } // namespace Poco::Data

71
Data/src/MetaColumn.cpp Normal file
View File

@@ -0,0 +1,71 @@
//
// MetaColumn.cpp
//
// $Id: //poco/Main/Data/src/MetaColumn.cpp#2 $
//
// Library: Data
// Package: DataCore
// Module: MetaColumn
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/MetaColumn.h"
namespace Poco {
namespace Data {
MetaColumn::MetaColumn()
{
}
MetaColumn::MetaColumn(std::size_t position,
const std::string& name,
ColumnDataType type,
std::size_t length,
std::size_t precision,
bool nullable):
_name(name),
_length(length),
_precision(precision),
_position(position),
_type(type),
_nullable(nullable)
{
poco_assert(position > 0);
}
MetaColumn::~MetaColumn()
{
}
} } // namespace Poco::Data

View File

@@ -0,0 +1,56 @@
//
// PooledSessionHolder.cpp
//
// $Id: //poco/Main/Data/src/PooledSessionHolder.cpp#1 $
//
// Library: Data
// Package: SessionPooling
// Module: PooledSessionHolder
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/PooledSessionHolder.h"
namespace Poco {
namespace Data {
PooledSessionHolder::PooledSessionHolder(SessionPool& owner, SessionImpl* pSessionImpl):
_owner(owner),
_pImpl(pSessionImpl, true)
{
}
PooledSessionHolder::~PooledSessionHolder()
{
}
} } // namespace Poco::Data

View File

@@ -0,0 +1,133 @@
//
// PooledSessionImpl.cpp
//
// $Id: //poco/Main/Data/src/PooledSessionImpl.cpp#2 $
//
// Library: Data
// Package: SessionPooling
// Module: PooledSessionImpl
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/PooledSessionImpl.h"
#include "Poco/Data/DataException.h"
#include "Poco/Data/SessionPool.h"
namespace Poco {
namespace Data {
PooledSessionImpl::PooledSessionImpl(PooledSessionHolder* pHolder):
_pHolder(pHolder, true)
{
}
PooledSessionImpl::~PooledSessionImpl()
{
close();
}
StatementImpl* PooledSessionImpl::createStatementImpl()
{
return access()->createStatementImpl();
}
void PooledSessionImpl::begin()
{
return access()->begin();
}
void PooledSessionImpl::commit()
{
return access()->commit();
}
bool PooledSessionImpl::isConnected()
{
return access()->isConnected();
}
void PooledSessionImpl::rollback()
{
return access()->rollback();
}
void PooledSessionImpl::close()
{
if (_pHolder)
{
_pHolder->owner().putBack(_pHolder);
_pHolder = 0;
}
}
void PooledSessionImpl::setFeature(const std::string& name, bool state)
{
access()->setFeature(name, state);
}
bool PooledSessionImpl::getFeature(const std::string& name)
{
return access()->getFeature(name);
}
void PooledSessionImpl::setProperty(const std::string& name, const Poco::Any& value)
{
access()->setProperty(name, value);
}
Poco::Any PooledSessionImpl::getProperty(const std::string& name)
{
return access()->getProperty(name);
}
SessionImpl* PooledSessionImpl::access()
{
if (_pHolder)
{
_pHolder->access();
return impl();
}
else throw SessionUnavailableException();
}
} } // namespace Poco::Data

59
Data/src/Range.cpp Normal file
View File

@@ -0,0 +1,59 @@
//
// Range.cpp
//
// $Id: //poco/Main/Data/src/Range.cpp#2 $
//
// Library: Data
// Package: DataCore
// Module: Range
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/Range.h"
#include "Poco/Data/DataException.h"
namespace Poco {
namespace Data {
Range::Range(Poco::UInt32 lowValue, Poco::UInt32 upValue, bool hardLimit):
_lower(lowerLimit(lowValue)),
_upper(upperLimit(upValue, hardLimit))
{
if (lowValue > upValue)
throw LimitException("lowerLimit > upperLimit!");
}
Range::~Range()
{
}
} } // namespace Poco::Data

102
Data/src/RecordSet.cpp Normal file
View File

@@ -0,0 +1,102 @@
//
// RecordSet.cpp
//
// $Id: //poco/Main/Data/src/RecordSet.cpp#2 $
//
// Library: Data
// Package: DataCore
// Module: RecordSet
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/RecordSet.h"
namespace Poco {
namespace Data {
RecordSet::RecordSet(const Statement& rStatement):
Statement(rStatement),
_currentRow(1)
{
}
RecordSet::~RecordSet()
{
}
DynamicAny RecordSet::value(std::size_t col, std::size_t row) const
{
switch (columnType(col))
{
case MetaColumn::FDT_BOOL:
case MetaColumn::FDT_INT8: return value<Int8>(col, row); break;
case MetaColumn::FDT_UINT8: return value<UInt8>(col, row); break;
case MetaColumn::FDT_INT16: return value<Int16>(col, row); break;
case MetaColumn::FDT_UINT16: return value<UInt16>(col, row); break;
case MetaColumn::FDT_INT32: return value<Int32>(col, row); break;
case MetaColumn::FDT_UINT32: return value<UInt32>(col, row); break;
case MetaColumn::FDT_INT64: return value<Int64>(col, row); break;
case MetaColumn::FDT_UINT64: return value<UInt64>(col, row); break;
case MetaColumn::FDT_FLOAT: return value<float>(col, row); break;
case MetaColumn::FDT_DOUBLE: return value<double>(col, row); break;
case MetaColumn::FDT_STRING: return value<std::string>(col, row); break;
case MetaColumn::FDT_BLOB: return value<BLOB>(col, row); break;
default:
throw Poco::InvalidArgumentException("Data type not supported.");
}
}
DynamicAny RecordSet::value(const std::string& name, std::size_t row) const
{
switch (columnType(name))
{
case MetaColumn::FDT_BOOL:
case MetaColumn::FDT_INT8: return value<Int8>(name, row); break;
case MetaColumn::FDT_UINT8: return value<UInt8>(name, row); break;
case MetaColumn::FDT_INT16: return value<Int16>(name, row); break;
case MetaColumn::FDT_UINT16: return value<UInt16>(name, row); break;
case MetaColumn::FDT_INT32: return value<Int32>(name, row); break;
case MetaColumn::FDT_UINT32: return value<UInt32>(name, row); break;
case MetaColumn::FDT_INT64: return value<Int64>(name, row); break;
case MetaColumn::FDT_UINT64: return value<UInt64>(name, row); break;
case MetaColumn::FDT_FLOAT: return value<float>(name, row); break;
case MetaColumn::FDT_DOUBLE: return value<double>(name, row); break;
case MetaColumn::FDT_STRING: return value<std::string>(name, row); break;
case MetaColumn::FDT_BLOB: return value<BLOB>(name, row); break;
default:
throw Poco::InvalidArgumentException("Data type not supported.");
}
}
} } // namespace Poco::Data

81
Data/src/Session.cpp Normal file
View File

@@ -0,0 +1,81 @@
//
// Session.cpp
//
// $Id: //poco/Main/Data/src/Session.cpp#3 $
//
// Library: Data
// Package: DataCore
// Module: Session
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/Session.h"
#include <algorithm>
namespace Poco {
namespace Data {
Session::Session(Poco::AutoPtr<SessionImpl> ptrImpl):
_ptrImpl(ptrImpl),
_statementCreator(ptrImpl)
{
poco_check_ptr (ptrImpl.get());
}
Session::Session(const Session& other):
_ptrImpl(other._ptrImpl),
_statementCreator(other._ptrImpl)
{
}
Session::~Session()
{
}
Session& Session::operator = (const Session& other)
{
Session tmp(other);
swap(tmp);
return *this;
}
void Session::swap(Session& other)
{
using std::swap;
swap(_statementCreator, other._statementCreator);
swap(_ptrImpl, other._ptrImpl);
}
} } // namespace Poco::Data

102
Data/src/SessionFactory.cpp Normal file
View File

@@ -0,0 +1,102 @@
//
// SessionFactory.cpp
//
// $Id: //poco/Main/Data/src/SessionFactory.cpp#4 $
//
// Library: Data
// Package: DataCore
// Module: SessionFactory
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/SessionFactory.h"
namespace Poco {
namespace Data {
SessionFactory::SessionFactory()
{
}
SessionFactory::~SessionFactory()
{
}
SessionFactory& SessionFactory::instance()
{
static SessionFactory sf;
return sf;
}
void SessionFactory::add(const std::string& key, SessionInstantiator* pIn)
{
Poco::FastMutex::ScopedLock lock(_mutex);
SessionInfo info(pIn);
std::pair<Instantiators::iterator, bool> res = _instantiators.insert(std::make_pair(key, info));
if (!res.second)
{
res.first->second.cnt++;
}
}
void SessionFactory::remove(const std::string& key)
{
Poco::FastMutex::ScopedLock lock(_mutex);
Instantiators::iterator it = _instantiators.find(key);
poco_assert (_instantiators.end() != it);
--(it->second.cnt);
if (it->second.cnt == 0)
_instantiators.erase(it);
}
Session SessionFactory::create(const std::string& key, const std::string& initString)
{
Poco::FastMutex::ScopedLock lock(_mutex);
Instantiators::iterator it = _instantiators.find(key);
poco_assert (_instantiators.end() != it);
return Session(it->second.ptrSI->create(initString));
}
SessionFactory::SessionInfo::SessionInfo(SessionInstantiator* pSI):
cnt(1),
ptrSI(pSI)
{
}
} } // namespace Poco::Data

54
Data/src/SessionImpl.cpp Normal file
View File

@@ -0,0 +1,54 @@
//
// SessionImpl.cpp
//
// $Id: //poco/Main/Data/src/SessionImpl.cpp#3 $
//
// Library: Data
// Package: DataCore
// Module: SessionImpl
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/SessionImpl.h"
namespace Poco {
namespace Data {
SessionImpl::SessionImpl()
{
}
SessionImpl::~SessionImpl()
{
}
} } // namespace Poco::Data

View File

@@ -0,0 +1,54 @@
//
// SessionInstantiator.cpp
//
// $Id: //poco/Main/Data/src/SessionInstantiator.cpp#2 $
//
// Library: Data
// Package: DataCore
// Module: SessionInstantiator
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/SessionInstantiator.h"
namespace Poco {
namespace Data {
SessionInstantiator::SessionInstantiator()
{
}
SessionInstantiator::~SessionInstantiator()
{
}
} } // namespace Poco::Data

208
Data/src/SessionPool.cpp Normal file
View File

@@ -0,0 +1,208 @@
//
// SessionPool.cpp
//
// $Id: //poco/Main/Data/src/SessionPool.cpp#2 $
//
// Library: Data
// Package: SessionPooling
// Module: SessionPool
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/SessionPool.h"
#include "Poco/Data/SessionFactory.h"
#include "Poco/Data/DataException.h"
#include <algorithm>
namespace Poco {
namespace Data {
SessionPool::SessionPool(const std::string& sessionKey, const std::string& initString, int minSessions, int maxSessions, int idleTime):
_sessionKey(sessionKey),
_initString(initString),
_minSessions(minSessions),
_maxSessions(maxSessions),
_idleTime(idleTime),
_nSessions(0),
_janitorTimer(idleTime, idleTime/4)
{
Poco::TimerCallback<SessionPool> callback(*this, &SessionPool::onJanitorTimer);
_janitorTimer.start(callback);
}
SessionPool::~SessionPool()
{
_janitorTimer.stop();
}
Session SessionPool::get()
{
Poco::FastMutex::ScopedLock lock(_mutex);
purgeDeadSessions();
if (_idleSessions.empty())
{
if (_nSessions < _maxSessions)
{
Session newSession(SessionFactory::instance().create(_sessionKey, _initString));
PooledSessionHolderPtr pHolder(new PooledSessionHolder(*this, newSession.impl()));
_idleSessions.push_front(pHolder);
++_nSessions;
}
else throw SessionPoolExhaustedException(_sessionKey, _initString);
}
PooledSessionHolderPtr pHolder(_idleSessions.front());
PooledSessionImplPtr pPSI(new PooledSessionImpl(pHolder));
_activeSessions.push_front(pHolder);
_idleSessions.pop_front();
return Session(pPSI);
}
void SessionPool::purgeDeadSessions()
{
SessionList::iterator it = _idleSessions.begin();
for (; it != _idleSessions.end(); )
{
if (!(*it)->session()->isConnected())
{
it = _idleSessions.erase(it);
--_nSessions;
}
else ++it;
}
}
int SessionPool::capacity() const
{
return _maxSessions;
}
int SessionPool::used() const
{
Poco::FastMutex::ScopedLock lock(_mutex);
return (int) _activeSessions.size();
}
int SessionPool::idle() const
{
Poco::FastMutex::ScopedLock lock(_mutex);
return (int) _idleSessions.size();
}
int SessionPool::dead()
{
Poco::FastMutex::ScopedLock lock(_mutex);
int count = 0;
SessionList::iterator it = _activeSessions.begin();
SessionList::iterator itEnd = _activeSessions.end();
for (; it != itEnd; ++it)
{
if (!(*it)->session()->isConnected())
++count;
}
return count;
}
int SessionPool::allocated() const
{
Poco::FastMutex::ScopedLock lock(_mutex);
return _nSessions;
}
int SessionPool::available() const
{
return _maxSessions - used();
}
void SessionPool::putBack(PooledSessionHolderPtr pHolder)
{
Poco::FastMutex::ScopedLock lock(_mutex);
SessionList::iterator it = std::find(_activeSessions.begin(), _activeSessions.end(), pHolder);
if (it != _activeSessions.end())
{
if (pHolder->session()->isConnected())
{
pHolder->access();
_idleSessions.push_front(pHolder);
}
else --_nSessions;
_activeSessions.erase(it);
}
else
{
poco_bugcheck_msg("Unknown session passed to SessionPool::putBack()");
}
}
void SessionPool::onJanitorTimer(Poco::Timer&)
{
Poco::FastMutex::ScopedLock lock(_mutex);
SessionList::iterator it = _idleSessions.begin();
while (_nSessions > _minSessions && it != _idleSessions.end())
{
if ((*it)->idle() > _idleTime || !(*it)->session()->isConnected())
{
try
{
(*it)->session()->close();
}
catch (...)
{
}
it = _idleSessions.erase(it);
--_nSessions;
}
else ++it;
}
}
} } // namespace Poco::Data

107
Data/src/Statement.cpp Normal file
View File

@@ -0,0 +1,107 @@
//
// Statement.cpp
//
// $Id: //poco/Main/Data/src/Statement.cpp#8 $
//
// Library: Data
// Package: DataCore
// Module: Statement
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/Statement.h"
#include "Poco/Data/DataException.h"
#include "Poco/Data/Extraction.h"
#include "Poco/Any.h"
#include "Poco/Tuple.h"
#include <algorithm>
namespace Poco {
namespace Data {
Statement::Statement(StatementImpl* pImpl):
_executed(false),
_ptr(pImpl)
{
poco_check_ptr (pImpl);
}
Statement::Statement(const Statement& stmt):
_executed(stmt._executed),
_ptr(stmt._ptr)
{
}
Statement::~Statement()
{
}
Statement& Statement::operator = (const Statement& stmt)
{
Statement tmp(stmt);
swap(tmp);
return *this;
}
void Statement::swap(Statement& other)
{
std::swap(_ptr, other._ptr);
std::swap(_executed, other._executed);
}
Poco::UInt32 Statement::execute()
{
if (done())
{
_ptr->reset();
}
_executed = true;
return _ptr->execute();
}
bool Statement::done()
{
return _ptr->getState() == StatementImpl::ST_DONE;
}
void now(Statement& statement)
{
statement.execute();
}
} } // namespace Poco::Data

View File

@@ -0,0 +1,77 @@
//
// StatementCreator.cpp
//
// $Id: //poco/Main/Data/src/StatementCreator.cpp#3 $
//
// Library: Data
// Package: DataCore
// Module: StatementCreator
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/StatementCreator.h"
#include <algorithm>
namespace Poco {
namespace Data {
StatementCreator::StatementCreator(Poco::AutoPtr<SessionImpl> ptrImpl):
_ptrImpl(ptrImpl)
{
}
StatementCreator::StatementCreator(const StatementCreator& other):
_ptrImpl(other._ptrImpl)
{
}
StatementCreator& StatementCreator::operator = (const StatementCreator& other)
{
StatementCreator tmp(other);
swap(tmp);
return *this;
}
void StatementCreator::swap(StatementCreator& other)
{
using std::swap;
swap(_ptrImpl, other._ptrImpl);
}
StatementCreator::~StatementCreator()
{
}
} } // namespace Poco::Data

321
Data/src/StatementImpl.cpp Normal file
View File

@@ -0,0 +1,321 @@
//
// StatementImpl.cpp
//
// $Id: //poco/Main/Data/src/StatementImpl.cpp#18 $
//
// Library: Data
// Package: DataCore
// Module: StatementImpl
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display, distribute,
// execute, and transmit the Software, and to prepare derivative works of the
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement, including
// the above license grant, this restriction and the following disclaimer,
// must be included in all copies of the Software, in whole or in part, and
// all derivative works of the Software, unless such copies or derivative
// works are solely in the form of machine-executable object code generated by
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
#include "Poco/Data/StatementImpl.h"
#include "Poco/Data/DataException.h"
#include "Poco/Data/AbstractBinder.h"
#include "Poco/Data/Extraction.h"
#include "Poco/Data/BLOB.h"
#include "Poco/SharedPtr.h"
#include "Poco/String.h"
#include "Poco/Exception.h"
namespace Poco {
namespace Data {
StatementImpl::StatementImpl():
_state(ST_INITIALIZED),
_extrLimit(upperLimit((Poco::UInt32) Limit::LIMIT_UNLIMITED, false)),
_lowerLimit(0),
_columnsExtracted(0),
_ostr(),
_bindings()
{
}
StatementImpl::~StatementImpl()
{
}
Poco::UInt32 StatementImpl::execute()
{
resetExtraction();
Poco::UInt32 lim = 0;
if (_lowerLimit > _extrLimit.value())
throw LimitException("Illegal Statement state. Upper limit must not be smaller than the lower limit.");
if (_extrLimit.value() == Limit::LIMIT_UNLIMITED)
lim = executeWithoutLimit();
else
lim = executeWithLimit();
if (lim < _lowerLimit)
{
throw LimitException("Did not receive enough data.");
}
return lim;
}
Poco::UInt32 StatementImpl::executeWithLimit()
{
poco_assert (_state != ST_DONE);
compile();
Poco::UInt32 count = 0;
do
{
bind();
while (hasNext() && count < _extrLimit.value())
{
next();
++count;
}
}
while (canBind());
if (!canBind() && (!hasNext() || _extrLimit.value() == 0))
_state = ST_DONE;
else if (hasNext() && _extrLimit.value() == count && _extrLimit.isHardLimit())
throw LimitException("HardLimit reached. We got more data than we asked for");
return count;
}
Poco::UInt32 StatementImpl::executeWithoutLimit()
{
poco_assert (_state != ST_DONE);
compile();
Poco::UInt32 count = 0;
do
{
bind();
while (hasNext())
{
next();
++count;
}
}
while (canBind());
_state = ST_DONE;
return count;
}
void StatementImpl::compile()
{
if (_state == ST_INITIALIZED)
{
compileImpl();
_state = ST_COMPILED;
if (!extractions().size())
{
Poco::UInt32 cols = columnsReturned();
if (cols) makeExtractors(cols);
}
fixupExtraction();
fixupBinding();
}
else if (_state == ST_RESET)
{
resetBinding();
resetExtraction();
_state = ST_COMPILED;
}
}
void StatementImpl::bind()
{
if (_state == ST_COMPILED)
{
bindImpl();
_state = ST_BOUND;
}
else if (_state == ST_BOUND)
{
if (!hasNext())
{
if (canBind())
{
bindImpl();
}
else
_state = ST_DONE;
}
}
}
void StatementImpl::reset()
{
_state = ST_RESET;
compile();
}
void StatementImpl::setExtractionLimit(const Limit& extrLimit)
{
if (!extrLimit.isLowerLimit())
_extrLimit = extrLimit;
else
_lowerLimit = extrLimit.value();
}
void StatementImpl::fixupExtraction()
{
Poco::Data::AbstractExtractionVec::iterator it = extractions().begin();
Poco::Data::AbstractExtractionVec::iterator itEnd = extractions().end();
AbstractExtractor& ex = extractor();
_columnsExtracted = 0;
for (; it != itEnd; ++it)
{
(*it)->setExtractor(&ex);
(*it)->setLimit(_extrLimit.value()),
_columnsExtracted += (int)(*it)->numOfColumnsHandled();
}
}
void StatementImpl::fixupBinding()
{
// no need to call binder().reset(); here will be called before each bind anyway
AbstractBindingVec::iterator it = bindings().begin();
AbstractBindingVec::iterator itEnd = bindings().end();
AbstractBinder& bin = binder();
std::size_t numRows = 0;
if (it != itEnd)
numRows = (*it)->numOfRowsHandled();
for (; it != itEnd; ++it)
{
if (numRows != (*it)->numOfRowsHandled())
{
throw BindingException("Size mismatch in Bindings. All Bindings MUST have the same size");
}
(*it)->setBinder(&bin);
}
}
void StatementImpl::resetBinding()
{
AbstractBindingVec::iterator it = bindings().begin();
AbstractBindingVec::iterator itEnd = bindings().end();
for (; it != itEnd; ++it)
{
(*it)->reset();
}
}
void StatementImpl::resetExtraction()
{
Poco::Data::AbstractExtractionVec::iterator it = extractions().begin();
Poco::Data::AbstractExtractionVec::iterator itEnd = extractions().end();
for (; it != itEnd; ++it)
{
(*it)->reset();
}
}
void StatementImpl::makeExtractors(Poco::UInt32 count)
{
for (int i = 0; i < count; ++i)
{
const MetaColumn& mc = metaColumn(i+1);
switch (mc.type())
{
case MetaColumn::FDT_BOOL:
case MetaColumn::FDT_INT8:
addInternalExtract<Int8, std::vector<Int8> >(mc);
break;
case MetaColumn::FDT_UINT8:
addInternalExtract<UInt8, std::vector<UInt8> >(mc);
break;
case MetaColumn::FDT_INT16:
addInternalExtract<Int16, std::vector<Int16> >(mc);
break;
case MetaColumn::FDT_UINT16:
addInternalExtract<UInt16, std::vector<UInt16> >(mc);
break;
case MetaColumn::FDT_INT32:
addInternalExtract<Int32, std::vector<Int32> >(mc);
break;
case MetaColumn::FDT_UINT32:
addInternalExtract<UInt32, std::vector<UInt32> >(mc);
break;
case MetaColumn::FDT_INT64:
addInternalExtract<Int64, std::vector<Int64> >(mc);
break;
case MetaColumn::FDT_UINT64:
addInternalExtract<UInt64, std::vector<UInt64> >(mc);
break;
case MetaColumn::FDT_FLOAT:
addInternalExtract<float, std::vector<float> >(mc);
break;
case MetaColumn::FDT_DOUBLE:
addInternalExtract<double, std::vector<double> >(mc);
break;
case MetaColumn::FDT_STRING:
addInternalExtract<std::string, std::vector<std::string> >(mc);
break;
case MetaColumn::FDT_BLOB:
addInternalExtract<BLOB, std::vector<BLOB> >(mc);
break;
default:
throw Poco::InvalidArgumentException("Data type not supported.");
}
}
}
const MetaColumn& StatementImpl::metaColumn(const std::string& name) const
{
Poco::UInt32 cols = columnsReturned();
for (Poco::UInt32 i = 0; i < cols; ++i)
{
const MetaColumn& column = metaColumn(i+1);
if (0 == icompare(column.name(), name)) return column;
}
throw NotFoundException(format("Invalid column name: %s", name));
}
} } // namespace Poco::Data