@Override public int executeNativeUpdate(NativeSQLQuerySpecification nativeQuerySpecification, QueryParameters queryParameters) throws HibernateException { errorIfClosed(); checkTransactionSynchStatus(); queryParameters.validateParameters(); NativeSQLQueryPlan plan = getNativeSQLQueryPlan( nativeQuerySpecification ); autoFlushIfRequired( plan.getCustomQuery().getQuerySpaces() ); boolean success = false; int result = 0; try { result = plan.performExecuteUpdate(queryParameters, this); success = true; } finally { afterOperation(success); delayedAfterCompletion(); } return result; }
public ScrollableResults scroll(ScrollMode scrollMode) throws HibernateException { verifyParameters(); before(); Map namedParams = getNamedParams(); NativeSQLQuerySpecification spec = generateQuerySpecification( namedParams ); QueryParameters qp = getQueryParameters( namedParams ); qp.setScrollMode( scrollMode ); try { return getSession().scroll( spec, qp ); } finally { after(); } }
@Override public int executeNativeUpdate(NativeSQLQuerySpecification nativeSQLQuerySpecification, QueryParameters queryParameters) throws HibernateException { errorIfClosed(); queryParameters.validateParameters(); NativeSQLQueryPlan plan = getNativeSQLQueryPlan(nativeSQLQuerySpecification); boolean success = false; int result = 0; try { result = plan.performExecuteUpdate(queryParameters, this); success = true; } finally { afterOperation(success); } temporaryPersistenceContext.clear(); return result; }
/** * Get the query plan for a native SQL query, creating it and caching it if not already cached * * @param spec The native SQL query specification * * @return The query plan * * @throws QueryException Indicates a problem translating the query * @throws MappingException Indicates a problem translating the query */ @SuppressWarnings("unchecked") public NativeSQLQueryPlan getNativeSQLQueryPlan(final NativeSQLQuerySpecification spec) { NativeSQLQueryPlan value = (NativeSQLQueryPlan) queryPlanCache.get( spec ); if ( value == null ) { LOG.tracev( "Unable to locate native-sql query plan in cache; generating ({0})", spec.getQueryString() ); value = nativeQueryInterpreterService.createQueryPlan( spec, factory ); queryPlanCache.putIfAbsent( spec, value ); } else { LOG.tracev( "Located native-sql query plan in cache ({0})", spec.getQueryString() ); } return value; }
@Override public NativeSQLQueryPlan createQueryPlan( NativeSQLQuerySpecification specification, SessionFactoryImplementor sessionFactory) { CustomQuery customQuery = new SQLCustomQuery( specification.getQueryString(), specification.getQueryReturns(), specification.getQuerySpaces(), sessionFactory ); return new NativeSQLQueryPlan( specification.getQueryString(), customQuery ); }
@Override public List list() throws HibernateException { verifyParameters(); before(); Map namedParams = getNamedParams(); NativeSQLQuerySpecification spec = generateQuerySpecification( namedParams ); try { return getSession().list( spec, getQueryParameters( namedParams ) ); } finally { after(); } }
private NativeSQLQuerySpecification generateQuerySpecification(Map namedParams) { return new NativeSQLQuerySpecification( expandParameterLists(namedParams), queryReturns.toArray( new NativeSQLQueryReturn[queryReturns.size()] ), querySpaces ); }
@Override public List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException { return sessionImplementor.list( spec, queryParameters ); }
@Override public ScrollableResults scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException { return sessionImplementor.scroll( spec, queryParameters ); }
@Override public int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters) throws HibernateException { return sessionImplementor.executeNativeUpdate( specification, queryParameters ); }
protected NativeSQLQueryPlan getNativeSQLQueryPlan(NativeSQLQuerySpecification spec) throws HibernateException { return factory.getQueryPlanCache().getNativeSQLQueryPlan( spec ); }
@Override public List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException { return listCustomQuery( getNativeSQLQueryPlan( spec ).getCustomQuery(), queryParameters ); }
@Override public ScrollableResults scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException { return scrollCustomQuery( getNativeSQLQueryPlan( spec ).getCustomQuery(), queryParameters ); }
@SuppressWarnings("rawtypes") @Override public List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException { return target.list(spec, queryParameters); }
@Override public ScrollableResultsImplementor scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters) { return target.scroll(spec, queryParameters); }
@Override public int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters) throws HibernateException { return target.executeNativeUpdate(specification, queryParameters); }
/** * Creates a new query plan for the specified native query. * * @param specification Describes the query to create a plan for * @param sessionFactory The current session factory * * @return A query plan for the specified native query. */ NativeSQLQueryPlan createQueryPlan(NativeSQLQuerySpecification specification, SessionFactoryImplementor sessionFactory);
/** * Execute a native SQL query, and return the results as a fully built list. * * @param spec The specification of the native SQL query to execute. * @param queryParameters The parameters by which to perform the execution. * * @return The result list. * * @throws HibernateException */ public List list(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException;
/** * Execute a native SQL query, and return the results as a scrollable result. * * @param spec The specification of the native SQL query to execute. * @param queryParameters The parameters by which to perform the execution. * * @return The resulting scrollable result. * * @throws HibernateException */ public ScrollableResults scroll(NativeSQLQuerySpecification spec, QueryParameters queryParameters) throws HibernateException;
/** * Execute a native SQL update or delete query */ int executeNativeUpdate(NativeSQLQuerySpecification specification, QueryParameters queryParameters) throws HibernateException;