Search in sources :

Example 96 with DAOException

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

the class SequenceDAO method getSequence.

/**
     * Enables retrieving sequences in the database without loading everything in memory
     * <p/>
     * Expected usage is
     * <code>
     * long count = getSequenceCount();
     * int offset = 0;
     * while( offset < count ) {
     * Sequence sequence = dao.getSequence(offset);
     * // do something with sequence
     * }
     * </code>
     *
     * @return Sequence at the specified offset
     * @throws DAOException
     */
public Sequence getSequence(int offset) {
    try {
        CriteriaQuery<Sequence> query = getBuilder().createQuery(Sequence.class);
        Root<Sequence> from = query.from(Sequence.class);
        Join<Sequence, Entry> entry = from.join("entry");
        query.where(getBuilder().equal(entry.get("visibility"), Visibility.OK.getValue()));
        return currentSession().createQuery(query).setFirstResult(offset).setMaxResults(1).uniqueResult();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException)

Example 97 with DAOException

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

the class SequenceDAO method hasOriginalSequence.

/**
     * Determines if the user uploaded a sequence file and associated it with an entry
     *
     * @param entryId unique identifier for entry
     * @return true if there is a sequence file that was originally uploaded by user, false otherwise
     * @throws DAOException
     */
public boolean hasOriginalSequence(long entryId) {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<Sequence> from = query.from(Sequence.class);
        Join<Sequence, Entry> entry = from.join("entry");
        query.select(getBuilder().countDistinct(from.get("id"))).where(getBuilder().equal(entry.get("id"), entryId), getBuilder().notEqual(from.get("sequenceUser"), ""), getBuilder().isNotNull(from.get("sequenceUser")));
        return currentSession().createQuery(query).uniqueResult() > 0;
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException)

Example 98 with DAOException

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

the class RequestRetriever method placeSampleInCart.

/**
     * Creates a new sample request for the specified user and specified entry.
     * The default status is "IN CART"
     */
public boolean placeSampleInCart(String userId, SampleRequest sampleRequest) {
    long partId = sampleRequest.getPartData().getId();
    Entry entry = entryDAO.get(sampleRequest.getPartData().getId());
    if (entry == null)
        throw new IllegalArgumentException("Cannot find entry with id: " + partId);
    Account account = DAOFactory.getAccountDAO().getByEmail(userId);
    // check if sample is already in cart with status of "IN CART"
    try {
        List<Request> requests = dao.getSampleRequestByStatus(account, entry, SampleRequestStatus.IN_CART);
        if (requests != null && !requests.isEmpty())
            return true;
        Request request = new Request();
        request.setAccount(account);
        request.setGrowthTemperature(sampleRequest.getGrowthTemperature());
        request.setEntry(entry);
        if (sampleRequest.getRequestType() == null)
            sampleRequest.setRequestType(SampleRequestType.LIQUID_CULTURE);
        request.setType(sampleRequest.getRequestType());
        request.setRequested(new Date(System.currentTimeMillis()));
        request.setUpdated(request.getRequested());
        request.setPlateDescription(sampleRequest.getPlateDescription());
        return dao.create(request) != null;
    } catch (DAOException e) {
        Logger.error(e);
        return false;
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Account(org.jbei.ice.storage.model.Account) Entry(org.jbei.ice.storage.model.Entry) Request(org.jbei.ice.storage.model.Request)

Example 99 with DAOException

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

the class AuditDAO method getAuditsForEntry.

public List<Audit> getAuditsForEntry(Entry entry, int limit, int offset, boolean asc, String sort) {
    try {
        if (sort == null)
            sort = "id";
        CriteriaQuery<Audit> query = getBuilder().createQuery(Audit.class);
        Root<Audit> from = query.from(Audit.class);
        query.where(getBuilder().equal(from.get("entry"), entry));
        query.orderBy(asc ? getBuilder().asc(from.get(sort)) : getBuilder().desc(from.get(sort)));
        return currentSession().createQuery(query).setFirstResult(offset).setMaxResults(limit).list();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Audit(org.jbei.ice.storage.model.Audit) HibernateException(org.hibernate.HibernateException)

Example 100 with DAOException

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

the class AuditDAO method deleteAll.

public int deleteAll(Entry entry) {
    try {
        CriteriaDelete<Audit> query = getBuilder().createCriteriaDelete(Audit.class);
        Root<Audit> from = query.from(Audit.class);
        query.where(getBuilder().equal(from.get("entry"), entry));
        return currentSession().createQuery(query).executeUpdate();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Audit(org.jbei.ice.storage.model.Audit) 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