summaryrefslogtreecommitdiff
path: root/cpp/src/Freeze/Util.cpp
diff options
context:
space:
mode:
authorBernard Normier <bernard@zeroc.com>2005-10-03 16:57:34 +0000
committerBernard Normier <bernard@zeroc.com>2005-10-03 16:57:34 +0000
commitd3578a4742a4d46d9ee38aa37e18f5483759278c (patch)
tree790b53f267cb55d8f9993d9338cbbbafec9886af /cpp/src/Freeze/Util.cpp
parentFixed bogus dependency on Internal.h in icegridadmin (diff)
downloadice-d3578a4742a4d46d9ee38aa37e18f5483759278c.tar.bz2
ice-d3578a4742a4d46d9ee38aa37e18f5483759278c.tar.xz
ice-d3578a4742a4d46d9ee38aa37e18f5483759278c.zip
Refactored code to work-around DB 4.3's DB_BUFFER_SMALL bug
Diffstat (limited to 'cpp/src/Freeze/Util.cpp')
-rw-r--r--cpp/src/Freeze/Util.cpp78
1 files changed, 48 insertions, 30 deletions
diff --git a/cpp/src/Freeze/Util.cpp b/cpp/src/Freeze/Util.cpp
index e3d86328e58..73ef47cb4eb 100644
--- a/cpp/src/Freeze/Util.cpp
+++ b/cpp/src/Freeze/Util.cpp
@@ -15,9 +15,25 @@ using namespace Ice;
using namespace std;
void
-Freeze::handleMemoryException(const DbMemoryException& dx, Key& key, Dbt& dbKey)
+Freeze::handleDbException(const DbException& dx,
+ const char* file, int line)
{
- if(dbKey.get_size() > dbKey.get_ulen())
+ throw DatabaseException(file, line, dx.what());
+}
+
+void
+Freeze::handleDbException(const DbException& dx,
+ Key& key, Dbt& dbKey,
+ const char* file, int line)
+{
+ bool bufferSmallException =
+#if (DB_VERSION_MAJOR == 4) && (DB_VERSION_MINOR == 2)
+ (dx.get_errno() == ENOMEM);
+#else
+ (dx.get_errno() == DB_BUFFER_SMALL);
+#endif
+
+ if(bufferSmallException && (dbKey.get_size() > dbKey.get_ulen()))
{
//
// Keep the old key size in case it's used as input
@@ -30,43 +46,45 @@ Freeze::handleMemoryException(const DbMemoryException& dx, Key& key, Dbt& dbKey)
}
else
{
- //
- // Real problem
- //
- DatabaseException ex(__FILE__, __LINE__);
- ex.message = dx.what();
- throw ex;
+ handleDbException(dx, file, line);
}
}
void
-Freeze::handleMemoryException(const DbMemoryException& dx, Key& key, Dbt& dbKey,
- Value& value, Dbt& dbValue)
+Freeze::handleDbException(const DbException& dx,
+ Key& key, Dbt& dbKey,
+ Value& value, Dbt& dbValue,
+ const char* file, int line)
{
- bool resized = false;
- if(dbKey.get_size() > dbKey.get_ulen())
- {
- size_t oldKeySize = key.size();
- key.resize(dbKey.get_size());
- initializeOutDbt(key, dbKey);
- dbKey.set_size(static_cast<u_int32_t>(oldKeySize));
- resized = true;
- }
-
- if(dbValue.get_size() > dbValue.get_ulen())
+ bool bufferSmallException =
+#if (DB_VERSION_MAJOR == 4) && (DB_VERSION_MINOR == 2)
+ (dx.get_errno() == ENOMEM);
+#else
+ (dx.get_errno() == DB_BUFFER_SMALL);
+#endif
+
+ bool resized = false;
+ if(bufferSmallException)
{
- value.resize(dbValue.get_size());
- initializeOutDbt(value, dbValue);
- resized = true;
+ if(dbKey.get_size() > dbKey.get_ulen())
+ {
+ size_t oldKeySize = key.size();
+ key.resize(dbKey.get_size());
+ initializeOutDbt(key, dbKey);
+ dbKey.set_size(static_cast<u_int32_t>(oldKeySize));
+ resized = true;
+ }
+
+ if(dbValue.get_size() > dbValue.get_ulen())
+ {
+ value.resize(dbValue.get_size());
+ initializeOutDbt(value, dbValue);
+ resized = true;
+ }
}
if(!resized)
{
- //
- // Real problem
- //
- DatabaseException ex(__FILE__, __LINE__);
- ex.message = dx.what();
- throw ex;
+ handleDbException(dx, file, line);
}
}