/** * Performs a check whether the Session is open, and if not:<ul> * <li>marks current transaction (if one) for rollback only</li> * <li>throws an IllegalStateException (JPA defines the exception type)</li> * </ul> */ default void checkOpen() { checkOpen( true ); }
@Override @SuppressWarnings("unchecked") public QueryImplementor setMaxResults(int maxResult) { getProducer().checkOpen(); if ( maxResult < 0 ) { throw new IllegalArgumentException( "max-results cannot be negative" ); } else { queryOptions.setMaxRows( maxResult ); } return this; }
@Override @SuppressWarnings("unchecked") public QueryImplementor setFirstResult(int startPosition) { getProducer().checkOpen(); if ( startPosition < 0 ) { throw new IllegalArgumentException( "first-result value cannot be negative : " + startPosition ); } queryOptions.setFirstRow( startPosition ); return this; }
@Override public Map<String, Object> getHints() { // Technically this should rollback, but that's insane :) // If the TCK ever adds a check for this, we may need to change this behavior getProducer().checkOpen( false ); final Map<String,Object> hints = new HashMap<>(); collectBaselineHints( hints ); collectHints( hints ); return hints; }
@Override @SuppressWarnings("unchecked") public QueryImplementor setFlushMode(FlushModeType flushModeType) { getProducer().checkOpen(); setHibernateFlushMode( FlushModeTypeHelper.getFlushMode( flushModeType ) ); return this; }
@Override public Set<Parameter<?>> getParameters() { getProducer().checkOpen( false ); return getParameterMetadata().collectAllParametersJpa(); }
@Override public int getFirstResult() { getProducer().checkOpen(); // to be JPA compliant this method returns an int - specifically the "magic number" 0 (ZERO) defined by the spec. // For access to the Integer (for checking), use #getQueryOptions#getFirstRow instead return queryOptions.getFirstRow() == null ? 0 : queryOptions.getFirstRow(); }
@Override public LockModeType getLockMode() { getProducer().checkOpen( false ); if ( !isSelect() ) { throw new IllegalStateException( "Illegal attempt to get lock mode on a non-SELECT query" ); } return LockModeTypeHelper.getLockModeType( lockOptions.getLockMode() ); }
@Override public boolean isBound(Parameter<?> parameter) { getProducer().checkOpen(); return getQueryParameterBindings().isBound( (QueryParameter) parameter ); }
@Override public int getMaxResults() { getProducer().checkOpen(); // to be JPA compliant this method returns an int - specifically the "magic number" Integer.MAX_VALUE defined by the spec. // For access to the Integer (for checking), use #getQueryOptions#getMaxRows instead return queryOptions.getMaxRows() == null ? Integer.MAX_VALUE : queryOptions.getMaxRows(); }
@Override @SuppressWarnings("unchecked") public QueryImplementor setLockMode(LockModeType lockModeType) { getProducer().checkOpen(); if ( !LockModeType.NONE.equals( lockModeType ) ) { if ( !isSelect() ) { throw new IllegalStateException( "Illegal attempt to set lock mode on a non-SELECT query" ); } } lockOptions.setLockMode( LockModeTypeHelper.getLockMode( lockModeType ) ); return this; }
@Override @SuppressWarnings("unchecked") public QueryImplementor setParameter(Parameter<Calendar> param, Calendar value, TemporalType temporalType) { getProducer().checkOpen(); getQueryParameterBindings().getBinding( (QueryParameter) param ).setBindValue( value, temporalType ); return this; }
@Override @SuppressWarnings("unchecked") public QueryImplementor setParameter(String name, Date value, TemporalType temporalType) { getProducer().checkOpen(); getQueryParameterBindings().getBinding( name ).setBindValue( value, temporalType ); return this; }
@Override @SuppressWarnings("unchecked") public QueryImplementor setParameter(Parameter<Date> param, Date value, TemporalType temporalType) { getProducer().checkOpen(); getQueryParameterBindings().getBinding( (QueryParameter) param ).setBindValue( value, temporalType ); return this; }
@Override @SuppressWarnings("unchecked") public QueryImplementor setParameter(int position, Calendar value, TemporalType temporalType) { getProducer().checkOpen(); getQueryParameterBindings().getBinding( position ).setBindValue( value, temporalType ); return this; }
@Override public FlushModeType getFlushMode() { getProducer().checkOpen(); return ( flushMode == null ? getProducer().getFlushMode() : FlushModeTypeHelper.getFlushModeType( flushMode ) ); }
@Override @SuppressWarnings("unchecked") public QueryImplementor setParameter(String name, Calendar value, TemporalType temporalType) { getProducer().checkOpen(); getQueryParameterBindings().getBinding( name ).setBindValue( value, temporalType ); return this; }
@Override @SuppressWarnings("unchecked") public QueryImplementor setParameter(int position, Date value, TemporalType temporalType) { getProducer().checkOpen(); getQueryParameterBindings().getBinding( position ).setBindValue( value, temporalType ); return this; }
@Override public <T> T getParameterValue(Parameter<T> parameter) { LOGGER.tracef( "#getParameterValue(%s)", parameter ); getProducer().checkOpen( false ); if ( !getParameterMetadata().containsReference( (QueryParameter) parameter ) ) { throw new IllegalArgumentException( "Parameter reference [" + parameter + "] did not come from this query" ); } final QueryParameterBinding<T> binding = getQueryParameterBindings().getBinding( (QueryParameter<T>) parameter ); LOGGER.debugf( "Checking whether parameter reference [%s] is bound : %s", parameter, binding.isBound() ); if ( !binding.isBound() ) { throw new IllegalStateException( "Parameter value not yet bound : " + parameter.toString() ); } return binding.getBindValue(); }
@Override public QueryParameter<?> getParameter(String name) { getProducer().checkOpen( false ); try { return getParameterMetadata().getQueryParameter( name ); } catch ( HibernateException e ) { throw getExceptionConverter().convert( e ); } }