Search in sources :

Example 11 with DAOException

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

the class TraceSequenceDAO method getCountByEntry.

/**
     * Get number of trace sequences available for specified entry
     *
     * @param entry entry whose entry count is being retrieved
     * @return number of traces available for the specified entry
     */
public int getCountByEntry(Entry entry) {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<TraceSequence> from = query.from(TraceSequence.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) TraceSequence(org.jbei.ice.storage.model.TraceSequence) HibernateException(org.hibernate.HibernateException)

Example 12 with DAOException

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

the class StorageDAO method retrieveStorageByIndex.

/**
     * Retrieve a {@link Storage} object by its index and {@link SampleType} fields.
     *
     * @param index index value
     * @param type  storage type
     * @return List of Storage objects
     */
public List<Storage> retrieveStorageByIndex(String index, SampleType type) {
    try {
        CriteriaQuery<Storage> query = getBuilder().createQuery(Storage.class);
        Root<Storage> from = query.from(Storage.class);
        query.where(getBuilder().equal(from.get("index"), index), getBuilder().equal(from.get("storageType"), type));
        return currentSession().createQuery(query).list();
    } catch (Exception e) {
        String msg = "Could not get Storage by index: " + index + " " + e.toString();
        Logger.error(msg, e);
        throw new DAOException(msg);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Storage(org.jbei.ice.storage.model.Storage) DAOException(org.jbei.ice.storage.DAOException)

Example 13 with DAOException

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

the class SequenceFeatureDAO method getEntryIdsByFeature.

public List<Long> getEntryIdsByFeature(Feature feature) {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<SequenceFeature> from = query.from(SequenceFeature.class);
        Join<SequenceFeature, Sequence> sequence = from.join("sequence");
        Join<Sequence, Entry> entry = sequence.join("entry");
        query.select(entry.get("id")).where(getBuilder().equal(from.get("feature"), feature));
        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 14 with DAOException

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

the class ShotgunSequenceDAO method delete.

public void delete(Path dir, ShotgunSequence shotgunSequence) {
    try {
        super.delete(shotgunSequence);
        Files.deleteIfExists(Paths.get(dir.toString(), shotgunSequence.getFileId()));
    } catch (IOException e) {
        throw new DAOException("Failed to delete Shotgun Sequence file!", e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) IOException(java.io.IOException)

Example 15 with DAOException

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

the class RequestRetriever method removeSampleFromCart.

public SampleRequest removeSampleFromCart(String userId, long requestId) {
    try {
        Request request = dao.get(requestId);
        if (request == null)
            return null;
        if (!request.getAccount().getEmail().equalsIgnoreCase(userId))
            return null;
        Logger.info(userId + ": Removing sample from cart for entry " + request.getEntry().getId());
        dao.delete(request);
        return request.toDataTransferObject();
    } catch (DAOException de) {
        Logger.error(de);
        return null;
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Request(org.jbei.ice.storage.model.Request)

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