org.hibernate.engine.query.spi.HQLQueryPlan Java Examples
The following examples show how to use
org.hibernate.engine.query.spi.HQLQueryPlan.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactiveSessionImpl.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 6 votes |
@Override public <T> CompletionStage<List<T>> reactiveList(String query, QueryParameters parameters) throws HibernateException { checkOpenOrWaitingForAutoClose(); pulseTransactionCoordinator(); parameters.validateParameters(); HQLQueryPlan plan = parameters.getQueryPlan(); if ( plan == null ) { plan = getQueryPlan( query, false ); } ReactiveHQLQueryPlan reactivePlan = (ReactiveHQLQueryPlan) plan; return reactiveAutoFlushIfRequired( plan.getQuerySpaces() ) // FIXME: I guess I can fix this as a separate issue // dontFlushFromFind++; //stops flush being called multiple times if this method is recursively called .thenCompose( v -> reactivePlan.performReactiveList(parameters, this ) ) .whenComplete( (list, x) -> { // dontFlushFromFind--; afterOperation( x == null ); delayedAfterCompletion(); } ) //TODO: this typecast is rubbish .thenApply( list -> (List<T>) list ); }
Example #2
Source File: SessionImpl.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public int executeUpdate(String query, QueryParameters queryParameters) throws HibernateException { checkOpenOrWaitingForAutoClose(); checkTransactionSynchStatus(); queryParameters.validateParameters(); HQLQueryPlan plan = getQueryPlan( query, false ); autoFlushIfRequired( plan.getQuerySpaces() ); verifyImmutableEntityUpdate( plan ); boolean success = false; int result = 0; try { result = plan.performExecuteUpdate( queryParameters, this ); success = true; } finally { afterOperation( success ); delayedAfterCompletion(); } return result; }
Example #3
Source File: SessionImpl.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public Iterator iterate(String query, QueryParameters queryParameters) throws HibernateException { checkOpenOrWaitingForAutoClose(); checkTransactionSynchStatus(); queryParameters.validateParameters(); HQLQueryPlan plan = queryParameters.getQueryPlan(); if ( plan == null ) { plan = getQueryPlan( query, true ); } autoFlushIfRequired( plan.getQuerySpaces() ); dontFlushFromFind++; //stops flush being called multiple times if this method is recursively called try { return plan.performIterate( queryParameters, this ); } finally { delayedAfterCompletion(); dontFlushFromFind--; } }
Example #4
Source File: SessionImpl.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public ScrollableResultsImplementor scroll(String query, QueryParameters queryParameters) throws HibernateException { checkOpenOrWaitingForAutoClose(); checkTransactionSynchStatus(); HQLQueryPlan plan = queryParameters.getQueryPlan(); if ( plan == null ) { plan = getQueryPlan( query, false ); } autoFlushIfRequired( plan.getQuerySpaces() ); dontFlushFromFind++; try { return plan.performScroll( queryParameters, this ); } finally { delayedAfterCompletion(); dontFlushFromFind--; } }
Example #5
Source File: StatelessSessionImpl.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public int executeUpdate(String query, QueryParameters queryParameters) throws HibernateException { checkOpen(); queryParameters.validateParameters(); HQLQueryPlan plan = getQueryPlan( query, false ); boolean success = false; int result = 0; try { result = plan.performExecuteUpdate( queryParameters, this ); success = true; } finally { afterOperation( success ); } temporaryPersistenceContext.clear(); return result; }
Example #6
Source File: StatelessSessionImpl.java From lams with GNU General Public License v2.0 | 6 votes |
@Override public List list(String query, QueryParameters queryParameters) throws HibernateException { checkOpen(); queryParameters.validateParameters(); HQLQueryPlan plan = getQueryPlan( query, false ); boolean success = false; List results = Collections.EMPTY_LIST; try { results = plan.performList( queryParameters, this ); success = true; } finally { afterOperation( success ); } temporaryPersistenceContext.clear(); return results; }
Example #7
Source File: ReactiveQueryImpl.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 5 votes |
/** * @see #makeQueryParametersForExecution(String) */ private QueryParameters makeReactiveQueryParametersForExecution(String hql) { QueryParameters queryParameters = super.makeQueryParametersForExecution( hql ); if ( queryParameters.getQueryPlan() != null ) { HQLQueryPlan plan = new ReactiveHQLQueryPlan( hql, false, getProducer().getLoadQueryInfluencers().getEnabledFilters(), getProducer().getFactory(), entityGraphQueryHint ); queryParameters.setQueryPlan( plan ); } return queryParameters; }
Example #8
Source File: FastBootEntityManagerFactoryBuilder.java From quarkus with Apache License 2.0 | 5 votes |
@Override public EntityManagerFactory build() { try { final SessionFactoryOptionsBuilder optionsBuilder = metadata.buildSessionFactoryOptionsBuilder(); populate(optionsBuilder, standardServiceRegistry, multiTenancyStrategy); return new SessionFactoryImpl(metadata.getOriginalMetadata(), optionsBuilder.buildOptions(), HQLQueryPlan::new); } catch (Exception e) { throw persistenceException("Unable to build Hibernate SessionFactory", e); } }
Example #9
Source File: SessionImpl.java From lams with GNU General Public License v2.0 | 5 votes |
@Override public List list(String query, QueryParameters queryParameters) throws HibernateException { checkOpenOrWaitingForAutoClose(); checkTransactionSynchStatus(); queryParameters.validateParameters(); HQLQueryPlan plan = queryParameters.getQueryPlan(); if ( plan == null ) { plan = getQueryPlan( query, false ); } autoFlushIfRequired( plan.getQuerySpaces() ); List results = Collections.EMPTY_LIST; boolean success = false; dontFlushFromFind++; //stops flush being called multiple times if this method is recursively called try { results = plan.performList( queryParameters, this ); success = true; } finally { dontFlushFromFind--; afterOperation( success ); delayedAfterCompletion(); } return results; }
Example #10
Source File: SessionImpl.java From lams with GNU General Public License v2.0 | 5 votes |
private void verifyImmutableEntityUpdate(HQLQueryPlan plan) { if ( plan.isUpdate() ) { for ( EntityPersister entityPersister : getSessionFactory().getMetamodel().entityPersisters().values() ) { if ( !entityPersister.isMutable() ) { List<Serializable> entityQuerySpaces = new ArrayList<>( Arrays.asList( entityPersister.getQuerySpaces() ) ); entityQuerySpaces.retainAll( plan.getQuerySpaces() ); if ( !entityQuerySpaces.isEmpty() ) { ImmutableEntityUpdateQueryHandlingMode immutableEntityUpdateQueryHandlingMode = getSessionFactory() .getSessionFactoryOptions() .getImmutableEntityUpdateQueryHandlingMode(); String querySpaces = Arrays.toString( entityQuerySpaces.toArray() ); switch ( immutableEntityUpdateQueryHandlingMode ) { case WARNING: log.immutableEntityUpdateQuery(plan.getSourceQuery(), querySpaces); break; case EXCEPTION: throw new HibernateException( "The query: [" + plan.getSourceQuery() + "] attempts to update an immutable entity: " + querySpaces ); default: throw new UnsupportedOperationException( "The "+ immutableEntityUpdateQueryHandlingMode + " is not supported!" ); } } } } } }
Example #11
Source File: QueryParameters.java From lams with GNU General Public License v2.0 | 4 votes |
public HQLQueryPlan getQueryPlan() { return queryPlan; }
Example #12
Source File: QueryParameters.java From lams with GNU General Public License v2.0 | 4 votes |
public void setQueryPlan(HQLQueryPlan queryPlan) { this.queryPlan = queryPlan; }
Example #13
Source File: AbstractSharedSessionContract.java From lams with GNU General Public License v2.0 | 4 votes |
protected HQLQueryPlan getQueryPlan(String query, boolean shallow) throws HibernateException { return getFactory().getQueryPlanCache().getHQLQueryPlan( query, shallow, getLoadQueryInfluencers().getEnabledFilters() ); }
Example #14
Source File: AbstractSharedSessionContract.java From lams with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings({"unchecked", "WeakerAccess", "StatementWithEmptyBody"}) protected void resultClassChecking(Class resultClass, org.hibernate.Query hqlQuery) { // make sure the query is a select -> HHH-7192 final HQLQueryPlan queryPlan = getFactory().getQueryPlanCache().getHQLQueryPlan( hqlQuery.getQueryString(), false, getLoadQueryInfluencers().getEnabledFilters() ); if ( queryPlan.getTranslators()[0].isManipulationStatement() ) { throw new IllegalArgumentException( "Update/delete queries cannot be typed" ); } // do some return type validation checking if ( Object[].class.equals( resultClass ) ) { // no validation needed } else if ( Tuple.class.equals( resultClass ) ) { TupleBuilderTransformer tupleTransformer = new TupleBuilderTransformer( hqlQuery ); hqlQuery.setResultTransformer( tupleTransformer ); } else { final Class dynamicInstantiationClass = queryPlan.getDynamicInstantiationResultType(); if ( dynamicInstantiationClass != null ) { if ( ! resultClass.isAssignableFrom( dynamicInstantiationClass ) ) { throw new IllegalArgumentException( "Mismatch in requested result type [" + resultClass.getName() + "] and actual result type [" + dynamicInstantiationClass.getName() + "]" ); } } else if ( queryPlan.getTranslators()[0].getReturnTypes().length == 1 ) { // if we have only a single return expression, its java type should match with the requested type final Type queryResultType = queryPlan.getTranslators()[0].getReturnTypes()[0]; if ( !resultClass.isAssignableFrom( queryResultType.getReturnedClass() ) ) { throw new IllegalArgumentException( "Type specified for TypedQuery [" + resultClass.getName() + "] is incompatible with query return type [" + queryResultType.getReturnedClass() + "]" ); } } else { throw new IllegalArgumentException( "Cannot create TypedQuery for query with more than one return using requested result type [" + resultClass.getName() + "]" ); } } }
Example #15
Source File: StatelessSessionImpl.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public ScrollableResultsImplementor scroll(String query, QueryParameters queryParameters) throws HibernateException { checkOpen(); HQLQueryPlan plan = getQueryPlan( query, false ); return plan.performScroll( queryParameters, this ); }