Thanks to your help, i've made some progress in my exploration of RIFE's
persistance framework.
Here is concretely what i did :
An address class :
public class Address {
private int id;
private String addr1;
private String addr2;
private String addr3;
private String addr4;
private String zipCode;
private String city;
private String country;
...
(I will avoid you the getters/setters !)
An address DAO :
public class AddressDAO {
static final Logger logger = Logger.getLogger(AddressDAO.class);
static GenericQueryManager manager = GenericQueryManagerFactory
.getInstance(Datasources.getRepInstance().getDatasource("mysql"),
Address.class);
public static long insert(Address address) {
try {
manager.install();
} catch (Exception e) {
}
return manager.save(address);
}
}
A simple Element to test all this :
public class TestPersistance extends Element {
public static final Logger logger =
Logger.getLogger(TestPersistance.class);
public void processElement() throws EngineException {
Address adr = new Address();
adr.setAddr1("5 square des rosiers");
adr.setZipCode("75020");
adr.setCity("Paris");
adr.setCountry("France");
logger.debug(AddressDAO.insert(adr));
}
}
At this point, my feelings are : Wow ! Great ! My table is created with
no effort, no complex configuration ! (Even though i didn't find out how
to provide a different type than int for the primarykey).
And the save performed without problem ! Hum... Wait.... Actually there
is a big problem : my data were inserted in a weird way : the city in
place of zip code, and so on : only the primarykey is at the right place
! What did i miss ?
And what if i now want to put a Person bean, which of course has an
address ?
I tried something like :
public void processElement() throws EngineException {
Address adr = new Address();
adr.setAddr1("5 square des rosiers");
adr.setZipCode("75020");
adr.setCity("Paris");
adr.setCountry("France");
Person person=new Person();
person.setFirstName("laki");
person.setLastName("roganovic");
person.setDateOfBirth(new Date(1970,11,29));
person.setGender(Gender.male);
person.setAddress(adr);
logger.debug(AddressDAO.insert(adr));
PersonDAO.insert(person);
}
But only obtained :
"Setting a typed parameter is not supported for index '1', target type
'testpackage.beans.Address and value '[EMAIL PROTECTED]'.
What is the right way to handle associations between beans ?
After looking at my code, i'm not sure about the necessity of having a
DAO for each bean, while i could call a "save" or "load" when i need
them, for example directly in an element. But it would imply that i call
something like
GenericQueryManager manager = GenericQueryManagerFactory
.getInstance(Datasources.getRepInstance().getDatasource("mysql"),
Address.class);
before each operation...
Is there a simpler way to access a manager in elements?
Thanks to anyone who had the patience to read this long mail !
_______________________________________________
Rife-users mailing list
[email protected]
http://lists.uwyn.com/mailman/listinfo/rife-users