Пример #1
0
  @SuppressWarnings("unchecked")
  @Override
  public <T> List<? extends T> findNonPurged(
      Class<T> mapType, Class<?> resourceType, long resourceId) {
    String type = schemaFactory.getSchemaName(mapType);

    Table<?> table = getTable(mapType);

    Relationship reference = getRelationship(mapType, resourceType);
    TableField<?, Object> referenceField =
        JooqUtils.getTableField(metaDataManager, type, reference.getPropertyName());
    TableField<?, Object> state =
        JooqUtils.getTableField(metaDataManager, type, ObjectMetaDataManager.STATE_FIELD);

    if (referenceField == null || state == null) {
      throw new IllegalArgumentException(
          "Type [" + mapType + "] is missing required reference or state column");
    }

    return (List<? extends T>)
        create()
            .selectFrom(table)
            .where(referenceField.eq(resourceId).and(state.ne(CommonStatesConstants.PURGED)))
            .fetch();
  }
Пример #2
0
 protected static org.jooq.Condition toCondition(TableField<?, Object> field, Condition value) {
   Condition condition = value;
   switch (condition.getConditionType()) {
     case EQ:
       return field.eq(condition.getValue());
     case GT:
       return field.gt(condition.getValue());
     case GTE:
       return field.ge(condition.getValue());
     case IN:
       List<Object> values = condition.getValues();
       if (values.size() == 1) {
         return field.eq(values.get(0));
       } else {
         return field.in(condition.getValues());
       }
     case NOTIN:
       List<Object> vals = condition.getValues();
       if (vals.size() == 1) {
         return field.ne(vals.get(0));
       } else {
         return field.notIn(condition.getValues());
       }
     case LIKE:
       return field.like(condition.getValue().toString());
     case LT:
       return field.lt(condition.getValue());
     case LTE:
       return field.le(condition.getValue());
     case NE:
       return field.ne(condition.getValue());
     case NOTLIKE:
       return field.notLike(condition.getValue().toString());
     case NOTNULL:
       return field.isNotNull();
     case NULL:
       return field.isNull();
     case PREFIX:
       return field.like(condition.getValue() + "%");
     case OR:
       return toCondition(field, condition.getLeft()).or(toCondition(field, condition.getRight()));
     default:
       throw new IllegalArgumentException(
           "Invalid condition type [" + condition.getConditionType() + "]");
   }
 }