FAQ
Dear all,

I'm implementing a new project using Cayenne based on some code currently
running in a live application built using WO/EOF/Wonder (see
https://github.com/wardle/rsterminology)

Migrating to Cayenne has been very straightforward so far.

Within Project Wonder, there are a large number of utility methods to make
it easy to deal with qualifiers (expressions) and perform database agnostic
batch operations without using SQL.

ERXEOControlUtilities.objectCountWithQualifier(ec, entityName, qual);

which takes a qualifier (essentially a Cayenne expression) and an entity
and performs a count.

ERXEOAccessUtilities.insertRow(ec, entityName, data);

which takes a context, entity name and dictionary (a map) and inserts the
values without having to deal with entities (a bit like a DataRow I think
in Cayenne?).

For example, we have
ERXEOAccessUtilities.updateRowsDescribedByQualifier(ec, entityName, qual,
data);
which takes a context, entity name, qualifier and a dictionary of data and
updates rows based on that data.

Are there equivalent utility methods within Cayenne please? I have found
SQLTemplate but, it looks as if I'd have to hand-tune the expression to
update and get embroiled in creating to logic to understand the DbEntity
and its properties in order to map a map. It feels as if I'm probably
fighting the framework and so normally that suggests I'm approaching it
wrong!

Advice for a WO-er appreciated.

Best wishes,

Mark

Search Discussions

  • Michael Gentry at Jun 12, 2016 at 11:30 pm
    Hi Mark,

    For doing a count (and a few others), you can try using this:

    https://github.com/mrg/cbe/blob/master/FetchingObjects/Aggregates/src/main/java/cbe/fetching/utilities/AggregateUtils.java

    Example usage code is here:

    https://github.com/mrg/cbe/blob/master/FetchingObjects/Aggregates/src/main/java/cbe/fetching/Aggregates.java

    For your insert/update rows, I think you'll have to write that yourself.
    If your "data" dictionary/map object uses keys that match your entity's
    attribute names, You can probably loop over they keys and write the values
    using CayenneDataObject's writeProperty() method (CDO is a superclass of
    your actual entities).

    mrg


    On Sun, Jun 12, 2016 at 4:53 PM, Mark Wardle wrote:

    Dear all,

    I'm implementing a new project using Cayenne based on some code currently
    running in a live application built using WO/EOF/Wonder (see
    https://github.com/wardle/rsterminology)

    Migrating to Cayenne has been very straightforward so far.

    Within Project Wonder, there are a large number of utility methods to make
    it easy to deal with qualifiers (expressions) and perform database agnostic
    batch operations without using SQL.

    ERXEOControlUtilities.objectCountWithQualifier(ec, entityName, qual);

    which takes a qualifier (essentially a Cayenne expression) and an entity
    and performs a count.

    ERXEOAccessUtilities.insertRow(ec, entityName, data);

    which takes a context, entity name and dictionary (a map) and inserts the
    values without having to deal with entities (a bit like a DataRow I think
    in Cayenne?).

    For example, we have
    ERXEOAccessUtilities.updateRowsDescribedByQualifier(ec, entityName, qual,
    data);
    which takes a context, entity name, qualifier and a dictionary of data and
    updates rows based on that data.

    Are there equivalent utility methods within Cayenne please? I have found
    SQLTemplate but, it looks as if I'd have to hand-tune the expression to
    update and get embroiled in creating to logic to understand the DbEntity
    and its properties in order to map a map. It feels as if I'm probably
    fighting the framework and so normally that suggests I'm approaching it
    wrong!

    Advice for a WO-er appreciated.

    Best wishes,

    Mark
  • Hugi Thordarson at Jun 13, 2016 at 1:51 pm
    Hi Mark,

    here are also a few utility methods we use to execute aggregate methods, updated for Cayenne 4.0.M4.

    https://bitbucket.org/loftfar/jambalaya/src/6b952b8f65e6ac45b77e16bcfa5e97f2b9a27245/src/main/java/jambalaya/CayenneUtils.java?at=master&fileviewer=file-view-default

    Cheers,
    - hugi


    On 12. jún. 2016, at 23:30, Michael Gentry wrote:

    Hi Mark,

    For doing a count (and a few others), you can try using this:

    https://github.com/mrg/cbe/blob/master/FetchingObjects/Aggregates/src/main/java/cbe/fetching/utilities/AggregateUtils.java

    Example usage code is here:

    https://github.com/mrg/cbe/blob/master/FetchingObjects/Aggregates/src/main/java/cbe/fetching/Aggregates.java

    For your insert/update rows, I think you'll have to write that yourself.
    If your "data" dictionary/map object uses keys that match your entity's
    attribute names, You can probably loop over they keys and write the values
    using CayenneDataObject's writeProperty() method (CDO is a superclass of
    your actual entities).

    mrg


    On Sun, Jun 12, 2016 at 4:53 PM, Mark Wardle wrote:

    Dear all,

    I'm implementing a new project using Cayenne based on some code currently
    running in a live application built using WO/EOF/Wonder (see
    https://github.com/wardle/rsterminology)

    Migrating to Cayenne has been very straightforward so far.

    Within Project Wonder, there are a large number of utility methods to make
    it easy to deal with qualifiers (expressions) and perform database agnostic
    batch operations without using SQL.

    ERXEOControlUtilities.objectCountWithQualifier(ec, entityName, qual);

    which takes a qualifier (essentially a Cayenne expression) and an entity
    and performs a count.

    ERXEOAccessUtilities.insertRow(ec, entityName, data);

    which takes a context, entity name and dictionary (a map) and inserts the
    values without having to deal with entities (a bit like a DataRow I think
    in Cayenne?).

    For example, we have
    ERXEOAccessUtilities.updateRowsDescribedByQualifier(ec, entityName, qual,
    data);
    which takes a context, entity name, qualifier and a dictionary of data and
    updates rows based on that data.

    Are there equivalent utility methods within Cayenne please? I have found
    SQLTemplate but, it looks as if I'd have to hand-tune the expression to
    update and get embroiled in creating to logic to understand the DbEntity
    and its properties in order to map a map. It feels as if I'm probably
    fighting the framework and so normally that suggests I'm approaching it
    wrong!

    Advice for a WO-er appreciated.

    Best wishes,

    Mark
  • Mark Wardle at Jun 16, 2016 at 3:03 pm
    Thank you both Hugi and Michael - very useful.

    It seems to me that this kind of aggregation functionality requirement is common enough to warrant adding a @sum/@avg/@max/@count to the Property much like in EOF? Perhaps I’ll create myself a custom superclass template for my entities...

    Mark
    On 13 Jun 2016, at 14:51, Hugi Thordarson wrote:

    Hi Mark,

    here are also a few utility methods we use to execute aggregate methods, updated for Cayenne 4.0.M4.

    https://bitbucket.org/loftfar/jambalaya/src/6b952b8f65e6ac45b77e16bcfa5e97f2b9a27245/src/main/java/jambalaya/CayenneUtils.java?at=master&fileviewer=file-view-default

    Cheers,
    - hugi


    On 12. jún. 2016, at 23:30, Michael Gentry wrote:

    Hi Mark,

    For doing a count (and a few others), you can try using this:

    https://github.com/mrg/cbe/blob/master/FetchingObjects/Aggregates/src/main/java/cbe/fetching/utilities/AggregateUtils.java

    Example usage code is here:

    https://github.com/mrg/cbe/blob/master/FetchingObjects/Aggregates/src/main/java/cbe/fetching/Aggregates.java

    For your insert/update rows, I think you'll have to write that yourself.
    If your "data" dictionary/map object uses keys that match your entity's
    attribute names, You can probably loop over they keys and write the values
    using CayenneDataObject's writeProperty() method (CDO is a superclass of
    your actual entities).

    mrg


    On Sun, Jun 12, 2016 at 4:53 PM, Mark Wardle wrote:

    Dear all,

    I'm implementing a new project using Cayenne based on some code currently
    running in a live application built using WO/EOF/Wonder (see
    https://github.com/wardle/rsterminology)

    Migrating to Cayenne has been very straightforward so far.

    Within Project Wonder, there are a large number of utility methods to make
    it easy to deal with qualifiers (expressions) and perform database agnostic
    batch operations without using SQL.

    ERXEOControlUtilities.objectCountWithQualifier(ec, entityName, qual);

    which takes a qualifier (essentially a Cayenne expression) and an entity
    and performs a count.

    ERXEOAccessUtilities.insertRow(ec, entityName, data);

    which takes a context, entity name and dictionary (a map) and inserts the
    values without having to deal with entities (a bit like a DataRow I think
    in Cayenne?).

    For example, we have
    ERXEOAccessUtilities.updateRowsDescribedByQualifier(ec, entityName, qual,
    data);
    which takes a context, entity name, qualifier and a dictionary of data and
    updates rows based on that data.

    Are there equivalent utility methods within Cayenne please? I have found
    SQLTemplate but, it looks as if I'd have to hand-tune the expression to
    update and get embroiled in creating to logic to understand the DbEntity
    and its properties in order to map a map. It feels as if I'm probably
    fighting the framework and so normally that suggests I'm approaching it
    wrong!

    Advice for a WO-er appreciated.

    Best wishes,

    Mark

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedJun 12, '16 at 8:53p
activeJun 16, '16 at 3:03p
posts4
users3
websitecayenne.apache.org

People

Translate

site design / logo © 2019 Grokbase