@Transactional(readOnly = true) public Object doWork(org.hibernate.Session session, ServiceFactory sf) { return sf.getQueryService().projection(projection, parameters); } });
/** * Perform the database query to discover the IDs of the related objects. * @param toType the type of the objects to which the query object may be related, not <code>null</code> * @param fromType the query object's type, not <code>null</code> * @param fromIds the query objects' database IDs, none <code>null</code> * @return pairs of database IDs: of the query object, and an object to which it relates */ private List<Object[]> doQuery(String toType, String fromType, Collection<Long> fromIds) { final String queryString = hqlFromTo.get(Maps.immutableEntry(fromType, toType)); if (queryString == null) { throw new IllegalArgumentException("not implemented for " + fromType + " to " + toType); } return this.iQuery.projection(queryString, new Parameters().addIds(fromIds)); }
public String getUserInstitution(long userId, ServiceFactory sf) { final Parameters parameters = new Parameters().addId(userId); final List<Object[]> results = sf.getQueryService().projection(LOAD_USER_INSTITUTION, parameters); if (results instanceof List && results.get(0) instanceof Object[]) { final Object[] firstResult = (Object[]) results.get(0); if (firstResult.length > 0 && firstResult[0] instanceof String) { return (String) firstResult[0]; } } return null; }
private void loadFromQuery(Set<String> addresses) { for (Object[] o : getQueryService().projection( "select e.email from Experimenter e " + "join e.groupExperimenterMap m " + "join m.parent g where g.id = :id", new Parameters().addId(getRoles().getSystemGroupId()))) { if (o != null && o.length >= 1 && o[0] != null) { String email = o[0].toString(); if (!email.isEmpty()) { addresses.add(email); } } } }
@Transactional(readOnly = true) public Object doWork(Session session, ServiceFactory sf) { List<Object[]> rv = sf.getQueryService().projection( "select o.id from RenderingDef r join r.details.owner o " + "where r.id = :id", new Parameters().addId(rendDefObj.getId())); Long currentUser = getCurrentEventContext().getCurrentUserId(); Long ownerId = (Long) rv.get(0)[0]; return ownerId.equals(currentUser); }}); }
/** * Retrieves the series for a given set of pixels. * @param pixels Set of pixels to return the series for. * @return The series as specified by the pixels parameters or * <code>0</code> (the first series). */ protected int getSeries(Pixels pixels) { try { final String query = "SELECT image.series FROM Pixels WHERE id = :id"; final List<Object[]> results = iQuery.projection(query, new Parameters().addId(pixels.getId())); return (Integer) results.get(0)[0]; } catch (Exception e) // NumberFormatException, NullPointerException { return 0; } }
targetObjects.put(queryClassName, idList); for (final Object[] id : iQuery.projection(hql, params)) { idList.add((Long) id[0]);
/** * Looks up a user id by principal. If the name of the principal is actually * a removed user session, then a {@link RemovedSessionException} is thrown. */ private long executeLookupUser(ServiceFactory sf, Principal p) { List<Object[]> rv = sf.getQueryService().projection("select e.id from Experimenter e where e.omeName = :name", new Parameters().addString("name", p.getName())); if (rv.size() == 0) { throw new RemovedSessionException("Cannot find a user with name " + p.getName()); } return (Long) rv.get(0)[0]; }
for (final Object[] resultRow : queryService.projection("SELECT id, details.group.id FROM Pixels WHERE id IN (:ids)", new Parameters().addIds(pixelsIds))) { final Long pixelsId = (Long) resultRow[0];
/** * Use {@link IQuery#projection(String, Parameters)} to load the first * long which matches the given query. This means that the first return * value in the select statement should likely be the id of an object. */ protected omero.RLong firstIdOrNull(String query) { List<Object[]> ids = helper.getServiceFactory().getQueryService() .projection(query, new Parameters().addId(imageId).page(0, 1)); if (ids != null && ids.size() > 0) { Object[] id = ids.get(0); if (id != null && id.length > 0) { return omero.rtypes.rlong((Long) id[0]); } } return null; }
for (final Object[] resultRow : queryService.projection(hql, parameters)) { if (resultRow != null) { final Long pixelsId = (Long) resultRow[0]; for (final Object[] resultRow : queryService.projection(hql, parameters)) { if (resultRow != null) { final Long thumbnailId = (Long) resultRow[0]; for (final Object[] resultRow : queryService.projection(hql, parameters)) { if (resultRow != null && resultRow[3] instanceof Long) { final Long fileId = (Long) resultRow[0]; for (final Object[] resultRow : queryService.projection(hql, parameters)) { if (resultRow != null && resultRow[0] instanceof Long) { final Long fileId = (Long) resultRow[0];
for (final Object[] resultRow : queryService.projection(hql, null)) { if (resultRow != null) { final Long objectId = (Long) resultRow[0]; for (final Object[] resultRow : queryService.projection(hql, parameters)) { if (resultRow != null) { final Long pixelsId = (Long) resultRow[0]; for (final Object[] resultRow : queryService.projection(hql, parameters)) { if (resultRow != null) { final Long thumbnailId = (Long) resultRow[0]; for (final Object[] resultRow : queryService.projection(hql, parameters)) { if (resultRow != null && resultRow[3] instanceof Long) { final Long fileId = (Long) resultRow[0]; final String hql = "SELECT " + getIdPropertyFor(resultClassName) + " FROM " + resultClassName + " WHERE details.owner.id IN (:ids)"; for (final Object[] resultRow : queryService.projection(hql, parameters)) { objectsToProcess.put(resultClassName, (Long) resultRow[0]); final String hql = "SELECT " + getIdPropertyFor(resultClassName) + " FROM " + resultClassName + " WHERE details.group.id IN (:ids)"; for (final Object[] resultRow : queryService.projection(hql, parameters)) { objectsToProcess.put(resultClassName, (Long) resultRow[0]); final String resultClassName = query.getKey(); final String hql = query.getValue(); for (final Object[] resultRow : queryService.projection(hql, parameters)) {
for (final Object[] resultRow : queryService.projection(hql, null)) { if (resultRow != null) { final Long objectId = (Long) resultRow[0];
final String query = "SELECT details.owner.id, details.group.id FROM OriginalFile WHERE id = :id"; final Parameters parameters = new Parameters().addId(parentId); final Object[] results = sf.getQueryService().projection(query, parameters).get(0); parentObjectOwnerId = (Long) results[0]; parentObjectGroupId = (Long) results[1];