Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2015-Present Entando Inc. (http://www.entando.com) All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.agiletec.aps.system.common;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Utility Class for searching operation on db. This class presents utility
* method for searching on db table throw Field search filter.
*
* @author E.Santoboni
*/
@SuppressWarnings(value = {"serial", "rawtypes"})
public abstract class AbstractSearcherDAO extends AbstractDAO {
private static final Logger logger = LoggerFactory.getLogger(AbstractSearcherDAO.class);
private static final String DEFAULT_LIKE_CLAUSE = "LIKE ? ";
private String likeClause;
private String dataSourceClassName;
protected List searchId(FieldSearchFilter[] filters) {
Connection conn = null;
List idList = new ArrayList();
PreparedStatement stat = null;
ResultSet result = null;
try {
conn = this.getConnection();
stat = this.buildStatement(filters, false, false, conn);
result = stat.executeQuery();
while (result.next()) {
String id = result.getString(this.getMasterTableIdFieldName());
if (!idList.contains(id)) {
idList.add(id);
}
}
} catch (Throwable t) {
logger.error("Error while loading the list of IDs", t);
throw new RuntimeException("Error while loading the list of IDs", t);
} finally {
closeDaoResources(result, stat, conn);
}
return idList;
}
protected Integer countId(FieldSearchFilter[] filters) {
Connection conn = null;
int count = 0;
PreparedStatement stat = null;
ResultSet result = null;
try {
conn = this.getConnection();
stat = this.buildStatement(filters, true, false, conn);
result = stat.executeQuery();
if (result.next()) {
count = result.getInt(1);
}
} catch (Throwable t) {
logger.error("Error while loading the count of IDs", t);
throw new RuntimeException("Error while loading the count of IDs", t);
} finally {
closeDaoResources(result, stat, conn);
}
return count;
}
protected FieldSearchFilter[] addFilter(FieldSearchFilter[] filters, FieldSearchFilter filterToAdd) {
int len = 0;
if (filters != null) {
len = filters.length;
}
FieldSearchFilter[] newFilters = new FieldSearchFilter[len + 1];
for (int i = 0; i < len; i++) {
newFilters[i] = filters[i];
}
newFilters[len] = filterToAdd;
return newFilters;
}
protected PreparedStatement buildStatement(FieldSearchFilter[] filters, boolean isCount, boolean selectAll, Connection conn) {
String query = this.createQueryString(filters, isCount, selectAll);
logger.trace("{}", query);
PreparedStatement stat = null;
try {
stat = conn.prepareStatement(query);
int index = 0;
index = this.addMetadataFieldFilterStatementBlock(filters, index, stat);
} catch (Throwable t) {
logger.error("Error while creating the statement", t);
throw new RuntimeException("Error while creating the statement", t);
}
return stat;
}
/**
* 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(FieldSearchFilter[] filters, int index, PreparedStatement stat) throws Throwable {
if (filters == null) {
return index;
}
for (FieldSearchFilter filter : filters) {
if (filter.getKey() != null) {
index = this.addObjectSearchStatementBlock(filter, index, stat);
}
}
return index;
}
/**
* 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(FieldSearchFilter filter, int index, PreparedStatement stat) throws SQLException {
if (filter.isNullOption()) {
return index;
}
if (filter.getAllowedValues() != null && filter.getAllowedValues().size() > 0) {
List