private static void buildQueryHints(List<Element> elements, AnnotationDescriptor ann){ List<QueryHint> queryHints = new ArrayList<QueryHint>( elements.size() ); for ( Element hint : elements ) { AnnotationDescriptor hintDescriptor = new AnnotationDescriptor( QueryHint.class ); String value = hint.attributeValue( "name" ); if ( value == null ) { throw new AnnotationException( "<hint> without name. " + SCHEMA_VALIDATION ); } hintDescriptor.setValue( "name", value ); value = hint.attributeValue( "value" ); if ( value == null ) { throw new AnnotationException( "<hint> without value. " + SCHEMA_VALIDATION ); } hintDescriptor.setValue( "value", value ); queryHints.add( (QueryHint) AnnotationFactory.create( hintDescriptor ) ); } ann.setValue( "hints", queryHints.toArray( new QueryHint[queryHints.size()] ) ); }
public XAnnotation<javax.persistence.NamedQuery> createNamedQuery( NamedQuery source) { return source == null ? null : // new XAnnotation<javax.persistence.NamedQuery>( javax.persistence.NamedQuery.class, // AnnotationUtils.create("query", source.getQuery()), // AnnotationUtils.create("hints", createQueryHint(source.getHint()), QueryHint.class), // AnnotationUtils.create("name", source.getName()), AnnotationUtils.create("lockMode", createLockMode(source.getLockMode())) // ); }
protected void addLockModeOps(InstructionList il, LockModeType lockMode, QueryHint[] hints) { // setQueryHints() processQueryHints(hints, il, TQ_CLASS); // setLockMode() if (lockMode != null && lockMode != LockModeType.NONE) { ObjectType lm = new ObjectType("javax.persistence.LockModeType"); il.append(_factory.createFieldAccess( "javax.persistence.LockModeType", lockMode.name(), lm, Constants.GETSTATIC)); il.append(_factory.createInvoke(TQ_CLASS, "setLockMode", new ObjectType(TQ_CLASS), new Type[] { lm }, Constants.INVOKEINTERFACE)); } }
protected void processQueryHints(QueryHint[] hints, InstructionList il, String queryClass) { for (QueryHint qh : hints) { il.append(new PUSH(_cp, qh.name())); il.append(new PUSH(_cp, qh.value())); il.append(_factory.createInvoke(queryClass, "setQueryHint", new ObjectType(queryClass), new Type[] { Type.STRING, Type.OBJECT }, Constants.INVOKEINTERFACE)); } }
@Query("select q from Question q where q.id in :questionIds") @QueryHints(value = { @QueryHint(name = org.eclipse.persistence.config.QueryHints.BATCH_TYPE, value = "IN"), @QueryHint(name = org.eclipse.persistence.config.QueryHints.BATCH, value = "q.questionOptions"), @QueryHint(name = org.eclipse.persistence.config.QueryHints.BATCH, value = "q.subquestions"), @QueryHint(name = org.eclipse.persistence.config.QueryHints.BATCH, value = "q.translations"), @QueryHint(name = org.eclipse.persistence.config.QueryHints.BATCH, value = "questionOptions.translations"), @QueryHint(name = org.eclipse.persistence.config.QueryHints.BATCH, value = "subquestions.translations"), @QueryHint(name = org.eclipse.persistence.config.QueryHints.BATCH, value = "subquestions.questionOptions"), }, forCounting = false) List<Question> findInList(@Param("questionIds") List<Integer> questionIds);
public Query applyRestrictions(Query query) { Parameters params = getParams(); Method method = getMethod(); if (params.hasSizeRestriction()) { query.setMaxResults(params.getSizeRestriciton()); } if (params.hasFirstResult()) { query.setFirstResult(params.getFirstResult()); } LockModeType lockMode = extractLockMode(); if (lockMode != null) { query.setLockMode(lockMode); } QueryHint[] hints = extractQueryHints(); if (hints != null) { for (QueryHint hint : hints) { query.setHint(hint.name(), hint.value()); } } applyEntityGraph(query, method); query = applyJpaQueryPostProcessors(query); return query; }
private QueryHint[] extractQueryHints() { org.apache.deltaspike.data.api.Query query = getRepositoryMethodMetadata().getQuery(); if (query != null && query.hints().length > 0) { return query.hints(); } return null; }
@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") }) public List<Dictionary> findByType(int type);
@QueryHints(value = @QueryHint(name = HINT_FETCH_SIZE, value = "1")) @Query("SELECT r FROM RouteDataRevision r WHERE validFrom <= :date AND (validTo >= :date OR validTo IS NULL)") Stream<RouteDataRevision> findValid(@Param("date") Date date);
@QueryHints(value = { @QueryHint (name = "org.hibernate.cacheable", value = "true")}) List<Country> findByPopulationGreaterThan(Integer population);
@Query("from RunningExecutionPlan r where r.flowUUID = :flowUUID") @QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value ="true") }) public List<RunningExecutionPlan> findByUuidCached(@Param("flowUUID") String flowUUID);
@QueryHints(value = { @QueryHint(name = "org.hibernate.readOnly", value = "true")}) Person findById(Long id);
@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value = "true") , @QueryHint(name = "org.hibernate.cacheRegion", value = "omoikane.entities.Usuario") } ) @Query("FROM Usuario u") List<Usuario> findAll();
@QueryHints({ @QueryHint(name = "org.hibernate.cacheable", value = "true") , @QueryHint(name = "org.hibernate.cacheRegion", value = "omoikane.entities.Usuario") } ) @Query("SELECT COUNT(*) as count FROM Usuario u") Long countIt();
@Query(hints = { @QueryHint(name = "openjpa.hint.OptimizeResultCount", value = "some.invalid.value"), @QueryHint(name = "org.hibernate.comment", value = "I'm a little comment short and stout") }) Simple findBy(Long id);
/** * Retrieve users by their lastname. The finder {@literal User.findByLastname} is declared in * {@literal META-INF/orm.xml} . * * @param lastname * @return all users with the given lastname */ @QueryHints({@QueryHint(name = "foo", value = "bar")}) List<User> findByLastname(String lastname);