Strange behaviour @ postgres

Andre Burkovski <[email protected]> Fri, 21 May 2010 13:01:00 +0200
Newsgroups gmane.comp.java.orm.simpleorm
Message-ID <[email protected]>
Hi,

i have some difficulties with a workflow. The task is simple: retrieval 
of an java.sql.Array Object and through that the actual array object. At 
the End of the post is a simple example.

First i encountered some strange behaviour, when i switched from 
postgres driver 8.1.414 (jdbc3) to 8.4.701 (jdbc3)
The code below only works for 8.1 driver. For 8.4 one get a strange 
exception. I was able to track it down to
AbstractJdbc2Array.java where in 8.4 a connection is required to be open.
I posted this issue @jdbc.postgres mailinglist here:
http://archives.postgresql.org/pgsql-jdbc/2010-05/msg00037.php

Now i'm stuck.

Actually, if one comments out the commented code for both drivers the 
results are positive and without error.
I think it is strange if one have to retrieve an Object for every 
already queried data (and cached! The debugger show the right contents 
of the array!)

The expected behaviour is when the DataSet is detached and connection is 
closed, that all the descriptive data is available. This is not the case 
for arrays when using 8.4 diver version.

Any suggestions?

Greetings
Andre


I created the following SSCCE:
The code below works for postgres jdbc driver version 8.1 but not 8.4.

@SQL

create table testable (
    someid int primary key,
    somearr int[]
);
insert into testable values (1,'{1,2,3}');
select * from testable;



@Java
TestTableObject.java

public class TestTableObject extends SRecordInstance {

     private static final long    serialVersionUID    = 1L;

     public static final SRecordMeta<TestTableObject>  META =
         new SRecordMeta<TestTableObject>(TestTableObject.class,
         "testtable");

     public static final SFieldInteger ID = new SFieldInteger(META, 
"someid", SFieldFlags.SPRIMARY_KEY);


     public static final SFieldObject SOME_ARRAY = new 
SFieldObject(META, "somearr");


     protected Array getArray(SFieldMeta field) {
         Object o = getObject(field);
         Array result = null;
         if (o instanceof Array) {
             result = (Array) o;
         } else if (o != null) {
             throw new SException("The object " + o + " for the given 
field " + field + " is not an instance of java.sql.Array ") {
                 private static final long    serialVersionUID    = 1L;
             };
         }
         return result;

     }


     /**
      * The return type depends on the driver used. In 8.4 the array has 
the Integer object type; in 8.1 int type.
      * For demonstration we return just an Object. One can always 
perform an instanceof
      * operator on int[] or Integer[]
      */

     public Object getSomeArray() {
         try {
             return getArray(SOME_ARRAY).getArray();
         } catch (SQLException e) {
             e.printStackTrace();
         }
         return null;
     }

     @Override public SRecordMeta<?>  getMeta() {
         return META;
     }
}


TestTableSSCCE.java

     public static void main(String[] args) throws Exception {

         Class.forName("org.postgresql.Driver");

         Connection con = DriverManager.getConnection(
                 "jdbc:postgresql://localhost/postgres",
                 "user",
                 "password");

         SSessionJdbc ses = SSessionJdbc.open(con, "Arrays test");

         ses.begin();

         SQuery<TestTableObject>  query = new 
SQuery<TestTableObject>(TestTableObject.META);

         SQueryResult<TestTableObject>  result = ses.query(query);


         /*
          * The commented code below works for both implementations
          * This means that once the array is retrieved 8.4 drivers use
          * the cached data
          */

//        for (TestTableObject tto : result) {
//            System.out.println(tto.getSomeArray());
//        }


         ses.commitAndDetachDataSet();

         ses.close();


         /*
          * If the above code is commented then the following will only work
          * for 8.1 drivers.
          */

         for (TestTableObject tto : result) {
             System.out.println(tto.getSomeArray());
         }

     }



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/SimpleORM/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/SimpleORM/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/