Grokbase Groups Cayenne dev July 2013
FAQ
[taking to dev]
On Jul 11, 2013, at 10:21 PM, John Huss (JIRA) wrote:

Support in ConverterFactory is for integration with Jersey where I am using PropertyUtils.setProperty to convert from strings like "2013-05-01 00:00:00.000" to DateTimes, etc. I'm currently doing this beforehand and it works fine, but moving it into ConverterFactory will help reduce duplication. I swear I've got at least 4 instances of this conversion in various parts of apps. It's not really something that has to be in Cayenne itself though; I'm just looking to create options.
Interesting, I just wrote an entire JAX-RS engine on top of Cayenne (closed source). With Joda date encoders coincidentally.

The architecture is really simple. Request URL defines the root entity and related entities (actually it is more fine grained - it can define the result up to individual attributes if needed). This information is matched with Cayenne mapping, and at the select stage is used to build SelectQuery prefetches, and later when generating response - to build a hierarchical encoder tree. Root encoder and result list are placed in the response object, and it then handed to a special MessageBodyWriter that generates JSON.

Encoders are external to Cayenne and are not using PropertyUtils. I have encoders for DataObjects (that access properties via 'readProperty'). And for "simple" properties, I have my own encoder map, that includes singleton Encoders for Joda classes.

I wish we had a similar framework as open source. LOE creating it (once we nailed the URL protocol details) was not that big, just a couple of weeks. I guess the most tricky part is to provide a flexible user-facing (REST) protocol. My example was designed with Sencha/ExtJS in mind. Someone else may probably want a different flavor. Although the basic operations are going to be the same no matter what the client is.

Anyways, just wanted to mention this… Maybe someone will like the idea, so that we can somehow start collaborating on it.

Andrus

Search Discussions

  • John Huss at Jul 11, 2013 at 8:16 pm
    We have something that we could probably contribute. There some rough
    edges though since it is was built to meet our specific uses. I don't have
    much experience with other projects in this space (like Rails) so it's hard
    to know what is the best/standard way for doing things.

    The trickiest thing we found to deal with was avoiding infinite loops in
    serialization due to reverse relationships. If your model allows you to
    choose one side of the relationship in every case then you can avoid it,
    but if you need it to be dynamic it becomes more painful.



    On Thu, Jul 11, 2013 at 2:53 PM, Andrus Adamchik [taking to dev]
    On Jul 11, 2013, at 10:21 PM, John Huss (JIRA) wrote:

    Support in ConverterFactory is for integration with Jersey where I am
    using PropertyUtils.setProperty to convert from strings like "2013-05-01
    00:00:00.000" to DateTimes, etc. I'm currently doing this beforehand and
    it works fine, but moving it into ConverterFactory will help reduce
    duplication. I swear I've got at least 4 instances of this conversion in
    various parts of apps. It's not really something that has to be in Cayenne
    itself though; I'm just looking to create options.

    Interesting, I just wrote an entire JAX-RS engine on top of Cayenne
    (closed source). With Joda date encoders coincidentally.

    The architecture is really simple. Request URL defines the root entity and
    related entities (actually it is more fine grained - it can define the
    result up to individual attributes if needed). This information is matched
    with Cayenne mapping, and at the select stage is used to build SelectQuery
    prefetches, and later when generating response - to build a hierarchical
    encoder tree. Root encoder and result list are placed in the response
    object, and it then handed to a special MessageBodyWriter that generates
    JSON.

    Encoders are external to Cayenne and are not using PropertyUtils. I have
    encoders for DataObjects (that access properties via 'readProperty'). And
    for "simple" properties, I have my own encoder map, that includes singleton
    Encoders for Joda classes.

    I wish we had a similar framework as open source. LOE creating it (once we
    nailed the URL protocol details) was not that big, just a couple of weeks.
    I guess the most tricky part is to provide a flexible user-facing (REST)
    protocol. My example was designed with Sencha/ExtJS in mind. Someone else
    may probably want a different flavor. Although the basic operations are
    going to be the same no matter what the client is.

    Anyways, just wanted to mention this… Maybe someone will like the idea, so
    that we can somehow start collaborating on it.

    Andrus
  • Andrus Adamchik at Jul 12, 2013 at 6:14 am

    On Jul 11, 2013, at 11:16 PM, John Huss wrote:

    The trickiest thing we found to deal with was avoiding infinite loops in
    serialization due to reverse relationships. If your model allows you to
    choose one side of the relationship in every case then you can avoid it,
    but if you need it to be dynamic it becomes more painful.
    In my implementation I don't serialize based on the DataMap alone. There has to be a path tree describing the result associated with a given request (either inferred from request parameters, or created server-side for a given REST method). It solves this problem completely by providing constraints on the subgraph returned to the caller.

    FWIW this is not unlike serialization Cayenne is doing for ROP, that is also explicitly bound by a similar tree inferred from the query prefetches.

    Andrus

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdev @
categoriescayenne
postedJul 11, '13 at 7:54p
activeJul 12, '13 at 6:14a
posts3
users2
websitecayenne.apache.org

2 users in discussion

Andrus Adamchik: 2 posts John Huss: 1 post

People

Translate

site design / logo © 2022 Grokbase