List of usage examples for org.hibernate Session disableFilter
void disableFilter(String filterName);
From source file:ome.security.basic.AbstractSecurityFilter.java
License:Open Source License
protected void disableBaseFilters(Session sess) { sess.disableFilter("owner_or_admin"); }
From source file:ome.services.query.Query.java
License:Open Source License
/** * turns the filters off that are listed in {@link #newlyEnabledFilters} *//* w w w.ja v a2 s.c om*/ protected void disableFilters(Session session) { for (String enabledFilter : newlyEnabledFilters) { session.disableFilter(enabledFilter); } }
From source file:org.bonitasoft.engine.persistence.TenantHibernatePersistenceService.java
License:Open Source License
protected void updateTenantFilter(final Session session, final boolean useTenant) throws SPersistenceException { if (useTenant) { try {/*from ww w.j av a2 s.c o m*/ session.enableFilter(TENANT_FILTER).setParameter(TENANT_ID, getTenantId()); } catch (final STenantIdNotSetException e) { throw new SPersistenceException(e); } } else { session.disableFilter(TENANT_FILTER); } }
From source file:org.eclipse.emf.teneo.hibernate.test.emf.sample.EmployeeAction.java
License:Open Source License
/** Creates an item, an address and links them to a po. */ @Override//www .j a va 2 s . co m public void doAction(TestStore store) { final EmployeeFactory f = EmployeeFactory.eINSTANCE; { final Employee e1 = f.createEmployee(); e1.setName("e1"); e1.setAge(29); e1.setSalary(100); e1.setHireDate(new Date(System.currentTimeMillis() + 100000)); final Employee e2 = f.createEmployee(); e2.setName("e2"); e2.setAge(39); e2.setSalary(1000); final long ONE_DAY = 3600 * 1000 * 24; e2.setHireDate(new Date(System.currentTimeMillis() - ONE_DAY - ONE_DAY)); final Employee e3 = f.createEmployee(); e3.setName("e3"); e3.setAge(49); e3.setSalary(10000); e3.setHireDate(new Date(System.currentTimeMillis() + 100000)); final Employee e4 = f.createEmployee(); e4.setName("e4"); e4.setAge(59); e4.setSalary(100000); e4.setHireDate(new Date(System.currentTimeMillis() + 100000)); final Department d = f.createDepartment(); d.setName("d1"); d.getEmployees().add(e1); d.getEmployees().add(e2); d.getEmployees().add(e3); d.getEmployees().add(e4); store.beginTransaction(); store.store(d); store.commitTransaction(); } { final Session s = ((HibernateTestStore) store).getSession(); store.beginTransaction(); List<?> es = store.getObjects(Employee.class); checkList(es, new String[] { "e1", "e2", "e3", "e4" }); s.enableFilter("ageRange").setParameter("fromAge", 35).setParameter("toAge", 55); es = store.getObjects(Employee.class); checkList(es, new String[] { "e2", "e3" }); s.enableFilter("salaryHigherThan").setParameter("salary", 5000); es = store.getObjects(Employee.class); checkList(es, new String[] { "e3" }); s.disableFilter("salaryHigherThan"); s.enableFilter("ageRange").setParameter("fromAge", 25).setParameter("toAge", 55); es = store.getObjects(Employee.class); checkList(es, new String[] { "e1", "e2", "e3" }); s.enableFilter("salaryHigherThan").setParameter("salary", 500); es = store.getObjects(Employee.class); checkList(es, new String[] { "e2", "e3" }); final Date dt = new Date(); s.enableFilter("hireDate").setParameter("date", dt); es = store.getObjects(Employee.class); checkList(es, new String[] { "e3" }); s.disableFilter("salaryHigherThan"); s.disableFilter("ageRange"); s.disableFilter("hireDate"); store.commitTransaction(); } { Session s = ((HibernateTestStore) store).getSession(); store.beginTransaction(); Department d = store.getObject(Department.class); List<?> es = d.getEmployees(); checkList(es, new String[] { "e1", "e2", "e3", "e4" }); store.commitTransaction(); store.beginTransaction(); s = ((HibernateTestStore) store).getSession(); s.enableFilter("ageRange").setParameter("fromAge", 35).setParameter("toAge", 55); d = store.getObject(Department.class); es = d.getEmployees(); checkList(es, new String[] { "e2", "e3" }); store.commitTransaction(); store.beginTransaction(); s = ((HibernateTestStore) store).getSession(); s.enableFilter("ageRange").setParameter("fromAge", 35).setParameter("toAge", 55); s.enableFilter("salaryHigherThan").setParameter("salary", 5000); d = store.getObject(Department.class); es = d.getEmployees(); checkList(es, new String[] { "e3" }); store.commitTransaction(); store.beginTransaction(); s = ((HibernateTestStore) store).getSession(); s.enableFilter("ageRange").setParameter("fromAge", 25).setParameter("toAge", 55); d = store.getObject(Department.class); es = d.getEmployees(); checkList(es, new String[] { "e1", "e2", "e3" }); store.commitTransaction(); store.beginTransaction(); s = ((HibernateTestStore) store).getSession(); s.enableFilter("ageRange").setParameter("fromAge", 25).setParameter("toAge", 55); s.enableFilter("salaryHigherThan").setParameter("salary", 500); d = store.getObject(Department.class); es = d.getEmployees(); checkList(es, new String[] { "e2", "e3" }); store.commitTransaction(); } }
From source file:org.openeos.erp.core.ui.internal.ClientFilterProvider.java
License:Apache License
public void disableFilter(Session session) { session.disableFilter(CLIENT_FILTER_NAME); session.disableFilter(CLIENT_ORGANIZATION_FILTER_NAME); }
From source file:org.opennms.netmgt.dao.AuthorizationIT.java
License:Open Source License
public void disableAuthorizationFilter() { HibernateCallback<Object> cb = new HibernateCallback<Object>() { @Override/*w w w.jav a 2 s. com*/ public Object doInHibernate(Session session) throws HibernateException, SQLException { session.disableFilter("authorizedOnly"); return null; } }; ((AlarmDaoHibernate) m_alarmDao).getHibernateTemplate().execute(cb); }
From source file:org.opennms.netmgt.dao.hibernate.HibernateFilterManager.java
License:Open Source License
/** * <p>disableAuthorizationFilter</p> *//*from w w w . j a v a 2 s . com*/ @Override public void disableAuthorizationFilter() { m_authorizationGroups = null; HibernateCallback<Object> cb = new HibernateCallback<Object>() { @Override public Object doInHibernate(Session session) throws HibernateException, SQLException { session.disableFilter(AUTH_FILTER_NAME); return null; } }; m_template.execute(cb); }
From source file:org.sigmah.server.endpoint.gwtrpc.handler.GetMonitoredPointsHandler.java
License:Open Source License
@Override public CommandResult execute(GetMonitoredPoints cmd, User user) throws CommandException { final ArrayList<MonitoredPointDTO> dtos = new ArrayList<MonitoredPointDTO>(); final Session session = ((HibernateEntityManager) em).getSession(); session.disableFilter("userVisible"); // Use a set to be avoid duplicated entries. final HashSet<OrgUnit> units = new HashSet<OrgUnit>(); // Crawl the org units hierarchy from the user root org unit. GetProjectHandler.crawlUnits(user.getOrgUnitWithProfiles().getOrgUnit(), units, false); // Retrieves all the corresponding org units. for (final OrgUnit unit : units) { // Builds and executes the query. final Query query = em .createQuery("SELECT p.pointsList.points FROM Project p WHERE :unit MEMBER OF p.partners"); query.setParameter("unit", unit); final List<MonitoredPoint> monitoredPoints = (List<MonitoredPoint>) query.getResultList(); for (final MonitoredPoint monitoredPoint : monitoredPoints) { if (monitoredPoint.getCompletionDate() == null) // Not completed only {//from w ww . j a va2 s . c o m MonitoredPointDTO pointDTO = mapper.map(monitoredPoint, MonitoredPointDTO.class); pointDTO.setDeleted(monitoredPoint.isDeleted()); dtos.add(pointDTO); } } } final MonitoredPointsResultList result = new MonitoredPointsResultList(); result.setList(dtos); return result; }
From source file:org.sigmah.server.endpoint.gwtrpc.handler.GetProjectsFromIdHandler.java
License:Open Source License
/** * Gets the projects list from the database. * /*from ww w. j av a 2s .co m*/ * @param cmd * @param user * * @return a {@link CommandResult} object containing the * {@link ProjectListResult} object. */ @Override @SuppressWarnings("unchecked") public CommandResult execute(GetProjectsFromId cmd, User user) throws CommandException { // Disable the ActivityInfo filter on Userdatabase. org.hibernate.Session session = ((HibernateEntityManager) em).getSession(); session.disableFilter("userVisible"); if (LOG.isDebugEnabled()) { LOG.debug("[execute] Gets projects: " + cmd + "."); } final Query query = em.createQuery("SELECT p FROM Project p WHERE p.id IN (:ids)"); query.setParameter("ids", cmd.getIds()); final List<Project> projects = (List<Project>) query.getResultList(); // --------------- // Mapping and return. // --------------- final ProjectListResult result = new ProjectListResult(); // Mapping into DTO objects final ArrayList<ProjectDTOLight> projectDTOList = new ArrayList<ProjectDTOLight>(); for (final Project project : projects) { final ProjectDTOLight pLight = mapper.map(project, true); projectDTOList.add(pLight); } result.setListProjectsLightDTO(projectDTOList); if (LOG.isDebugEnabled()) { LOG.debug("[execute] Found " + projects.size() + " project(s)."); } return result; }
From source file:org.sigmah.server.endpoint.gwtrpc.handler.GetProjectsHandler.java
License:Open Source License
/** * Gets the projects list from the database. * //from www . j av a2s . c o m * @param cmd * @param user * * @return a {@link CommandResult} object containing the * {@link ProjectListResult} object. */ @Override @SuppressWarnings("unchecked") public CommandResult execute(GetProjects cmd, User user) throws CommandException { // Disable the ActivityInfo filter on Userdatabase. org.hibernate.Session session = ((HibernateEntityManager) em).getSession(); session.disableFilter("userVisible"); if (LOG.isDebugEnabled()) { LOG.debug("[execute] Gets projects: " + cmd + "."); } // Retrieves command parameters. final HashSet<Project> projects = new HashSet<Project>(); final ProjectModelType modelType = cmd.getModelType(); // --------------- // Projects which I own or I manage. // --------------- if (cmd.getViewOwnOrManage()) { final Query ownerManagerQuery = em .createQuery("SELECT p FROM Project p WHERE p.owner = :ouser OR p.manager = :muser"); ownerManagerQuery.setParameter("ouser", user); ownerManagerQuery.setParameter("muser", user); for (final Project p : (List<Project>) ownerManagerQuery.getResultList()) { projects.add(p); } } // --------------- // Projects in my visible organization units. // --------------- final List<Integer> ids = cmd.getOrgUnitsIds(); // Use a set to be avoid duplicated entries. final HashSet<OrgUnit> units = new HashSet<OrgUnit>(); // Checks if there is at least one org unit id specified. if (ids == null) { if (LOG.isDebugEnabled()) { LOG.debug("[execute] No org unit specified, gets all projects for the user org unit."); } // Crawl the org units hierarchy from the user root org unit. GetProjectHandler.crawlUnits(user.getOrgUnitWithProfiles().getOrgUnit(), units, true); } else { // Crawl the org units hierarchy from each specified org unit. OrgUnit unit; for (final Integer id : ids) { if ((unit = em.find(OrgUnit.class, id)) != null) { GetProjectHandler.crawlUnits(unit, units, true); } } } // Retrieves all the corresponding org units. for (final OrgUnit unit : units) { // Builds and executes the query. final Query query = em.createQuery("SELECT p FROM Project p WHERE :unit MEMBER OF p.partners"); query.setParameter("unit", unit); int count = 0; final List<Project> listResults = (List<Project>) query.getResultList(); for (final Project p : listResults) { if (modelType == null) { projects.add(p); count++; } // Filters by model type. else { if (p.getProjectModel().getVisibility(user.getOrganization()) == modelType) { projects.add(p); count++; } } } if (LOG.isDebugEnabled()) { LOG.debug("[execute] Found " + count + "/" + listResults.size() + " projects for org unit #" + unit.getName() + "."); } } // --------------- // Mapping and return. // --------------- final ProjectListResult result = new ProjectListResult(); switch (cmd.getReturnType()) { case PROJECT: // Not implemented. break; case ID: final ArrayList<Integer> projectsIds = new ArrayList<Integer>(); for (final Project project : projects) { projectsIds.add(project.getId()); } result.setListProjectsIds(projectsIds); break; case PROJECT_LIGHT: default: // Mapping into DTO objects final ArrayList<ProjectDTOLight> projectDTOList = new ArrayList<ProjectDTOLight>(); for (final Project project : projects) { final ProjectDTOLight pLight = mapper.map(project, true); projectDTOList.add(pLight); } result.setListProjectsLightDTO(projectDTOList); break; } if (LOG.isDebugEnabled()) { LOG.debug("[execute] Found " + projects.size() + " project(s)."); } return result; }