* If this is an attribute
*/
if (column.indexOf('[') != -1) {
try {
String attrName = column.substring(column.indexOf('[')+2, column.indexOf(']')-1);
AbstractAttribute attr = attributesClass.newInstance();
attr.setName(attrName);
attr.setStringValue((String)var);
addAttributeFilter(cq, builder, from, Arrays.asList(attr), NamingConstants.PARENT, preList);
}
catch (Exception ex) {
throw (new EJBException(ex));
}
continue;
}
if (column.indexOf('.') != -1) {
/*
* This is not simple query because this field could become a reason for table join
*/
String[] fields = column.split("\\.");
/*
* This is simple join. This filter allowed only simple joins
*/
if (fields.length == 2) {
/*
* Get main attribute
*/
Path attr = from.get(fields[0]);
/*
* If filterable column is id then just get desired object by it's identifier
*/
if (fields[1].equals(NamingConstants.ID)) {
try {
BigInteger id = BigInteger.valueOf(NumberFormat.getInstance().parse(var.toString()).longValue());
Object value = getEntityManager().find(attr.getJavaType(), id);
preList.add(builder.equal(from.get(fields[0]), value));
}
catch (ParseException ex) {
Logger.getLogger(AbstractFacade.class.getName()).log(Level.SEVERE, null, ex);
}
}
else {
/*
* Create subquery to find by attribute
*/
Subquery subquery = cq.subquery(attr.getJavaType());
Root fromAttr = subquery.from(attr.getJavaType());
subquery.select(fromAttr.get(NamingConstants.ID));
if (var instanceof String && ((String)var).contains("%")) {
/*
* This is a like query