Search in sources :

Example 36 with DAOException

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

the class SequenceDAO method deleteSequence.

/**
     * Delete the given {@link Sequence} object in the database.
     *
     * @param sequence          sequence to delete
     * @param pigeonImageFolder path of the image folder where the pigeon images are cached
     */
public void deleteSequence(Sequence sequence, String pigeonImageFolder) {
    String sequenceHash = sequence.getFwdHash();
    try {
        sequence.setEntry(null);
        sequence.getSequenceFeatures();
        super.delete(sequence);
        currentSession().flush();
        Files.deleteIfExists(Paths.get(pigeonImageFolder, sequenceHash + ".png"));
    } catch (IOException e) {
        Logger.warn(e.getMessage());
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) IOException(java.io.IOException)

Example 37 with DAOException

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

the class SequenceDAO method hasSequence.

public boolean hasSequence(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)).distinct(true);
        return currentSession().createQuery(query).setMaxResults(1).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 38 with DAOException

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

the class RemoteClientModelDAO method getClientCount.

/**
     * Retrieves number of clients for the specified group
     *
     * @param group group whose clients are of interest
     * @return number of clients for group
     * @throws DAOException
     */
public int getClientCount(Group group) {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<RemoteClientModel> from = query.from(RemoteClientModel.class);
        Join<RemoteClientModel, Group> groups = from.join("groups");
        query.select(getBuilder().countDistinct(from.get("id")));
        query.where(getBuilder().equal(groups.get("id"), group.getId()), getBuilder().isNotNull(from.get("email")));
        return currentSession().createQuery(query).uniqueResult().intValue();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) Group(org.jbei.ice.storage.model.Group) HibernateException(org.hibernate.HibernateException) RemoteClientModel(org.jbei.ice.storage.model.RemoteClientModel)

Example 39 with DAOException

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

the class SelectionMarkerDAO method getMatchingSelectionMarkers.

public List<String> getMatchingSelectionMarkers(String token, int limit) {
    try {
        CriteriaQuery<String> query = getBuilder().createQuery(String.class);
        Root<SelectionMarker> from = query.from(SelectionMarker.class);
        query.where(getBuilder().like(getBuilder().lower(from.get("name")), "%" + token.toLowerCase() + "%"));
        query.select(from.get("name")).distinct(true);
        return currentSession().createQuery(query).setMaxResults(limit).list();
    //            return currentSession().createCriteria(SelectionMarker.class)
    //                    .add(Restrictions.ilike("name", token, MatchMode.ANYWHERE))
    //                    .setMaxResults(limit)
    //                    .setProjection(Projections.distinct(Projections.property("name")))
    //                    .list();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) SelectionMarker(org.jbei.ice.storage.model.SelectionMarker)

Example 40 with DAOException

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

the class SampleDAO method getSamplesByStorage.

/**
     * Retrieve {@link Sample} objects associated with the given {@link Storage} object.
     *
     * @param storage
     * @return ArrayList of Sample objects.
     * @throws DAOException
     */
public List<Sample> getSamplesByStorage(Storage storage) {
    try {
        CriteriaQuery<Sample> query = getBuilder().createQuery(Sample.class);
        Root<Sample> from = query.from(Sample.class);
        query.where(getBuilder().equal(from.get("storage"), storage));
        return currentSession().createQuery(query).list();
    } catch (HibernateException e) {
        Logger.error(e);
        throw new DAOException("Failed to retrieve sample by storage id: " + storage.getId(), e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Sample(org.jbei.ice.storage.model.Sample)

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