Foros de discusión

finder помогите придумать как

Juriy Rood, modificado hace 12 años.

finder помогите придумать как

New Member Mensajes: 2 Fecha de incorporación: 11/08/11 Mensajes recientes
Всем доброго времени суток,

Помогите придумать как такое реализовать, а то уже голову сломал

Допустим есть таблица
ID long
description String
UserID long
CreateDate Date
Done Boolean

Нужно дать пользователю возможность ставить фильтры по полям UserID, CreateDate, Done причем фильтры могут быть в разных вариациях

Как-то можно это реализовать через один файндер или только предусматривать все варианты использования фильтров? Или можент это как-то по другому реализовать?
Dmitriy Cheremnov, modificado hace 12 años.

Используйте DynamicQuery

New Member Mensajes: 16 Fecha de incorporación: 19/03/10 Mensajes recientes
Добрый день!

Как вариант - используйте DynamicQuery.
Сделайте 3 реализации метода: 1) возвращение getCount 2) возвращение списка с int start, int end, 3) возвращение всего списка.
Пример реализации 2):

public static List<Demand> getDemandList(Long demandId, Long userId,
Long organizationId, String name, String city, Long regionId,
Long countryId, Integer statusId, Long categoryId,
Long subCategoryId, int start, int end,
OrderByComparator orderByComparator) throws SystemException {
DynamicQuery query = prepareQuery(demandId, userId, organizationId,
name, city, regionId, countryId, statusId, categoryId,
subCategoryId);
@SuppressWarnings("unchecked")
List<Demand> list = DemandLocalServiceUtil.dynamicQuery(query, start,
end, orderByComparator);
return list;
}


private static DynamicQuery prepareQuery(Long demandId, Long userId,
Long organizationId, String name, String city, Long regionId,
Long countryId, Integer statusId, Long categoryId,
Long subCategoryId) {
DynamicQuery query = DynamicQueryFactoryUtil.forClass(Demand.class,
DEMAND_TABLE, DemandUtil.class.getClassLoader());
if (demandId != null) {
query.add(PropertyFactoryUtil.forName(DEMAND_ID_FIELD).eq(demandId));
}
if (userId != null) {
query.add(PropertyFactoryUtil.forName(USER_ID_FIELD).eq(userId));
}
.......
if (city != null) {
query.add(PropertyFactoryUtil.forName(CITY_FIELD).like(city));
}
return query;
}

Удачи!
Juriy Rood, modificado hace 12 años.

RE: Используйте DynamicQuery

New Member Mensajes: 2 Fecha de incorporación: 11/08/11 Mensajes recientes
Спасибо за совет.

Впринципе уже сам догадался и сделал через динамик квери emoticon