List of usage examples for org.hibernate Filter setParameter
public Filter setParameter(String name, Object value);
From source file:it.eng.spagobi.commons.dao.AbstractHibernateDAO.java
License:Mozilla Public License
protected void enableTenantFilter(Session session, String tenantId) { Filter filter = session.enableFilter(TENANT_FILTER_NAME); filter.setParameter("tenant", tenantId); }
From source file:nz.co.nomadconsulting.simplepersistence.TransactionInterceptor.java
License:Apache License
private void enableFilter(final Filter f, final EntityManager entityManager) { try {//from ww w . ja v a2s. co m if (!(Boolean) expressions.evaluateValueExpression(f.getEnabledExpression())) { return; } final org.hibernate.Filter filter = getSession(entityManager).enableFilter(f.getName()); for (final Map.Entry<String, String> me : f.getParameters().entrySet()) { final Object filterValue = expressions.evaluateValueExpression(me.getValue()); if (filterValue instanceof Collection) { filter.setParameterList(me.getKey(), (Collection<?>) filterValue); } else { filter.setParameter(me.getKey(), filterValue); } } filter.validate(); } catch (final NotHibernateException nhe) { throw new RuntimeException("bob"); } }
From source file:ome.security.basic.AbstractSecurityFilter.java
License:Open Source License
protected void enableBaseFilters(Session sess, int admin01, Long currentUserId) { final Filter sessionFilter = sess.enableFilter("owner_or_admin"); sessionFilter.setParameter("is_admin", admin01); sessionFilter.setParameter("current_user", currentUserId); }
From source file:ome.security.basic.AllGroupsSecurityFilter.java
License:Open Source License
/*** * Since we assume that the group is "-1" for this method, we have to pass * in lists of all groups as we did before group permissions (~4.2). *//*from www.j a v a2s . c o m*/ public void enable(Session sess, EventContext ec) { final Filter filter = sess.enableFilter(getName()); final int share01 = isShare(ec) ? 1 : 0; final int admin01 = ec.isCurrentUserAdmin() ? 1 : 0; filter.setParameter(is_admin, admin01); filter.setParameter(SecurityFilter.is_share, share01); // ticket:2219, not checking -1 here. filter.setParameter(SecurityFilter.current_user, ec.getCurrentUserId()); filter.setParameterList(member_of_groups, configGroup(ec, ec.getMemberOfGroupsList())); filter.setParameterList(leader_of_groups, configGroup(ec, ec.getLeaderOfGroupsList())); enableBaseFilters(sess, admin01, ec.getCurrentUserId()); }
From source file:ome.security.basic.OneGroupSecurityFilter.java
License:Open Source License
public void enable(Session sess, EventContext ec) { final Filter filter = sess.enableFilter(getName()); final Long groupId = ec.getCurrentGroupId(); final Long shareId = ec.getCurrentShareId(); int share01 = shareId != null ? 1 : 0; // non-final; "ticket:3529" below final int adminOrPi01 = (ec.isCurrentUserAdmin() || ec.getLeaderOfGroupsList().contains(ec.getCurrentGroupId())) ? 1 : 0; final int nonpriv01 = (ec.getCurrentGroupPermissions().isGranted(Role.GROUP, Right.READ) || ec.getCurrentGroupPermissions().isGranted(Role.WORLD, Right.READ)) ? 1 : 0; if (groupId < 0) { // Special marker throwNegOne();//from w w w. j a v a 2s .com } filter.setParameter(SecurityFilter.is_share, share01); // ticket:2219, not checking -1 here. filter.setParameter(SecurityFilter.is_adminorpi, adminOrPi01); filter.setParameter(SecurityFilter.is_nonprivate, nonpriv01); filter.setParameter(SecurityFilter.current_user, ec.getCurrentUserId()); filter.setParameter(current_group, groupId); enableBaseFilters(sess, ec.isCurrentUserAdmin() ? 1 : 0, ec.getCurrentUserId()); }
From source file:ome.security.basic.SharingSecurityFilter.java
License:Open Source License
@Override public void enable(Session session, EventContext ec) { List<Long> imageIds = null; final Long shareId = ec.getCurrentShareId(); if (shareId != null) { final ShareData shareData = shares.get(shareId); if (shareData != null && shareData.enabled) { imageIds = shareData.objectMap.get(Image.class.getName()); }//from w ww . j a v a2s. c o m } if (CollectionUtils.isEmpty(imageIds)) { imageIds = ImmutableList.of(-1L); } final int isAdmin01 = ec.isCurrentUserAdmin() ? 1 : 0; final int isShare01 = isShare(ec) ? 1 : 0; final Filter filter = session.enableFilter(getName()); filter.setParameter("is_admin", isAdmin01); filter.setParameter("is_share", isShare01); filter.setParameterList("images", imageIds); enableBaseFilters(session, isAdmin01, ec.getCurrentUserId()); }
From source file:org.activityinfo.server.database.hibernate.entity.DomainFilters.java
License:Open Source License
public static void applyVisibleFilter(int userId, EntityManager em) { /* Hide entities that this user does not have permission to view */ org.hibernate.Session session = ((HibernateEntityManager) em).getSession(); Filter filter = session.enableFilter("userVisible"); filter.setParameter("currentUserId", userId); }
From source file:org.candlepin.model.PoolCurator.java
License:Open Source License
/** * @param session/*from w ww . j a v a2s.c o m*/ * @param consumerFilter */ private void enableIfPrevEnabled(Filter consumerFilter) { // if filter was previously enabled, restore it. if (consumerFilter != null) { FilterImpl filterImpl = (FilterImpl) consumerFilter; Filter filter = currentSession().enableFilter(CONSUMER_FILTER); filter.setParameter("consumer_id", filterImpl.getParameter("consumer_id")); } }
From source file:org.jasig.portlet.ClassifiedsPortlet.service.HeadingServiceImpl.java
License:Apache License
public List<Heading> getHeadings() { final String query = "from Heading order by headingname "; HibernateCallback callback = new HibernateCallback() { public Object doInHibernate(Session session) throws HibernateException, SQLException { org.hibernate.Filter filter = session.enableFilter("VALID_ADS"); filter.setParameter("categoryRecordFilterParam", new Date()); return session.createQuery(query).setCacheable(true).list(); }//from w ww. java 2 s . co m }; return (List<Heading>) getHibernateTemplate().execute(callback); }
From source file:org.jdbcluster.template.hibernate.HibernateSession.java
License:Apache License
/** * activates the given Filter on the Session. The Filter contains the name, parameter name * @param sessionFilter the filter with the given name will be activated on the session. *///from w w w .ja v a2 s . c o m public void enableFilter(SessionFilter sessionFilter) { Filter filter = hibernateSession.enableFilter(sessionFilter.getFilterName()); if (filter == null) { throw new RuntimeException("Filter with name '" + sessionFilter.getFilterName() + "' is null - check your Hibernate filter configuration"); } for (Object value : sessionFilter.getValues()) { if (sessionFilter.getParameterName() != null && !sessionFilter.getParameterName().equals("") && value != null) { filter.setParameter(sessionFilter.getParameterName(), value); } } }