List attributesFilter,
String joinColumn,
List<Predicate> preList)
{
Subquery<A> subquery = cq.subquery(attributesClass);
Root fromAttr = subquery.from(attributesClass);
subquery.select(fromAttr.get(joinColumn).get(NamingConstants.ID));
subquery.groupBy(fromAttr.get(joinColumn).get(NamingConstants.ID));
subquery.having(builder.equal(builder.count(fromAttr.get(joinColumn).get(NamingConstants.ID)), attributesFilter.size()));
Predicate wherePredicates = null;
for (Object a : attributesFilter) {
if (!(a instanceof AbstractAttribute))
continue;
AbstractAttribute attr = (AbstractAttribute)a;
Predicate pp = null;
switch (attr.getDataType()) {
case STRING:
pp = builder.and (
builder.equal(fromAttr.get(NamingConstants.NAME), attr.getName()),
builder.equal(
fromAttr.get(NamingConstants.STRING_VALUE),
attr.getStringValue())
);
break;
case NUMBER:
pp = builder.and (
builder.equal(fromAttr.get(NamingConstants.NAME), attr.getName()),
builder.equal(
fromAttr.get(NamingConstants.NUMBER_VALUE),
attr.getNumberValue())
);
break;
case DATE:
pp = builder.and (
builder.equal(fromAttr.get(NamingConstants.NAME), attr.getName()),
builder.equal(
fromAttr.get(NamingConstants.DATE_VALUE),
attr.getDateValue())
);
break;
}