List of usage examples for org.hibernate.criterion Restrictions ne
public static SimpleExpression ne(String propertyName, Object value)
From source file:net.firejack.platform.core.store.registry.RoleStore.java
License:Apache License
@Override @SuppressWarnings("unchecked") @Transactional(readOnly = true)/*from www .j av a 2 s . c om*/ public List<RoleModel> findContextRolesByLookupListWithPermissions(List<String> lookupList) { List<RoleModel> contextRoles; if (lookupList == null || lookupList.isEmpty()) { contextRoles = new ArrayList<RoleModel>(); } else { Criteria criteria = getSession().createCriteria(RoleModel.class); criteria.add(Restrictions.in("lookup", lookupList)); criteria.createAlias("parent", "parent"); criteria.add(Restrictions.ne("parent.class", "PKG")); contextRoles = (List<RoleModel>) criteria.list(); if (!contextRoles.isEmpty()) { for (RoleModel roleModel : contextRoles) { Hibernate.initialize(roleModel.getPermissions()); } } } return contextRoles; }
From source file:net.frontlinesms.plugins.reminders.data.repository.hibernate.HibernateReminderDao.java
License:Open Source License
/** @see ReminderDao#getPendingReminders() */ public Collection<Reminder> getPendingReminders() { DetachedCriteria criteria = super.getCriterion(); Criterion notSent = Restrictions.ne(Field.STATUS.getFieldName(), Reminder.Status.SENT); Criterion isNull = Restrictions.isNull(Field.STATUS.getFieldName()); criteria.add(Restrictions.or(notSent, isNull)); return super.getList(criteria); }
From source file:net.hybridcore.crowley.habbo.messages.outgoing.friendlist.HabboSearchResultComposer.java
License:BEER-WARE LICENSE
@Override public void run() { Habbo habbo = this.gameSession.getHabbo(); Session session = DatastoreUtil.currentSession(); List results = session.createCriteria(Habbo.class) .add(Restrictions.like("name", "%" + this.clientMessage.readString() + "%").ignoreCase()) .add(Restrictions.ne("id", habbo.getId())).setMaxResults(25).list(); List<Habbo> friends = new ArrayList<Habbo>(); List<Habbo> others = new ArrayList<Habbo>(); for (Object result : results) { if (result instanceof Habbo) { boolean resultFriend = false; for (Habbo friend : habbo.getFriends()) { if (((Habbo) result).getId().equals(friend.getId())) { resultFriend = true; break; }/*from w w w . j av a2s.c o m*/ } if (resultFriend) { friends.add((Habbo) result); } else { others.add((Habbo) result); } } } ServerMessage serverMessage = new ServerMessage(435); serverMessage.append(friends.size()); for (Habbo friend : friends) { friend.serializeMessenger(serverMessage, true); } serverMessage.append(others.size()); for (Habbo other : others) { other.serializeMessenger(serverMessage, true); } this.gameSession.sendMessage(serverMessage); }
From source file:net.umpay.mailbill.hql.orm.hibernate.HibernateDao.java
License:Apache License
/** * ??Criterion,./*from w w w . j a v a 2 s . c o m*/ */ protected Criterion buildPropertyFilterCriterion(final String propertyName, final Object propertyValue, final MatchType matchType) { Assert.hasText(propertyName, "propertyName?"); Criterion criterion = null; try { //?MatchTypecriterion if (MatchType.EQ.equals(matchType)) { criterion = Restrictions.eq(propertyName, propertyValue); } else if (MatchType.LIKE.equals(matchType)) { criterion = Restrictions.like(propertyName, (String) propertyValue, MatchMode.ANYWHERE); } else if (MatchType.LE.equals(matchType)) { criterion = Restrictions.le(propertyName, propertyValue); } else if (MatchType.LT.equals(matchType)) { criterion = Restrictions.lt(propertyName, propertyValue); } else if (MatchType.GE.equals(matchType)) { criterion = Restrictions.ge(propertyName, propertyValue); } else if (MatchType.GT.equals(matchType)) { criterion = Restrictions.gt(propertyName, propertyValue); } else if (MatchType.NE.equals(matchType)) { criterion = Restrictions.ne(propertyName, propertyValue); } } catch (Exception e) { throw ReflectionUtils.convertReflectionExceptionToUnchecked(e); } return criterion; }
From source file:nl.surfnet.coin.teams.service.impl.TeamInviteServiceHibernateImpl.java
License:Apache License
/** * {@inheritDoc}//from w ww.j av a 2 s. c o m */ @Override public List<Invitation> findPendingInvitationsByEmail(String email) { cleanupExpiredInvitations(); return findByCriteria(Restrictions.eq("email", email), Restrictions.ne("declined", true), Restrictions.ne("accepted", true)); }
From source file:np.com.drose.studentmanagementsystem.dao.impl.ProjectDAOImpl.java
@Override public List<Project> getProjectList() { Session session = sessionFactory.openSession(); Transaction tx = session.beginTransaction(); List<Project> result = session.createCriteria(Project.class) .add(Restrictions.ne("projectStatus", Project.ProjectStatus.FINISHED)).list(); tx.commit();/*from ww w . j a v a2s . c om*/ session.close(); return result; }
From source file:ome.services.search.SearchAction.java
License:Open Source License
void on(Criteria criteria, boolean equals) { check();/* w ww .ja va 2 s . c o m*/ if (equals) { criteria.add(Restrictions.eq(path, id)); } else { criteria.add(Restrictions.ne(path, id)); } }
From source file:org.ambraproject.admin.service.impl.AdminServiceImpl.java
License:Apache License
@Override @Transactional(readOnly = true)/*ww w .j a v a 2 s. c om*/ @SuppressWarnings("unchecked") public List<String> getCrossPubbedArticles(Journal journal) { return hibernateTemplate.findByCriteria(DetachedCriteria.forClass(Article.class) .add(Restrictions.ne("eIssn", journal.geteIssn())).createAlias("journals", "j") .add(Restrictions.eq("j.eIssn", journal.geteIssn())).setProjection(Projections.property("doi"))); }
From source file:org.ambraproject.admin.service.impl.DocumentManagementServiceImpl.java
License:Apache License
@Override @Transactional(rollbackFor = { Throwable.class }) public void delete(String articleDoi, final String authId) throws Exception { permissionsService.checkPermission(Permission.DELETE_ARTICLES, authId); log.debug("Deleting Article:" + articleDoi); //delete the article from the db List articles = hibernateTemplate.findByCriteria(DetachedCriteria.forClass(Article.class) .add(Restrictions.eq("doi", articleDoi)).setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)); if (articles.size() == 0) { throw new NoSuchArticleIdException(articleDoi); }// w w w . j a va 2 s . co m //delete any views on the article hibernateTemplate.deleteAll(hibernateTemplate.findByCriteria(DetachedCriteria.forClass(ArticleView.class) .add(Restrictions.eq("articleID", ((Article) articles.get(0)).getID())) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY))); //delete any trackbacks on the article hibernateTemplate.deleteAll(hibernateTemplate.findByCriteria(DetachedCriteria.forClass(Trackback.class) .add(Restrictions.eq("articleID", ((Article) articles.get(0)).getID())) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY))); //delete any syndications on the article hibernateTemplate.deleteAll(hibernateTemplate.findByCriteria(DetachedCriteria.forClass(Syndication.class) .add(Restrictions.eq("doi", ((Article) articles.get(0)).getDoi())) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY))); //unlink any foreign article relationships hibernateTemplate.bulkUpdate( "update ArticleRelationship set otherArticleID = null where otherArticleID = ?", ((Article) articles.get(0)).getID()); //delete any annotations on the article (need to do this recursivly b/c of replies List<Annotation> topLevelAnnotations = hibernateTemplate.findByCriteria(DetachedCriteria .forClass(Annotation.class).add(Restrictions.eq("articleID", ((Article) articles.get(0)).getID())) .add(Restrictions.ne("type", AnnotationType.REPLY)) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY)); for (Annotation annotation : topLevelAnnotations) { deleteRepliesRecursively(annotation); } hibernateTemplate.delete(articles.get(0)); removeFromFileSystem(articleDoi); invokeOnDeleteListeners(articleDoi); }
From source file:org.ambraproject.service.user.UserServiceImpl.java
License:Apache License
/** * {@inheritDoc}// w ww . ja v a 2 s . c o m */ @Override @Transactional public void saveUserOrcid(Long userProfileId, OrcidAuthorization orcidAuthorization) throws DuplicateOrcidException { UserOrcid userOrcid = (UserOrcid) DataAccessUtils .uniqueResult(hibernateTemplate.findByCriteria(DetachedCriteria.forClass(UserOrcid.class) .add(Restrictions.eq("orcid", orcidAuthorization.getOrcid())) .add(Restrictions.ne("ID", userProfileId)) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY))); if (userOrcid != null) { throw new DuplicateOrcidException( "ORCiD: '" + orcidAuthorization.getOrcid() + "' is already in use by another account"); } userOrcid = (UserOrcid) DataAccessUtils.uniqueResult(hibernateTemplate .findByCriteria(DetachedCriteria.forClass(UserOrcid.class).add(Restrictions.eq("ID", userProfileId)) .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY))); boolean isNew = (userOrcid == null); if (isNew) { userOrcid = new UserOrcid(); userOrcid.setID(userProfileId); } //Note we don't store the token type property of the OrcidAuthorization object. //http://support.orcid.org/knowledgebase/articles/119985-post-oauth-token //The token type for our purposes will always be "bearer" userOrcid.setOrcid(orcidAuthorization.getOrcid()); userOrcid.setAccessToken(orcidAuthorization.getAccessToken()); userOrcid.setRefreshToken(orcidAuthorization.getRefreshToken()); userOrcid.setTokenScope(orcidAuthorization.getScope()); Calendar newExpiresIn = Calendar.getInstance(); //expires-in is "seconds from now" newExpiresIn.setTimeInMillis(newExpiresIn.getTimeInMillis() + (orcidAuthorization.getExpiresIn() * 1000)); userOrcid.setTokenExpires(newExpiresIn); if (isNew) { hibernateTemplate.save(userOrcid); } else { hibernateTemplate.update(userOrcid); } }