List of usage examples for org.hibernate Query setEntity
@Deprecated @SuppressWarnings("unchecked") Query<R> setEntity(String name, Object val);
From source file:com.appeligo.search.entity.User.java
License:Apache License
public boolean isEmailAvailableForUser(String email) { Session session = getSession();/*from w w w . j a va 2 s. com*/ Query query = session.getNamedQuery("User.checkEmailAvailableForUser"); query.setString("email", email); query.setEntity("user", this); List test = query.list(); if (test.size() > 0) { return false; } else { return true; } }
From source file:com.autobizlogic.abl.rule.MinMaxRule.java
License:Open Source License
/** * When there is no other way, we have to issue a SQL to figure out the new min/max value. *///from ww w .j av a2s. co m /*private*/ void sqlRecompute(PersistentBean bean, LogicTransactionContext context) { String minMax = "max"; if (type == MinMaxType.MIN) minMax = "min"; String sql = "select " + minMax + "(" + getWatchedFieldName() + ") from " + getRole().getOtherMetaEntity().getEntityName() + " where " + getRole().getOtherMetaRole().getRoleName() + " = :parent"; if (getQualificationSQL() != null) sql += " and (" + getQualificationSQL() + ")"; Query query = context.getSession().createQuery(sql); query.setEntity("parent", bean.getEntity()); Object result = query.uniqueResult(); Class<?> attType = bean.getMetaEntity().getMetaAttribute(getBeanAttributeName()).getType(); Number newMax = NumberUtil.convertNumberToType((Number) result, attType); bean.put(getBeanAttributeName(), newMax); }
From source file:com.bloatit.data.DaoDescription.java
License:Open Source License
/** * Get a translation for a given locale. * /* ww w.j ava 2 s. co m*/ * @param locale the locale in which we want the description * @return null if no translation exists for this locale. */ public DaoTranslation getTranslation(final Language language) { final Query q = SessionManager.getNamedQuery("description.getTranslations.byLocale"); q.setString("locale", language.getCode()); q.setEntity("this", this); return (DaoTranslation) q.uniqueResult(); }
From source file:com.bloatit.data.DaoFeature.java
License:Open Source License
/** * Count open bugs.//from w w w .ja va2s . c o m * * @return the int */ public int countOpenBugs() { if (selectedOffer == null) { return 0; } final Query query = SessionManager.getNamedQuery("feature.getBugs.byNonState.size"); query.setEntity("offer", this.selectedOffer); query.setParameter("state", DaoBug.BugState.RESOLVED); return ((Long) query.uniqueResult()).intValue(); }
From source file:com.bloatit.data.DaoKudosable.java
License:Open Source License
/** * Use a HQL query to find if a member as already kudosed this kudosable. * // w w w . ja v a 2 s . c o m * @param member The member that could have kudosed this kudosable. (Don't * even think of passing a null member) * @return true if member has kudosed, false otherwise. */ public boolean hasKudosed(final DaoMember member) { final Query q = SessionManager.getNamedQuery("kudosable.getKudos.byMember.size"); q.setEntity("member", member); q.setEntity("this", this); return (Long) q.uniqueResult() > 0; }
From source file:com.bloatit.data.DaoKudosable.java
License:Open Source License
/** * Use a HQL query to find if a member as already kudosed this kudosable. * /*from ww w . j a va 2s.com*/ * @param member The member that could have kudosed this kudosable. (Don't * even think of passing a null member) * @return true if member has kudosed, false otherwise. */ public int getVote(final DaoMember member) { final Query q = SessionManager.getNamedQuery("kudosable.getKudos.byMember.value"); q.setEntity("member", member); q.setEntity("this", this); // return 0 if no vote final Integer vote = (Integer) q.uniqueResult(); if (vote == null) { return 0; } return vote; }
From source file:com.bloatit.data.DaoMember.java
License:Open Source License
public long getInvitationCount() { final Query q = SessionManager.getNamedQuery("member.invitationCount"); q.setEntity("member", this); q.setParameter("state", State.PENDING); return (Long) q.uniqueResult(); }
From source file:com.bloatit.data.DaoMember.java
License:Open Source License
/** * Checks if is in team./*from w ww. j av a 2s. co m*/ * * @param team the team * @return if the current member is in the "team". */ public boolean isInTeam(final DaoTeam team) { final Query q = SessionManager.getNamedQuery("member.isInTeam"); q.setEntity("member", this); q.setEntity("team", team); return ((Long) q.uniqueResult()) >= 1; }
From source file:com.bloatit.data.DaoMilestone.java
License:Open Source License
public BigDecimal getAmountPaid() { final Query q = SessionManager.getNamedQuery("milestone.getAmountPaid"); q.setEntity("this", this); final BigDecimal uniqueResult = (BigDecimal) q.uniqueResult(); if (uniqueResult == null) { return BigDecimal.ZERO; }//from ww w.j a v a 2 s . c o m return uniqueResult; }
From source file:com.bloatit.data.DaoTeam.java
License:Open Source License
/** * Finds if a member is in this team, and which is its status. * //from ww w . ja v a2 s .c o m * @param member The member we want to know its status. * @return {@code null} if the member is not in this team, or a set * otherwise. <br /> * Note, the returned set can be empty if the user is only a Member */ public EnumSet<UserTeamRight> getUserTeamRight(final DaoMember member) { final Query q = SessionManager.getNamedQuery("team.getUserTeamRights"); q.setEntity("member", member); q.setEntity("team", this); final DaoTeamMembership gm = (DaoTeamMembership) q.uniqueResult(); final EnumSet<UserTeamRight> rights = EnumSet.noneOf(UserTeamRight.class); if (gm == null || gm.getRights() == null) { return rights; } for (final DaoTeamRight teamRight : gm.getRights()) { rights.add(teamRight.getUserStatus()); } return rights; }