protected Collection<Object> queryByProperties(
String partitioningPropertyName,
final Map<String, Object> propertyNameValueMap,
final Integer firstResult, final Integer maxResults,
final boolean justCount) {
final EntityIndexConfig entityIndexConfig = resolveEntityIndexConfig(partitioningPropertyName);
Session session = createSessionForIndex(config, entityIndexConfig, propertyNameValueMap.get(partitioningPropertyName));
final Map<String, Entry<EntityIndexConfig, Object>> propertyNameEntityIndexConfigValueMap = createPropertyNameToValueMap(propertyNameValueMap);
QueryCallback query;
if (Filter.isMatch(new Predicate<String>() {
public boolean f(String propertyName) {
return isPrimitiveCollection(propertyName);
}
}, propertyNameEntityIndexConfigValueMap.keySet()))
query = new QueryCallback() {
public Collection<Object> execute(Session session) {
Map<String, Object> revisedPropertyNameValueMap = Transform.toMap(
new Unary<Entry<String, Entry<EntityIndexConfig, Object>>, String>() {
public String f(Map.Entry<String, Map.Entry<EntityIndexConfig, Object>> item) {
return item.getKey();
}
},
new Unary<Entry<String, Entry<EntityIndexConfig, Object>>, Object>() {
public Object f(Map.Entry<String, Map.Entry<EntityIndexConfig, Object>> item) {
return item.getValue().getValue();
}
},
propertyNameEntityIndexConfigValueMap.entrySet());
return justCount
? queryWithHQLRowCount(session, revisedPropertyNameValueMap, firstResult, maxResults)
: queryWithHQL(session, revisedPropertyNameValueMap, firstResult, maxResults);
}
};
else
query = new QueryCallback() {
@SuppressWarnings("unchecked")
public Collection<Object> execute(Session session) {
Criteria criteria = session.createCriteria(config.getRepresentedInterface()).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
for (Entry<EntityIndexConfig, Object> entityIndexConfigValueEntry : propertyNameEntityIndexConfigValueMap.values()) {
EntityIndexConfig entityIndexConfig = entityIndexConfigValueEntry.getKey();
Object value = entityIndexConfigValueEntry.getValue();
addPropertyRestriction(entityIndexConfig, criteria, entityIndexConfig.getPropertyName(), value);
}
addPaging(firstResult, maxResults, criteria);
if (justCount)
criteria.setProjection(Projections.rowCount());
return criteria.list();