javax.persistence.criteria.Fetch.getAttribute()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(148)

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

Fetch.getAttribute介绍

[英]Return the metamodel attribute corresponding to the fetch join.
[中]返回与获取联接对应的元模型属性。

代码示例

代码示例来源:origin: spring-projects/spring-data-jpa

/**
 * Return whether the given {@link From} contains a fetch declaration for the attribute with the given name.
 *
 * @param from the {@link From} to check for fetches.
 * @param attribute the attribute name to check.
 * @return
 */
private static boolean isAlreadyFetched(From<?, ?> from, String attribute) {
  for (Fetch<?, ?> fetch : from.getFetches()) {
    boolean sameName = fetch.getAttribute().getName().equals(attribute);
    if (sameName && fetch.getJoinType().equals(JoinType.LEFT)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: org.omnifaces/omnipersistence

@Override
public Attribute<? super Z, ?> getAttribute() {
  return getWrapped().getAttribute();
}

代码示例来源:origin: org.apache.openejb.patch/openjpa

protected void evalFetchJoin(QueryExpressions exps, ExpressionFactory factory, CriteriaQueryImpl<?> q) {
  List<String> iPaths = new ArrayList<String>();
  List<String> oPaths = new ArrayList<String>();
  Set<Root<?>> roots = q.getRoots();
  for (Root root : roots) {
    Set<Fetch> fetches = root.getFetches();
    if (fetches == null)
      continue;
    for (Fetch<?,?> fetch : fetches) {
      String fPath = ((Members.Member<?, ?>)fetch.getAttribute()).fmd.getFullName(false);
      oPaths.add(fPath);
      if (fetch.getJoinType() == JoinType.INNER) {
        iPaths.add(fPath);
      } 
    }
  }
  if (!iPaths.isEmpty()) {
    exps.fetchInnerPaths = iPaths.toArray(new String[iPaths.size()]);
  }
  if (!oPaths.isEmpty()) {
    exps.fetchPaths = oPaths.toArray(new String[oPaths.size()]);
  }
}

代码示例来源:origin: org.apache.openejb.patch/openjpa-persistence

protected void evalFetchJoin(QueryExpressions exps, ExpressionFactory factory, CriteriaQueryImpl<?> q) {
  List<String> iPaths = new ArrayList<String>();
  List<String> oPaths = new ArrayList<String>();
  Set<Root<?>> roots = q.getRoots();
  for (Root root : roots) {
    Set<Fetch> fetches = root.getFetches();
    if (fetches == null)
      continue;
    for (Fetch<?,?> fetch : fetches) {
      String fPath = ((Members.Member<?, ?>)fetch.getAttribute()).fmd.getFullName(false);
      oPaths.add(fPath);
      if (fetch.getJoinType() == JoinType.INNER) {
        iPaths.add(fPath);
      } 
    }
  }
  if (!iPaths.isEmpty()) {
    exps.fetchInnerPaths = iPaths.toArray(new String[iPaths.size()]);
  }
  if (!oPaths.isEmpty()) {
    exps.fetchPaths = oPaths.toArray(new String[oPaths.size()]);
  }
}

代码示例来源:origin: org.apache.openjpa/openjpa-persistence

protected void evalFetchJoin(QueryExpressions exps, ExpressionFactory factory, CriteriaQueryImpl<?> q) {
  List<String> iPaths = new ArrayList<String>();
  List<String> oPaths = new ArrayList<String>();
  Set<Root<?>> roots = q.getRoots();
  for (Root root : roots) {
    Set<Fetch> fetches = root.getFetches();
    if (fetches == null)
      continue;
    for (Fetch<?,?> fetch : fetches) {
      String fPath = ((Members.Member<?, ?>)fetch.getAttribute()).fmd.getFullName(false);
      oPaths.add(fPath);
      if (fetch.getJoinType() == JoinType.INNER) {
        iPaths.add(fPath);
      } 
    }
  }
  if (!iPaths.isEmpty()) {
    exps.fetchInnerPaths = iPaths.toArray(new String[iPaths.size()]);
  }
  if (!oPaths.isEmpty()) {
    exps.fetchPaths = oPaths.toArray(new String[oPaths.size()]);
  }
}

代码示例来源:origin: org.apache.openjpa/openjpa-all

protected void evalFetchJoin(QueryExpressions exps, ExpressionFactory factory, CriteriaQueryImpl<?> q) {
  List<String> iPaths = new ArrayList<String>();
  List<String> oPaths = new ArrayList<String>();
  Set<Root<?>> roots = q.getRoots();
  for (Root root : roots) {
    Set<Fetch> fetches = root.getFetches();
    if (fetches == null)
      continue;
    for (Fetch<?,?> fetch : fetches) {
      String fPath = ((Members.Member<?, ?>)fetch.getAttribute()).fmd.getFullName(false);
      oPaths.add(fPath);
      if (fetch.getJoinType() == JoinType.INNER) {
        iPaths.add(fPath);
      } 
    }
  }
  if (!iPaths.isEmpty()) {
    exps.fetchInnerPaths = iPaths.toArray(new String[iPaths.size()]);
  }
  if (!oPaths.isEmpty()) {
    exps.fetchPaths = oPaths.toArray(new String[oPaths.size()]);
  }
}

代码示例来源:origin: org.ligoj.bootstrap/bootstrap-business

private Fetch<?, ?> getFetchedAssoc(final FetchParent<?, ?> parent, final JoinType joinType, final String propertyToFetch) {
  // Search within current fetches
  for (final Fetch<?, ?> fetch : parent.getFetches()) {
    if (fetch.getAttribute().getName().equals(propertyToFetch)) {
      return fetch;
    }
  }
  // Create a new one
  return parent.fetch(propertyToFetch, joinType);
}

代码示例来源:origin: org.omnifaces/omnipersistence

private static void collectJoins(Path<?> path, Map<String, Path<?>> joins) {
  if (path instanceof From) {
    ((From<?, ?>) path).getJoins().forEach(join -> collectJoins(join, joins));
  }
  if (path instanceof FetchParent) {
    try {
      ((FetchParent<?, ?>) path).getFetches().stream().filter(fetch -> fetch instanceof Path).forEach(fetch -> collectJoins((Path<?>) fetch, joins));
    }
    catch (NullPointerException openJPAWillThrowThisOnEmptyFetches) {
      // Ignore and continue.
    }
  }
  if (path instanceof Join) {
    joins.put(((Join<?, ?>) path).getAttribute().getName(), path);
  }
  else if (path instanceof Fetch) {
    joins.put(((Fetch<?, ?>) path).getAttribute().getName(), path);
  }
}

代码示例来源:origin: org.springframework.data/spring-data-jpa

/**
 * Return whether the given {@link From} contains a fetch declaration for the attribute with the given name.
 *
 * @param from the {@link From} to check for fetches.
 * @param attribute the attribute name to check.
 * @return
 */
private static boolean isAlreadyFetched(From<?, ?> from, String attribute) {
  for (Fetch<?, ?> fetch : from.getFetches()) {
    boolean sameName = fetch.getAttribute().getName().equals(attribute);
    if (sameName && fetch.getJoinType().equals(JoinType.LEFT)) {
      return true;
    }
  }
  return false;
}

代码示例来源:origin: katharsis-project/katharsis-framework

private static boolean containsMultiRelationFetch(Set<?> fetches) {
 for (Object fetchObj : fetches) {
  Fetch<?, ?> fetch = (Fetch<?, ?>) fetchObj;
  Attribute<?, ?> attr = fetch.getAttribute();
  if (attr.isAssociation() && attr.isCollection())
   return true;
  if (containsMultiRelationFetch(fetch.getFetches()))
   return true;
 }
 return false;
}

代码示例来源:origin: katharsis-project/katharsis-framework

private static boolean containsMultiRelationJoin(Set<?> fetches) {
 for (Object fetchObj : fetches) {
  Fetch<?, ?> fetch = (Fetch<?, ?>) fetchObj;
  Attribute<?, ?> attr = fetch.getAttribute();
  if (attr.isAssociation() && attr.isCollection())
   return true;
  if (containsMultiRelationFetch(fetch.getFetches()))
   return true;
 }
 return false;
}

代码示例来源:origin: jaxio/jpa-query-by-example

@SuppressWarnings({"unchecked", "rawtypes"})
  protected void fetches(SearchParameters sp, Root<E> root) {
    for (List<Attribute<?, ?>> args : sp.getFetches()) {
      FetchParent<?, ?> from = root;
      for (Attribute<?, ?> arg : args) {
        boolean found = false;
        for (Fetch<?, ?> fetch : from.getFetches()) {
          if (arg.equals(fetch.getAttribute())) {
            from = fetch;
            found = true;
            break;
          }
        }
        if (!found) {
          if (arg instanceof PluralAttribute) {
            from = from.fetch((PluralAttribute) arg, JoinType.LEFT);
          } else {
            from = from.fetch((SingularAttribute) arg, JoinType.LEFT);
          }
        }
      }
    }
  }
}

代码示例来源:origin: org.jboss.pressgang.ccms/pressgang-ccms-query

/**
   * Copy Fetches
   *
   * @param from source Fetch
   * @param to   dest Fetch
   */
  public static void copyFetches(Fetch<?, ?> from, Fetch<?, ?> to) {
    for (Fetch<?, ?> f : from.getFetches()) {
      Fetch<?, ?> toFetch = to.fetch(f.getAttribute().getName());
      // recursively copy fetches
      copyFetches(f, toFetch);
    }
  }
}

代码示例来源:origin: org.apache.openejb.patch/openjpa-persistence

protected void evalAccessPaths(QueryExpressions exps, ExpressionFactory factory, CriteriaQueryImpl<?> q) {
  Set<ClassMetaData> metas = new HashSet<ClassMetaData>();
  MetamodelImpl metamodel = q.getMetamodel();    
  for (Root<?> root : q.getRoots()) {
    metas.add(((AbstractManagedType<?>)root.getModel()).meta);
    for (Join<?,?> join : root.getJoins()) {
      Class<?> cls = join.getAttribute().getJavaType();
      if (join.getAttribute().isAssociation()) {
        ClassMetaData meta = metamodel.getRepository().getMetaData(cls, null, true);
        PersistenceType type = MetamodelImpl.getPersistenceType(meta);
        if (type == PersistenceType.ENTITY || type == PersistenceType.EMBEDDABLE) 
          metas.add(meta);
      }
    }
    for (Fetch<?,?> fetch : root.getFetches()) {
      metas.add(metamodel.getRepository().getCachedMetaData(fetch.getAttribute().getJavaType()));
    }
  }
  exps.accessPath = metas.toArray(new ClassMetaData[metas.size()]);
}

代码示例来源:origin: org.apache.openejb.patch/openjpa

protected void evalAccessPaths(QueryExpressions exps, ExpressionFactory factory, CriteriaQueryImpl<?> q) {
  Set<ClassMetaData> metas = new HashSet<ClassMetaData>();
  MetamodelImpl metamodel = q.getMetamodel();    
  for (Root<?> root : q.getRoots()) {
    metas.add(((AbstractManagedType<?>)root.getModel()).meta);
    for (Join<?,?> join : root.getJoins()) {
      Class<?> cls = join.getAttribute().getJavaType();
      if (join.getAttribute().isAssociation()) {
        ClassMetaData meta = metamodel.getRepository().getMetaData(cls, null, true);
        PersistenceType type = MetamodelImpl.getPersistenceType(meta);
        if (type == PersistenceType.ENTITY || type == PersistenceType.EMBEDDABLE) 
          metas.add(meta);
      }
    }
    for (Fetch<?,?> fetch : root.getFetches()) {
      metas.add(metamodel.getRepository().getCachedMetaData(fetch.getAttribute().getJavaType()));
    }
  }
  exps.accessPath = metas.toArray(new ClassMetaData[metas.size()]);
}

代码示例来源:origin: org.datanucleus/datanucleus-jpa

Attribute attr = join.getAttribute();
tuples.add(attr.getName());
PrimaryExpression primExpr = new PrimaryExpression(new ArrayList(tuples));

代码示例来源:origin: jaxio/jpa-query-by-example

@SuppressWarnings("unchecked")
public <E, F> Path<F> getPath(Root<E> root, List<Attribute<?, ?>> attributes) {
  Path<?> path = root;
  for (Attribute<?, ?> attribute : attributes) {
    boolean found = false;
    if (path instanceof FetchParent) {
      for (Fetch<E, ?> fetch : ((FetchParent<?, E>) path).getFetches()) {
        if (attribute.getName().equals(fetch.getAttribute().getName()) && (fetch instanceof Join<?, ?>)) {
          path = (Join<E, ?>) fetch;
          found = true;
          break;
        }
      }
    }
    if (!found) {
      if (attribute instanceof PluralAttribute) {
        path = ((From<?, ?>) path).join(attribute.getName(), JoinType.LEFT);
      } else {
        path = path.get(attribute.getName());
      }
    }
  }
  return (Path<F>) path;
}

代码示例来源:origin: jaxio/generated-projects

/**
 * Convert the passed propertyPath into a JPA path.
 * <p>
 * Note: JPA will do joins if the property is in an associated entity.
 */
@SuppressWarnings("unchecked")
public <E, F> Path<F> getPath(Root<E> root, List<Attribute<?, ?>> attributes) {
  Path<?> path = root;
  for (Attribute<?, ?> attribute : attributes) {
    boolean found = false;
    if (path instanceof FetchParent) {
      for (Fetch<E, ?> fetch : ((FetchParent<?, E>) path).getFetches()) {
        if (attribute.getName().equals(fetch.getAttribute().getName()) && (fetch instanceof Join<?, ?>)) {
          path = (Join<E, ?>) fetch;
          found = true;
          break;
        }
      }
    }
    if (!found) {
      if (attribute instanceof PluralAttribute) {
        path = ((From<?, ?>) path).join(attribute.getName(), JoinType.LEFT);
      } else {
        path = path.get(attribute.getName());
      }
    }
  }
  return (Path<F>) path;
}

代码示例来源:origin: org.jboss.pressgang.ccms/pressgang-ccms-query

/**
 * Copy Joins
 *
 * @param from source Join
 * @param to   destination Join
 */
public static void copyJoins(From<?, ?> from, From<?, ?> to) {
  for (Join<?, ?> j : from.getJoins()) {
    Join<?, ?> toJoin = to.join(j.getAttribute().getName(), j.getJoinType());
    toJoin.alias(getOrCreateAlias(j));
    copyJoins(j, toJoin);
  }
  for (Fetch<?, ?> f : from.getFetches()) {
    Fetch<?, ?> toFetch = to.fetch(f.getAttribute().getName());
    copyFetches(f, toFetch);
  }
}

相关文章

微信公众号

最新文章

更多