[ 
https://issues.apache.org/jira/browse/CAY-1734?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13440292#comment-13440292
 ] 

Malcolm Edgar commented on CAY-1734:
------------------------------------

One issue I have been facing is the NuoDB JDBC drivers strict typing with the 
PreparedStatement method setObject : 
http://docs.oracle.com/javase/1.4.2/docs/api/java/sql/PreparedStatement.html#setObject(int,
 java.lang.Object, int)

The first case I hit with this was converting a Java Boolean value into a 
database INTEGER value via setObject(). Some relational databases such as 
Oracle don't have support the the SQL BOOLEAN data type, so in our database 
schema we use the INTEGER to store boolean values and rely on Cayenne / JDBC 
driver to handle to marshal these values in and out of storage. This strategy 
has worked for the MySQL, Oracle and SQL Server JDBC drivers, but not with the 
NuoDB driver.

The work around for this was to handle this marshaling in the Cayenne 
BooleanType class, by adding an Type.INTEGER switch below:

    public void setJdbcObject(
            PreparedStatement st,
            Object val,
            int pos,
            int type,
            int precision) throws Exception {

        if (val == null) {
            st.setNull(pos, type);
        }
        else if (type == Types.BIT || type == Types.BOOLEAN) {
            boolean flag = Boolean.TRUE.equals(val);
            st.setBoolean(pos, flag);
        }
        else if (type == Types.INTEGER) {
            int intVal = Boolean.TRUE.equals(val) ? 1 : 0;
            st.setInt(pos, intVal);
        }
        else {
            st.setObject(pos, val, type);
        }
    }

The next related issue was with passing PK string values into Cayenne queries 
where the underlying database data type was a BIGINT.  While this is arguably 
not very type safe, the Cayenne API's don't prevent this, and the MySQL, Oracle 
and SQL Server JDBC drivers have no problem marshalling numeric string values 
into BIGINT values. An example NuoDB exception stack is provided below:

java.lang.String cannot be cast to java.lang.Long
 at com.nuodb.jdbc.ValueLong.<init>(ValueLong.java:28)
 at com.nuodb.jdbc.RemPreparedStatement.setObject(RemPreparedStatement.java:655)
 at com.nuodb.jdbc.RemPreparedStatement.setObject(RemPreparedStatement.java:644)

This issue could be addressed in a number of ways:
* changed to NuoDB driver
* modify the Cayenne CharType to marshal the value into the correct JDBC type
* update calling application code to marshal value into the matching Java/JDBC 
type

While the Boolean conversion could be arguably handled with Cayenne 
BooleanType, I think using CharType to marshal string values into arbitrary 
JDBC type is more problematic, and probably should not be the role of this 
class.
                
> Add NuoDB database support
> --------------------------
>
>                 Key: CAY-1734
>                 URL: https://issues.apache.org/jira/browse/CAY-1734
>             Project: Cayenne
>          Issue Type: Improvement
>          Components: Core Library, Modeler
>            Reporter: Malcolm Edgar
>            Assignee: Malcolm Edgar
>             Fix For: 3.0.3, 3.1B2
>
>
> Add support for NuoDB database (https://www.nuodb.com/)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to