private void predicate( JPAQuery query, QSpecial special, Integer[] siteId, Integer[] categoryId, Date beginDate, Date endDate, Boolean isWithImage, Boolean isRecommend) { query.from(special); BooleanBuilder exp = new BooleanBuilder(); if (ArrayUtils.isNotEmpty(siteId)) { exp = exp.and(special.site.id.in(siteId)); } if (ArrayUtils.isNotEmpty(categoryId)) { exp = exp.and(special.category.id.in(categoryId)); } if (beginDate != null) { exp = exp.and(special.creationDate.goe(beginDate)); } if (endDate != null) { exp = exp.and(special.creationDate.goe(endDate)); } if (isWithImage != null) { exp = exp.and(special.withImage.eq(isWithImage)); } if (isRecommend != null) { exp = exp.and(special.recommend.eq(isRecommend)); } query.where(exp); }
public List<Model> findList(Integer siteId, Integer type) { JPAQuery query = new JPAQuery(this.em); QModel model = QModel.model; query.from(model); BooleanBuilder exp = new BooleanBuilder(); exp = exp.and(model.site.id.eq(siteId)); if (type != null) { exp = exp.and(model.type.eq(type)); } query.where(exp); query.orderBy(model.seq.asc()); return query.list(model); }
public Model findDefault(Integer siteId, Integer type) { JPAQuery query = new JPAQuery(this.em); QModel model = QModel.model; query.from(model); BooleanBuilder exp = new BooleanBuilder(); exp = exp.and(model.site.id.eq(siteId)); exp = exp.and(model.type.eq(type)); query.where(exp); query.orderBy(model.seq.asc()); query.limit(1); List<Model> list = query.list(model); return !list.isEmpty() ? list.get(0) : null; }
protected List<Identifiable> getObjectsFor(RegistryObject ro) throws XDSException { List<Identifiable> objects = new ArrayList<Identifiable>(); if (ro != null) { objects.add(ro); JPAQuery query = new JPAQuery(getSession().getEntityManager()).from(QAssociation.association); StoredQueryParam paramConfidentialityCode = getQueryParam(XDSConstants.QRY_DOCUMENT_ENTRY_CONFIDENTIALITY_CODE); StoredQueryParam paramFormatCode = getQueryParam(XDSConstants.QRY_DOCUMENT_ENTRY_FORMAT_CODE); if (paramConfidentialityCode != null || paramFormatCode != null) { BooleanBuilder docBuilder = new BooleanBuilder(); docBuilder.and( QXDSDocumentEntry.xDSDocumentEntry.eq(QAssociation.association.targetObject)); addXdsCodeMatch( docBuilder, getQueryParam(XDSConstants.QRY_DOCUMENT_ENTRY_CONFIDENTIALITY_CODE), XDSConstants.UUID_XDSDocumentEntry_confidentialityCode, QXDSDocumentEntry.xDSDocumentEntry.xdsCodes); addXdsCodeMatch( docBuilder, getQueryParam(XDSConstants.QRY_DOCUMENT_ENTRY_FORMAT_CODE), XDSConstants.UUID_XDSDocumentEntry_formatCode, QXDSDocumentEntry.xDSDocumentEntry.xdsCodes); BooleanBuilder orBuilder = new BooleanBuilder(); orBuilder .orNot(QAssociation.association.targetObject.instanceOf(XDSDocumentEntry.class)) .or( new JPASubQuery() .from(QXDSDocumentEntry.xDSDocumentEntry) .where(docBuilder) .exists()); query.where( QAssociation.association.sourceObject.eq(ro), QAssociation.association.assocType.id.eq(XDSConstants.HAS_MEMBER), orBuilder); } else { query.where( QAssociation.association.sourceObject.eq(ro), QAssociation.association.assocType.id.eq(XDSConstants.HAS_MEMBER)); } List<Association> associations = query.list(QAssociation.association); log.debug("#### Found Associations: {}", associations); objects.addAll(associations); RegistryObject obj; List<Association[]> childAssocs = new ArrayList<Association[]>(); for (Association assoc : associations) { obj = assoc.getTargetObject(); if (obj instanceof Association) { childAssocs.add(new Association[] {(Association) obj, assoc}); } else { objects.add(obj); } } for (Association[] assoc : childAssocs) { if (objects.contains(assoc[0].getTargetObject()) && // Add only Associations with source AND target object in result! objects.contains(assoc[0].getSourceObject())) { objects.add(assoc[0]); } else { objects.remove( assoc[1]); // Remove association because target (Association) is not in result } } } return objects; }