Search in sources :

Example 66 with DAOException

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

the class FeatureDAO method getFeaturesGroupBy.

public Map<String, List<Feature>> getFeaturesGroupBy(int offset, int size) {
    Map<String, List<Feature>> results = new HashMap<>();
    try {
        CriteriaQuery<String> query = getBuilder().createQuery(String.class);
        Root<Feature> from = query.from(Feature.class);
        query.select(from.get("name")).distinct(true);
        query.where(getBuilder().isNotNull(from.get("name")), getBuilder().notEqual(from.get("name"), ""));
        query.orderBy(getBuilder().asc(from.get("name")));
        List<String> names = currentSession().createQuery(query).setFirstResult(offset).setMaxResults(size).list();
        for (String name : names) {
            CriteriaQuery<Feature> featureQuery = getBuilder().createQuery(Feature.class);
            Root<Feature> root = featureQuery.from(Feature.class);
            featureQuery.where(getBuilder().equal(getBuilder().lower(root.get("name")), name.toLowerCase()));
            List<Feature> result = currentSession().createQuery(featureQuery).list();
            results.put(name, result);
        }
        return results;
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HashMap(java.util.HashMap) HibernateException(org.hibernate.HibernateException) List(java.util.List) Feature(org.jbei.ice.storage.model.Feature)

Example 67 with DAOException

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

the class FolderDAO method getFoldersByType.

public List<Folder> getFoldersByType(FolderType type) {
    try {
        CriteriaQuery<Folder> query = getBuilder().createQuery(Folder.class);
        Root<Folder> from = query.from(Folder.class);
        query.where(getBuilder().equal(from.get("type"), type));
        return currentSession().createQuery(query).list();
    } catch (HibernateException e) {
        Logger.error(e);
        throw new DAOException(e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException)

Example 68 with DAOException

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

the class FolderDAO method getCanEditFolders.

/**
     * Retrieves folders that the specified account owns, or has write privileges on based on the permissions
     *
     * @param account       account that is expected to have write privileges on the folders that are returned
     * @param accountGroups groups that account belongs to that is expected to have write privileges
     * @return list of folders that the account or groups that the account belongs to has write privileges on
     * @throws DAOException
     */
public List<Folder> getCanEditFolders(Account account, Set<Group> accountGroups) {
    try {
        CriteriaQuery<Folder> query = getBuilder().createQuery(Folder.class);
        Root<Permission> from = query.from(Permission.class);
        Join<Permission, Folder> folder = from.join("folder");
        // where ((account = account or group in groups) and canWrite)) or is owner
        Predicate predicate = getBuilder().and(getBuilder().or(getBuilder().equal(from.get("account"), account), from.get("group").in(accountGroups)), getBuilder().equal(from.get("canWrite"), true), getBuilder().isNotNull(from.get("folder")));
        query.select(folder).where(predicate);
        return currentSession().createQuery(query).list();
    } catch (HibernateException e) {
        Logger.error(e);
        throw new DAOException(e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Predicate(javax.persistence.criteria.Predicate)

Example 69 with DAOException

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

the class ExperimentDAO method getExperimentCount.

public int getExperimentCount(long entryId) throws DAOException {
    try {
        String sql = "SELECT count(*) FROM experiment_entry WHERE entry_id=:id";
        NativeQuery query = currentSession().createNativeQuery(sql);
        query.setParameter("id", entryId);
        Number result = (Number) query.uniqueResult();
        return result.intValue();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) NativeQuery(org.hibernate.query.NativeQuery) HibernateException(org.hibernate.HibernateException)

Example 70 with DAOException

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

the class FeatureDAO method getFeatureCount.

public long getFeatureCount(String filter) {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<Feature> from = query.from(Feature.class);
        query.select(getBuilder().countDistinct(from.get("id")));
        if (filter != null && !filter.isEmpty())
            query.where(getBuilder().like(getBuilder().lower(from.get("name")), "%" + filter.toLowerCase() + "%"));
        else
            query.where(getBuilder().isNotNull(from.get("name")), getBuilder().notEqual(from.get("name"), ""));
        return currentSession().createQuery(query).uniqueResult();
    } catch (HibernateException he) {
        Logger.error(he);
        throw new DAOException(he);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Feature(org.jbei.ice.storage.model.Feature)

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