You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2004/08/19 10:11:27 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/platforms PlatformDefaultImpl.java
arminw 2004/08/19 01:11:27
Modified: src/java/org/apache/ojb/broker/platforms
PlatformDefaultImpl.java
Log:
fix issue with BigDecimal fields when using DB2 or Sybase.
More info see
http://nagoya.apache.org/eyebrowse/ReadMsg?listName=ojb-user@db.apache.org&msgNo=14113
Revision Changes Path
1.28 +41 -17 db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java
Index: PlatformDefaultImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/platforms/PlatformDefaultImpl.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- PlatformDefaultImpl.java 22 May 2004 09:55:33 -0000 1.27
+++ PlatformDefaultImpl.java 19 Aug 2004 08:11:27 -0000 1.28
@@ -15,13 +15,6 @@
* limitations under the License.
*/
-import org.apache.ojb.broker.PersistenceBrokerException;
-import org.apache.ojb.broker.accesslayer.JoinSyntaxTypes;
-import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
-import org.apache.ojb.broker.query.LikeCriteria;
-import org.apache.ojb.broker.util.logging.Logger;
-import org.apache.ojb.broker.util.logging.LoggerFactory;
-
import java.io.StringReader;
import java.sql.CallableStatement;
import java.sql.Connection;
@@ -32,13 +25,21 @@
import java.sql.Statement;
import java.sql.Types;
+import org.apache.ojb.broker.PersistenceBrokerException;
+import org.apache.ojb.broker.accesslayer.JoinSyntaxTypes;
+import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor;
+import org.apache.ojb.broker.query.LikeCriteria;
+import org.apache.ojb.broker.util.logging.Logger;
+import org.apache.ojb.broker.util.logging.LoggerFactory;
+
/**
* This class is a concrete implementation of <code>Platform</code>. Provides default implementations for all
* methods declared in <code>Platform</code>.
* It is intended as a vanilla implementation and as baseclass for
* platform specific implementations.
- * @author Thomas Mahler
+ *
* @version $Id$
+ * @author Thomas Mahler
*/
public class PlatformDefaultImpl implements Platform, JoinSyntaxTypes
{
@@ -56,6 +57,7 @@
* Sets platform information for if the jdbc driver/db combo support
* batch operations. Will only be checked once, then have same batch
* support setting for the entire session.
+ *
* @param conn
*/
protected void checkForBatchSupport(Connection conn)
@@ -140,7 +142,7 @@
*/
public void initializeJdbcConnection(JdbcConnectionDescriptor jcd, Connection conn) throws PlatformException
{
- if(jcd.getBatchMode()) checkForBatchSupport(conn);
+ if (jcd.getBatchMode()) checkForBatchSupport(conn);
switch (jcd.getUseAutoCommit())
{
case JdbcConnectionDescriptor.AUTO_COMMIT_IGNORE_STATE:
@@ -222,6 +224,26 @@
String s = (String) value;
ps.setCharacterStream(index, new StringReader(s), s.length());
}
+ /*
+ PATCH for BigDecimal truncation problem. Seems that several databases (e.g. DB2, Sybase)
+ has problem with BigDecimal fields if the sql-type was set. The problem was discussed here
+ http://nagoya.apache.org/eyebrowse/ReadMsg?listName=ojb-user@db.apache.org&msgNo=14113
+ A better option will be
+ <snip>
+ else if ((value instanceof BigDecimal) && (sqlType == Types.DECIMAL
+ || sqlType == Types.NUMERIC))
+ {
+ ps.setObject(index, value, sqlType,
+ ((BigDecimal) value).scale());
+ }
+ </snip>
+ But this way maxDB/sapDB does not work correct, so we use the most flexible solution
+ and let the jdbc-driver handle BigDecimal objects by itself.
+ */
+ else if(sqlType == Types.DECIMAL || sqlType == Types.NUMERIC)
+ {
+ ps.setObject(index, value);
+ }
else
{
ps.setObject(index, value, sqlType);
@@ -238,6 +260,7 @@
/**
* Get join syntax type for this RDBMS - one on of the constants from JoinSyntaxType interface
+ *
* @see Platform#getJoinSyntaxType
*/
public byte getJoinSyntaxType()
@@ -248,6 +271,7 @@
/**
* Override default ResultSet size determination (rs.last();rs.getRow())
* with select count(*) operation
+ *
* @see Platform#useCountForResultsetSize()
*/
public boolean useCountForResultsetSize()
@@ -302,13 +326,13 @@
{
// do nothing
}
-
+
/**
* @see org.apache.ojb.broker.platforms.Platform#bindPagingParametersFirst()
*/
public boolean bindPagingParametersFirst()
{
- return false;
+ return false;
}
/**
@@ -333,12 +357,12 @@
/**
* Answer the Character for Concatenation
- */
+ */
protected String getConcatenationCharacter()
{
return "||";
}
-
+
/**
* @see org.apache.ojb.broker.platforms.Platform#concatenate(java.lang.String[])
*/
@@ -351,7 +375,7 @@
StringBuffer buf = new StringBuffer();
String concatChar = getConcatenationCharacter();
-
+
for (int i = 0; i < theColumns.length; i++)
{
if (i > 0)
@@ -363,15 +387,15 @@
return buf.toString();
}
-
+
/**
* @see org.apache.ojb.broker.platforms.Platform#getEscapeClause(org.apache.ojb.broker.query.LikeCriteria)
*/
public String getEscapeClause(LikeCriteria aCriteria)
{
- String value = (String)aCriteria.getValue();
+ String value = (String) aCriteria.getValue();
char escapeChar = LikeCriteria.getEscapeCharacter();
-
+
if (value.indexOf(escapeChar) >= 0)
{
return " ESCAPE '" + escapeChar + "'";
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org