Пример #1
0
  @Override
  public A findByAttrUniqueValue(final String schemaKey, final PlainAttrValue attrUniqueValue) {
    PlainSchema schema = plainSchemaDAO.find(schemaKey);
    if (schema == null) {
      LOG.error("Invalid schema name '{}'", schemaKey);
      return null;
    }
    if (!schema.isUniqueConstraint()) {
      LOG.error("This schema has not unique constraint: '{}'", schemaKey);
      return null;
    }

    List<A> result = findByAttrValue(schemaKey, attrUniqueValue);
    return result.isEmpty() ? null : result.iterator().next();
  }
Пример #2
0
  @Override
  @SuppressWarnings("unchecked")
  public List<A> findByAttrValue(final String schemaKey, final PlainAttrValue attrValue) {
    PlainSchema schema = plainSchemaDAO.find(schemaKey);
    if (schema == null) {
      LOG.error("Invalid schema name '{}'", schemaKey);
      return Collections.<A>emptyList();
    }

    String entityName =
        schema.isUniqueConstraint()
            ? getAnyUtils().plainAttrUniqueValueClass().getName()
            : getAnyUtils().plainAttrValueClass().getName();
    Query query = findByAttrValueQuery(entityName);
    query.setParameter("schemaKey", schemaKey);
    query.setParameter("stringValue", attrValue.getStringValue());
    query.setParameter(
        "booleanValue",
        attrValue.getBooleanValue() == null
            ? null
            : ((AbstractPlainAttrValue) attrValue)
                .getBooleanAsInteger(attrValue.getBooleanValue()));
    if (attrValue.getDateValue() == null) {
      query.setParameter("dateValue", null);
    } else {
      query.setParameter("dateValue", attrValue.getDateValue(), TemporalType.TIMESTAMP);
    }
    query.setParameter("longValue", attrValue.getLongValue());
    query.setParameter("doubleValue", attrValue.getDoubleValue());

    List<A> result = new ArrayList<>();
    for (PlainAttrValue value : (List<PlainAttrValue>) query.getResultList()) {
      A any = (A) value.getAttr().getOwner();
      if (!result.contains(any)) {
        result.add(any);
      }
    }

    return result;
  }