Search in sources :

Example 21 with DAOException

use of org.jbei.ice.storage.DAOException in project ice by JBEI.

the class BulkUploadDAO method retrieveSavedDraftCount.

public int retrieveSavedDraftCount(long draftId) {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<BulkUpload> from = query.from(BulkUpload.class);
        Join<BulkUpload, Entry> contents = from.join("contents");
        query.select(getBuilder().countDistinct(contents.get("id"))).where(getBuilder().equal(from.get("id"), draftId));
        return currentSession().createQuery(query).uniqueResult().intValue();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
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)

Example 22 with DAOException

use of org.jbei.ice.storage.DAOException in project ice by JBEI.

the class BulkUploadDAO method retrieveByAccount.

public List<BulkUpload> retrieveByAccount(Account account) {
    try {
        CriteriaQuery<BulkUpload> query = getBuilder().createQuery(BulkUpload.class);
        Root<BulkUpload> from = query.from(BulkUpload.class);
        query.where(getBuilder().equal(from.get("account"), account), getBuilder().notEqual(from.get("status"), BulkUploadStatus.PENDING_APPROVAL));
        return currentSession().createQuery(query).list();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) BulkUpload(org.jbei.ice.storage.model.BulkUpload)

Example 23 with DAOException

use of org.jbei.ice.storage.DAOException in project ice by JBEI.

the class EntryDAO method getOwnerEntryIds.

/**
     * Retrieves list of entry ids whose owner email column matches the specified ownerEmail parameter,
     * with a visibility of <pre>OK</pre> or <pre>PENDING</pre> and if not null, matches the type
     *
     * @param ownerEmail value of owner email column that desired entries must match
     * @param type       option entry type parameter
     * @return list of ids for all matching entries
     */
public List<Long> getOwnerEntryIds(String ownerEmail, EntryType type) {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<Entry> from = query.from(Entry.class);
        ArrayList<Predicate> predicates = new ArrayList<>();
        predicates.add(getBuilder().equal(from.get("ownerEmail"), ownerEmail));
        predicates.add(getBuilder().or(getBuilder().equal(from.get("visibility"), Visibility.OK.getValue()), getBuilder().equal(from.get("visibility"), Visibility.PENDING.getValue())));
        if (type != null)
            predicates.add(getBuilder().equal(from.get("recordType"), type.getName()));
        query.select(getBuilder().countDistinct(from.get("id"))).where(predicates.toArray(new Predicate[predicates.size()]));
        return currentSession().createQuery(query).list();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) ArrayList(java.util.ArrayList)

Example 24 with DAOException

use of org.jbei.ice.storage.DAOException in project ice by JBEI.

the class EntryDAO method getMatchingEntryPartNumbers.

public List<String> getMatchingEntryPartNumbers(String token, int limit, Set<String> include) {
    try {
        CriteriaQuery<String> query = getBuilder().createQuery(String.class);
        Root<Entry> from = query.from(Entry.class);
        ArrayList<Predicate> predicates = new ArrayList<>();
        predicates.add(getBuilder().like(getBuilder().lower(from.get("partNumber")), "%" + token.toLowerCase() + "%"));
        if (include != null && !include.isEmpty()) {
            predicates.add(from.get("recordType").in(include));
        }
        query.select(from.get("partNumber")).distinct(true).where(predicates.toArray(new Predicate[predicates.size()]));
        return currentSession().createQuery(query).setMaxResults(limit).list();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) ArrayList(java.util.ArrayList)

Example 25 with DAOException

use of org.jbei.ice.storage.DAOException in project ice by JBEI.

the class CommentDAO method getCommentCount.

public int getCommentCount(Entry entry) {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<Comment> from = query.from(Comment.class);
        query.select(getBuilder().countDistinct(from.get("id"))).where(getBuilder().equal(from.get("entry"), entry));
        return currentSession().createQuery(query).uniqueResult().intValue();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Comment(org.jbei.ice.storage.model.Comment) HibernateException(org.hibernate.HibernateException)

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