laki roganovic schrieb:
I'm a total noob with RIFE, and very impressed by its features.
Finding that using hibernate for persistence is as efficient as
killing a mosquito with a bazooka, i'm looking at RIFE's built in
persistence, and it seems to be exactly what i need.
My first question is about design : coming from Hibernate, i'm used to
Data Access Objects.
Porting it to RIFE with my new project, i have an Address bean, so i
made an AddressDAO, extending DbQueryManager. Is it the right way to
do this, or is it completely dumb ?
Hmm, I wanted to comment on RIFE's persistence framework for a while
now. It is much easier than Hibernate and I doubt that Hibernate is
useful for anything but making development more complex. The persistence
framework I like most is Ammentos. It is far from being perfect, but the
only framework I know that has the feeling I'm looking for. It is like
900 kB and you create your beans/entities (or whatever you want to call
it) like this:
@PersistentEntity
class Machine
{
@PersistentField(automatic=true)
private String id;
@PersistentField
private String model;
private String getModel() {
return model;
}
private void setModel(String model) {
this.model = model.toUpperCase();
}
}
done.
So you have a machine table with an primary key called id and one field
called model.
Now, if you want your machine to have references to "MachinePart"
objects, you do this:
// add this field to Machine.java ...
@PersistentList(query="machineId=?", cascadeOnDelete=true)
private List<MachinePart> machineParts;
... and create a new file called MachineParts.java:
class MachinePart
{
@PersistentField(automatic=true)
private String id;
@PersistentField(fieldName = "machineId")
private Machine machine;
}
And if you need a machine from the database you can get it using:
Machine machine = Ammentos.load(Machine.class, "my_machine_id");
// or use some more complex query that is similar to RIFE, Hibernate et al.
(Actually, in this area I favor RIFE's approach over Ammentos' QueryFilter.)
// If you want to create a new machine part, create it ...
MachinePart mp = new MachinePart();
//... and add it to your machine ...
// if you created a getter for the list
machine.getMachineParts().add(mp);
// or, if you've defined a custom function to add parts
machine.addPart(mp);
// To store something in the database, do:
Ammentos.save(machine);
Getters and setters are optional for Ammentos. So you don't need to add
them for the primary key for example or for the list in Machine. You
only define those accessors that you need in you application. That leads
to much nicer APIs on your entities.
Please note that I'm not the big expert in persistence, so I may be
totally wrong in every regard. But on the other hand, maybe this
provides some ideas to make persistence easier in RIFE. I did not look
at RIFE constraints in-depth yet, but from what I saw, references to
other objects are more complex than in this example.
Again, Ammentos is not perfect, but simply better than anything I've
used yet.
Looking forwards to your opinions.
Best regards,
Stefan :)
_______________________________________________
Rife-users mailing list
[email protected]
http://lists.uwyn.com/mailman/listinfo/rife-users