Search in sources :

Example 1 with DAOException

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);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) ApiKey(org.jbei.ice.storage.model.ApiKey) HibernateException(org.hibernate.HibernateException)

Example 2 with DAOException

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);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Attachment(org.jbei.ice.storage.model.Attachment)

Example 3 with DAOException

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);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Attachment(org.jbei.ice.storage.model.Attachment)

Example 4 with DAOException

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);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Account(org.jbei.ice.storage.model.Account) HibernateException(org.hibernate.HibernateException)

Example 5 with DAOException

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);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Entry(org.jbei.ice.storage.model.Entry) HibernateException(org.hibernate.HibernateException) BulkUpload(org.jbei.ice.storage.model.BulkUpload)

Aggregations

DAOException (org.jbei.ice.storage.DAOException)150 HibernateException (org.hibernate.HibernateException)144 ArrayList (java.util.ArrayList)26 Group (org.jbei.ice.storage.model.Group)14 Account (org.jbei.ice.storage.model.Account)8 Request (org.jbei.ice.storage.model.Request)8 Predicate (javax.persistence.criteria.Predicate)7 SampleRequest (org.jbei.ice.lib.dto.sample.SampleRequest)6 Entry (org.jbei.ice.storage.model.Entry)6 Session (org.hibernate.Session)5 ApiKey (org.jbei.ice.storage.model.ApiKey)5 BulkUpload (org.jbei.ice.storage.model.BulkUpload)5 NativeQuery (org.hibernate.query.NativeQuery)4 Feature (org.jbei.ice.storage.model.Feature)4 Preference (org.jbei.ice.storage.model.Preference)4 Sample (org.jbei.ice.storage.model.Sample)4 Attachment (org.jbei.ice.storage.model.Attachment)3 Audit (org.jbei.ice.storage.model.Audit)3 RemoteClientModel (org.jbei.ice.storage.model.RemoteClientModel)3 ShotgunSequence (org.jbei.ice.storage.model.ShotgunSequence)3