本文整理汇总了Java中org.hibernate.criterion.Restrictions类的典型用法代码示例。如果您正苦于以下问题:Java Restrictions类的具体用法?Java Restrictions怎么用?Java Restrictions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Restrictions类属于org.hibernate.criterion包,在下文中一共展示了Restrictions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUserByUsername
import org.hibernate.criterion.Restrictions; //导入依赖的package包/类
public User getUserByUsername(String name) {
SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
Session session = sessionFactory.getCurrentSession();
try
{
User user = null;
session.beginTransaction();
Criteria crit = session.createCriteria(User.class);
crit.add(Restrictions.eq("username",name));
List<User> resultList = crit.list();
if (resultList.size() > 0) {
user = (User) crit.list().get(0);
}
session.getTransaction().commit();
return user;
}
catch (HibernateException e)
{
System.out.println("Hibernate Exception" + e.getMessage());
session.getTransaction().rollback();
throw new RuntimeException(e);
}
}
示例2: findPage
import org.hibernate.criterion.Restrictions; //导入依赖的package包/类
@Override
public Page<SurveyDirectory> findPage(Page<SurveyDirectory> page,
SurveyDirectory entity) {
page.setOrderBy("createDate");
page.setOrderDir("desc");
List<Criterion> criterions=new ArrayList<Criterion>();
criterions.add(Restrictions.eq("visibility", 1));
criterions.add(Restrictions.eq("surveyState", 1));
criterions.add(Restrictions.eq("dirType", 2));
criterions.add(Restrictions.eq("surveyModel", 1));
Integer share = entity.getIsShare();
if(share!=null && share==1){
criterions.add(Restrictions.eq("isShare", share));
}
return surveyDirectoryDao.findPageList(page, criterions);
}
示例3: buildCriterions
import org.hibernate.criterion.Restrictions; //导入依赖的package包/类
private void buildCriterions(Collection<com.bstek.dorado.data.provider.Criterion> criterions,
org.hibernate.criterion.Junction dc) {
for (com.bstek.dorado.data.provider.Criterion c : criterions) {
if (c instanceof SingleValueFilterCriterion) {
SingleValueFilterCriterion fc = (SingleValueFilterCriterion) c;
dc.add(this.buildCriterion(fc));
}
if (c instanceof Junction) {
Junction jun = (Junction) c;
org.hibernate.criterion.Junction junction = null;
if (jun instanceof Or) {
junction = Restrictions.disjunction();
} else if (jun instanceof And) {
junction = Restrictions.conjunction();
}
Collection<com.bstek.dorado.data.provider.Criterion> subCriterions = jun.getCriterions();
if (subCriterions != null) {
buildCriterions(subCriterions, dc);
}
dc.add(junction);
}
}
}
示例4: handleGetCount
import org.hibernate.criterion.Restrictions; //导入依赖的package包/类
@Override
protected long handleGetCount(Long trialId, Long groupId, Long visitId, Boolean active) throws Exception {
org.hibernate.Criteria ecrfCriteria = createEcrfCriteria(null);
if (trialId != null) {
ecrfCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
}
if (groupId != null) {
ecrfCriteria.add(Restrictions.or(Restrictions.eq("group.id", groupId.longValue()),
Restrictions.isNull("group.id")));
}
if (visitId != null) {
ecrfCriteria.add(Restrictions.or(Restrictions.eq("visit.id", visitId.longValue()),
Restrictions.isNull("visit.id")));
}
if (active != null) {
ecrfCriteria.add(Restrictions.eq("active", active.booleanValue()));
}
return (Long) ecrfCriteria.setProjection(Projections.rowCount()).uniqueResult();
}
示例5: getDownloadedSizeByUserSince
import org.hibernate.criterion.Restrictions; //导入依赖的package包/类
public long getDownloadedSizeByUserSince (final User user, final Date date)
{
Long result =
getHibernateTemplate ().execute (new HibernateCallback<Long> ()
{
@Override
public Long doInHibernate (Session session)
throws HibernateException, SQLException
{
Criteria criteria = session.createCriteria (
NetworkUsage.class);
criteria.setProjection (Projections.sum ("size"));
criteria.add (Restrictions.eq ("isDownload", true));
criteria.add (Restrictions.eq ("user", user));
criteria.add (Restrictions.gt ("date", date));
return (Long) criteria.uniqueResult ();
}
});
return (result == null) ? 0 : result;
}
示例6: showZipAndUnClassifyFolder
import org.hibernate.criterion.Restrictions; //导入依赖的package包/类
/**
* 展示已经解压未识别的列表
*/
@Override
public List<Zip> showZipAndUnClassifyFolder() {
List<Zip> zips = new ArrayList<Zip>();
Session session = HibernateUtils.getSession();//生成Session实例
Transaction tx = session.beginTransaction();//生成事务实例
try {
zips = session.createCriteria(Zip.class).add(Restrictions.eq("isZip", 1)).add(Restrictions.eq("isClassify", 0)).list();
tx.commit();//提交事务
} catch (Exception e) {
e.printStackTrace();
tx.rollback();
}finally {
HibernateUtils.closeSession();//关闭session实例
}
return zips;
}
示例7: handleFindByDepartmentPayoffs
import org.hibernate.criterion.Restrictions; //导入依赖的package包/类
@Override
protected Collection<Trial> handleFindByDepartmentPayoffs(Long departmentId, Boolean payoffs, PSFVO psf) throws Exception {
org.hibernate.Criteria trialCriteria = createTrialCriteria(null);
SubCriteriaMap criteriaMap = new SubCriteriaMap(Trial.class, trialCriteria);
if (departmentId != null) {
trialCriteria.add(Restrictions.eq("department.id", departmentId.longValue()));
}
if (payoffs != null) {
if (payoffs) {
trialCriteria.add(Restrictions.sizeGt("payoffs", 0));
} else {
trialCriteria.add(Restrictions.sizeEq("payoffs", 0));
}
}
CriteriaUtil.applyPSFVO(criteriaMap, psf);
return trialCriteria.list();
}
示例8: handleFindByPersonOrganisationIdExcel
import org.hibernate.criterion.Restrictions; //导入依赖的package包/类
@Override
protected Collection<StaffTag> handleFindByPersonOrganisationIdExcel(
Boolean person, Boolean organisation, Long tagId, Boolean excel) throws Exception {
org.hibernate.Criteria staffTagCriteria = this.getSession().createCriteria(StaffTag.class);
staffTagCriteria.setCacheable(true);
if (excel != null) {
staffTagCriteria.add(Restrictions.eq("excel", excel.booleanValue()));
}
if (person != null) {
if (tagId != null) {
staffTagCriteria.add(Restrictions.or(Restrictions.eq("person", person.booleanValue()), Restrictions.idEq(tagId.longValue())));
} else {
staffTagCriteria.add(Restrictions.eq("person", person.booleanValue()));
}
}
if (organisation != null) {
if (tagId != null) {
staffTagCriteria.add(Restrictions.or(Restrictions.eq("organisation", organisation.booleanValue()), Restrictions.idEq(tagId.longValue())));
} else {
staffTagCriteria.add(Restrictions.eq("organisation", organisation.booleanValue()));
}
}
return staffTagCriteria.list();
}
示例9: handleFindByTrialExcelEcrfProbandSorted
import org.hibernate.criterion.Restrictions; //导入依赖的package包/类
@Override
protected Collection<ProbandListEntryTag> handleFindByTrialExcelEcrfProbandSorted(Long trialId, Boolean excel, Boolean ecrf, Long probandId) throws Exception {
org.hibernate.Criteria listEntryTagCriteria = createListEntryTagCriteria();
if (trialId != null) {
listEntryTagCriteria.add(Restrictions.eq("trial.id", trialId.longValue()));
}
if (excel != null) {
listEntryTagCriteria.add(Restrictions.or(Restrictions.eq("excelValue", excel.booleanValue()),
Restrictions.eq("excelDate", excel.booleanValue())));
}
if (ecrf != null) {
listEntryTagCriteria.add(Restrictions.eq("ecrfValue", ecrf.booleanValue()));
}
if (probandId != null) {
listEntryTagCriteria.createCriteria("tagValues", CriteriaSpecification.INNER_JOIN).createCriteria("listEntry", CriteriaSpecification.INNER_JOIN)
.add(Restrictions.eq("proband.id", probandId.longValue()));
}
applySortOrders(listEntryTagCriteria);
// listEntryTagCriteria.setResultTransformer(org.hibernate.Criteria.DISTINCT_ROOT_ENTITY);
// return listEntryTagCriteria.list();
return CriteriaUtil.listDistinctRoot(listEntryTagCriteria, this, "trial.id", "position");
}
示例10: handleFindByModuleCategory
import org.hibernate.criterion.Restrictions; //导入依赖的package包/类
@Override
protected Collection<Criteria> handleFindByModuleCategory(DBModule module,
String category, Boolean loadByDefault, PSFVO psf) throws Exception {
org.hibernate.Criteria criteriaCriteria = createCriteriaCriteria();
SubCriteriaMap criteriaMap = new SubCriteriaMap(Criteria.class, criteriaCriteria);
if (module != null) {
criteriaCriteria.add(Restrictions.eq("module", module));
}
if (loadByDefault != null) {
criteriaCriteria.add(Restrictions.eq("loadByDefault", loadByDefault.booleanValue()));
}
if (category != null && category.length() > 0) {
criteriaCriteria.add(Restrictions.eq("category", category));
} else {
criteriaCriteria.add(Restrictions.or(Restrictions.eq("category", ""), Restrictions.isNull("category")));
}
CriteriaUtil.applyPSFVO(criteriaMap, psf);
return criteriaCriteria.list();
}
示例11: buildCriterions
import org.hibernate.criterion.Restrictions; //导入依赖的package包/类
private void buildCriterions(Collection<com.bstek.dorado.data.provider.Criterion> criterions,DetachedCriteria dc){
for(com.bstek.dorado.data.provider.Criterion c : criterions){
if (c instanceof SingleValueFilterCriterion){
SingleValueFilterCriterion fc = (SingleValueFilterCriterion) c;
dc.add(this.buildCriterion(fc));
}
if (c instanceof Junction) {
Junction jun = (Junction) c;
org.hibernate.criterion.Junction junction = null;
if (jun instanceof Or) {
junction = Restrictions.disjunction();
} else if (jun instanceof And) {
junction = Restrictions.conjunction();
}
Collection<com.bstek.dorado.data.provider.Criterion> subCriterions = jun.getCriterions();
if (subCriterions != null) {
buildCriterions(subCriterions, junction);
}
dc.add(junction);
}
}
}
示例12: on
import org.hibernate.criterion.Restrictions; //导入依赖的package包/类
@Transactional
@Listen
public void on(PullRequestEvent event) {
if (event instanceof MarkdownAware) {
String markdown = ((MarkdownAware)event).getMarkdown();
if (markdown != null) {
String html = markdownManager.render(markdown, null, false);
for (PullRequest referenced: new PullRequestParser().parseRequests(html)) {
if (!referenced.equals(event.getRequest())) {
EntityCriteria<PullRequestReference> criteria = EntityCriteria.of(PullRequestReference.class);
criteria.add(Restrictions.eq("referenced", referenced));
criteria.add(Restrictions.eq("referencedBy", event.getRequest()));
if (dao.find(criteria) == null) {
PullRequestReference reference = new PullRequestReference();
reference.setReferencedBy(event.getRequest());
reference.setReferenced(referenced);
reference.setDate(new Date());
reference.setUser(userManager.getCurrent());
save(reference);
}
}
}
}
}
}
示例13: handleFindAllSorted
import org.hibernate.criterion.Restrictions; //导入依赖的package包/类
@Override
protected Collection<ProbandListEntryTag> handleFindAllSorted(String nameInfix, Integer limit) throws Exception {
org.hibernate.Criteria listEntryTagCriteria = createListEntryTagCriteria();
if (!CommonUtil.isEmptyString(nameInfix)) {
org.hibernate.Criteria trialCriteria = listEntryTagCriteria.createCriteria("trial", "trial0", CriteriaSpecification.INNER_JOIN);
org.hibernate.Criteria fieldCriteria = listEntryTagCriteria.createCriteria("field", "inputField", CriteriaSpecification.INNER_JOIN);
//fieldCriteria.add(Restrictions.eq("localized", false));
listEntryTagCriteria.add(Restrictions.or(
(new CategoryCriterion(nameInfix, "inputField.nameL10nKey", MatchMode.ANYWHERE)).getRestriction(),
(new CategoryCriterion(nameInfix, "trial0.name", MatchMode.ANYWHERE)).getRestriction()
));
}
applySortOrders(listEntryTagCriteria);
CriteriaUtil.applyLimit(limit, Settings.getIntNullable(SettingCodes.PROBAND_LIST_ENTRY_TAG_FIELD_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT, Bundle.SETTINGS,
DefaultSettings.PROBAND_LIST_ENTRY_TAG_FIELD_AUTOCOMPLETE_DEFAULT_RESULT_LIMIT), listEntryTagCriteria);
return listEntryTagCriteria.list();
}
示例14: getLatest
import org.hibernate.criterion.Restrictions; //导入依赖的package包/类
@Override
public List<App> getLatest(short catalog, Integer subCatalog, Long date, int currentPage, int pageSize,
Boolean noAds, Boolean noVirus, Boolean official) {
Criteria cri = getSession().createCriteria(App.class);
getLastestByFilter(catalog, subCatalog, date, cri);
cri.add(Restrictions.eq("hidden", false));
filterAdVirusOfficial(noAds, noVirus, official, cri);
if (date != null) {
cri.addOrder(Order.desc("viewCount"));
} else {
// 不查询日期,按日期先排序.
cri.addOrder(Order.desc("lastUpdateTime"));
}
cri.setFirstResult(HibernateHelper.firstResult(currentPage, pageSize));
cri.setMaxResults(pageSize);
List<App> list = HibernateHelper.list(cri);
return list;
}
示例15: lockEntity
import org.hibernate.criterion.Restrictions; //导入依赖的package包/类
@Override
@Transactional
public EntityLock lockEntity(BaseEntity entity, String sessionId)
{
EntityLock lock = entityLockDao.findByCriteria(Restrictions.eq("entity", entity));
if( lock != null )
{
throw new LockedException("Entity is already locked", lock.getUserID(), lock.getUserSession(),
entity.getId());
}
else
{
lock = new EntityLock();
lock.setEntity(entity);
lock.setUserID(CurrentUser.getUserID());
lock.setUserSession(sessionId);
lock.setInstitution(CurrentInstitution.get());
entityLockDao.save(lock);
return lock;
}
}