public Query createQuery(String ejbqlString) { //adjustFlushMode(); try { return new QueryImpl( getSession().createQuery( ejbqlString ), this ); } catch (HibernateException he) { throwPersistenceException( he ); return null; } }
/** * {@inheritDoc} */ public TypedQuery<X> setParameter(int position, Object value) { try { if ( isJpaPositionalParameter( position ) ) { this.setParameter( Integer.toString( position ), value ); } else { query.setParameter( position - 1, value ); registerParameterBinding( getParameter( position ), value ); } return this; } catch (QueryParameterException e) { throw new IllegalArgumentException( e ); } catch (HibernateException he) { throw getEntityManager().convert( he ); } }
public QueryImpl( org.hibernate.Query query, AbstractEntityManagerImpl em, Map<String,Class> namedParameterTypeRedefinitions) { super( em ); this.query = query; extractParameterInfo( namedParameterTypeRedefinitions ); }
public Query setParameter(int position, Object value) { try { if ( isPositionalParameter() ) { this.setParameter( Integer.toString( position ), value ); } else { query.setParameter( position - 1, value ); } return this; } catch (QueryParameterException e) { throw new IllegalArgumentException( e ); } catch (HibernateException he) { em.throwPersistenceException( he ); return null; } }
/** * {@inheritDoc} */ public TypedQuery<X> setParameter(String name, Object value) { try { if ( value instanceof Collection ) { query.setParameterList( name, (Collection) value ); } else { query.setParameter( name, value ); } registerParameterBinding( getParameter( name ), value ); return this; } catch (QueryParameterException e) { throw new IllegalArgumentException( e ); } catch (HibernateException he) { throw getEntityManager().convert( he ); } }
public <T> TypedQuery<X> setParameter(Parameter<T> param, T value) { if ( ! parameters.contains( param ) ) { throw new IllegalArgumentException( "Specified parameter was not found in query" ); } if ( param.getName() != null ) { // a named param, for not delegate out. Eventually delegate *into* this method... setParameter( param.getName(), value ); } else { setParameter( param.getPosition(), value ); } return this; }
/** * {@inheritDoc} */ public Parameter<?> getParameter(int position) { if ( isJpaPositionalParameter( position ) ) { return getParameter( Integer.toString( position ) ); } else { for ( Parameter parameter : parameters ) { if ( parameter.getPosition() != null && position == parameter.getPosition() ) { return parameter; } } throw new IllegalArgumentException( "Unable to locate parameter with position [" + position + "]" ); } }
@Override @SuppressWarnings({ "unchecked" }) public TypedQuery<X> setLockMode(javax.persistence.LockModeType lockModeType) { if (! getEntityManager().isTransactionInProgress()) { throw new TransactionRequiredException( "no transaction is in progress" ); } if ( ! canApplyLockModes() ) { throw new IllegalStateException( "Not a JPAQL/Criteria query" ); } this.jpaLockMode = lockModeType; ( (org.hibernate.internal.QueryImpl) query ).getLockOptions().setLockMode( LockModeTypeHelper.getLockMode( lockModeType ) ); return this; }
if ( getSpecifiedMaxResults() != 1 && ! ( SQLQuery.class.isAssignableFrom( query.getClass() ) ) ) { mucked = true; query.setMaxResults( getSpecifiedMaxResults() ); getEntityManager().handlePersistenceException( nre ); throw nre; if ( uniqueResult.size() > 1 ) { NonUniqueResultException nure = new NonUniqueResultException( "result returns more than one elements" ); getEntityManager().handlePersistenceException( nure ); throw nure; throw getEntityManager().convert( he );
/** * {@inheritDoc} */ @SuppressWarnings({ "unchecked", "RedundantCast" }) public List<X> getResultList() { try { return query.list(); } catch (QueryExecutionRequestException he) { throw new IllegalStateException(he); } catch( TypeMismatchException e ) { throw new IllegalArgumentException(e); } catch (HibernateException he) { throw getEntityManager().convert( he ); } }
/** * {@inheritDoc} */ @SuppressWarnings({ "unchecked" }) public <T> Parameter<T> getParameter(String name, Class<T> type) { Parameter param = getParameter( name ); if ( param.getParameterType() != null ) { // we were able to determine the expected type during analysis, so validate it here throw new IllegalArgumentException( "Parameter type [" + param.getParameterType().getName() + "] is not assignment compatible with requested type [" + type.getName() + "]" ); } return param; }
@Override public PageList<Alert> findAlertsByCriteria(Subject subject, AlertCriteria criteria) { CriteriaQueryGenerator generator = new CriteriaQueryGenerator(subject, criteria); if (!authorizationManager.isInventoryManager(subject)) { generator.setAuthorizationResourceFragment(CriteriaQueryGenerator.AuthorizationTokenType.RESOURCE, "alertDefinition.resource", subject.getId()); } Query query = generator.getQuery(entityManager); if (log.isDebugEnabled()) { QueryImpl queryImpl = (QueryImpl) query; PageControl pageControl = CriteriaQueryGenerator.getPageControl(criteria); log.debug("*Executing JPA query: " + queryImpl.getHibernateQuery().getQueryString() + ", selection=[" + pageControl.getStartRow() + ".." + (pageControl.getStartRow() + pageControl.getPageSize() - 1) + "]..."); } CriteriaQueryRunner<Alert> queryRunner = new CriteriaQueryRunner<Alert>(criteria, generator, entityManager); PageList<Alert> alerts = queryRunner.execute(); fetchCollectionFields(alerts); return alerts; } }
public Query setParameter(int position, Calendar value, TemporalType temporalType) { try { if ( isPositionalParameter() ) { String name = Integer.toString( position ); this.setParameter( name, value, temporalType ); } else { if ( temporalType == DATE ) { query.setCalendarDate( position - 1, value ); } else if ( temporalType == TIME ) { throw new IllegalArgumentException( "not yet implemented" ); } else if ( temporalType == TIMESTAMP ) { query.setCalendar( position - 1, value ); } } return this; } catch (QueryParameterException e) { throw new IllegalArgumentException( e ); } catch (HibernateException he) { em.throwPersistenceException( he ); return null; } }
public TypedQuery<X> setParameter(Parameter<Date> param, Date value, TemporalType temporalType) { if ( ! parameters.contains( param ) ) { throw new IllegalArgumentException( "Specified parameter was not found in query" ); } if ( param.getName() != null ) { // a named param, for not delegate out. Eventually delegate *into* this method... setParameter( param.getName(), value, temporalType ); } else { setParameter( param.getPosition(), value, temporalType ); } return this; }
/** * {@inheritDoc} */ public TypedQuery<X> setParameter(String name, Calendar value, TemporalType temporalType) { try { if ( temporalType == DATE ) { query.setCalendarDate( name, value ); } else if ( temporalType == TIME ) { throw new IllegalArgumentException( "not yet implemented" ); } else if ( temporalType == TIMESTAMP ) { query.setCalendar( name, value ); } registerParameterBinding( getParameter(name), value ); return this; } catch (QueryParameterException e) { throw new IllegalArgumentException( e ); } catch (HibernateException he) { throw getEntityManager().convert( he ); } }
private SessionFactoryImplementor sfi() { return (SessionFactoryImplementor) getEntityManager().getFactory().getSessionFactory(); }
/** * {@inheritDoc} */ @SuppressWarnings({ "unchecked" }) public <T> Parameter<T> getParameter(int position, Class<T> type) { Parameter param = getParameter( position ); if ( param.getParameterType() != null ) { // we were able to determine the expected type during analysis, so validate it here throw new IllegalArgumentException( "Parameter type [" + param.getParameterType().getName() + "] is not assignment compatible with requested type [" + type.getName() + "]" ); } return param; }
public Query createQuery(String ejbqlString) { //adjustFlushMode(); try { return new QueryImpl( getSession().createQuery( ejbqlString ), this ); } catch (HibernateException he) { throwPersistenceException( he ); return null; } }
/** * {@inheritDoc} */ public TypedQuery<X> setParameter(int position, Calendar value, TemporalType temporalType) { try { if ( isJpaPositionalParameter( position ) ) { String name = Integer.toString( position ); this.setParameter( name, value, temporalType ); } else { if ( temporalType == DATE ) { query.setCalendarDate( position - 1, value ); } else if ( temporalType == TIME ) { throw new IllegalArgumentException( "not yet implemented" ); } else if ( temporalType == TIMESTAMP ) { query.setCalendar( position - 1, value ); } registerParameterBinding( getParameter( position ), value ); } return this; } catch (QueryParameterException e) { throw new IllegalArgumentException( e ); } catch (HibernateException he) { throw getEntityManager().convert( he ); } }
public Query setParameter(int position, Date value, TemporalType temporalType) { try { if ( isPositionalParameter() ) { String name = Integer.toString( position ); this.setParameter( name, value, temporalType ); } else { if ( temporalType == DATE ) { query.setDate( position - 1, value ); } else if ( temporalType == TIME ) { query.setTime( position - 1, value ); } else if ( temporalType == TIMESTAMP ) { query.setTimestamp( position - 1, value ); } } return this; } catch (QueryParameterException e) { throw new IllegalArgumentException( e ); } catch (HibernateException he) { em.throwPersistenceException( he ); return null; } }