예제 #1
0
 @Override
 protected void putJoinTabalis(Map<Class, String> map) {
   if (this.joinClass != null && !map.containsKey(this.joinClass))
     map.put(joinClass, String.valueOf((char) ('b' + map.size())));
   if (this.nodes == null) return;
   for (FilterNode node : this.nodes) {
     node.putJoinTabalis(map);
   }
 }
예제 #2
0
 @Override
 protected boolean isCacheUseable(final Function<Class, EntityInfo> entityApplyer) {
   if (this.joinEntity == null) this.joinEntity = entityApplyer.apply(this.joinClass);
   if (!this.joinEntity.isCacheFullLoaded()) return false;
   if (this.nodes == null) return true;
   for (FilterNode node : this.nodes) {
     if (!node.isCacheUseable(entityApplyer)) return false;
   }
   return true;
 }
예제 #3
0
  @Override
  protected <T, E> Predicate<T> createPredicate(final EntityCache<T> cache) {
    if (column == null && this.nodes == null) return null;
    final EntityCache<E> joinCache = this.joinEntity.getCache();
    final AtomicBoolean more = new AtomicBoolean();
    Predicate<E> filter = createJoinPredicate(more);
    Predicate<T> rs = null;
    if (filter == null && !more.get()) return rs;
    if (filter != null) {
      final Predicate<E> inner = filter;
      rs =
          new Predicate<T>() {

            @Override
            public boolean test(final T t) {
              Predicate<E> joinPredicate = null;
              for (String joinColumn : joinColumns) {
                final Serializable key = cache.getAttribute(joinColumn).get(t);
                final Attribute<E, Serializable> joinAttr = joinCache.getAttribute(joinColumn);
                Predicate<E> p = (E e) -> key.equals(joinAttr.get(e));
                joinPredicate = joinPredicate == null ? p : joinPredicate.and(p);
              }
              return joinCache.exists(inner.and(joinPredicate));
            }

            @Override
            public String toString() {
              StringBuilder sb = new StringBuilder();
              sb.append(" #-- ON ")
                  .append(joinColumns[0])
                  .append("=")
                  .append(joinClass == null ? "null" : joinClass.getSimpleName())
                  .append(".")
                  .append(joinColumns[0]);
              for (int i = 1; i < joinColumns.length; i++) {
                sb.append(" AND ")
                    .append(joinColumns[i])
                    .append("=")
                    .append(joinClass == null ? "null" : joinClass.getSimpleName())
                    .append(".")
                    .append(joinColumns[i]);
              }
              sb.append(" --# ").append(inner.toString());
              return sb.toString();
            }
          };
    }
    if (more.get()) { // 存在不同Class的关联表
      if (this.nodes != null) {
        for (FilterNode node : this.nodes) {
          if (((FilterJoinNode) node).joinClass == this.joinClass) continue;
          Predicate<T> f = node.createPredicate(cache);
          if (f == null) continue;
          final Predicate<T> one = rs;
          final Predicate<T> two = f;
          rs =
              (rs == null)
                  ? f
                  : (or
                      ? new Predicate<T>() {

                        @Override
                        public boolean test(T t) {
                          return one.test(t) || two.test(t);
                        }

                        @Override
                        public String toString() {
                          return "(" + one + " OR " + two + ")";
                        }
                      }
                      : new Predicate<T>() {

                        @Override
                        public boolean test(T t) {
                          return one.test(t) && two.test(t);
                        }

                        @Override
                        public String toString() {
                          return "(" + one + " AND " + two + ")";
                        }
                      });
        }
      }
    }
    return rs;
  }