本文整理了Java中javax.persistence.Query.setHint
方法的一些代码示例,展示了Query.setHint
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setHint
方法的具体详情如下:
包路径:javax.persistence.Query
类名称:Query
方法名:setHint
[英]Set a query property or hint. The hints elements may be used to specify query properties and hints. Properties defined by this specification must be observed by the provider. Vendor-specific hints that are not recognized by a provider must be silently ignored. Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, this hint may or may not be observed.
[中]设置查询属性或提示。提示元素可用于指定查询属性和提示。供应商必须遵守本规范定义的属性。供应商无法识别的特定于供应商的提示必须默默忽略。便携式应用程序不应依赖标准超时提示。根据所使用的数据库和提供程序使用的锁定机制,可能会或可能不会观察到此提示。
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<AdminModule> readAllAdminModules() {
Query query = em.createNamedQuery("BC_READ_ALL_ADMIN_MODULES");
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "blAdminSecurityQuery");
List<AdminModule> modules = query.getResultList();
return modules;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<AdminSection> readAllAdminSections() {
Query query = em.createNamedQuery("BC_READ_ALL_ADMIN_SECTIONS");
query.setHint(org.hibernate.ejb.QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "blAdminSecurityQuery");
List<AdminSection> sections = query.getResultList();
return sections;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@SuppressWarnings("unchecked")
@Override
public List<ModuleConfiguration> readByType(Class<? extends ModuleConfiguration> type) {
//TODO change this to a JPA criteria expression
Query query = em.createQuery("SELECT config FROM " + type.getName() + " config");
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "blConfigurationModuleElements");
return query.getResultList();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@SuppressWarnings("unchecked")
public List<Country> findCountries() {
Query query = em.createNamedQuery("BC_FIND_COUNTRIES");
query.setHint(QueryHints.HINT_CACHEABLE, true);
return query.getResultList();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@SuppressWarnings("unchecked")
public List<Country> findCountries() {
Query query = em.createNamedQuery("BC_FIND_COUNTRIES");
query.setHint(QueryHints.HINT_CACHEABLE, true);
return query.getResultList();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
@SuppressWarnings("unchecked")
public List<CountrySubdivision> findSubdivisions() {
Query query = em.createNamedQuery("BC_FIND_COUNTRY_SUBDIVISIONS");
query.setHint(QueryHints.HINT_CACHEABLE, true);
return query.getResultList();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
@SuppressWarnings("unchecked")
public List<CountrySubdivision> findSubdivisions(String countryAbbreviation) {
Query query = em.createNamedQuery("BC_FIND_SUBDIVISIONS_BY_COUNTRY_ABBREVIATION");
query.setParameter("countryAbbreviation", countryAbbreviation);
query.setHint(QueryHints.HINT_CACHEABLE, true);
return query.getResultList();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
@SuppressWarnings("unchecked")
public List<Store> readAllStores() {
Query query = em.createNamedQuery("BC_FIND_ALL_STORES");
query.setParameter("archived", 'N');
query.setHint(QueryHints.HINT_CACHEABLE, true);
return query.getResultList();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@SuppressWarnings("unchecked")
public List<State> findStates(String countryAbbreviation) {
Query query = em.createNamedQuery("BC_FIND_STATES_BY_COUNTRY_ABBREVIATION");
query.setParameter("countryAbbreviation", countryAbbreviation);
query.setHint(QueryHints.HINT_CACHEABLE, true);
return query.getResultList();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<CountrySubdivision> findSubdivisionsByCountryAndCategory(String countryAbbreviation, String category) {
Query query = em.createNamedQuery("BC_FIND_SUBDIVISIONS_BY_COUNTRY_ABBREVIATION_AND_CATEGORY");
query.setParameter("countryAbbreviation", countryAbbreviation);
query.setParameter("category", category);
query.setHint(QueryHints.HINT_CACHEABLE, true);
return query.getResultList();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
@SuppressWarnings("unchecked")
public List<Store> readAllStoresByState(final String state) {
Query query = em.createNamedQuery("BC_FIND_ALL_STORES_BY_STATE");
query.setParameter("state", state);
query.setParameter("archived", 'N');
query.setHint(QueryHints.HINT_CACHEABLE, true);
return query.getResultList();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public BroadleafCurrency findDefaultBroadleafCurrency() {
Query query = em.createNamedQuery("BC_READ_DEFAULT_CURRENCY");
query.setHint(org.hibernate.ejb.QueryHints.HINT_CACHEABLE, true);
List<BroadleafCurrency> currencyList = query.getResultList();
if (currencyList.size() >= 1) {
return currencyList.get(0);
}
return null;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public StructuredContentType findStructuredContentTypeByName(String name) {
Query query = em.createNamedQuery("BC_READ_STRUCTURED_CONTENT_TYPE_BY_NAME");
query.setParameter("name",name);
query.setHint(QueryHints.HINT_CACHEABLE, true);
List<StructuredContentType> results = query.getResultList();
if (results.size() > 0) {
return results.get(0);
} else {
return null;
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
@SuppressWarnings("unchecked")
public Store readStoreByStoreCode(final String storeCode) {
Query query = em.createNamedQuery("BC_FIND_STORE_BY_STORE_NAME");
query.setParameter("storeName", storeCode.toUpperCase());
query.setHint(QueryHints.HINT_CACHEABLE, true);
List result = query.getResultList();
return (result.size() > 0) ? (Store) result.get(0) : null;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public SearchRedirect findSearchRedirectBySearchTerm(String searchTerm) {
Query query = em.createQuery(buildFindSearchRedirectBySearchTermCriteria(searchTerm));
query.setMaxResults(1);
query.setHint(QueryHints.HINT_CACHEABLE, true);
List<SearchRedirect> results = query.getResultList();
if (results != null && !results.isEmpty()) {
return results.get(0);
} else {
return null;
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<RatingSummary> readRatingSummaries(final List<String> itemIds, final RatingType type) {
final Query query = em.createNamedQuery("BC_READ_RATING_SUMMARIES_BY_ITEM_ID_AND_TYPE");
query.setParameter("ratingType", type.getType());
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
List<RatingSummary> ratings = batchExecuteReadQuery(query, itemIds, "itemIds");
return ratings;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public void execute() throws Throwable {
Query q = em.createNamedQuery("BC_ORDER_LOCK_RELEASE");
q.setParameter("orderId", order.getId());
q.setParameter("key", getOrderLockKey());
q.setHint(QueryHints.HINT_CACHEABLE, false);
int rowsAffected = q.executeUpdate();
response[0] = rowsAffected == 1;
}
代码示例来源:origin: spring-projects/spring-data-jpa
private void applyQueryHints(Query query) {
for (Entry<String, Object> hint : getQueryHints().withFetchGraphs(em)) {
query.setHint(hint.getKey(), hint.getValue());
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Apply the current transaction timeout, if any, to the given JPA Query object.
* <p>This method sets the JPA 2.0 query hint "javax.persistence.query.timeout" accordingly.
* @param query the JPA Query object
* @param emf the JPA EntityManagerFactory that the Query was created for
*/
public static void applyTransactionTimeout(Query query, EntityManagerFactory emf) {
EntityManagerHolder emHolder = (EntityManagerHolder) TransactionSynchronizationManager.getResource(emf);
if (emHolder != null && emHolder.hasTimeout()) {
int timeoutValue = (int) emHolder.getTimeToLiveInMillis();
try {
query.setHint("javax.persistence.query.timeout", timeoutValue);
}
catch (IllegalArgumentException ex) {
// oh well, at least we tried...
}
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void test_jpql_api_basic_usage_example() {
doInJPA( this::entityManagerFactory, entityManager -> {
//tag::jpql-api-basic-usage-example[]
Query query = entityManager.createQuery(
"select p " +
"from Person p " +
"where p.name like :name" )
// timeout - in milliseconds
.setHint( "javax.persistence.query.timeout", 2000 )
// flush only at commit time
.setFlushMode( FlushModeType.COMMIT );
//end::jpql-api-basic-usage-example[]
});
}
内容来源于网络,如有侵权,请联系作者删除!