[ 
https://issues.apache.org/cayenne/browse/CAY-988?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

David Marko updated CAY-988:
----------------------------

    Attachment: co_manager.zip

> 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
>         Attachments: co_manager.zip
>
>
> Hello,
> 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. 
> David
> 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(); 
> co_manager.setContext(DataContext.createDataContext());
> 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
> co_manager.find(Class).byId(id) 
> // find all items by property and given condition
> co_manager.find(Class).byProperty("property").EQUALS(value) 
> // find first item by property and given condition
> co_manager.find(Class).byProperty("property").BETWEEN(value1,value2).first() 
> co_manager.find(Class).byProperty("property").LIKE(value).first() 
> co_manager.find(Class).byProperty("property").IN(range).first() 
> // find all items
> co_manager.find(Class).all() 
> // 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
> co_manager.find(Class).byProperty("property").EQUAL(value1).to_pairs(key,value)
> // aggregate functions
> co_manager.aggregate(Class).count("property") 
> co_manager.aggregate(Class).count("property", COQuery query) 
> co_manager.aggregate(Class).sum("property") 
> co_manager.aggregate(Class).sum("property", COQuery query) 
> co_manager.aggregate(Class).avg("property") 
> co_manager.aggregate(Class).avg("property", COQuery query) 
> co_manager.aggregate(Class).count("property", Query.where("year 
> >$year").addParam("year", 2003));
> // common actions
> co_manager.create(Class) 
> co_manager.save()

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to