List of usage examples for org.hibernate Query setEntity
@Deprecated @SuppressWarnings("unchecked") Query<R> setEntity(String name, Object val);
From source file:itensil.workflow.activities.UserActivities.java
License:Open Source License
/** * //from w w w .j ava 2s . c om * @param activity * @param timerId * @return */ public ActivityTimer getActivityTimer(Activity activity, String timerId) { Query qry = getSession().getNamedQuery("Timer.getTimer"); qry.setString("tid", timerId); qry.setEntity("act", activity); return (ActivityTimer) qry.uniqueResult(); }
From source file:itensil.workflow.activities.UserActivities.java
License:Open Source License
/** * //from ww w .j av a 2 s .c o m * @param fstate * @return */ public Activity getFirstFlowActivity(FlowState fstate) { Query qry = getSession().getNamedQuery("Activity.getFlowActivity"); qry.setEntity("flow", fstate); Iterator itr = qry.iterate(); return itr.hasNext() ? (Activity) itr.next() : null; }
From source file:itensil.workflow.activities.UserActivities.java
License:Open Source License
/** * /*w ww. j av a 2 s .c o m*/ * @param flow * @param variation * @param includeEnded * @return * @throws DAOException */ public Collection<Activity> getFlowActivities(FlowState flow, String variation, boolean includeEnded) throws DAOException { Query qry; if (Check.isEmpty(variation)) { qry = getSession().getNamedQuery("Activity.getFlowActivities"); } else { qry = getSession().getNamedQuery("Activity.getFlowActivitiesVar"); qry.setString("variation", variation); } qry.setString("userSpaceId", user.getUserSpaceId()); qry.setEntity("flow", flow); qry.setInteger("filtSubState", includeEnded ? -1 : SubState.ENTER_END.ordinal()); List res = qry.list(); ArrayList<Activity> acts = new ArrayList<Activity>(res.size()); for (Object oAct : res) { Activity act = (Activity) oAct; if (includeEnded || !act.getStates().isEmpty()) { acts.add(act); } } return acts; }
From source file:modelo.dao.UsuarioDAO.java
License:Open Source License
/** * Validara si el usuario se encuentra inscrito en un grupo. * * @param usuario El usuario a validar si existe en un grupo. * @return Verdadero si el usuario esta inscrito a un grupo.<br> * Falso de otra forma.//from ww w . ja va 2 s. c o m */ public boolean perteneceAGrupo(UsuarioDTO usuario) { boolean ok = false; Session s = getSession(); Transaction tx = null; if (s == null) { System.out.println("Session nula, regresando null...."); } try { tx = s.beginTransaction(); Query query = s.createQuery(USUARIO_PERTENECE_A_GRUPO); query.setEntity("usuario", usuario); List list = query.list(); if (list.size() > 0) { ok = true; } tx.commit(); } catch (Exception e) { System.out.println(e); if (tx != null) { tx.rollback(); } System.out.println("olololol"); } finally { s.close(); System.out.println("Session cerrada"); } return ok; }
From source file:net.commerce.zocalo.hibernate.HibernateUtil.java
License:Open Source License
public static List tradeListForJsp(String claimName) { Claim claim = getClaimByName(claimName); Session session = currentSession();/* w ww . j av a 2s .c om*/ Query mQ = session.createQuery("select t from Trade t " + "join t.pos p " + "where t.pos = p.id and p.claim = :cl " + "order by t.time"); mQ.setEntity("cl", claim); mQ.setCacheable(true); return mQ.list(); }
From source file:net.commerce.zocalo.hibernate.HibernateUtil.java
License:Open Source License
public static List maxTradeTime(String claimName) { Claim claim = getClaimByName(claimName); Session session = currentSession();//from w w w . ja va2 s . c om Query mQ = session.createQuery( "select max(t.time) from Trade t " + "join t.pos p " + "where t.pos = p.id and p.claim = :cl "); mQ.setEntity("cl", claim); mQ.setCacheable(true); return mQ.list(); }
From source file:net.commerce.zocalo.hibernate.HibernateUtil.java
License:Open Source License
public static List couponOwners(Claim claim) { Session session = currentSession();//from w w w .j av a 2 s . co m //TODO: I can't see how to access the Claims that are the keys of acct's positions map. //TODO: that would require two fewer joins! //select owner.user_id" + //from public.USER owner, public.accounts acct, PUBLIC.ACCOUNT_HOLDINGS assets, PUBLIC.POSITIONS pos " + // where owner.accounts = acct.accounts_id" + // and acct.accounts_id = assets.accounts_id" // and assets.POSITIONS_ID = pos.positions_id " + // and pos.claims_ID=2 " + Query qa = session.createQuery("select u \n" + "from SecureUser u \n" + " join u.accounts acct\n" + " join acct.positions coupon \n" + "where u.accounts = acct.id and coupon.position.claim = :claim "); qa.setEntity("claim", claim); qa.setCacheable(true); return qa.list(); }
From source file:net.sf.ehcache.hibernate.domain.EventManager.java
License:Apache License
/** * Call setEntity() on a cacheable query - see FORGE-265 *///from w w w . ja v a2s . co m public List listEventsOfOrganizer(Person organizer) { Session session = sessionFactory.getCurrentSession(); session.beginTransaction(); Query query = session.createQuery("from Event ev where ev.organizer = :organizer"); query.setCacheable(true); query.setEntity("organizer", organizer); List result = query.list(); session.getTransaction().commit(); return result; }
From source file:net.webpasswordsafe.server.dao.PasswordDAOHibernate.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public Password findAllowedPasswordById(long passwordId, User user, AccessLevel accessLevel) { Password foundPassword = null;// w ww . j a va2 s .com String sqlAccessLevelIn = null; switch (accessLevel) { case GRANT: sqlAccessLevelIn = "(:aclgrant) "; break; case WRITE: sqlAccessLevelIn = "(:aclwrite, :aclgrant) "; break; case READ: sqlAccessLevelIn = "(:aclread, :aclwrite, :aclgrant) "; break; } StringBuilder hqlString = new StringBuilder(); hqlString .append("select distinct pw.id from Password pw join pw.permissions pm where pw.id = :passwordId "); if (!authorizer.isAuthorized(user, Function.BYPASS_PASSWORD_PERMISSIONS.name())) { hqlString.append(" and pm.accessLevel in "); hqlString.append(sqlAccessLevelIn); hqlString.append( "and ((pm.subject = :user) or (pm.subject in (select g from Group g join g.users u where u = :user)))"); } Query hqlQuery = getSession().createQuery(hqlString.toString()); hqlQuery.setLong("passwordId", passwordId); if (!authorizer.isAuthorized(user, Function.BYPASS_PASSWORD_PERMISSIONS.name())) { hqlQuery.setEntity("user", user); if (accessLevel.equals(AccessLevel.GRANT) || accessLevel.equals(AccessLevel.WRITE) || accessLevel.equals(AccessLevel.READ)) { hqlQuery.setString("aclgrant", AccessLevel.GRANT.name()); } if (accessLevel.equals(AccessLevel.WRITE) || accessLevel.equals(AccessLevel.READ)) { hqlQuery.setString("aclwrite", AccessLevel.WRITE.name()); } if (accessLevel.equals(AccessLevel.READ)) { hqlQuery.setString("aclread", AccessLevel.READ.name()); } } List<Long> passwordIds = hqlQuery.list(); if (passwordIds.size() > 0) { foundPassword = findById(passwordIds.get(0)); foundPassword.getPermissions().size(); foundPassword.getTags().size(); } return foundPassword; }
From source file:net.webpasswordsafe.server.dao.PasswordDAOHibernate.java
License:Open Source License
@Override @SuppressWarnings("unchecked") public AccessLevel getMaxEffectiveAccessLevel(Password password, User user) { AccessLevel maxEffectiveAccessLevel = null; if (authorizer.isAuthorized(user, Function.BYPASS_PASSWORD_PERMISSIONS.name())) { maxEffectiveAccessLevel = AccessLevel.GRANT; } else {/*w w w .j a va 2 s . c om*/ StringBuilder hqlString = new StringBuilder(); hqlString.append("select distinct pm.accessLevel from Permission pm "); hqlString.append("where pm.password = :password "); hqlString.append("and pm.accessLevel in (:aclread, :aclwrite, :aclgrant) "); hqlString.append( "and ((pm.subject = :user) or (pm.subject in (select g from Group g join g.users u where u = :user)))"); Query hqlQuery = getSession().createQuery(hqlString.toString()); hqlQuery.setEntity("password", password); hqlQuery.setEntity("user", user); hqlQuery.setString("aclread", AccessLevel.READ.name()); hqlQuery.setString("aclwrite", AccessLevel.WRITE.name()); hqlQuery.setString("aclgrant", AccessLevel.GRANT.name()); Set<String> accessLevels = new HashSet<String>(hqlQuery.list()); if (accessLevels.contains(AccessLevel.GRANT.name())) { maxEffectiveAccessLevel = AccessLevel.GRANT; } else if (accessLevels.contains(AccessLevel.WRITE.name())) { maxEffectiveAccessLevel = AccessLevel.WRITE; } else if (accessLevels.contains(AccessLevel.READ.name())) { maxEffectiveAccessLevel = AccessLevel.READ; } } return maxEffectiveAccessLevel; }