Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

CVS update of carob (2 files): msg#00214

db.carob.cvs

Subject: CVS update of carob (2 files)

Date: Monday, January 30, 2006 @ 22:46:17
Author: marc
Path: /cvsroot/carob/carob

Modified: include/ParameterStatement.hpp (1.10 -> 1.11)
src/ParameterStatement.cpp (1.17 -> 1.18)

Major change: templatized all setXXX() calls, opening the door for a
new great world of data types conversions made easy.
BREAKAGE WARNING: some setString() calls may not compile anymore;
check doxygen in .hpp for the explanation and the (trivial) fix.
Should be enough to close CAROB-55.


--------------------------------+
include/ParameterStatement.hpp | 97 +++++++++++++++++++++++-----------
src/ParameterStatement.cpp | 111 ++++++++++++++++++++++++++++++---------
2 files changed, 156 insertions(+), 52 deletions(-)


Index: carob/include/ParameterStatement.hpp
diff -u carob/include/ParameterStatement.hpp:1.10
carob/include/ParameterStatement.hpp:1.11
--- carob/include/ParameterStatement.hpp:1.10 Mon Jan 30 15:47:59 2006
+++ carob/include/ParameterStatement.hpp Mon Jan 30 22:46:17 2006
@@ -16,7 +16,7 @@
* limitations under the License.
*
* Initial developer(s): Zsolt Simon
- * Contributor(s): Gilles Rayrat
+ * Contributor(s): Gilles Rayrat, Marc Herbert
*/
#ifndef PARAMETERSTATEMENT_HPP_
#define PARAMETERSTATEMENT_HPP_
@@ -109,84 +109,113 @@
throw (DriverException, UnexpectedException);

/**
- * Sets a parameter to a boolean value. The driver converts this to a SQL
- * BIT value when it sends it to the database.
+ * This JDBC call will be forwarded to the JDBC driver of the
+ * backend(s) of a sequoia controller. Some type conversions of the
+ * value may happen on the way (at different places) when called
+ * with a argument of a type different from the corresponding java
+ * type.
+ *
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
*/
- void setBoolean(const int parameterIndex, const bool x)
+ template <typename CParamType>
+ void setBoolean(int parameterIndex, const CParamType& x)
throw (DriverException, UnexpectedException);

/**
- * Sets a parameter to a Java byte value.
+ * @see #setBoolean()
+ *
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
*/
- void setByte(const int parameterIndex, const java_byte x)
+ template <typename CParamType>
+ void setByte(int parameterIndex, const CParamType& x)
throw (DriverException, UnexpectedException);

/**
- * Sets a parameter to a short value. The driver converts this to a SQL
- * SMALLINT value when it sends it to the database.
+ * @see #setBoolean()
+ *
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
*/
- void setShort(const int parameterIndex, const short x)
+ template <typename CParamType>
+ void setShort(int parameterIndex, const CParamType& x)
throw (DriverException, UnexpectedException);

/**
- * Sets a parameter to an int value. The driver converts this to a SQL
- * INTEGER value when it sends it to the database.
+ * @see #setBoolean()
+ *
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
*/
- void setInt(const int parameterIndex, const int x)
+ template <typename CParamType>
+ void setInt(int parameterIndex, const CParamType& x)
throw (DriverException, UnexpectedException);

/**
- * Sets a parameter to a long value. The driver converts this to a SQL
- * BIGINT value when it sends it to the database.
+ * @see #setBoolean()
+ *
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
*/
- void setLong(const int parameterIndex, const long long x)
+ template <typename CParamType>
+ void setLong(int parameterIndex, const CParamType& x)
throw (DriverException, UnexpectedException);

/**
- * Sets a parameter to a float value. The driver converts this to a SQL
- * FLOAT value when it sends it to the database.
+ * @see #setBoolean()
+ *
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
*/
- void setFloat(const int parameterIndex, const float x)
+ template <typename CParamType>
+ void setFloat(int parameterIndex, const CParamType& x)
throw (DriverException, UnexpectedException);

/**
- * Sets a parameter to a double value. The driver converts this to a SQL
- * DOUBLE value when it sends it to the database.
+ * @see #setBoolean()
+ *
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
*/
- void setDouble(const int parameterIndex, const double x)
+ template <typename CParamType>
+ void setDouble(int parameterIndex, const CParamType& x)
throw (DriverException, UnexpectedException);

/**
- * Sets a parameter to a BigDecimal value. The driver converts this
- * to a SQL NUMERIC value when it sends it to the database.
+ * @see #setBoolean()
+ *
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
*/
- void setBigDecimal(const int parameterIndex, const
BigDecimal &x)
+ template <typename CParamType>
+ void setBigDecimal(int parameterIndex, const CParamType
&x)
throw (DriverException, UnexpectedException);

/**
- * Sets a parameter to string value. The driver converts this to a SQL
- * VARCHAR or LONGVARCHAR value (depending on the arguments size relative to
- * the driver's limits on VARCHARs) when it sends it to the database.
+ *
+ * Warning:
+ * setString (i, L"foo");
+ *
+ * does not compile with gcc 4.0.2 because it searches the following
instantiation:
+ * setString < wchar_t *> (int parameterIndex, const wchar_t *
const& x);
+ *
+ * which cannot exist. So you have to invoke the pointed-to-const instance:
+ * setString <const wchar_t *> (int parameterIndex, const wchar_t *
const& x);
+ *
+ * using a explicit instantiation like this:
+ * setString <const wchar_t *> (i, L"foo");
+ *
+ * Or you can use this std::wstring alternative:
+ * setString (i, std::wstring(L"foo");
+ *
+ * @see #setBoolean()
+ *
* @param parameterIndex the first parameter is 1...
* @param x the parameter value
*/
- void setString(const int parameterIndex, const
std::wstring &x)
+ template <typename CParamType>
+ void setString(int parameterIndex, const CParamType &x)
throw (DriverException, UnexpectedException);

/**
@@ -230,7 +259,8 @@
* Actually stores the IN parameter into parameters String array. Called by
* most setXXX() methods.
* @param paramIndex the index into the inString
- * @param typeTag type of the parameter
+ * @param typeTag the JDBC call that will be used by the controller
+ * @param value the parameter
* @exception DriverException if something goes wrong
*/
template <class T> void set(const int paramIndex, const std::wstring
&typeTag,
@@ -260,3 +290,12 @@

} //namespace CarobNS
#endif /*PARAMETERSTATEMENT_HPP_*/
+
+
+/*
+ * Local Variables:
+ * c-file-style: "bsd"
+ * c-basic-offset: 2
+ * indent-tabs-mode: nil
+ * End:
+ */
Index: carob/src/ParameterStatement.cpp
diff -u carob/src/ParameterStatement.cpp:1.17
carob/src/ParameterStatement.cpp:1.18
--- carob/src/ParameterStatement.cpp:1.17 Mon Jan 30 12:06:27 2006
+++ carob/src/ParameterStatement.cpp Mon Jan 30 22:46:17 2006
@@ -375,68 +375,133 @@
}


-// Don't add any code in here, use template specializations
-// above. CAROB-55: We may deprecate these methods in the future in
-// profit of the underlying templates
-
-void ParameterStatement::setBoolean(const int parameterIndex, const bool x)
+template<typename CParamType> void
+ParameterStatement::setBoolean(int parameterIndex, const CParamType& x)
throw (DriverException, UnexpectedException)
{
- set<bool>(parameterIndex, BOOLEAN_TAG, x);
+ set<CParamType>(parameterIndex, BOOLEAN_TAG, x);
}

-void ParameterStatement::setByte(const int parameterIndex, const java_byte x)
+template<typename CParamType> void
+ParameterStatement::setByte(int parameterIndex, const CParamType& x)
throw (DriverException, UnexpectedException)
{
- set<java_byte>(parameterIndex, BYTE_TAG, x);
+ set<CParamType>(parameterIndex, BYTE_TAG, x);
}

-void ParameterStatement::setShort(const int parameterIndex, const short x)
+template<typename CParamType> void
+ParameterStatement::setShort(int parameterIndex, const CParamType& x)
throw (DriverException, UnexpectedException)
{
- set<short>(parameterIndex, SHORT_TAG, x);
+ set<CParamType>(parameterIndex, SHORT_TAG, x);
}

-void ParameterStatement::setInt(const int parameterIndex, const int x)
+template<typename CParamType> void
+ParameterStatement::setInt(int parameterIndex, const CParamType& x)
throw (DriverException, UnexpectedException)
{
- set<int>(parameterIndex, INTEGER_TAG, x);
+ set<CParamType>(parameterIndex, INTEGER_TAG, x);
}

-void ParameterStatement::setLong(const int parameterIndex, const long long x)
+template<typename CParamType> void
+ParameterStatement::setLong(int parameterIndex, const CParamType& x)
throw (DriverException, UnexpectedException)
{
- set<long long>(parameterIndex, LONG_TAG, x);
+ set<CParamType>(parameterIndex, LONG_TAG, x);
}

-void ParameterStatement::setFloat(const int parameterIndex, const float x)
+template<typename CParamType> void
+ParameterStatement::setFloat(int parameterIndex, const CParamType& x)
throw (DriverException, UnexpectedException)
{
- set<float>(parameterIndex, FLOAT_TAG, x);
+ set<CParamType>(parameterIndex, FLOAT_TAG, x);
}

-void ParameterStatement::setDouble(const int parameterIndex, const double x)
+template<typename CParamType> void
+ParameterStatement::setDouble(int parameterIndex, const CParamType& x)
throw (DriverException, UnexpectedException)
{
- set<double>(parameterIndex, DOUBLE_TAG, x);
+ set<CParamType>(parameterIndex, DOUBLE_TAG, x);
}

-void ParameterStatement::setBigDecimal(const int parameterIndex, const
BigDecimal &x)
+template<typename CParamType> void
+ParameterStatement::setBigDecimal(int parameterIndex, const CParamType& x)
throw (DriverException, UnexpectedException)
{
- set<wstring>(parameterIndex, BIG_DECIMAL_TAG, x); // FIXME: should be
set<BigDecimal>, else explain
+ set<CParamType>(parameterIndex, BIG_DECIMAL_TAG, x);
}

-void ParameterStatement::setString(const int parameterIndex, const
std::wstring &x)
+template<typename CParamType> void
+ParameterStatement::setString(int parameterIndex, const CParamType& x)
throw (DriverException, UnexpectedException)
{
- set<wstring>(parameterIndex, STRING_TAG, x);
+ set<CParamType>(parameterIndex, STRING_TAG, x);
}

+
+/*
+ * Explicit instantiation of supported/approved setters
+ */
+
+/*
+ * 1. First the zero-converting setters. The C-types instantiated here
+ * are bit-compatible with the corresponding java type that will be
+ * deserialized by the controller.
+ *
+ */
+
+template void
+ParameterStatement::setBoolean<bool>(int parameterIndex, const bool& x);
+template void
+ParameterStatement::setByte<int8_t>(int parameterIndex, const int8_t& x);
+template void
+ParameterStatement::setShort<int16_t>(int parameterIndex, const int16_t& x);
+template void
+ParameterStatement::setInt<int32_t>(int parameterIndex, const int32_t& x);
+template void
+ParameterStatement::setLong<int64_t>(int parameterIndex, const int64_t& x);
+template void
+ParameterStatement::setFloat<float>(int parameterIndex, const float& x);
+template void
+ParameterStatement::setDouble<double>(int parameterIndex, const double& x);
+// template void // TODO
+// ParameterStatement::setBigDecimal<BigDecimal>(int parameterIndex, const
BigDecimal& x);
+template void
+ParameterStatement::setString<std::wstring>(int parameterIndex, const
std::wstring& x);
+template void // for convenience. See limitation in .hpp doxygen
+ParameterStatement::setString<const wchar_t *>(int parameterIndex, const
wchar_t * const& x);
+
+
+/*
+ * 2. Then the "sstream-converting" setters. Add new lines here only
+ * if you really understand what you are doing. -- MH.
+ *
+ * Related:
+ * - "ODBC Programmer's Reference: Converting Data from C to SQL Data Types"
+ *
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odbc/htm/odbcconverting_data_from_c_to_sql_data_types.asp>
+ * - Sun's "Getting Started" JDBC online guide, chapter "Mapping SQL and Java
Types"
+ * <http://java.sun.com/j2se/1.4.2/docs/guide/jdbc/getstart/mapping.html>
+ */
+
+/*
+ * Unfortunately we currently lose the original type, and the controller
+ * cannot/does not make the difference between:
+ * "setFloat<float>(f1)" vs "setFloat<otherType>(convertedf2)"
+ * Ideally we would be much more transparent than that, performing NO
+ * type conversion at all and letting the backend driver doing it
+ * alone by himself.
+ */
+
+// Current semantic: "true".equalsIgnoreCase("xxxx")
+// See: java.lang.Boolean#toBoolean()
+template void
+ParameterStatement::setBoolean<std::wstring>(int parameterIndex, const
std::wstring& x);
+
+
/*
* Local Variables:
* c-file-style: "bsd"
- * c-basic-offset: 2
+ * c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation

Home | advertise | OSDir is an inevitable website. super tiny logo