Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.inkubator.hrm.dao.impl; import com.inkubator.datacore.dao.impl.IDAOImpl; import com.inkubator.hrm.dao.BioPotensiSwotDao; import com.inkubator.hrm.entity.BioPotensiSwot; import com.inkubator.hrm.web.search.BioPotensiSwotSearchParameter; import java.util.List; import org.hibernate.Criteria; import org.hibernate.criterion.Disjunction; import org.hibernate.criterion.MatchMode; import org.hibernate.criterion.Order; import org.hibernate.criterion.Projections; import org.hibernate.criterion.Restrictions; import org.hibernate.sql.JoinType; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Repository; /** * * @author Deni */ @Repository(value = "bioPotensiSwotDao") @Lazy public class BioPotensiSwotDaoImpl extends IDAOImpl<BioPotensiSwot> implements BioPotensiSwotDao { @Override public Class<BioPotensiSwot> getEntityClass() { return BioPotensiSwot.class; } @Override public List<BioPotensiSwot> getByParam(BioPotensiSwotSearchParameter searchParameter, int firstResult, int maxResults, Order order) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); doSearchByParam(searchParameter, criteria); criteria.addOrder(order); criteria.setFirstResult(firstResult); criteria.setMaxResults(maxResults); return criteria.list(); } @Override public Long getTotalByParam(BioPotensiSwotSearchParameter searchParameter) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); doSearchByParam(searchParameter, criteria); return (Long) criteria.setProjection(Projections.rowCount()).uniqueResult(); } public void doSearchByParam(BioPotensiSwotSearchParameter searchParameter, Criteria criteria) { if (searchParameter.getName() != null) { criteria.createAlias("bioData", "bio", JoinType.INNER_JOIN); Disjunction disjunction = Restrictions.disjunction(); disjunction.add(Restrictions.like("bio.firstName", searchParameter.getName(), MatchMode.START)); disjunction.add(Restrictions.like("bio.lastName", searchParameter.getName(), MatchMode.START)); criteria.add(disjunction); } criteria.add(Restrictions.isNotNull("id")); } @Override public List<BioPotensiSwot> getAllDataByBioDataId(Long bioDataId) { Criteria criteria = getCurrentSession().createCriteria(getEntityClass()); criteria.add(Restrictions.eq("bioData.id", bioDataId)); return criteria.list(); } }