High performance bean translator / copier


have you considered using an ORM like Hibernate for example? Combined with JPA, the mapping can be pretty easy to setup…on the other hand i don't really know about the performances, it could be worst than Reflection in the end…

But that would worth a try.

Are you using jdbc in your DAO layer ?

What kind of database are you using?

Oh I do use hibernate for my database layer. The thing is, the DAO (Data Access Object) objects I use for my database layer contain database related stuff. I don't want the other layers of my application to have knowlegde of that database related stuff. This makes my layers loosely coupled, which is turn makes for better programming.

This does mean that I need to have a seperate type of objetc, VO (Value Object) objects. These contain just the data, no stuff that is related to anything layer specific. These I can transfer from one layer to the next without problems.

This is also true for the network layer with JGN. I can have these VO objects arive in the network layer, transform them to JGN Messages and send them across the network.

Transforming beans in this way is something I do a lot, and thus is a good place to try and tweak performance. Which is why I use these translators, they just instantiate a new object (cheap) and the use the getters and setters to straight copy the content (also cheap).

All this has nothing to do with which ORM I use, since those relate data to objects. I already have an object and need to transofrm one bean to another. This is a completely different type of activity.

That makes sense, but that's what Java Persistance API is made for : prevent adherence between the DAO layer and Business Objects.

Persistance mapping is declared in the BO with java annotations, so you can plug any JPA complient ORM (pretty much any up to date orm) and it will be able to populate your beans without the use of reflection.

How is hibernate doing from a performance point of view?

I'm not familiar with game production, and i wouldn't have imagined that an orm could be used…even a database.

I'm very interested in the subject.

I haven't used hibernate on a gameserver before either, but I have used in on high load web applications and with the correct caching etc. it works like a charm.

I haven't used that persistence api myself either, I'll have to read up on that one, see how it works. But if it is anything like the old bean utils, it uses reflection, which is slow as snails.

No JPA does not use reflection, it's like hibernate xml mapping, but directly in the java beans.

But forget about it, that was just a thought, you made yourself through the problem with a pretty clever solution.

Who cares about standards as long as your solution fits exactly to your needs?

Ah ok, you can also use JPA to transform one bean to another. From what I understood JPA was a framework used to store data from a bean in a persistant data store.