org.hibernate.criterion.Restrictions.and()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(14.2k)|赞(0)|评价(0)|浏览(164)

本文整理了Java中org.hibernate.criterion.Restrictions.and方法的一些代码示例,展示了Restrictions.and的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Restrictions.and方法的具体详情如下:
包路径:org.hibernate.criterion.Restrictions
类名称:Restrictions
方法名:and

Restrictions.and介绍

[英]Return the conjuction of two expressions
[中]返回两个表达式的组合

代码示例

代码示例来源:origin: kaaproject/kaa

@Override
public Application findByNameAndTenantId(String name, String tenantId) {
 LOG.debug("Searching for application by name [{}] and tenant id [{}] ", name, tenantId);
 Application application = findOneByCriterionWithAlias(TENANT_PROPERTY, TENANT_ALIAS,
   Restrictions.and(
     Restrictions.eq(TENANT_REFERENCE, Long.valueOf(tenantId)),
     Restrictions.eq(APPLICATION_NAME_PROPERTY, name)));
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{},{}] Search result: {}.", name, tenantId, application);
 } else {
  LOG.debug("[{},{}] Search result: {}.", name, tenantId, application != null);
 }
 return application;
}

代码示例来源:origin: kaaproject/kaa

@Override
public List<User> findByTenantIdAndAuthority(String id, String authority) {
 LOG.debug("Searching users by tenant id [{}] and authority [{}]", id, authority);
 List<User> users = findListByCriterionWithAlias(TENANT_PROPERTY, TENANT_ALIAS, Restrictions.and(
   Restrictions.eq(TENANT_REFERENCE, Long.valueOf(id)),
   Restrictions.eq(AUTHORITY_PROPERTY, KaaAuthorityDto.parse(authority))));
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{},{}] Search result: {}.", id, authority, Arrays.toString(users.toArray()));
 } else {
  LOG.debug("[{},{}] Search result: {}.", id, authority, users.size());
 }
 return users;
}

代码示例来源:origin: kaaproject/kaa

@Override
public List<Topic> findTopicsByAppIdAndType(String appId, TopicTypeDto typeDto) {
 List<Topic> topics = Collections.emptyList();
 LOG.debug("Searching topics by application id [{}] and type [{}]", appId, typeDto);
 if (isNotBlank(appId)) {
  topics = findListByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS,
    and(
      eq(APPLICATION_REFERENCE, Long.valueOf(appId)),
      eq(TOPIC_TYPE_PROPERTY, typeDto)));
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{},{}] Search result: {}.", appId, typeDto, Arrays.toString(topics.toArray()));
 } else {
  LOG.debug("[{},{}] Search result: {}.", appId, typeDto, topics.size());
 }
 return topics;
}

代码示例来源:origin: kaaproject/kaa

@Override
public History findBySeqNumber(String appId, int seqNum) {
 History history = null;
 LOG.debug("Searching history by application id [{}] and sequence number [{}]", appId, seqNum);
 if (isNotBlank(appId)) {
  history = findOneByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS,
    Restrictions.and(
      Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)),
      Restrictions.eq(SEQUENCE_NUMBER_PROPERTY, seqNum)));
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{},{}] Search result: {}.", appId, seqNum, history);
 } else {
  LOG.debug("[{},{}] Search result: {}.", appId, seqNum, history != null);
 }
 return history;
}

代码示例来源:origin: kaaproject/kaa

@Override
public EndpointGroup findByAppIdAndWeight(String appId, int weight) {
 EndpointGroup group = null;
 LOG.debug("Searching endpoint group by application id [{}] and weight [{}]", appId, weight);
 if (isNotBlank(appId)) {
  group = findOneByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS,
    Restrictions.and(
      Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)),
      Restrictions.eq(WEIGHT_PROPERTY, weight)));
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{},{}] Search result: {}.", appId, weight, group);
 } else {
  LOG.debug("[{},{}] Search result: {}.", appId, weight, group != null);
 }
 return group;
}

代码示例来源:origin: kaaproject/kaa

@Override
public List<NotificationSchema> findNotificationSchemasByAppIdAndType(
    String appId, NotificationTypeDto type) {
 LOG.debug("Searching notification schema by application id {} type {}", appId, type);
 List<NotificationSchema> schemas = Collections.emptyList();
 if (isNotBlank(appId)) {
  schemas = findListByCriterion(Restrictions.and(
    Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)),
    Restrictions.eq(NOTIFICATION_SCHEMA_TYPE_PROPERTY, type)));
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{},{}] Search result: {}.", appId, type, Arrays.toString(schemas.toArray()));
 } else {
  LOG.debug("[{},{}] Search result: {}.", appId, type, schemas.size());
 }
 return schemas;
}

代码示例来源:origin: kaaproject/kaa

@Override
public Topic findTopicByAppIdAndName(String appId, String topicName) {
 Topic topic = null;
 LOG.debug("Searching topic by application id [{}] and name [{}]", appId, topicName);
 if (isNotBlank(appId) && isNotBlank(topicName)) {
  topic = findOneByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS,
    Restrictions.and(
      Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)),
      Restrictions.eq(TOPIC_NAME, topicName)));
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{},{}] Search result: {}.", appId, topicName, topic);
 } else {
  LOG.debug("[{},{}] Search result: {}.", appId, topicName, topic != null);
 }
 return topic;
}

代码示例来源:origin: kaaproject/kaa

@Override
public EndpointProfileSchema findByAppIdAndVersion(String appId, int version) {
 LOG.debug("Searching profile schema by application id [{}] and version [{}]", appId, version);
 EndpointProfileSchema schema = null;
 if (isNotBlank(appId)) {
  schema = findOneByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS,
      Restrictions.and(
    Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)),
    Restrictions.eq(VERSION_PROPERTY, version)));
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{},{}] Search result: {}.", appId, version, schema);
 } else {
  LOG.debug("[{},{}] Search result: {}.", appId, version, schema != null);
 }
 return schema;
}

代码示例来源:origin: kaaproject/kaa

@Override
public List<UserVerifier> findByAppId(String appId) {
 List<UserVerifier> appenders = Collections.emptyList();
 LOG.debug("Searching user verifiers by application id [{}]", appId);
 if (isNotBlank(appId)) {
  appenders = findListByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS,
    Restrictions.and(
      Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)))
  );
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{}] Search result: {}.", appId, Arrays.toString(appenders.toArray()));
 } else {
  LOG.debug("[{}] Search result: {}.", appId, appenders.size());
 }
 return appenders;
}

代码示例来源:origin: kaaproject/kaa

@Override
public EventClassFamily findByTenantIdAndName(String tenantId, String name) {
 LOG.debug("Searching event class family by tenant id [{}] and name [{}]", tenantId, name);
 EventClassFamily eventClassFamily = null;
 if (isNotBlank(tenantId)) {
  eventClassFamily = findOneByCriterionWithAlias(TENANT_PROPERTY, TENANT_ALIAS,
    Restrictions.and(
      Restrictions.eq(TENANT_REFERENCE, Long.valueOf(tenantId)),
      Restrictions.eq(NAME_PROPERTY, name)));
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{},{}] Search result: {}.", tenantId, name, eventClassFamily);
 } else {
  LOG.debug("[{},{}] Search result: {}.", tenantId, name, eventClassFamily != null);
 }
 return eventClassFamily;
}

代码示例来源:origin: kaaproject/kaa

@Override
public EndpointGroup findByAppIdAndName(String applicationId, String name) {
 EndpointGroup group = null;
 LOG.debug("Searching endpoint group by application id [{}] and name [{}]", applicationId, name);
 if (isNotBlank(applicationId)) {
  group = findOneByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS,
    Restrictions.and(
      Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(applicationId)),
      Restrictions.eq(NAME_PROPERTY, name)));
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{},{}] Search result: {}.", applicationId, name, group);
 } else {
  LOG.debug("[{},{}] Search result: {}.", applicationId, name, group != null);
 }
 return group;
}

代码示例来源:origin: kaaproject/kaa

@Override
public List<EventClass> findByTenantIdAndFqn(String tenantId, String fqn) {
 LOG.debug("Searching event classes by tenant id [{}] and fqn [{}]", tenantId, fqn);
 List<EventClass> eventClasses = Collections.emptyList();
 if (isNotBlank(tenantId)) {
  eventClasses = findListByCriterionWithAlias(TENANT_PROPERTY, TENANT_ALIAS,
    Restrictions.and(
      Restrictions.eq(TENANT_REFERENCE, Long.valueOf(tenantId)),
      Restrictions.eq(FQN_PROPERTY, fqn)));
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{},{}] Search result: {}.", tenantId, fqn, Arrays.toString(
      eventClasses.toArray()));
 } else {
  LOG.debug("[{},{}] Search result: {}.", tenantId, fqn, eventClasses.size());
 }
 return eventClasses;
}

代码示例来源:origin: kaaproject/kaa

@Override
public LogSchema findByApplicationIdAndVersion(String applicationId, int version) {
 LOG.debug("Searching log schema by applicationId [{}] and version [{}] ",
     applicationId, version);
 LogSchema logSchema = null;
 if (isNotBlank(applicationId)) {
  logSchema = findOneByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS,
      Restrictions.and(
    Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(applicationId)),
    Restrictions.eq(VERSION_PROPERTY, version)));
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{},{}] Search result: {}.", applicationId, version, logSchema);
 } else {
  LOG.debug("[{},{}] Search result: {}.", applicationId, version, logSchema != null);
 }
 return logSchema;
}

代码示例来源:origin: kaaproject/kaa

@Override
public ConfigurationSchema findByAppIdAndVersion(String appId, int version) {
 ConfigurationSchema schema = null;
 LOG.debug("Searching configuration schema by application id [{}] and version [{}]",
   appId, version);
 if (isNotBlank(appId)) {
  schema = findOneByCriterionWithAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS,
    Restrictions.and(
      Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)),
      Restrictions.eq(VERSION_PROPERTY, version)));
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{},{}] Search result: {}.", appId, version, schema);
 } else {
  LOG.debug("[{},{}] Search result: {}.", appId, version, schema != null);
 }
 return schema;
}

代码示例来源:origin: kaaproject/kaa

private Criterion buildSearchCriterion(String fqn, String tenantId, String applicationId) {
 List<Criterion> searchCriterions = new ArrayList<>();
 searchCriterions.add(Restrictions.eq(CTL_SCHEMA_META_INFO_FQN, fqn));
 if (isNotBlank(tenantId)) {
  searchCriterions.add(Restrictions.eq(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS,
      Long.valueOf(tenantId)));
 } else {
  searchCriterions.add(Restrictions.isNull(CTL_SCHEMA_META_INFO_TENANT_ID_ALIAS));
 }
 if (isNotBlank(applicationId)) {
  searchCriterions.add(Restrictions.eq(CTL_SCHEMA_META_INFO_APPLICATION_ID_ALIAS,
      Long.valueOf(applicationId)));
 } else {
  searchCriterions.add(Restrictions.isNull(CTL_SCHEMA_META_INFO_APPLICATION_ID_ALIAS));
 }
 return Restrictions.and(searchCriterions.toArray(new Criterion[searchCriterions.size()]));
}

代码示例来源:origin: kaaproject/kaa

@Override
public List<ProfileFilter> findActualByEndpointGroupId(String groupId) {
 LOG.debug("Searching actual profile filters by endpoint group id [{}] ", groupId);
 List<ProfileFilter> filters = Collections.emptyList();
 if (isNotBlank(groupId)) {
  filters = findListByCriterionWithAlias(ENDPOINT_GROUP_PROPERTY, ENDPOINT_GROUP_ALIAS,
    Restrictions.and(
      Restrictions.eq(ENDPOINT_GROUP_REFERENCE, Long.valueOf(groupId)),
      Restrictions.ne(STATUS_PROPERTY, UpdateStatus.DEPRECATED)));
 }
 if (LOG.isTraceEnabled()) {
  LOG.trace("[{}] Search result: {}.", groupId, Arrays.toString(filters.toArray()));
 } else {
  LOG.debug("[{}] Search result: {}.", groupId, filters.size());
 }
 return filters;
}

代码示例来源:origin: kaaproject/kaa

@Override
public boolean validateName(String tenantId, String ecfId, String name) {
 LOG.debug("Validating by tenant id [{}], ecf id [{}], name [{}]", tenantId, ecfId, name);
 Criteria criteria = getCriteria();
 criteria.createAlias(TENANT_PROPERTY, TENANT_ALIAS);
 criteria.add(Restrictions.and(
   Restrictions.eq(TENANT_REFERENCE, Long.valueOf(tenantId)),
   Restrictions.eq(NAME_PROPERTY, name)));
 if (isNotBlank(ecfId)) {
  criteria = criteria.add(Restrictions.ne(ID_PROPERTY, Long.valueOf(ecfId)));
 }
 List<EventClassFamily> eventClassFamilies = findListByCriteria(criteria);
 boolean result = eventClassFamilies == null || eventClassFamilies.isEmpty();
 LOG.debug("[{},{},{}] Validating result: {}", tenantId, ecfId, name, result);
 return result;
}

代码示例来源:origin: kaaproject/kaa

@Override
 public boolean validateClassName(String tenantId, String ecfId, String className) {
  LOG.debug("Validating fqn, tenant id [{}], ecf id [{}], className [{}]",
      tenantId, ecfId, className);
  Criteria criteria = getCriteria();
  criteria.createAlias(TENANT_PROPERTY, TENANT_ALIAS);
  criteria.add(Restrictions.and(
    Restrictions.eq(TENANT_REFERENCE, Long.valueOf(tenantId)),
    Restrictions.eq(CLASS_NAME_PROPERTY, className)));
  if (isNotBlank(ecfId)) {
   criteria = criteria.add(Restrictions.ne(ID_PROPERTY, Long.valueOf(ecfId)));
  }
  List<EventClassFamily> eventClassFamilies = findListByCriteria(criteria);
  boolean result = eventClassFamilies == null || eventClassFamilies.isEmpty();
  LOG.debug("[{},{},{}] Validating result: {}", tenantId, ecfId, className, result);
  return result;
 }
}

代码示例来源:origin: kaaproject/kaa

@Override
public boolean validateApplicationEventFamilyMap(String appId, String ecfId, int version) {
 LOG.debug("Validating application event family map by application id [{}], ecf id [{}], "
      + "version [{}]", appId, ecfId, version);
 Criteria criteria = getCriteria();
 criteria.createAlias(APPLICATION_PROPERTY, APPLICATION_ALIAS);
 criteria.createAlias(ECF_PROPERTY, ECF_ALIAS);
 criteria.add(Restrictions.and(
   Restrictions.eq(APPLICATION_REFERENCE, Long.valueOf(appId)),
   Restrictions.eq(ECF_REFERENCE, Long.valueOf(ecfId)),
   Restrictions.eq(VERSION_PROPERTY, version)));
 Long count = (Long) criteria.setProjection(Projections.rowCount()).uniqueResult();
 boolean result = count != null ? count == 0 : false;
 LOG.debug("[{},{},{}] Validation result: {}.", appId, ecfId, version, result);
 return result;
}

代码示例来源:origin: gocd/gocd

private void loadModificationsForPMR(List<PipelineMaterialRevision> pmrs) {
  List<Criterion> criterions = new ArrayList<>();
  for (PipelineMaterialRevision pmr : pmrs) {
    if (goCache.get(pmrModificationsKey(pmr)) != null) {
      continue;
    }
    final Criterion modificationClause = Restrictions.between("id", pmr.getFromModification().getId(), pmr.getToModification().getId());
    final SimpleExpression idClause = Restrictions.eq("materialInstance", pmr.getMaterialInstance());
    criterions.add(Restrictions.and(idClause, modificationClause));
  }
  List<Modification> modifications = (List<Modification>) getHibernateTemplate().findByCriteria(buildModificationDetachedQuery(criterions));
  sortPersistentObjectsById(modifications, false);
  for (Modification modification : modifications) {
    List<String> cacheKeys = pmrModificationsKey(modification, pmrs);
    for (String cacheKey : cacheKeys) {
      List<Modification> modificationList = (List<Modification>) goCache.get(cacheKey);
      if (modificationList == null) {
        modificationList = new ArrayList<>();
        goCache.put(cacheKey, modificationList);
      }
      modificationList.add(modification);
    }
  }
}

相关文章