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

Reply via email to