use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class GroupDAO method getMemberCount.
public long getMemberCount(String uuid) {
try {
CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
Root<Group> from = query.from(Group.class);
Join<Group, Account> member = from.join("members");
query.select(getBuilder().countDistinct(member.get("id")));
query.where(getBuilder().equal(from.get("uuid"), uuid));
return currentSession().createQuery(query).uniqueResult();
} catch (HibernateException e) {
Logger.error(e);
throw new DAOException(e);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class GroupDAO method retrieveMemberGroups.
public List<Group> retrieveMemberGroups(Account account) {
try {
CriteriaQuery<Group> query = getBuilder().createQuery(Group.class).distinct(true);
Root<Group> from = query.from(Group.class);
Join<Group, Account> members = from.join("members", JoinType.LEFT);
query.where(getBuilder().or(getBuilder().equal(from.get("owner"), account), getBuilder().equal(members.get("email"), account.getEmail())));
return currentSession().createQuery(query).list();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class GroupDAO method getMatchingGroups.
public List<Group> getMatchingGroups(Account account, String token, int limit) {
Set<Group> userGroups = account.getGroups();
try {
token = token.toUpperCase();
CriteriaQuery<Group> query = getBuilder().createQuery(Group.class).distinct(true);
Root<Group> from = query.from(Group.class);
List<Predicate> predicates = new ArrayList<>();
predicates.add(getBuilder().like(getBuilder().upper(from.get("label")), "%" + token + "%"));
predicates.add(getBuilder().notEqual(from.get("uuid"), GroupController.PUBLIC_GROUP_UUID));
Predicate predicate = getBuilder().or(getBuilder().equal(from.get("type"), GroupType.PUBLIC), getBuilder().equal(from.get("owner"), account));
if (userGroups != null && !userGroups.isEmpty()) {
predicate.getExpressions().add(from.in(userGroups));
}
predicates.add(predicate);
query.where(predicates.toArray(new Predicate[predicates.size()]));
return currentSession().createQuery(query).setMaxResults(limit).list();
} catch (HibernateException e) {
Logger.error(e);
throw new DAOException("Error retrieving matching groups", e);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class FeatureDAO method getFeaturesGroupByCount.
public long getFeaturesGroupByCount() {
try {
CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
Root<Feature> from = query.from(Feature.class);
query.select(getBuilder().countDistinct(from.get("name"))).where(getBuilder().isNotNull(from.get("name")), getBuilder().notEqual(from.get("name"), ""));
return currentSession().createQuery(query).uniqueResult();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class FeatureDAO method getFeatures.
public List<Feature> getFeatures(int offset, int size, String filter) {
try {
CriteriaQuery<Feature> query = getBuilder().createQuery(Feature.class);
Root<Feature> from = query.from(Feature.class);
if (filter != null && !filter.isEmpty())
query.where(getBuilder().like(getBuilder().lower(from.get("name")), "%" + filter.toLowerCase() + "%"));
else
query.where(getBuilder().isNotNull(from.get("name")), getBuilder().notEqual(from.get("name"), ""));
return currentSession().createQuery(query).setFirstResult(offset).setMaxResults(size).list();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
Aggregations