本文整理汇总了Java中javax.persistence.criteria.CriteriaBuilder.equal方法的典型用法代码示例。如果您正苦于以下问题:Java CriteriaBuilder.equal方法的具体用法?Java CriteriaBuilder.equal怎么用?Java CriteriaBuilder.equal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.criteria.CriteriaBuilder
的用法示例。
在下文中一共展示了CriteriaBuilder.equal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toPredicate
import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query,
CriteriaBuilder builder) {
Path expression = null;
if(fieldName.contains(".")){
String[] names = StringUtils.split(fieldName, ".");
expression = root.get(names[0]);
for (int i = 1; i < names.length; i++) {
expression = expression.get(names[i]);
}
}else{
expression = root.get(fieldName);
}
switch (operator) {
case EQ:
return builder.equal(expression, value);
case NE:
return builder.notEqual(expression, value);
case LIKE:
return builder.like((Expression<String>) expression, "%" + value + "%");
case LT:
return builder.lessThan(expression, (Comparable) value);
case GT:
return builder.greaterThan(expression, (Comparable) value);
case LTE:
return builder.lessThanOrEqualTo(expression, (Comparable) value);
case GTE:
return builder.greaterThanOrEqualTo(expression, (Comparable) value);
default:
return null;
}
}
示例2: findByDateRange
import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
public Collection<EndPointCheck> findByDateRange(final EndPoint endPoint, final Date startDate,
final Date endDate) {
final CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder();
final CriteriaQuery<EndPointCheck> criteriaQuery = criteriaBuilder.createQuery(getEntityClass());
final Root<EndPointCheck> root = criteriaQuery
.from(getEntityManager().getMetamodel().entity(getEntityClass()));
final ParameterExpression<EndPoint> endPointParameter = criteriaBuilder.parameter(EndPoint.class);
final ParameterExpression<Date> startDateParameter = criteriaBuilder.parameter(Date.class);
final ParameterExpression<Date> endDateParameter = criteriaBuilder.parameter(Date.class);
final Predicate endPointIdPredicate = criteriaBuilder
.equal(root.get("endPoint"), endPointParameter);
final Path<Date> checkDatePath = root.<Date> get("checkDate");
final Predicate startDatePredicate = criteriaBuilder
.greaterThanOrEqualTo(checkDatePath, startDateParameter);
final Predicate endDatePredicate = criteriaBuilder.lessThanOrEqualTo(
checkDatePath,
endDateParameter);
criteriaQuery.where(criteriaBuilder.and(endPointIdPredicate, startDatePredicate, endDatePredicate));
criteriaQuery.orderBy(Arrays.asList(criteriaBuilder.asc(checkDatePath)));
return getEntityManager().createQuery(criteriaQuery)
.setParameter(endPointParameter, endPoint)
.setParameter(startDateParameter, startDate, TemporalType.DATE)
.setParameter(endDateParameter, endDate, TemporalType.DATE)
.getResultList();
}
示例3: accountExpiresBefore
import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
/**
* All customers with an {@link Account} expiring before the given date.
*
* @param date
* @return
*/
public static Specification<Customer> accountExpiresBefore(final LocalDate date) {
return new Specification<Customer>() {
@Override
public Predicate toPredicate(Root<Customer> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
Root<Account> accounts = query.from(Account.class);
Path<Date> expiryDate = accounts.<Date> get("expiryDate");
Predicate customerIsAccountOwner = cb.equal(accounts.<Customer> get("customer"), root);
Predicate accountExpiryDateBefore = cb.lessThan(expiryDate, date.toDateTimeAtStartOfDay().toDate());
return cb.and(customerIsAccountOwner, accountExpiryDateBefore);
}
};
}
示例4: search
import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
@Override
public Optional<SearchResponse> search(final ServiceUser user,
final SearchRequest request){
final String dataSourceUuid = request.getQuery().getDataSource().getUuid();
try (final Session session = database.openSession()) {
final CriteriaBuilder cb = session.getCriteriaBuilder();
final CriteriaQuery<Tuple> cq = cb.createTupleQuery();
final Root<T> root = cq.from(this.dtoClass);
cq.multiselect(this.fields.stream()
.map(f -> root.get(f.getName()))
.collect(Collectors.toList()));
final Predicate requestPredicate = getPredicate(cb, root, request.getQuery().getExpression());
final Predicate dataSourcePredicate = cb.equal(root.get(QueryableEntity.DATA_SOURCE_UUID), dataSourceUuid);
cq.where(cb.and(requestPredicate, dataSourcePredicate));
final List<Tuple> tuples = session.createQuery(cq).getResultList();
final SearchResponse searchResponse = projectResults(request, tuples);
return Optional.of(searchResponse);
}
}
示例5: createFindByNameQuery
import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
private TypedQuery<Dto> createFindByNameQuery(String name) {
EntityManager em = createEntityManager();
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<Dto> query = builder.createQuery(this.classVersion);
Root<Dto> entity = query.from(this.classVersion);
Predicate namePredicate = builder.equal(entity.get(DEPLOY_TARGET_NAME), name);
return em.createQuery(query.select(entity).where(namePredicate));
}
示例6: buildPredicate
import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
@SuppressWarnings ({ "unchecked", "rawtypes" })
protected Predicate buildPredicate(Path<T> root, SearchField field)
{
Path<T> tt = (!field.getField().contains(".")) ? root.get(field.getField()) : fetchNestedPath(root, field.getField());
CriteriaBuilder criteriaBuilder = this.entitymanager.getCriteriaBuilder();
Class<?> javaType = tt.getJavaType();
if (!classCompatibleWithOperator(javaType, field.getOperator()))
{
throw new RuntimeException("operator incompatible with field");
}
Object valueObject = convertStringValueToObject(field.getValue(), javaType);
switch (field.getOperator())
{
case GE:
return criteriaBuilder.greaterThan((Expression) tt, (Comparable) valueObject);
case GTE:
return criteriaBuilder.greaterThanOrEqualTo((Expression) tt, (Comparable) valueObject);
case LE:
return criteriaBuilder.lessThan((Expression) tt, (Comparable) valueObject);
case LTE:
return criteriaBuilder.lessThanOrEqualTo((Expression) tt, (Comparable) valueObject);
case NE:
return criteriaBuilder.notEqual(tt, valueObject);
case EX:
return criteriaBuilder.like((Expression) tt, "%"+field.getValue()+"%");
default:
{
//EQ
return criteriaBuilder.equal(tt, valueObject);
}
}
}
示例7: findValueSetEntity
import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
private ValueSetEntity findValueSetEntity(IdType theId) {
ValueSetEntity valueSetEntity = null;
// Only look up if the id is numeric else need to do a search
if (daoutils.isNumeric(theId.getValue())) {
valueSetEntity =(ValueSetEntity) em.find(ValueSetEntity.class, theId.getValue());
}
// if null try a search on strId
if (valueSetEntity == null)
{
CriteriaBuilder builder = em.getCriteriaBuilder();
CriteriaQuery<ValueSetEntity> criteria = builder.createQuery(ValueSetEntity.class);
Root<ValueSetEntity> root = criteria.from(ValueSetEntity.class);
List<Predicate> predList = new LinkedList<Predicate>();
Predicate p = builder.equal(root.<String>get("strId"),theId.getValue());
predList.add(p);
Predicate[] predArray = new Predicate[predList.size()];
predList.toArray(predArray);
if (predList.size()>0)
{
criteria.select(root).where(predArray);
List<ValueSetEntity> qryResults = em.createQuery(criteria).getResultList();
for (ValueSetEntity cme : qryResults)
{
valueSetEntity = cme;
break;
}
}
}
return valueSetEntity;
}
示例8: findSystem
import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
@Override
@Transactional
public SystemEntity findSystem(String system) {
CriteriaBuilder builder = em.getCriteriaBuilder();
SystemEntity systemEntity = null;
CriteriaQuery<SystemEntity> criteria = builder.createQuery(SystemEntity.class);
Root<SystemEntity> root = criteria.from(SystemEntity.class);
List<Predicate> predList = new LinkedList<Predicate>();
log.debug("Looking for System = " + system);
Predicate p = builder.equal(root.<String>get("codeSystemUri"),system);
predList.add(p);
Predicate[] predArray = new Predicate[predList.size()];
predList.toArray(predArray);
if (predList.size()>0)
{
log.debug("Found System "+system);
criteria.select(root).where(predArray);
List<SystemEntity> qryResults = em.createQuery(criteria).getResultList();
for (SystemEntity cme : qryResults) {
systemEntity = cme;
break;
}
}
if (systemEntity == null) {
log.info("Not found. Adding SystemEntity = "+system);
systemEntity = new SystemEntity();
systemEntity.setUri(system);
em.persist(systemEntity);
}
return systemEntity;
}
示例9: findBySystem
import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
@Override
@Transactional
public CodeSystemEntity findBySystem(String system) {
CriteriaBuilder builder = em.getCriteriaBuilder();
CodeSystemEntity codeSystemEntity = null;
CriteriaQuery<CodeSystemEntity> criteria = builder.createQuery(CodeSystemEntity.class);
Root<CodeSystemEntity> root = criteria.from(CodeSystemEntity.class);
List<Predicate> predList = new LinkedList<Predicate>();
log.trace("FlushMode = "+em.getFlushMode());
log.trace("Entity Manager Properties = "+ em.getProperties().toString());
Predicate p = builder.equal(root.<String>get("codeSystemUri"),system);
predList.add(p);
Predicate[] predArray = new Predicate[predList.size()];
predList.toArray(predArray);
if (predList.size()>0)
{
log.trace("Found CodeSystem "+system);
criteria.select(root).where(predArray);
List<CodeSystemEntity> qryResults = em.createQuery(criteria).getResultList();
for (CodeSystemEntity cme : qryResults) {
codeSystemEntity = cme;
break;
}
}
if (codeSystemEntity == null) {
log.info("Not found adding CodeSystem = "+system);
codeSystemEntity = new CodeSystemEntity();
codeSystemEntity.setCodeSystemUri(system);
save(codeSystemEntity);
}
return codeSystemEntity;
}
示例10: toPredicate
import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
@Override
public Predicate toPredicate(final Root<?> leveringsautorisatieRoot, final CriteriaQuery<?> query, final CriteriaBuilder cb) {
final Root<ToegangLeveringsAutorisatie> toegangLeveringsAutorisaties = query.from(ToegangLeveringsAutorisatie.class);
final Predicate joinPredicateToegangLeveringsAutorisatie =
leveringsautorisatieRoot.get(ID).in(toegangLeveringsAutorisaties.get(LEVERINGSAUTORISATIE).get(ID));
final Predicate geautoriseerdePredicate = cb.equal(toegangLeveringsAutorisaties.get(field), value);
return cb.and(joinPredicateToegangLeveringsAutorisatie, geautoriseerdePredicate);
}
示例11: toPredicate
import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
@Override
public Predicate toPredicate(final Root<?> leveringsautorisatieRoot, final CriteriaQuery<?> query, final CriteriaBuilder cb) {
final Root<ToegangBijhoudingsautorisatie> toegangLeveringsAutorisaties = query.from(ToegangBijhoudingsautorisatie.class);
final Predicate joinPredicateToegangLeveringsAutorisatie =
leveringsautorisatieRoot.get(ID).in(toegangLeveringsAutorisaties.get(BIJHOUDINGSAUTORISATIE).get(ID));
final Predicate geautoriseerdePredicate = cb.equal(toegangLeveringsAutorisaties.get(field), value);
return cb.and(joinPredicateToegangLeveringsAutorisatie, geautoriseerdePredicate);
}
示例12: toPredicate
import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
@Override
public Predicate toPredicate(final Root<?> administratieveHandelingRoot, final CriteriaQuery<?> query, final CriteriaBuilder cb) {
final Root<PersoonAfgeleidAdministratiefHistorie> persoonHistoryRoot = query.from(PersoonAfgeleidAdministratiefHistorie.class);
// Join persoon
final Predicate joinPredicate = administratieveHandelingRoot.get(ID).in(persoonHistoryRoot.get(ADMINISTRATIEVE_HANDELING).get(ID));
// Bsn
final Predicate bsnPredicate = cb.equal(persoonHistoryRoot.get(PERSOON).get(ADMINISTRATIE_NUMMER), value);
return cb.and(bsnPredicate, joinPredicate);
}
示例13: toPredicate
import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
public Predicate toPredicate(Root<?> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
Path expression = null;
if (fieldName.contains(".")) {
System.out.println(root);
String[] names = StringUtils.split(fieldName, ".");
expression = root.get(names[0]);
for (int i = 1; i < names.length; i++) {
expression = expression.get(names[i]);
}
} else {
expression = root.get(fieldName);
}
switch (operator) {
case EQ:
return builder.equal(expression, value);
case NE:
return builder.notEqual(expression, value);
case LIKE:
return builder.like((Expression<String>) expression, "%" + value + "%");
case RLIKE:
return builder.like((Expression<String>) expression, value + "%");
case LLIKE:
return builder.like((Expression<String>) expression, value + "%");
case LT:
return builder.lessThan(expression, (Comparable) value);
case GT:
return builder.greaterThan(expression, (Comparable) value);
case LTE:
return builder.lessThanOrEqualTo(expression, (Comparable) value);
case GTE:
return builder.greaterThanOrEqualTo(expression, (Comparable) value);
case ISNULL:
return builder.isNull(expression);
case NOTNULL:
return builder.isNotNull(expression);
default:
return null;
}
}
示例14: getEntityFieldsSpec
import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
private Specification<RelationEntity> getEntityFieldsSpec(EntityId from, String relationType,
RelationTypeGroup typeGroup, ThingType childType) {
return new Specification<RelationEntity>() {
@Override
public Predicate toPredicate(Root<RelationEntity> root, CriteriaQuery<?> criteriaQuery,
CriteriaBuilder criteriaBuilder) {
List<Predicate> predicates = new ArrayList<>();
if (from != null) {
Predicate fromIdPredicate = criteriaBuilder.equal(root.get("fromId"),
UUIDConverter.fromTimeUUID(from.getId()));
predicates.add(fromIdPredicate);
Predicate fromEntityTypePredicate = criteriaBuilder.equal(root.get("fromType"), from.getEntityType().name());
predicates.add(fromEntityTypePredicate);
}
if (relationType != null) {
Predicate relationTypePredicate = criteriaBuilder.equal(root.get("relationType"), relationType);
predicates.add(relationTypePredicate);
}
if (typeGroup != null) {
Predicate typeGroupPredicate = criteriaBuilder.equal(root.get("relationTypeGroup"), typeGroup.name());
predicates.add(typeGroupPredicate);
}
if (childType != null) {
Predicate childTypePredicate = criteriaBuilder.equal(root.get("toType"), childType.name());
predicates.add(childTypePredicate);
}
return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
}
};
}
示例15: buildJpaPredicate
import javax.persistence.criteria.CriteriaBuilder; //导入方法依赖的package包/类
@Override
public Predicate buildJpaPredicate(CriteriaBuilder cb, Root<?> root) {
Expression<Object> path = QueryFormHelper.getPath(root, field);
return cb.equal(path, value);
}