Search in sources :

Example 6 with DAOException

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

the class AccountDAO method getAccountsCount.

/**
     * Retrieves maximum number of distinct accounts available and, if specified, whose firstName, lastName and email
     * fields match the filter token. This is intended to be used for paging.
     *
     * @param filter optional token used to match against the firstName, lastName and email fields of accounts
     * @return number of accounts that match the optional filter.
     * @throws DAOException on {@link HibernateException} retrieving the number
     */
public long getAccountsCount(String filter) {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.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.select(getBuilder().countDistinct(from.get("id")));
        return currentSession().createQuery(query).uniqueResult();
    } 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 7 with DAOException

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

the class SequenceFeatureDAO method getEntrySequenceFeatures.

public List<SequenceFeature> getEntrySequenceFeatures(Entry entry) {
    try {
        CriteriaQuery<SequenceFeature> query = getBuilder().createQuery(SequenceFeature.class);
        Root<SequenceFeature> from = query.from(SequenceFeature.class);
        Join<SequenceFeature, Sequence> sequence = from.join("sequence");
        query.where(getBuilder().equal(sequence.get("entry"), entry)).distinct(true);
        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)

Example 8 with DAOException

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

the class TraceSequenceDAO method save.

/**
     * Save the given {@link TraceSequence} object in the database.
     *
     * @param traceSequence object to save
     * @return Saved TraceSequence object.
     * @throws DAOException on hibernate exception saving
     */
public TraceSequence save(TraceSequence traceSequence) {
    TraceSequenceAlignment traceSequenceAlignment = traceSequence.getTraceSequenceAlignment();
    Session session = currentSession();
    try {
        session.saveOrUpdate(traceSequenceAlignment);
        traceSequence.setTraceSequenceAlignment(traceSequenceAlignment);
        session.saveOrUpdate(traceSequence);
        return traceSequence;
    } catch (HibernateException e) {
        throw new DAOException("Error saving trace sequence", e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) TraceSequenceAlignment(org.jbei.ice.storage.model.TraceSequenceAlignment) HibernateException(org.hibernate.HibernateException) Session(org.hibernate.Session)

Example 9 with DAOException

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

the class TraceSequenceDAO method getByEntry.

/**
     * Retrieve all {@link TraceSequence} objects associated with the given {@link Entry} object
     * using the paging parameters, ordered by creation time in ascending order
     *
     * @param entry entry whose trace sequences are being retrieved
     * @param start start for traces retrieval
     * @param limit maximum number of trace records to retrieve
     * @return List of TraceSequence objects.
     * @throws DAOException
     */
public List<TraceSequence> getByEntry(Entry entry, int start, int limit) {
    try {
        CriteriaQuery<TraceSequence> query = getBuilder().createQuery(TraceSequence.class);
        Root<TraceSequence> from = query.from(TraceSequence.class);
        query.where(getBuilder().equal(from.get("entry"), entry));
        query.orderBy(getBuilder().asc(from.get("creationTime")));
        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) TraceSequence(org.jbei.ice.storage.model.TraceSequence) HibernateException(org.hibernate.HibernateException)

Example 10 with DAOException

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

the class TraceSequenceDAO method getByFileId.

/**
     * Retrieve the {@link TraceSequence} object by its fileId.
     *
     * @param fileId unique file identifier
     * @return {@link Optional} container that contains the trace sequence if found.
     * @throws DAOException
     */
public Optional<TraceSequence> getByFileId(String fileId) {
    try {
        CriteriaQuery<TraceSequence> query = getBuilder().createQuery(TraceSequence.class);
        Root<TraceSequence> from = query.from(TraceSequence.class);
        query.where(getBuilder().equal(from.get("fileId"), fileId));
        return currentSession().createQuery(query).uniqueResultOptional();
    } catch (HibernateException e) {
        throw new DAOException("Failed to retrieve entry by fileId: " + fileId, e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) TraceSequence(org.jbei.ice.storage.model.TraceSequence) 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