String sortOrder,
String locale,
int offset,
int length) throws WebloggerException {
WeblogCategory cat = null;
if (StringUtils.isNotEmpty(catName) && website != null) {
cat = getWeblogCategoryByPath(website, catName);
if (cat == null) catName = null;
}
if (catName != null && catName.trim().equals("/")) {
catName = null;
}
List params = new ArrayList();
int size = 0;
StringBuffer queryString = new StringBuffer();
//queryString.append("SELECT e FROM WeblogEntry e WHERE ");
if (tags == null || tags.size()==0) {
queryString.append("SELECT e FROM WeblogEntry e WHERE ");
} else {
queryString.append("SELECT e FROM WeblogEntry e JOIN e.tags t WHERE ");
queryString.append("(");
for(int i = 0; i < tags.size(); i++) {
if (i != 0) queryString.append(" OR ");
params.add(size++, tags.get(i));
queryString.append(" t.name = ?").append(size);
}
queryString.append(") AND ");
}
if (website != null) {
params.add(size++, website.getId());
queryString.append("e.website.id = ?").append(size);
} else {
params.add(size++, Boolean.TRUE);
queryString.append("e.website.enabled = ?").append(size);
}
/*if (tags != null && tags.size() > 0) {
// A JOIN with WeblogEntryTag in parent quert will cause a DISTINCT in SELECT clause
// WeblogEntry has a clob field and many databases do not link DISTINCT for CLOB fields
// Hence as a workaround using corelated EXISTS query.
queryString.append(" AND EXISTS (SELECT t FROM WeblogEntryTag t WHERE "
+ " t.weblogEntry = e AND t.name IN (");
final String PARAM_SEPERATOR = ", ";
for(int i = 0; i < tags.size(); i++) {
params.add(size++, tags.get(i));
queryString.append("?").append(size).append(PARAM_SEPERATOR);
}
// Remove the trailing PARAM_SEPERATOR
queryString.delete(queryString.length() - PARAM_SEPERATOR.length(),
queryString.length());
// Close the brace FOR IN clause and EXIST clause
queryString.append(" ) )");
}*/
if (user != null) {
params.add(size++, user.getUserName());
queryString.append(" AND e.creatorUserName = ?").append(size);
}
if (startDate != null) {
Timestamp start = new Timestamp(startDate.getTime());
params.add(size++, start);
queryString.append(" AND e.pubTime >= ?").append(size);
}
if (endDate != null) {
Timestamp end = new Timestamp(endDate.getTime());
params.add(size++, end);
queryString.append(" AND e.pubTime <= ?").append(size);
}
if (cat != null && website != null) {
params.add(size++, cat.getId());
queryString.append(" AND e.category.id = ?").append(size);
}
if (status != null) {
params.add(size++, status);