Note that you can return more data than the client asks for, that's
what the JPA sample code does.  At some point you might consider
adding a bean-filter that nulls out entries that the client did not
ask for.

On Mon, Dec 13, 2010 at 1:04 AM, franck tankoua <[email protected]> wrote:
> Agreed Indeed.
> I think for people who are in the same configuration as me  ( one DB +
> Hibernate (lazy)) This could be a generic way of doing things.
>
> Thanks
>
> On Sun, Dec 12, 2010 at 10:13 PM, Paul Lindner <[email protected]> wrote:
>
>> When a person object is a composite of data from multiple backend
>> services you want the fields up front.  This allows you to optimize
>> data access and may allow you to avoid expensive queries.
>>
>>
>> On Fri, Dec 10, 2010 at 1:13 AM, franck tankoua <[email protected]>
>> wrote:
>> > Hi all.
>> >
>> > I have a shindig container with hibernate. the probem is that for me it
>> is
>> > more easy to do something like "select u from users u" in JPQL, then
>> filter
>> > after using introspection.
>> >
>> > The interface PersonService for instance force us to handle the field in
>> > that method but I think we really don't need and this could be automated.
>> > Instead of this :
>> > public Future<RestfulCollection<Person>> getPeople(Set<UserId> userIds,
>> >            GroupId groupId, CollectionOptions collectionOptions,
>> >            Set<String> fields, SecurityToken token) throws
>> > ProtocolException
>> >
>> > what about having this ( without the set of fields) :
>> >
>> > public Future<RestfulCollection<Person>> getPeople(Set<UserId> userIds,
>> >            GroupId groupId, CollectionOptions collectionOptions,
>> > SecurityToken token) throws ProtocolException
>> >
>> > And  use something a  method like this  to select fields :
>> > {{{
>> >
>> > public static <T> T getFilteredBean(Set<String> field, T bean) {
>> >        if (field != null && !field.isEmpty()) {
>> >            try {
>> >                Object copiedBean = bean.getClass().getConstructor(new
>> > Class[] {}).newInstance(new Object[] {});
>> >                PropertyDescriptor[] properties = getBeanProperties(bean
>> >                        .getClass());
>> >                for (PropertyDescriptor prop : properties) {
>> >                    if (field.contains(prop.getName())) {
>> >                        try{
>> >                        Method readMethod = prop.getReadMethod();
>> >                        Method writeMethod = prop.getWriteMethod();
>> >                        Object value = readMethod.invoke(bean, new
>> Object[]
>> > {});
>> >                        writeMethod.invoke(copiedBean, new Object[] {
>> value
>> > });
>> >                        }catch(Exception e){
>> >                            logger.error("Failed to copy filtered
>> > Bean"+bean.getClass()+". Error while setting the property
>> "+prop.getName(),
>> > e);
>> >                        }
>> >                    }
>> >                }
>> >                return (T) copiedBean;
>> >            } catch (Exception e) {
>> >                logger.error("failed to copy filtered Bean ", e);
>> >            }
>> >        }
>> >        return bean;
>> >    }
>> >
>> > }}}
>> >
>> > --
>> > Franck
>> >
>>
>>
>>
>> --
>> Paul Lindner -- [email protected] -- linkedin.com/in/plindner
>>
>
>
>
> --
> Franck
>



-- 
Paul Lindner -- [email protected] -- linkedin.com/in/plindner

Reply via email to