Search in sources :

Example 91 with DAOException

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

the class RequestDAO method getAccountRequests.

public List<Request> getAccountRequests(Account account, SampleRequestStatus status, int start, int limit, String sort, boolean asc) {
    try {
        CriteriaQuery<Request> query = getBuilder().createQuery(Request.class);
        Root<Request> from = query.from(Request.class);
        if (status != null) {
            query.where(getBuilder().equal(from.get("account"), account), getBuilder().equal(from.get("status"), status));
        } else {
            query.where(getBuilder().equal(from.get("account"), account));
        }
        query.orderBy(asc ? getBuilder().asc(from.get(sort)) : getBuilder().desc(from.get(sort)));
        return currentSession().createQuery(query).setFirstResult(start).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) Request(org.jbei.ice.storage.model.Request) SampleRequest(org.jbei.ice.lib.dto.sample.SampleRequest)

Example 92 with DAOException

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

the class RequestDAO method getSampleRequestByStatus.

public List<Request> getSampleRequestByStatus(Account account, Entry entry, SampleRequestStatus status) {
    try {
        CriteriaQuery<Request> query = getBuilder().createQuery(Request.class);
        Root<Request> from = query.from(Request.class);
        query.where(getBuilder().and(getBuilder().equal(from.get("status"), status), getBuilder().equal(from.get("entry"), entry), getBuilder().equal(from.get("account"), account)));
        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) Request(org.jbei.ice.storage.model.Request) SampleRequest(org.jbei.ice.lib.dto.sample.SampleRequest)

Example 93 with DAOException

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

the class RequestDAO method get.

public List<Request> get(int start, int limit, String sort, boolean asc, SampleRequestStatus status, String filter) {
    try {
        CriteriaQuery<Request> query = getBuilder().createQuery(Request.class).distinct(true);
        Root<Request> from = query.from(Request.class);
        List<Predicate> predicates = createPredicates(from, filter, status);
        if (!predicates.isEmpty())
            query.where(predicates.toArray(new Predicate[predicates.size()]));
        query.orderBy(asc ? getBuilder().asc(from.get(sort)) : getBuilder().desc(from.get(sort)));
        return currentSession().createQuery(query).setMaxResults(limit).setFirstResult(start).list();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Request(org.jbei.ice.storage.model.Request) SampleRequest(org.jbei.ice.lib.dto.sample.SampleRequest) Predicate(javax.persistence.criteria.Predicate)

Example 94 with DAOException

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

the class PreferencesDAO method getPreference.

public Preference getPreference(Account account, String key) {
    try {
        CriteriaQuery<Preference> query = getBuilder().createQuery(Preference.class);
        Root<Preference> from = query.from(Preference.class);
        query.where(getBuilder().equal(from.get("account"), account), getBuilder().equal(from.get("key"), key.toUpperCase()));
        return currentSession().createQuery(query).uniqueResult();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Preference(org.jbei.ice.storage.model.Preference) HibernateException(org.hibernate.HibernateException)

Example 95 with DAOException

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

the class PreferencesDAO method retrievePreferenceValues.

public HashMap<String, String> retrievePreferenceValues(Account account, HashSet<String> keys) {
    try {
        CriteriaQuery<Preference> query = getBuilder().createQuery(Preference.class);
        Root<Preference> from = query.from(Preference.class);
        query.where(getBuilder().equal(from.get("account"), account), from.get("key").in(keys));
        List<Preference> result = currentSession().createQuery(query).list();
        Iterator iterator = result.iterator();
        HashMap<String, String> results = new HashMap<>();
        while (iterator.hasNext()) {
            Preference preference = (Preference) iterator.next();
            if (keys.contains(preference.getKey().toUpperCase())) {
                results.put(preference.getKey().toUpperCase().trim(), preference.getValue().trim());
            }
        }
        return results;
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Preference(org.jbei.ice.storage.model.Preference) 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