Search in sources :

Example 71 with DAOException

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

the class GroupDAO method getGroupsBy.

/**
     * Retrieves groups by type and <code>autoJoin</code> value
     *
     * @param type       type of groups to retrieve
     * @param isAutoJoin auto join status
     * @return list of groups found that match the parameters
     * @throws DAOException on HibernateException retrieving groups
     */
public List<Group> getGroupsBy(GroupType type, boolean isAutoJoin) {
    try {
        CriteriaQuery<Group> query = getBuilder().createQuery(Group.class).distinct(true);
        Root<Group> from = query.from(Group.class);
        query.where(getBuilder().equal(from.get("type"), type), getBuilder().equal((from.get("autoJoin")), isAutoJoin));
        return currentSession().createQuery(query).list();
    } 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)

Example 72 with DAOException

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

the class GroupDAO method getGroupsByType.

public List<Group> getGroupsByType(GroupType type, int offset, int limit) {
    try {
        CriteriaQuery<Group> query = getBuilder().createQuery(Group.class).distinct(true);
        Root<Group> from = query.from(Group.class);
        query.where(getBuilder().equal(from.get("type"), type));
        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) Group(org.jbei.ice.storage.model.Group) HibernateException(org.hibernate.HibernateException)

Example 73 with DAOException

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

the class EntryDAO method ownerEntryCount.

// does not check permissions (includes pending entries)
public long ownerEntryCount(String ownerEmail) {
    try {
        CriteriaQuery<Long> query = getBuilder().createQuery(Long.class);
        Root<Entry> from = query.from(Entry.class);
        ArrayList<Predicate> predicates = new ArrayList<>();
        predicates.add(getBuilder().equal(from.get("ownerEmail"), ownerEmail));
        predicates.add(getBuilder().or(getBuilder().equal(from.get("visibility"), Visibility.OK.getValue()), getBuilder().equal(from.get("visibility"), Visibility.PENDING.getValue())));
        query.select(getBuilder().countDistinct(from.get("id"))).where(predicates.toArray(new Predicate[predicates.size()]));
        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) ArrayList(java.util.ArrayList)

Example 74 with DAOException

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

the class EntryDAO method setEntryVisibility.

public int setEntryVisibility(List<Long> list, Visibility ok) {
    try {
        CriteriaUpdate<Entry> update = getBuilder().createCriteriaUpdate(Entry.class);
        Root<Entry> from = update.from(Entry.class);
        update.set(from.get("visibility"), ok.getValue());
        update.where(from.get("id").in(list));
        return currentSession().createQuery(update).executeUpdate();
    } catch (HibernateException e) {
        Logger.error(e);
        throw new DAOException(e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException)

Example 75 with DAOException

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

the class FolderDAO method addFolderContents.

public Folder addFolderContents(Folder folder, List<Entry> entrys) {
    Session session = currentSession();
    try {
        folder = session.get(Folder.class, folder.getId());
        folder.getContents().addAll(entrys);
        folder.setModificationTime(new Date());
        session.saveOrUpdate(folder);
        return folder;
    } catch (HibernateException e) {
        Logger.error(e);
        throw new DAOException(e);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) Session(org.hibernate.Session)

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