[JIRA] Created: (CAY-988) CayenneObjectManager - alternative API for using Apache Cayenne

From: David Marko (JIRA) ("David)
Date: Sun Feb 24 2008 - 05:10:16 EST

  • Next message: David Marko (JIRA): "[JIRA] Updated: (CAY-988) CayenneObjectManager - alternative API for using Apache Cayenne"

    CayenneObjectManager - alternative API for using Apache Cayenne

                     Key: CAY-988
                     URL: https://issues.apache.org/cayenne/browse/CAY-988
                 Project: Cayenne
              Issue Type: Improvement
        Affects Versions: 3.0
                Reporter: David Marko
                Assignee: Andrus Adamchik
                Priority: Trivial

    a few months ago a wrote about creating alternative approach to using Apache Cayenne. Actualy I use Cayenne with Click Framework and following scenario came from pratice on several projects. The main idea is to use Cayenne as very stable background(engine) but alter API to something closer to ActiveRecord like approach. The result is CayenneObjectManager that implementes alternative API that, as result, generate standard Cayenne queries.

    CayenneObjectManager API assumes Java5 as generics are used extensively and is tested with latest Apache Cayenne M3. Entire package is rather small and is intended to be extended by other methods. I'm not very experienced JAVA developer so one thing I would like to ask is, if someone can review the concept and correct some potencial mistakes or contribute with some ideas etc. I'm open for correction.


    For quick example just image you have a simple table with Role names and imagine how simply you can work with this.
    // Load role object by its name
    COManager manager=new COManagerImpl();
    // init is based on usage scenario. This can be used in standalone app. for e.g. web app usage, the context is inititalized automaticly from DataContext.getThreadDataContext();
    Role role_admin=co_manager.find(Role.class).byProperty("name").EQUALS("admin").first();

    // all roles from allowed list as key-pair for checkbox field
    Map<String,String> roles=co_manager.find(Role.class).byProperty(Role.NAME_PROPERTY).IN(allowed_roles).to_pairs("name", "id");

    CayenneObjectsManager - alternative API for working with Apache Cayenne subsystem
    // Available use cases
    // find one item by ID

    // find all items by property and given condition

    // find first item by property and given condition

    // find all items

    // find all items by based on CayenneObjectsQuery
    co_manager.find(Class).allByQuery(COQuery query)

    // find all firts item by based on CayenneObjectsQuery
    co_manager.find(Class).allByQuery(COQuery query).firts()
    //find all selected items as key-pairs available e.g. for checkbox field

    // aggregate functions
    co_manager.aggregate(Class).count("property", COQuery query)
    co_manager.aggregate(Class).sum("property", COQuery query)
    co_manager.aggregate(Class).avg("property", COQuery query)
    co_manager.aggregate(Class).count("property", Query.where("year >$year").addParam("year", 2003));

    // common actions

    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 : Sun Feb 24 2008 - 05:11:05 EST