use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class ApiKeyDAO method getApiKeysCount.
public long getApiKeysCount(String userId) {
try {
CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
Root<ApiKey> from = query.from(ApiKey.class);
query.select(getBuilder().countDistinct(from.get("id")));
if (userId != null)
query.where(getBuilder().equal(from.get("ownerEmail"), userId)).distinct(true);
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 AttachmentDAO method getByEntry.
/**
* Retrieve all {@link Attachment}s associated with the given {@link Entry}.
*
* @param entry Entry whose attachments are desired
* @return ArrayList of Attachments.
* @throws DAOException
*/
public List<Attachment> getByEntry(Entry entry) {
try {
CriteriaQuery<Attachment> query = getBuilder().createQuery(Attachment.class);
Root<Attachment> from = query.from(Attachment.class);
query.where(getBuilder().equal(from.get("entry"), entry));
query.orderBy(getBuilder().desc(from.get("id")));
return currentSession().createQuery(query).list();
} catch (HibernateException e) {
Logger.error(e);
throw new DAOException("Failed to retrieve attachment by entry: " + entry.getId(), e);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class AttachmentDAO method hasAttachment.
public boolean hasAttachment(Entry entry) {
try {
CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
Root<Attachment> from = query.from(Attachment.class);
query.select(getBuilder().countDistinct(from.get("id"))).where(getBuilder().equal(from.get("entry"), entry));
return currentSession().createQuery(query).uniqueResult() > 0;
} catch (HibernateException e) {
Logger.error(e);
throw new DAOException("Failed to retrieve attachment by entry: " + entry.getId(), e);
}
}
use of org.jbei.ice.storage.DAOException in project ice by JBEI.
the class AccountDAO method getAccounts.
/**
* Retrieves list of pageable accounts, matching the parameter values
*
* @param offset offset to start retrieving matching accounts
* @param limit maximum number of accounts to retrieve
* @param sort sort order for retrieval
* @param asc whether to sort in ascending or descending order
* @param filter optional filter to for matching text against firstName, lastName or email fields of accounts
* @return list of matching accounts
* @throws DAOException on {@link HibernateException} retrieving accounts
*/
public List<Account> getAccounts(int offset, int limit, String sort, boolean asc, String filter) {
try {
CriteriaQuery<Account> query = getBuilder().createQuery(Account.class);
Root<Account> from = query.from(Account.class);
if (filter != null && !filter.isEmpty()) {
filter = filter.toLowerCase();
query.where(getBuilder().or(getBuilder().like(getBuilder().lower(from.get("firstName")), "%" + filter + "%"), getBuilder().like(getBuilder().lower(from.get("lastName")), "%" + filter + "%"), getBuilder().like(getBuilder().lower(from.get("email")), "%" + filter + "%")));
}
query.distinct(true).orderBy(asc ? getBuilder().asc(from.get(sort)) : getBuilder().desc(from.get(sort)));
return currentSession().createQuery(query).setMaxResults(limit).setFirstResult(offset).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 BulkUploadDAO method retrieveDraftEntries.
public List<Entry> retrieveDraftEntries(long id, int start, int limit) {
try {
CriteriaQuery<Entry> query = getBuilder().createQuery(Entry.class);
Root<BulkUpload> from = query.from(BulkUpload.class);
Join<BulkUpload, Entry> contents = from.join("contents");
query.select(contents).where(getBuilder().equal(from.get("id"), id)).orderBy(getBuilder().asc(contents.get("id")));
return currentSession().createQuery(query).setFirstResult(start).setMaxResults(limit).list();
} catch (HibernateException e) {
Logger.error(e);
throw new DAOException(e);
}
}
Aggregations