The solution requires Java 5 as generics and some other features are being used.
Here are just a few code snippets of how it can be used.
Various syntax examples:
Its just a special API interface that let you work with Apache Cayenne in very easy way.
EntityManager em;
// create and save object
Contact contact=em.create(Contact.class);
em.saveChanges();
// find object by id
Contact contact=em.findById(Contact.class, id);
// find object by property
Contact contact=em.findFirstByProperty (Contact.class, "username", form.getFieldValue("username"));
// find many objects by property
List contacts=em.findAllByProperty(Contact.class, "subdomain.name", form.getFieldValue("subdomain"));
// find objects based on user defined query
List contacts=em.findAllByQuery(
Contact.class,
Query.where("subdomain = $subdomain and age > $age")
.param("subdomain", current_user.getSubdomain())
.param("age",18)
.order("lastname",true)
.offset(200)
.limit(10)
.include(Contact.ROLE_ARRAY_PROPERTY)
);
I can share the code if someone find it usefull.
Žádné komentáře:
Okomentovat