
org.dspace.content.dao.impl.WorkspaceItemDAOImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dspace-api Show documentation
Show all versions of dspace-api Show documentation
DSpace core data model and service APIs.
The newest version!
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.content.dao.impl;
import java.sql.SQLException;
import java.util.AbstractMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import jakarta.persistence.Query;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Root;
import org.dspace.content.Collection;
import org.dspace.content.Item;
import org.dspace.content.WorkspaceItem;
import org.dspace.content.WorkspaceItem_;
import org.dspace.content.dao.WorkspaceItemDAO;
import org.dspace.core.AbstractHibernateDAO;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
/**
* Hibernate implementation of the Database Access Object interface class for the WorkspaceItem object.
* This class is responsible for all database calls for the WorkspaceItem object and is autowired by Spring.
* This class should never be accessed directly.
*
* @author kevinvandevelde at atmire.com
*/
public class WorkspaceItemDAOImpl extends AbstractHibernateDAO implements WorkspaceItemDAO {
protected WorkspaceItemDAOImpl() {
super();
}
@Override
public List findByEPerson(Context context, EPerson ep) throws SQLException {
Query query = createQuery(context,
"from WorkspaceItem ws where ws.item.submitter = :submitter order by " +
"workspaceItemId");
query.setParameter("submitter", ep);
return list(query);
}
@Override
public List findByEPerson(Context context, EPerson ep, Integer limit, Integer offset)
throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, WorkspaceItem.class);
Root workspaceItemRoot = criteriaQuery.from(WorkspaceItem.class);
criteriaQuery.select(workspaceItemRoot);
criteriaQuery.where(criteriaBuilder.equal(workspaceItemRoot.get(WorkspaceItem_.item).get("submitter"), ep));
criteriaQuery.orderBy(criteriaBuilder.asc(workspaceItemRoot.get(WorkspaceItem_.workspaceItemId)));
return list(context, criteriaQuery, false, WorkspaceItem.class, limit, offset);
}
@Override
public List findByCollection(Context context, Collection c) throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, WorkspaceItem.class);
Root workspaceItemRoot = criteriaQuery.from(WorkspaceItem.class);
criteriaQuery.select(workspaceItemRoot);
criteriaQuery.where(criteriaBuilder.equal(workspaceItemRoot.get(WorkspaceItem_.collection), c));
criteriaQuery.orderBy(criteriaBuilder.asc(workspaceItemRoot.get(WorkspaceItem_.workspaceItemId)));
return list(context, criteriaQuery, false, WorkspaceItem.class, -1, -1);
}
@Override
public WorkspaceItem findByItem(Context context, Item i) throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, WorkspaceItem.class);
Root workspaceItemRoot = criteriaQuery.from(WorkspaceItem.class);
criteriaQuery.select(workspaceItemRoot);
criteriaQuery.where(criteriaBuilder.equal(workspaceItemRoot.get(WorkspaceItem_.item), i));
return uniqueResult(context, criteriaQuery, false, WorkspaceItem.class);
}
@Override
public List findAll(Context context) throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, WorkspaceItem.class);
Root workspaceItemRoot = criteriaQuery.from(WorkspaceItem.class);
criteriaQuery.select(workspaceItemRoot);
List orderList = new LinkedList<>();
orderList.add(criteriaBuilder.asc(workspaceItemRoot.get(WorkspaceItem_.workspaceItemId)));
criteriaQuery.orderBy(orderList);
return list(context, criteriaQuery, false, WorkspaceItem.class, -1, -1);
}
@Override
public List findAll(Context context, Integer limit, Integer offset) throws SQLException {
CriteriaBuilder criteriaBuilder = getCriteriaBuilder(context);
CriteriaQuery criteriaQuery = getCriteriaQuery(criteriaBuilder, WorkspaceItem.class);
Root workspaceItemRoot = criteriaQuery.from(WorkspaceItem.class);
criteriaQuery.select(workspaceItemRoot);
List orderList = new LinkedList<>();
orderList.add(criteriaBuilder.asc(workspaceItemRoot.get(WorkspaceItem_.workspaceItemId)));
criteriaQuery.orderBy(orderList);
return list(context, criteriaQuery, false, WorkspaceItem.class, limit, offset);
}
@Override
public int countRows(Context context) throws SQLException {
return count(createQuery(context, "SELECT count(*) from WorkspaceItem"));
}
@Override
public int countRows(Context context, EPerson ep) throws SQLException {
Query query = createQuery(context,
"SELECT count(*) from WorkspaceItem ws where ws.item.submitter = :submitter");
query.setParameter("submitter", ep);
return count(query);
}
@Override
@SuppressWarnings("unchecked")
public List> getStageReachedCounts(Context context) throws SQLException {
Query query = createQuery(context,
"SELECT wi.stageReached as stage_reached, count(*) as cnt from WorkspaceItem wi" +
" group by wi.stageReached order by wi.stageReached");
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy