You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Peter Karich <pe...@yahoo.de> on 2007/03/08 23:39:05 UTC

Store BitSet

Hallo!

I want to store (and read) a BitSet into (from) the database.
The long[] array is private and I don't want to hack it by using
reflection or even store this as String with toString :-)

So, how can I transform any object to a byte[] array and vice versa??

Is there any further documentation on that subject? Because I can't find
useful informations in javadocs and google results.
Does anyone has a simple example of reading+writing an arbitrary object?

Thank you,
Peter Karich.

		
___________________________________________________________ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de

Re: Store BitSet

Posted by Tore Halset <ha...@pvv.ntnu.no>.
Hello Peter.

On Mar 8, 2007, at 23:39, Peter Karich wrote:

> I want to store (and read) a BitSet into (from) the database.
> The long[] array is private and I don't want to hack it by using
> reflection or even store this as String with toString :-)

It depend on how you want to store it in the database. PostgreSQL has  
a bit string datatype

http://www.postgresql.org/docs/8.2/interactive/datatype-bit.html

Then you create a Extended Type to tell cayenne how to store and  
fetch this data type in your application

http://cayenne.apache.org/doc20/extended-types.html

Depending on your jdbc-driver, you may have to encode the bits as a  
String in your Extended Type before sending it to the database. This  
is currently the case for PostgreSQL, but this may change in the future.

> So, how can I transform any object to a byte[] array and vice versa??

Serialization, but your data will then only be usable from java. You  
can not use it in a (db-side) query and so on.

Good luck!

Regards,
  - Tore.