use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class FeatureDAO method getFeaturesGroupBy.
public Map<String, List<Feature>> getFeaturesGroupBy(int offset, int size) {
Map<String, List<Feature>> results = new HashMap<>();
try {
CriteriaQuery<String> query = getBuilder().createQuery(String.class);
Root<Feature> from = query.from(Feature.class);
query.select(from.get("name")).distinct(true);
query.where(getBuilder().isNotNull(from.get("name")), getBuilder().notEqual(from.get("name"), ""));
query.orderBy(getBuilder().asc(from.get("name")));
List<String> names = currentSession().createQuery(query).setFirstResult(offset).setMaxResults(size).list();
for (String name : names) {
CriteriaQuery<Feature> featureQuery = getBuilder().createQuery(Feature.class);
Root<Feature> root = featureQuery.from(Feature.class);
featureQuery.where(getBuilder().equal(getBuilder().lower(root.get("name")), name.toLowerCase()));
List<Feature> result = currentSession().createQuery(featureQuery).list();
results.put(name, result);
}
return results;
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class FolderDAO method getFoldersByType.
public List<Folder> getFoldersByType(FolderType type) {
try {
CriteriaQuery<Folder> query = getBuilder().createQuery(Folder.class);
Root<Folder> from = query.from(Folder.class);
query.where(getBuilder().equal(from.get("type"), type));
return currentSession().createQuery(query).list();
} catch (HibernateException e) {
Logger.error(e);
throw new DAOException(e);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class FolderDAO method getCanEditFolders.
/**
* Retrieves folders that the specified account owns, or has write privileges on based on the permissions
*
* @param account account that is expected to have write privileges on the folders that are returned
* @param accountGroups groups that account belongs to that is expected to have write privileges
* @return list of folders that the account or groups that the account belongs to has write privileges on
* @throws DAOException
*/
public List<Folder> getCanEditFolders(Account account, Set<Group> accountGroups) {
try {
CriteriaQuery<Folder> query = getBuilder().createQuery(Folder.class);
Root<Permission> from = query.from(Permission.class);
Join<Permission, Folder> folder = from.join("folder");
// where ((account = account or group in groups) and canWrite)) or is owner
Predicate predicate = getBuilder().and(getBuilder().or(getBuilder().equal(from.get("account"), account), from.get("group").in(accountGroups)), getBuilder().equal(from.get("canWrite"), true), getBuilder().isNotNull(from.get("folder")));
query.select(folder).where(predicate);
return currentSession().createQuery(query).list();
} catch (HibernateException e) {
Logger.error(e);
throw new DAOException(e);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class ExperimentDAO method getExperimentCount.
public int getExperimentCount(long entryId) throws DAOException {
try {
String sql = "SELECT count(*) FROM experiment_entry WHERE entry_id=:id";
NativeQuery query = currentSession().createNativeQuery(sql);
query.setParameter("id", entryId);
Number result = (Number) query.uniqueResult();
return result.intValue();
} 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 getFeatureCount.
public long getFeatureCount(String filter) {
try {
CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
Root<Feature> from = query.from(Feature.class);
query.select(getBuilder().countDistinct(from.get("id")));
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).uniqueResult();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
Aggregations