/**
  * Add to the statement a filter on a attribute.
  *
  * @param filter The filter on the attribute to apply in the statement.
  * @param index The last index used to associate the elements to the statement.
  * @param stat The statement where the filters are applied.
  * @return The last used index.
  * @throws SQLException In case of error.
  */
 protected int addObjectSearchStatementBlock(
     EntitySearchFilter filter, int index, PreparedStatement stat) throws SQLException {
   if (filter.isAttributeFilter() && null != filter.getLangCode()) {
     stat.setString(++index, filter.getLangCode());
   }
   return super.addObjectSearchStatementBlock(filter, index, stat);
 }
 private void addAttributeOrderQueryBlock(
     String searchTableNameAlias, StringBuffer query, EntitySearchFilter filter, String order) {
   if (order == null) {
     order = "";
   }
   Object object = filter.getValue();
   if (object == null) {
     object = filter.getStart();
   }
   if (object == null) {
     object = filter.getEnd();
   }
   if (null == object) {
     query
         .append(searchTableNameAlias)
         .append(".textvalue ")
         .append(order)
         .append(", ")
         .append(searchTableNameAlias)
         .append(".datevalue ")
         .append(order)
         .append(", ")
         .append(searchTableNameAlias)
         .append(".numvalue ")
         .append(order);
     return;
   }
   query
       .append(searchTableNameAlias)
       .append(".")
       .append(this.getAttributeFieldColunm(object))
       .append(" ");
   query.append(order);
 }
 protected boolean verifyLikeFieldFilters(ResultSet result, EntitySearchFilter[] likeFieldFilters)
     throws SQLException {
   boolean verify = true;
   for (int i = 0; i < likeFieldFilters.length; i++) {
     EntitySearchFilter filter = likeFieldFilters[i];
     if (filter.getKey() == null || !filter.isLikeOption() || !this.isForceTextCaseSearch()) {
       continue;
     }
     String fieldName = null;
     if (filter.isAttributeFilter()) {
       fieldName = this.getAttributeFieldColunm(filter) + i;
     } else {
       fieldName = this.getTableFieldName(filter.getKey());
     }
     String value = result.getString(fieldName);
     if (null != filter.getValue()) {
       verify = this.checkText((String) filter.getValue(), value);
       if (!verify) {
         break;
       }
     } else if (filter.getAllowedValues() != null && filter.getAllowedValues().size() > 0) {
       List<Object> allowedValues = filter.getAllowedValues();
       verify = this.verifyLikeAllowedValuesFilter(value, allowedValues);
       if (!verify) {
         break;
       }
     }
   }
   return verify;
 }
 protected boolean addAttributeLangQueryBlock(
     String searchTableName,
     StringBuffer query,
     EntitySearchFilter filter,
     boolean hasAppendWhereClause) {
   if (filter.isAttributeFilter() && null != filter.getLangCode()) {
     hasAppendWhereClause = this.verifyWhereClauseAppend(query, hasAppendWhereClause);
     query.append(searchTableName).append(".langcode = ? ");
   }
   return hasAppendWhereClause;
 }
 /**
  * Add to the statement the filters on the entity metadata.
  *
  * @param filters the filters to add to the statement.
  * @param index The current index of the statement.
  * @param stat The statement.
  * @return The current statement index, eventually incremented by filters.
  * @throws Throwable In case of error.
  */
 protected int addMetadataFieldFilterStatementBlock(
     EntitySearchFilter[] filters, int index, PreparedStatement stat) throws Throwable {
   if (filters == null) {
     return index;
   }
   for (int i = 0; i < filters.length; i++) {
     EntitySearchFilter filter = filters[i];
     if (filter.getKey() != null && !filter.isAttributeFilter()) {
       index = this.addObjectSearchStatementBlock(filter, index, stat);
     }
   }
   return index;
 }
 protected boolean appendOrderQueryBlocks(
     EntitySearchFilter[] filters, StringBuffer query, boolean ordered) {
   if (filters == null) {
     return ordered;
   }
   for (int i = 0; i < filters.length; i++) {
     EntitySearchFilter filter = filters[i];
     if (null != filter.getKey() && null != filter.getOrder() && !filter.isNullOption()) {
       if (!ordered) {
         query.append("ORDER BY ");
         ordered = true;
       } else {
         query.append(", ");
       }
       if (filter.isAttributeFilter()) {
         String tableName = this.getEntitySearchTableName() + i;
         this.addAttributeOrderQueryBlock(tableName, query, filter, filter.getOrder());
       } else {
         String fieldName = this.getTableFieldName(filter.getKey());
         query
             .append(this.getEntityMasterTableName())
             .append(".")
             .append(fieldName)
             .append(" ")
             .append(filter.getOrder());
       }
     }
   }
   return ordered;
 }
 protected boolean appendMetadataFieldFilterQueryBlocks(
     EntitySearchFilter[] filters, StringBuffer query, boolean hasAppendWhereClause) {
   if (filters == null) {
     return hasAppendWhereClause;
   }
   for (int i = 0; i < filters.length; i++) {
     EntitySearchFilter filter = filters[i];
     if (filter.getKey() != null && !filter.isAttributeFilter()) {
       hasAppendWhereClause =
           this.addMetadataFieldFilterQueryBlock(filter, query, hasAppendWhereClause);
     }
   }
   return hasAppendWhereClause;
 }
 /**
  * Add the attribute filters to the statement.
  *
  * @param filters The filters on the entity filters to insert in the statement.
  * @param index The last index used to associate the elements to the statement.
  * @param stat The statement where the filters are applied.
  * @return The last used index.
  * @throws SQLException In case of error.
  */
 protected int addAttributeFilterStatementBlock(
     EntitySearchFilter[] filters, int index, PreparedStatement stat) throws SQLException {
   if (filters == null) {
     return index;
   }
   for (int i = 0; i < filters.length; i++) {
     EntitySearchFilter filter = filters[i];
     if (filter.getKey() != null && filter.isAttributeFilter()) {
       stat.setString(++index, filter.getKey());
       index = this.addObjectSearchStatementBlock(filter, index, stat);
     }
   }
   return index;
 }
 private String getAttributeFieldColunm(EntitySearchFilter filter) {
   Object object = null;
   if (null != filter.getAllowedValues() && filter.getAllowedValues().size() > 0) {
     object = filter.getAllowedValues().get(0);
   } else if (null != filter.getValue()) {
     object = filter.getValue();
   } else if (null != filter.getStart()) {
     object = filter.getStart();
   } else if (null != filter.getEnd()) {
     object = filter.getEnd();
   } else {
     return null;
   }
   return this.getAttributeFieldColunm(object);
 }
 protected boolean appendFullAttributeFilterQueryBlocks(
     EntitySearchFilter[] filters, StringBuffer query, boolean hasAppendWhereClause) {
   if (filters != null) {
     for (int i = 0; i < filters.length; i++) {
       EntitySearchFilter filter = filters[i];
       if (filter.getKey() == null || !filter.isAttributeFilter()) {
         continue;
       }
       if (filter.isNullOption()) {
         hasAppendWhereClause =
             this.appendNullAttributeFilterQueryBlocks(filter, query, hasAppendWhereClause);
       } else {
         hasAppendWhereClause =
             this.appendValuedAttributeFilterQueryBlocks(filter, i, query, hasAppendWhereClause);
       }
     }
   }
   return hasAppendWhereClause;
 }
 private StringBuffer createMasterSelectQueryBlock(
     EntitySearchFilter[] filters, boolean selectAll) {
   String masterTableName = this.getEntityMasterTableName();
   StringBuffer query = new StringBuffer("SELECT ").append(masterTableName).append(".");
   if (selectAll) {
     query.append("* ");
   } else {
     query.append(this.getEntityMasterTableIdFieldName());
   }
   if (this.isForceTextCaseSearch() && filters != null) {
     String searchTableName = this.getEntitySearchTableName();
     for (int i = 0; i < filters.length; i++) {
       EntitySearchFilter filter = filters[i];
       if (!filter.isAttributeFilter() && filter.isLikeOption()) {
         String tableFieldName = this.getTableFieldName(filter.getKey());
         // check for id column already present
         if (!tableFieldName.equals(this.getMasterTableIdFieldName())) {
           query.append(", ").append(masterTableName).append(".").append(tableFieldName);
         }
       } else if (filter.isAttributeFilter() && filter.isLikeOption()) {
         String columnName = this.getAttributeFieldColunm(filter);
         query.append(", ").append(searchTableName).append(i).append(".").append(columnName);
         query.append(" AS ").append(columnName).append(i).append(" ");
       }
     }
   }
   query.append(" FROM ").append(masterTableName).append(" ");
   return query;
 }
 private boolean appendValuedAttributeFilterQueryBlocks(
     EntitySearchFilter filter, int index, StringBuffer query, boolean hasAppendWhereClause) {
   String searchTableNameAlias = this.getEntitySearchTableName() + index;
   hasAppendWhereClause = this.verifyWhereClauseAppend(query, hasAppendWhereClause);
   query.append(searchTableNameAlias).append(".attrname = ? ");
   hasAppendWhereClause =
       this.addAttributeLangQueryBlock(searchTableNameAlias, query, filter, hasAppendWhereClause);
   if (filter.isLikeOption() && this.isForceTextCaseSearch()) {
     return hasAppendWhereClause;
   }
   if (filter.getAllowedValues() != null && filter.getAllowedValues().size() > 0) {
     hasAppendWhereClause = this.verifyWhereClauseAppend(query, hasAppendWhereClause);
     List<Object> allowedValues = filter.getAllowedValues();
     for (int j = 0; j < allowedValues.size(); j++) {
       Object allowedValue = allowedValues.get(j);
       if (j == 0) {
         query.append(" ( ");
       } else {
         query.append(" OR ");
       }
       String operator = filter.isLikeOption() ? this.getLikeClause() : "= ? ";
       query
           .append(searchTableNameAlias)
           .append(".")
           .append(this.getAttributeFieldColunm(allowedValue))
           .append(" ");
       query.append(operator);
       if (j == (allowedValues.size() - 1)) {
         query.append(" ) ");
       }
     }
   } else if (filter.getValue() != null) {
     Object object = filter.getValue();
     String operator = filter.isLikeOption() ? this.getLikeClause() : "= ? ";
     hasAppendWhereClause =
         this.addAttributeObjectSearchQueryBlock(
             searchTableNameAlias,
             query,
             object,
             operator,
             hasAppendWhereClause,
             filter.getLangCode());
   } else {
     // creazione blocco selezione su tabella ricerca
     if (null != filter.getStart()) {
       hasAppendWhereClause =
           this.addAttributeObjectSearchQueryBlock(
               searchTableNameAlias,
               query,
               filter.getStart(),
               ">= ? ",
               hasAppendWhereClause,
               filter.getLangCode());
     }
     if (null != filter.getEnd()) {
       hasAppendWhereClause =
           this.addAttributeObjectSearchQueryBlock(
               searchTableNameAlias,
               query,
               filter.getEnd(),
               "<= ? ",
               hasAppendWhereClause,
               filter.getLangCode());
     }
     if (null == filter.getStart() && null == filter.getEnd()) {
       hasAppendWhereClause = this.verifyWhereClauseAppend(query, hasAppendWhereClause);
       query
           .append(" (")
           .append(searchTableNameAlias)
           .append(".datevalue IS NOT NULL OR ")
           .append(searchTableNameAlias)
           .append(".textvalue IS NOT NULL OR ")
           .append(searchTableNameAlias)
           .append(".numvalue IS NOT NULL) ");
     }
   }
   return hasAppendWhereClause;
 }