本文整理汇总了Java中org.eclipse.persistence.jpa.JpaQuery类的典型用法代码示例。如果您正苦于以下问题:Java JpaQuery类的具体用法?Java JpaQuery怎么用?Java JpaQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JpaQuery类属于org.eclipse.persistence.jpa包,在下文中一共展示了JpaQuery类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getResultList
import org.eclipse.persistence.jpa.JpaQuery; //导入依赖的package包/类
@Override
public List<T> getResultList() {
if (log.isDebugEnabled())
log.debug(queryString.replaceAll("[\\t\\n\\x0B\\f\\r]", " "));
singleResultExpected = false;
JpaQuery<T> query = getQuery();
preExecute(query);
@SuppressWarnings("unchecked")
List<T> resultList = (List<T>) getResultFromCache(query, false, obj -> {
((List) obj).stream().filter(item -> item instanceof Entity).forEach(item -> {
for (View view : views) {
entityFetcher.fetch((Entity) item, view);
}
});
});
return resultList;
}
开发者ID:cuba-platform,项目名称:cuba,代码行数:20,代码来源:QueryImpl.java
示例2: getSingleResult
import org.eclipse.persistence.jpa.JpaQuery; //导入依赖的package包/类
@Override
public T getSingleResult() {
if (log.isDebugEnabled())
log.debug(queryString.replaceAll("[\\t\\n\\x0B\\f\\r]", " "));
singleResultExpected = true;
JpaQuery<T> jpaQuery = getQuery();
preExecute(jpaQuery);
@SuppressWarnings("unchecked")
T result = (T) getResultFromCache(jpaQuery, true, obj -> {
if (obj instanceof Entity) {
for (View view : views) {
entityFetcher.fetch((Entity) obj, view);
}
}
});
return result;
}
开发者ID:cuba-platform,项目名称:cuba,代码行数:20,代码来源:QueryImpl.java
示例3: executeUpdate
import org.eclipse.persistence.jpa.JpaQuery; //导入依赖的package包/类
@Override
public int executeUpdate() {
JpaQuery<T> jpaQuery = getQuery();
// In some cache configurations (in particular, when shared cache is on, but for some entities cache is set to ISOLATED),
// EclipseLink does not evict updated entities from cache automatically.
Cache cache = jpaQuery.getEntityManager().getEntityManagerFactory().getCache();
Class referenceClass = jpaQuery.getDatabaseQuery().getReferenceClass();
if (referenceClass != null) {
cache.evict(referenceClass);
queryCacheMgr.invalidate(referenceClass, true);
} else {
cache.evictAll();
queryCacheMgr.invalidateAll(true);
}
preExecute(jpaQuery);
return jpaQuery.executeUpdate();
}
开发者ID:cuba-platform,项目名称:cuba,代码行数:18,代码来源:QueryImpl.java
示例4: addView
import org.eclipse.persistence.jpa.JpaQuery; //导入依赖的package包/类
public void addView(JpaQuery query, String queryString, View view, boolean singleResultExpected) {
Preconditions.checkNotNullArgument(query, "query is null");
Preconditions.checkNotNullArgument(view, "view is null");
Map<String, Object> hints = query.getHints();
AttributeGroup ag = null;
if (view.loadPartialEntities()) {
if (hints != null)
ag = (FetchGroup) hints.get(QueryHints.FETCH_GROUP);
if (ag == null)
ag = new FetchGroup();
} else {
if (hints != null)
ag = (LoadGroup) hints.get(QueryHints.LOAD_GROUP);
if (ag == null)
ag = new LoadGroup();
}
applyView(query, queryString, ag, view, singleResultExpected);
}
开发者ID:cuba-platform,项目名称:cuba,代码行数:21,代码来源:FetchGroupManager.java
示例5: getSingleResultOrNull
import org.eclipse.persistence.jpa.JpaQuery; //导入依赖的package包/类
public R getSingleResultOrNull(boolean dump)
{
limit(1);
TypedQuery<R> prepareQuery = prepareQuery();
List<R> resultList = prepareQuery.getResultList();
if (dump)
{
logger.warn(prepareQuery.unwrap(JpaQuery.class).getDatabaseQuery().getSQLString());
}
if (resultList.size() == 0)
{
return null;
}
return resultList.get(0);
}
开发者ID:rlsutton1,项目名称:VaadinUtils,代码行数:17,代码来源:JpaDslAbstract.java
示例6: getFirstResult
import org.eclipse.persistence.jpa.JpaQuery; //导入依赖的package包/类
@Override
@Nullable
public T getFirstResult() {
if (log.isDebugEnabled())
log.debug(queryString.replaceAll("[\\t\\n\\x0B\\f\\r]", " "));
Integer saveMaxResults = maxResults;
maxResults = 1;
try {
JpaQuery<T> query = getQuery();
preExecute(query);
@SuppressWarnings("unchecked")
List<T> resultList = (List<T>) getResultFromCache(query, false, obj -> {
List list = (List) obj;
if (!list.isEmpty()) {
Object item = list.get(0);
if (item instanceof Entity) {
for (View view : views) {
entityFetcher.fetch((Entity) item, view);
}
}
}
});
if (resultList.isEmpty()) {
return null;
} else {
return resultList.get(0);
}
} finally {
maxResults = saveMaxResults;
}
}
开发者ID:cuba-platform,项目名称:cuba,代码行数:33,代码来源:QueryImpl.java
示例7: preExecute
import org.eclipse.persistence.jpa.JpaQuery; //导入依赖的package包/类
protected void preExecute(JpaQuery jpaQuery) {
// copying behaviour of org.eclipse.persistence.internal.jpa.QueryImpl.executeReadQuery()
DatabaseQuery elDbQuery = ((EJBQueryImpl) jpaQuery).getDatabaseQueryInternal();
boolean isObjectLevelReadQuery = elDbQuery.isObjectLevelReadQuery();
if (jpaQuery.getFlushMode() == FlushModeType.AUTO
&& (!isObjectLevelReadQuery || !((ObjectLevelReadQuery) elDbQuery).isReadOnly())) {
// flush is expected
support.fireEntityListeners(entityManager, true);
}
}
开发者ID:cuba-platform,项目名称:cuba,代码行数:11,代码来源:QueryImpl.java
示例8: getResultFromCache
import org.eclipse.persistence.jpa.JpaQuery; //导入依赖的package包/类
protected Object getResultFromCache(JpaQuery jpaQuery, boolean singleResult, Consumer<Object> fetcher) {
Preconditions.checkNotNull(fetcher);
boolean useQueryCache = cacheable && !isNative && queryCacheMgr.isEnabled() && lockMode == null;
Object result;
if (useQueryCache) {
QueryParser parser = QueryTransformerFactory.createParser(transformedQueryString);
String entityName = parser.getEntityName();
useQueryCache = parser.isEntitySelect(entityName);
QueryKey queryKey = null;
if (useQueryCache) {
queryKey = QueryKey.create(transformedQueryString, entityManager.isSoftDeletion(), singleResult, jpaQuery);
result = singleResult ? queryCacheMgr.getSingleResultFromCache(queryKey, views) :
queryCacheMgr.getResultListFromCache(queryKey, views);
if (result != null) {
return result;
}
}
try {
result = singleResult ? jpaQuery.getSingleResult() : jpaQuery.getResultList();
} catch (NoResultException | NonUniqueResultException ex) {
if (useQueryCache && singleResult) {
queryCacheMgr.putResultToCache(queryKey, null, entityName, parser.getAllEntityNames(), ex);
}
throw ex;
}
fetcher.accept(result);
if (useQueryCache) {
queryCacheMgr.putResultToCache(queryKey,
singleResult ? Collections.singletonList(result) : (List) result,
entityName, parser.getAllEntityNames());
}
} else {
result = singleResult ? jpaQuery.getSingleResult() : jpaQuery.getResultList();
fetcher.accept(result);
}
return result;
}
开发者ID:cuba-platform,项目名称:cuba,代码行数:38,代码来源:QueryImpl.java
示例9: apply
import org.eclipse.persistence.jpa.JpaQuery; //导入依赖的package包/类
public void apply(JpaQuery query) {
if (temporalType != null) {
if (name instanceof Integer)
query.setParameter((int) name, (Date) value, temporalType);
else
query.setParameter((String) name, (Date) value, temporalType);
} else {
if (name instanceof Integer)
query.setParameter((int) name, value);
else
query.setParameter((String) name, value);
}
}
开发者ID:cuba-platform,项目名称:cuba,代码行数:14,代码来源:QueryImpl.java
示例10: setView
import org.eclipse.persistence.jpa.JpaQuery; //导入依赖的package包/类
public void setView(JpaQuery query, String queryString, @Nullable View view, boolean singleResultExpected) {
Preconditions.checkNotNullArgument(query, "query is null");
if (view != null) {
AttributeGroup ag = view.loadPartialEntities() ? new FetchGroup() : new LoadGroup();
applyView(query, queryString, ag, view, singleResultExpected);
} else {
query.setHint(QueryHints.FETCH_GROUP, null);
}
}
开发者ID:cuba-platform,项目名称:cuba,代码行数:10,代码来源:FetchGroupManager.java
示例11: queryIndexOf
import org.eclipse.persistence.jpa.JpaQuery; //导入依赖的package包/类
private Integer queryIndexOf(final JpaEntityItem<TEntityType> item) {
final EntityManager em = lookup(EntityManager.class);
final CriteriaBuilder cb = em.getCriteriaBuilder();
final CriteriaQuery query = cb.createQuery();
final Root<TEntityType> root = query.from(entityClass);
// Добавляем фильтр контейнера
final List<Predicate> predicates = createContainerFilterPredicates(cb, query, root);
if (!predicates.isEmpty()) {
query.where(CollectionUtil.toArray(Predicate.class, predicates));
}
// Добавляем сортировку
final List<JpaSortBy> sortByList = sortBySupplier.get();
if (!sortByList.isEmpty()) {
final List<Order> orders = newArrayListWithCapacity(sortByList.size());
for (final JpaSortBy sortBy : sortByList)
orders.add(translateSortBy(sortBy, cb, root));
query.orderBy(orders);
}
final Path<String> idPath = root.get(IdentifiedObject_.id);
query.select(idPath).distinct(true);
final TypedQuery<Long> tq = em.createQuery(query);
final DatabaseQuery databaseQuery = tq.unwrap(JpaQuery.class).getDatabaseQuery();
final DatabaseRecord translationRow = new DatabaseRecord();
final JpaEntityManager jpaEm = em.unwrap(JpaEntityManager.class);
databaseQuery.prepareCall(jpaEm.getSession(), translationRow);
final String querySql = databaseQuery.getTranslatedSQLString(jpaEm.getSession(), translationRow);
final String itemId = item.getBean().getId();
final Query nativeQuery = em.createNativeQuery(
MessageFormat.format(
"SELECT q.rownum AS indx " +
"FROM (SELECT s.{2} AS id, (@rownum:[email protected] + 1) - 1 AS rownum " +
" FROM (SELECT @rownum:=0) i, ({0}) s) q " +
"WHERE q.id = ''{1}''", querySql, itemId, IdentifiedObject_.id.getName()));
// nativeQuery.unwrap(JpaQuery.class).getDatabaseQuery().setTranslationRow(translationRow);
final Object result;
try {
result = nativeQuery.getSingleResult();
} catch (final NoResultException e) {
return -1;
}
return result != null /*&& result instanceof Number*/ ? ((Number) result).intValue() : -1;
}
开发者ID:ExtaSoft,项目名称:extacrm,代码行数:48,代码来源:JpaLazyItemList.java
注:本文中的org.eclipse.persistence.jpa.JpaQuery类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论