Commit 9bab9437 by Jan Hrabal

x

parent cacd490f
package com.jh.boot.attachment;
import java.util.Collections;
import java.util.List;
import javax.persistence.TypedQuery;
import org.springframework.stereotype.Repository;
import com.jh.boot.jpa.AbstractHibernateRepository;
import com.jh.boot.web.list.Page;
import com.jh.boot.web.list.PagingInfo;
/**
......@@ -24,18 +26,14 @@ public class AttachmentRepository extends AbstractHibernateRepository {
* @param paging the paging
* @return the page
*/
public List<Attachment> findForUnitIdAndObject(Long unitId, String objectType, Long objectId, PagingInfo paging) {
// Criteria c = criteria(Attachment.class);
// c.add(Restrictions.eq("unitId", unitId));
// c.add(Restrictions.eq("objectType", objectType));
// c.add(Restrictions.eq("objectId", objectId));
// c.addOrder(Order.desc("uploaded"));
// c.addOrder(Order.desc("name"));
// return pagedResult(c, paging);
return Collections.emptyList();
public Page<Attachment> findForUnitIdAndObject(Long unitId, String objectType, Long objectId, PagingInfo paging) {
TypedQuery<Attachment> query = getListQuery(unitId, objectType, objectId);
query.setFirstResult(paging.getPage() * paging.getPageSize());
query.setMaxResults(paging.getPageSize());
//return new Page<>(0, 0, 0, 0, null, objectType, null);
//FIXME
return Page.empty();
}
/**
......@@ -47,25 +45,37 @@ public class AttachmentRepository extends AbstractHibernateRepository {
* @return the list
*/
public List<Attachment> findForUnitIdAndObject(Long unitId, String objectType, Long objectId) {
return Collections.emptyList();
TypedQuery<Attachment> query = getListQuery(unitId, objectType, objectId);
return query.getResultList();
}
/**
* Find for unit id and id.
*
* @param unitId the unit id
* @param attachmentId the attachment id
* @return the attachment
*/
public Attachment findForUnitIdAndId(Long unitId, Long attachmentId) {
// Criteria c = criteria(Attachment.class);
//
// c.add(Restrictions.eq("unitId", unitId));
// c.add(Restrictions.idEq(attachmentId));
//
// return (Attachment) c.uniqueResult();
return null;
protected TypedQuery<Attachment> getListQuery(Long unitId, String objectType, Long objectId) {
String hql = "select a from Attachment a";
if (unitId != null || objectType != null || objectId != null) {
hql += " where ";
if (unitId != null) {
hql += " a.unitId = :unitId";
}
if (objectType != null) {
hql += " a.objectType = :objectType";
}
if (objectId != null) {
hql += " a.objectId = :objectId";
}
}
TypedQuery<Attachment> query = entityManager.createQuery(hql, Attachment.class);
if (unitId != null) {
query.setParameter("unitId", unitId);
}
if (objectType != null) {
query.setParameter("objectType", objectType);
}
if (objectId != null) {
query.setParameter("objectId", objectId);
}
return query;
}
......@@ -78,8 +88,8 @@ public class AttachmentRepository extends AbstractHibernateRepository {
* @param attachmentId the attachment id
* @param name the name
*/
public void rename(Long unitId, String objectType, Long objectId, Long attachmentId, String name) {
Attachment a = findForUnitIdAndId(unitId, attachmentId);
public void rename(Long attachmentId, String name) {
Attachment a = findById(attachmentId);
a.setName(name);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment