// Only one table is expected here.
List<TableReference> fromList = query.getFrom();
Iterator<TableReference> itr = fromList.iterator();
if(!itr.hasNext()) {
final String msg = LDAPPlugin.Util.getString("IQueryToLdapSearchParser.noTablesInFromError"); //$NON-NLS-1$
throw new TranslatorException(msg);
}
TableReference fItm = itr.next();
if(itr.hasNext()) {
final String msg = LDAPPlugin.Util.getString("IQueryToLdapSearchParser.multiItemsInFromError"); //$NON-NLS-1$
throw new TranslatorException(msg);
}
String contextName = getContextNameFromFromItem(fItm);
int searchScope = getSearchScopeFromFromItem(fItm);
// GHH 20080326 - added check for RESTRICT parameter in
// NameInSource of from item
String classRestriction = getRestrictToNamedClass(fItm);
// Parse the WHERE clause.
// Create an equivalent LDAP search filter.
List<String> searchStringList = new LinkedList<String>();
searchStringList = getSearchFilterFromWhereClause(query.getWhere(), searchStringList);
StringBuilder filterBuilder = new StringBuilder();
for (String string : searchStringList) {
filterBuilder.append(string);
}
// GHH 20080326 - if there is a class restriction,
// add it to the search filter
if (classRestriction != null && classRestriction.trim().length()>0) {
filterBuilder.insert(0, "(&").append("(objectClass=").append(classRestriction).append("))"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
// Parse the ORDER BY clause.
// Create an ordered sort list.
OrderBy orderBy = query.getOrderBy();
// Referenced the JNDI standard...arguably, this should not be done inside this
// class, and we should make our own key class. In practice, this makes things simpler.
SortKey[] sortKeys = getSortKeysFromOrderByClause(orderBy);
// Parse LIMIT clause.
// Note that offsets are not supported.
Limit limit = query.getLimit();
long countLimit = -1;
if(limit != null) {
countLimit = limit.getRowLimit();
}
// Create Search Details
LDAPSearchDetails sd = new LDAPSearchDetails(contextName, searchScope, filterBuilder.toString(), attributeList, sortKeys, countLimit, elementList);
// Search Details logging
try {
sd.printDetailsToLog();
} catch (NamingException nme) {
final String msg = LDAPPlugin.Util.getString("IQueryToLdapSearchParser.searchDetailsLoggingError"); //$NON-NLS-1$
throw new TranslatorException(msg);
}
return sd;
}