Commit 9bab9437 by Jan Hrabal

x

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