Search in sources :

Example 31 with DAOException

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

the class SampleDAO method getSampleCount.

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

Example 32 with DAOException

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

the class SequenceDAO method getByEntry.

/**
     * Retrieve the {@link Sequence} object associated with the given {@link Entry} object.
     *
     * @param entry entry associated with sequence
     * @return Sequence object.
     */
public Sequence getByEntry(Entry entry) {
    try {
        CriteriaQuery<Sequence> query = getBuilder().createQuery(Sequence.class);
        Root<Sequence> from = query.from(Sequence.class);
        query.where(getBuilder().equal(from.get("entry"), entry));
        Optional<Sequence> sequence = currentSession().createQuery(query).uniqueResultOptional();
        if (!sequence.isPresent())
            return null;
        return normalizeAnnotationLocations(sequence.get());
    } catch (HibernateException e) {
        Logger.error(e);
        throw new DAOException("Failed to retrieve sequence by entry: " + entry.getId(), e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException)

Example 33 with DAOException

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

the class SequenceDAO method getSequenceFilename.

public String getSequenceFilename(Entry entry) {
    try {
        CriteriaQuery<String> query = getBuilder().createQuery(String.class);
        Root<Sequence> from = query.from(Sequence.class);
        query.select(from.get("fileName")).where(getBuilder().equal(from.get("entry"), entry));
        return currentSession().createQuery(query).getSingleResult();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException)

Example 34 with DAOException

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

the class SequenceDAO method getFeatureBySequence.

/**
     * Retrieve the {@link Feature} object with the given DNA sequence string.
     *
     * @param featureDnaSequence dna sequence of feature
     * @return Feature object.
     * @throws DAOException
     */
private Feature getFeatureBySequence(String featureDnaSequence) {
    featureDnaSequence = featureDnaSequence.toLowerCase();
    try {
        String hash = SequenceUtils.calculateSequenceHash(featureDnaSequence);
        CriteriaQuery<Feature> query = getBuilder().createQuery(Feature.class);
        Root<Feature> from = query.from(Feature.class);
        query.where(getBuilder().equal(from.get("hash"), hash));
        Optional<Feature> result = currentSession().createQuery(query).uniqueResultOptional();
        if (result.isPresent())
            return result.get();
        String reverseComplement = SequenceUtils.reverseComplement(featureDnaSequence);
        String sequenceHash = SequenceUtils.calculateSequenceHash(reverseComplement);
        query.getRestriction().getExpressions().clear();
        query.where(getBuilder().equal(from.get("hash"), sequenceHash));
        return currentSession().createQuery(query).uniqueResult();
    } catch (HibernateException | UtilityException e) {
        Logger.error(e);
        throw new DAOException("Failed to get Feature by sequence!", e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) UtilityException(org.jbei.ice.lib.utils.UtilityException)

Example 35 with DAOException

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

the class RequestDAO method getSampleRequestInCart.

public Request getSampleRequestInCart(Account account, Entry entry) {
    try {
        CriteriaQuery<Request> query = getBuilder().createQuery(Request.class);
        Root<Request> from = query.from(Request.class);
        query.where(getBuilder().and(getBuilder().equal(from.get("status"), SampleRequestStatus.IN_CART), getBuilder().equal(from.get("entry"), entry), getBuilder().equal(from.get("account"), account)));
        List<Request> list = currentSession().createQuery(query).list();
        if (list.isEmpty())
            return null;
        HashSet<Request> inCart = new HashSet<>(list);
        if (inCart.size() > 1) {
            Logger.error("Multiple sample requests found for entry " + entry.getId());
        }
        return (Request) inCart.toArray()[0];
    } 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) HashSet(java.util.HashSet)

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