I have a situation where I have several different input formats that
ultimately need to construct a List<Map<String,Object>> and at some
point I will need to write out the same datatype as well. Classic
serialization.
The input source could be a proprietary formatted config file, XML, a
Database, and so on.
I have in my mind that somehow implementing the Serializable interface
on my own subclasses of List an Map (implementing the writeObject()
and readObject()) respectively is what I am looking for.
Problem is though, it wants me to write to a stream -- in the case of
files, this isn't a problem but in the case of a Database it seems a
stretch to refer to a DB connection as some kinda stream (although not
an impossible stretch). And, I can't control what stream is passed to
those methods
Perhaps the better way would be to implement my own In/Out stream for
the different sources, and if it's and object of form List<map>, then
write out approrpriately. Then again, the writeInt/etc doesn't make
sense in the case of a DB because it is keyed. Only writeObject/
ReadObject has real meaning and only if it's the form I need
So, in summary: I need to load data from multiple sources and
reconstitute an object, then at some point turn it around and write it
back out.
I am looking for some ideas on this -- I would like to use the built
in Java facilities to do it
Christian Bongiorno
http://christian.bongiorno.org
Daniel Pitts - 25 Sep 2007 22:08 GMT
> I have a situation where I have several different input formats that
> ultimately need to construct a List<Map<String,Object>> and at some
[quoted text clipped - 28 lines]
>
> Christian Bongiornohttp://christian.bongiorno.org
Serialization and databases don't mix well. Look into a ORM solution
if you want to persist your java objects into a database.
I suggest Hibernate or Ibatis.
There are also utilities that will help you save object graph to an
XML file, but I don't have as much experience with those.
Lew - 25 Sep 2007 23:44 GMT
> Serialization and databases don't mix well. Look into a ORM solution
> if you want to persist your java objects into a database.
[quoted text clipped - 3 lines]
> There are also utilities that will help you save object graph to an
> XML file, but I don't have as much experience with those.
The Java Persistence API would likely be useful, too.

Signature
Lew
Roedy Green - 26 Sep 2007 01:35 GMT
>The Java Persistence API would likely be useful, too.
Did you mean by that PersistenceDelegate or Preferences?
Preferences stores stuff in the registry is a very fluffy format. So
you don't get the safety of backup of a true database.
See http://mindprod.com/jgloss/persistence.html
http://mindprod.com/jgloss/preferences.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
Lew - 26 Sep 2007 02:09 GMT
>> The Java Persistence API would likely be useful, too.
>
> Did you mean by that PersistenceDelegate or Preferences?
No, neither.
> Preferences stores stuff in the registry is a very fluffy format. So
> you don't get the safety of backup of a true database.
Not what I was discussing.
> See http://mindprod.com/jgloss/persistence.html
> http://mindprod.com/jgloss/preferences.html
I'm talking about
<http://java.sun.com/javaee/5/docs/tutorial/doc/bnbpy.html>
> The Java Persistence API provides an object/relational mapping
> facility to Java developers for managing relational data in Java applications.

Signature
Lew
Daniel Pitts - 26 Sep 2007 06:03 GMT
> > Serialization and databases don't mix well. Look into a ORM solution
> > if you want to persist your java objects into a database.
[quoted text clipped - 8 lines]
> --
> Lew
Hibernate 3.20 is a superset of the Java Persistence API.
Sideswipe - 06 Oct 2007 01:49 GMT
Yes, well I would love to go to Hibernate but unfortunately I am
dealing with legacy code and no one has any experience with hibernate
but me. It's frustrating. Also, the data doesn't necessarily come from
a database. It may come from a config file or XML
Daniel Pitts - 06 Oct 2007 18:13 GMT
> Yes, well I would love to go to Hibernate but unfortunately I am
> dealing with legacy code and no one has any experience with hibernate
> but me. It's frustrating. Also, the data doesn't necessarily come from
> a database. It may come from a config file or XML
Well, Hibernate doesn't prevent you for loading for elsewhere.
In any case, I find it useful to separate out the reading/writing from
the type itself. There are JavaBean serializers that will write/read
XML (I think they're standard). Or you can write your own DAO (Data
Access Object). Many people associate DAO's with databases, but it is
just as appropriate for file-stored data. You would have a different
implementation of the DAO for DB vs Config vs XML.
Hope this helps,
Daniel.

Signature
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
Roedy Green - 26 Sep 2007 01:22 GMT
On Tue, 25 Sep 2007 18:17:07 -0000, Sideswipe
<christian.bongiorno@gmail.com> wrote, quoted or indirectly quoted
someone who said :
>I have a situation where I have several different input formats that
>ultimately need to construct a List<Map<String,Object>> and at some
>point I will need to write out the same datatype as well. Classic
>serialization.
Maybe what you want is a POD.
See http://mindprod.com/jgloss/pod.html
I used one called ObjectStore.
See http://mindprod.com/jgloss/objectstore.html

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com