Re: Cayenne ActiveRecord like interface

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Tue Oct 09 2007 - 09:56:40 EDT

  • Next message: Andrus Adamchik: "Re: Cayenne ActiveRecord like interface"

    Looks nice. Any chance you'd like to dotae your work to Cayenne and
    work with Cayenne developers to package it in a form suitable for
    inclusion in the project?

    Thanks
    Andrus

    On Oct 9, 2007, at 3:21 PM, David Marko wrote:
    > Hello,
    > I like a ROR ActiveRecord a lot and I decided to create a special
    > interface for
    > Cayenne to let me work easier in most cases. I borrowed some ideas
    > and created a
    > wrapper for Apache Cayenne. Instead a common DAO like scenario of
    > using services
    > for each model, I can now use one EntityManager that serves for all
    > models.
    >
    > The solution requires Java 5 as generics and some other features
    > are beeing
    > used. Here are just a few code snippets of how it can be used.
    >
    > Syntax examples:
    > 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",
    > "subdomain");
    >
    > // find objects based on user defined query
    > List contacts=em.findAllByQuery(Contact.class,
    > Query.select().where("subdomain = $subdomain and age > $age")
    > .param("subdomain", "agh")
    > .param("age", 18)
    > .order("lastname",true)
    > .offset(200)
    > .limit(10)
    > .include(Contact.ROLE_ARRAY_PROPERTY));
    >
    > // count items per invoice
    > List counts=em.count(Item.class, "invoice_id")
    >
    > Its just a special API interface that let you work with Apache
    > Cayenne in very
    > easy way. Of course there is still a place for DAO for more
    > advanced situations.
    > Is anyone else working on some similar approach? I would like to share
    > experiences/ideas.
    >
    > David
    >
    >



    This archive was generated by hypermail 2.0.0 : Tue Oct 09 2007 - 09:57:17 EDT