One of the dangers of having delete/save/update in a DAO is that most
people familiar with DAOs may not realize that more than the specified
object will be deleted/saved/updated since Cayenne works on the
context-level and potentially everything in the context will get committed.
 I don't mind fetch* type methods, but shy away from branding things as
DAOs to avoid confusion.

mrg



On Tue, Dec 18, 2012 at 1:01 PM, John Huss <johnth...@gmail.com> wrote:

> I would welcome the addition of some DAO (data access object) methods in
> the entity templates that make it even easier to query the DB.  For example
> I have these defined in my entity template:
>
> public static List<Invoice> fetchAll(ObjectContext ec);
>
> public static List<Invoice> fetchAll(ObjectContext ec, List<? extends
> Ordering> sortOrderings);
>
> public static List<Invoice> fetch(ObjectContext ec, Expression qualifier);
>
> public static List<Invoice> fetch(ObjectContext ec, Expression qualifier,
> List<? extends Ordering> sortOrderings);
>
> public static List<Invoice> fetch(ObjectContext ec, Expression qualifier,
> List<? extends Ordering> sortOrderings, int fetchLimit);
>
> public static Invoice fetchOne(ObjectContext ec, Expression qualifier);
>
> This is something EOF/WebObjects does that I find useful.  However, I would
> lean towards creating an inner class for this along with a singleton called
> DAO and putting these methods there.  So you would do
> Invoice.DAO.fetchAll(...)
>
> But I don't really need .delete() or .save()
>
>
> On Mon, Dec 17, 2012 at 5:09 PM, Дробеня Илья <droben...@tut.by> wrote:
>
> > Hi!
> >
> > Now Cayenne usage in projects looks like data mapper (Fowler), but all
> > entities has dependecy on Cayenne (interface Persistent). For data mapper
> > it is disadvantage.
> > But it is acceptable for ActiveRecord. This is my first reason to propose
> > this solution. Second reason - we may simple add all posibile methods in
> > entities - because entities generates by modeler.
> >
> > Then my proposal - useful API that will be insert in each entity on
> > generation. For example, in this case we may use cayenne such -
> >
> > Role curRole = Role.newInstance();
> > curRole.setAuthority("MyAuthority");
> > curRole.save();
> >
> > Role curRole = Role.get(id);
> > curRole.delete();
> >
> > List<Role> roles = Role.findBy("firstName", name, "surname", lastName);
> > List<Role> roles = Role.findAll("birthDate < $date and name = $name",
> > "date", new Date(), "name", lastName);
> >
> > How we may to implement this?
> > Need to allow use Cayenne in classic mode without active record. Then we
> > may create separate set of templates and add its to Cayenne jars.
> >
> > Then for implement its we need:
> > 1. Create separate set of templates with needed methods
> > 2. Create singleton - that will provide access to ObjectContext
> > 3. Maybe add to modeler option for generate custom queries to entities
> > instead of add its to UntitledMap
> >
> > My questions to you:
> > 1. What do you think - do this functionality will really useful? Are you
> > ready to use it in your projects?
> > 2. Which methods you want to see in API?
> >
> > Thanks!
> > --
> > Ilya Drabenia
> > Software Engineer, ObjectStyle LLC
> >
>

Reply via email to