Re: [JIRA] Created: (CAY-877) ROR ActiveRecord like interface for Apache Cayenne

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Thu Oct 18 2007 - 07:32:30 EDT

  • Next message: Tore Halset: "TableBindingBuilder"

    David,

    not sure if you are on a dev list, so I am cc'ying to you directly.
    This looks nice. I think we can use it as an inspiration to build a
    utility class for querying the DB that we discussed before (can't
    find an archive link). Here is my assessment of what we need to do:

    * come up with the name of the new class(es) (EntityManager and Query
    are already reserved in Cayenne).
    * replace hardcoded SQLTemplates ("SELECT AVG($avg_field) as sum,
    $name as name FROM ROLE GROUP BY $name") with the generated EJBQL
    syntax.
    * we'd need to update it for Cayenne 3.0 (ObjectContext, Persistent
    instead of DataContext, DataObject)
    * as a part of the upcoming Java 5 switch of the trunk, maybe
    parameterize existing ObjectContext and Query.

    Thanks
    Andrus

    On Oct 9, 2007, at 10:08 PM, David Marko (JIRA) wrote:

    > ROR ActiveRecord like interface for Apache Cayenne
    > ---------------------------------------------------
    >
    > Key: CAY-877
    > URL: https://issues.apache.org/cayenne/browse/CAY-877
    > Project: Cayenne
    > Issue Type: New Feature
    > Affects Versions: 2.0 [STABLE]
    > Reporter: David Marko
    > Assignee: Andrus Adamchik
    > Priority: Minor
    >
    >
    > ROR ActiveRecord like interface for Cayenne. Solution tries to
    > bring alternative syntax for working with Apache Cayenne subsystem.
    > Though its working its still subject of discussion and improvement.
    > My idea is not to create other AR like ORM in JAVA but rather
    > create AR like interface for existing ORM. I expect discussion on
    > additional methods that will conform the concept.
    >
    > 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.
    >
    > Syntax examples:
    > EntityManager em=new EntityManager();
    > em.setContext(DataContext.createDataContext());
    >
    > // 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")
    >
    >
    >
    > --
    > This message is automatically generated by JIRA.
    > -
    > You can reply to this email to add a comment to the issue online.
    >
    >



    This archive was generated by hypermail 2.0.0 : Thu Oct 18 2007 - 07:32:59 EDT