/** * Adds a single clause of the form "AND (A OR B ...)" where each * {@link ScriptFileType} A, B, etc. is given a chance to define * its own clause. */ public void buildQuery(QueryBuilder qb) { boolean first = true; qb.and(" ("); // will prepend "AND" if not first clause. for (String mimetype : mimetypes) { if (first) { first = false; } else { qb.append(" OR "); } qb.append("o.mimetype = '" + mimetype + "'"); } qb.append(") "); }
/** * If the current user is not an admin, then this methods adds a subclause * to the HQL: * * AND ( share.owner.id = :userId or user.id = :userId ) * * {@link QueryBuilder#where()} should already have been called. */ protected void applyIfShareAccessible(QueryBuilder qb) { EventContext ec = getSecuritySystem().getEventContext(); if ( ! ec.isCurrentUserAdmin()) { qb.param("userId", ec.getCurrentUserId()); qb.and("("); qb.append("share.owner.id = :userId" ); qb.append(" OR "); qb.append("user.id = :userId" ); qb.append(" ) "); } }
public static void notNullOrLikeOrEqual(QueryBuilder qb, String path, Class type, Object value, boolean useLike, boolean caseSensitive) { if (null == value) { qb.and(path + " is null "); } else { String operator; if (useLike && String.class.isAssignableFrom(type)) { if (caseSensitive) { operator = "like"; } else { operator = "ilike"; } } else { operator = "="; } String alias = qb.unique_alias("main"); qb.and(path); qb.append(operator); qb.append(":"); qb.append(alias); qb.appendSpace(); qb.param(alias, value); } }
/** * In order to support the order() method in addition * to a filter, we allow applying the filter and nulling * the instance eagerly before the user calls order. */ public QueryBuilder filterNow() { if (filter != null && filterTarget != null) { if (filter.owner() >= 0) { this.and(filterTarget+".details.owner.id = "); String alias = this.unique_alias("owner"); this.append(":"); this.append(alias); this.param(alias, filter.owner()); appendSpace(); } if (filter.group() >= 0) { this.and(filterTarget+".details.group.id = "); String alias = this.unique_alias("group"); this.append(":"); this.append(alias); this.param(alias, filter.group()); appendSpace(); } } return this; }
qb.select("count(obj)"); qb.skipFrom(); qb.append(qString.replaceAll("@FETCH@", "")); } else { qb.select("obj"); qb.skipFrom(); qb.append(qString.replaceAll("@FETCH@", "fetch")); qb.append(")"); } else { throw new InternalException("No ownership info for: " String orderBy = ORDERBY.get(type); if (orderBy != null) { qb.append(orderBy);
qb.param("ns", NS_COMMENT + "%"); applyIfShareAccessible(qb); qb.append("group by share.id");
@Transactional(readOnly = true) public Object doWork(Session session, ServiceFactory sf) { QueryBuilder qb = new QueryBuilder(); qb.select("distinct fa"); qb.from("Image", "i"); qb.append(", Roi roi "); qb.join("roi.annotationLinks", "rlinks", false, false); qb.join("rlinks.child", "rfa", false, false); qb.join("i.wellSamples", "ws", false, false); qb.join("ws.well", "well", false, false); qb.join("well.plate", "plate", false, false); qb.join("plate.annotationLinks", "links", false, false); qb.join("links.child", "fa", false, false); qb.where(); qb.and("fa.ns = '" + NSMEASUREMENT.value + "'"); qb.and("rfa.id = fa.id"); qb.and("i.id = :id"); qb.and("i.id = roi.image"); qb.param("id", imageId); qb.filter("fa", filter(opts)); return qb.query(session).list(); } }));
qb.append("group by share2.id");