}
@SuppressWarnings("unchecked")
@Override
public final List<T> findByExample(T example) {
Criteria criteria = Criteria.forClass(_clazz);
PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(_clazz);
for (PropertyDescriptor descriptor : descriptors) {
String propName = descriptor.getName();
if (propName.equals(Identifiable.PROP_ID)) {
continue;
}
if (propName.equals(Activable.PROP_ACTIVE)) {
continue;
}
if (propName.equals(Defaultable.PROP_DEFAULT)) {
continue;
}
if (propName.equals(Undeletable.PROP_DELETED)) {
// always get item is not hidden
criteria.add(Restrictions.eq(Undeletable.PROP_DELETED, new Boolean(false)));
continue;
}
Method method = descriptor.getReadMethod();
if (!method.isAnnotationPresent(Column.class) && !method.isAnnotationPresent(Basic.class)) {
continue;
}
Object value = null;
try {
method.setAccessible(true);
value = method.invoke(example);
} catch (IllegalArgumentException e) {
continue;
} catch (IllegalAccessException e) {
continue;
} catch (InvocationTargetException e) {
continue;
}
if (value == null) {
continue;
}
criteria.add(Restrictions.eq(propName, value));
}
if (example instanceof Inheritable) {
if (((Inheritable) example).getParent() == null) {
criteria.add(Restrictions.isNull(Inheritable.PROP_PARENT));
} else {
criteria.add(Restrictions.eq(Inheritable.PROP_PARENT, ((Inheritable) example).getParent()));
}
}
return findByCriteria(criteria);
}