Package javax.persistence

Examples of javax.persistence.Parameter


  @Override
  @SuppressWarnings("unchecked")
  public <T> Parameter<T> getParameter(String name, Class<T> type) {
    checkOpen( false );
    Parameter param = getParameter( name );

    if ( param.getParameterType() != null ) {
      // we were able to determine the expected type during analysis, so validate it here
      if ( ! param.getParameterType().isAssignableFrom( type ) ) {
        throw new IllegalArgumentException(
            String.format(
                "Parameter type [%s] is not assignment compatible with requested type [%s] for parameter named [%s]",
                param.getParameterType().getName(),
                type.getName(),
                name
            )
        );
      }
View Full Code Here


  @Override
  @SuppressWarnings("unchecked")
  public <T> Parameter<T> getParameter(int position, Class<T> type) {
    checkOpen( false );

    Parameter param = getParameter( position );

    if ( param.getParameterType() != null ) {
      // we were able to determine the expected type during analysis, so validate it here
      if ( ! param.getParameterType().isAssignableFrom( type ) ) {
        throw new IllegalArgumentException(
            String.format(
                "Parameter type [%s] is not assignment compatible with requested type [%s] for parameter at position [%s]",
                param.getParameterType().getName(),
                type.getName(),
                position
            )
        );
      }
View Full Code Here

    entityManager.checkOpen( false );
    return getParameterValue( resolveExplicitCriteriaParameterName( name ) );
  }

  private Parameter resolveExplicitCriteriaParameterName(String name) {
    Parameter parameter = explicitParameterNameMapping.get( name );
    if ( parameter == null ) {
      throw new IllegalArgumentException( "Named parameter [" + name + "] not encountered" );
    }
    return parameter;
  }
View Full Code Here

  }

  @SuppressWarnings({ "unchecked" })
  public <T> Parameter<T> getParameter(String name, Class<T> type) {
    entityManager.checkOpen( false );
    Parameter parameter = resolveExplicitCriteriaParameterName( name );
    if ( type.isAssignableFrom( parameter.getParameterType() ) ) {
      return parameter;
    }
    throw new IllegalArgumentException(
        "Named parameter [" + name + "] type is not assignanle to request type ["
            + type.getName() + "]"
View Full Code Here

    );
    return this;
  }

  private Parameter resolveExplicitCriteriaParameterName(String name, Object value) {
    Parameter parameter = resolveExplicitCriteriaParameterName( name );
    // todo : is null valid?
    if ( value != null ) {
      if ( ! parameter.getParameterType().isInstance( value ) ) {
        throw new IllegalArgumentException(
            "Named parameter [" + name + "] type mismatch; expecting ["
                + parameter.getParameterType().getName() + "], found ["
                + value.getClass().getName() + "]"
        );
      }
    }
    return parameter;
View Full Code Here

  }

  @SuppressWarnings({ "unchecked" })
  public TypedQuery<X> setParameter(String name, Calendar calendar, TemporalType temporalType) {
    entityManager.checkOpen( true );
    Parameter parameter = resolveExplicitCriteriaParameterName( name );
    if ( ! Calendar.class.isAssignableFrom( parameter.getParameterType() ) ) {
      throw new IllegalArgumentException(
          "Named parameter [" + name + "] type mismatch; expecting ["
              + Calendar.class.getName() + "], found ["
              + parameter.getParameterType().getName() + "]"
      );
    }
    setParameter( parameter, calendar, temporalType );
    return this;
  }
View Full Code Here

  }

  @SuppressWarnings({ "unchecked" })
  public TypedQuery<X> setParameter(String name, Date date, TemporalType temporalType) {
    entityManager.checkOpen( true );
    Parameter parameter = resolveExplicitCriteriaParameterName( name );
    if ( ! Date.class.isAssignableFrom( parameter.getParameterType() ) ) {
      throw new IllegalArgumentException(
          "Named parameter [" + name + "] type mismatch; expecting ["
              + Date.class.getName() + "], found ["
              + parameter.getParameterType().getName() + "]"
      );
    }
    setParameter( parameter, date, temporalType );
    return this;
  }
View Full Code Here

      public Object getParameterValue(String name) {
        return getParameterValue( resolveExplicitCriteriaParameterName( name ) );
      }

      private Parameter resolveExplicitCriteriaParameterName(String name) {
        Parameter parameter = explicitParameterNameMapping.get( name );
        if ( parameter == null ) {
          throw new IllegalArgumentException( "Named parameter [" + name + "] not encountered" );
        }
        return parameter;
      }

      public Parameter<?> getParameter(String name) {
        return mapToNamedParameter( resolveExplicitCriteriaParameterName( name ) );
      }

      @SuppressWarnings({ "unchecked" })
      public <T> Parameter<T> getParameter(String name, Class<T> type) {
        Parameter parameter = resolveExplicitCriteriaParameterName( name );
        if ( type.isAssignableFrom( parameter.getParameterType() ) ) {
          return parameter;
        }
        throw new IllegalArgumentException(
            "Named parameter [" + name + "] type is not assignanle to request type ["
                + type.getName() + "]"
        );
      }

      @SuppressWarnings({ "unchecked" })
      public TypedQuery<X> setParameter(String name, Object value) {
        setParameter(
            resolveExplicitCriteriaParameterName( name, value ),
            value
        );
        return this;
      }

      private Parameter resolveExplicitCriteriaParameterName(String name, Object value) {
        Parameter parameter = resolveExplicitCriteriaParameterName( name );
        // todo : is null valid?
        if ( value != null ) {
          if ( ! parameter.getParameterType().isInstance( value ) ) {
            throw new IllegalArgumentException(
                "Named parameter [" + name + "] type mismatch; expecting ["
                    + parameter.getParameterType().getName() + "], found ["
                    + value.getClass().getName() + "]"
            );
          }
        }
        return parameter;
      }

      @SuppressWarnings({ "unchecked" })
      public TypedQuery<X> setParameter(String name, Calendar calendar, TemporalType temporalType) {
        Parameter parameter = resolveExplicitCriteriaParameterName( name );
        if ( ! Calendar.class.isAssignableFrom( parameter.getParameterType() ) ) {
          throw new IllegalArgumentException(
              "Named parameter [" + name + "] type mismatch; expecting ["
                  + Calendar.class.getName() + "], found ["
                  + parameter.getParameterType().getName() + "]"
          );
        }
        setParameter( parameter, calendar, temporalType );
        return this;
      }

      @SuppressWarnings({ "unchecked" })
      public TypedQuery<X> setParameter(String name, Date date, TemporalType temporalType) {
        Parameter parameter = resolveExplicitCriteriaParameterName( name );
        if ( ! Date.class.isAssignableFrom( parameter.getParameterType() ) ) {
          throw new IllegalArgumentException(
              "Named parameter [" + name + "] type mismatch; expecting ["
                  + Date.class.getName() + "], found ["
                  + parameter.getParameterType().getName() + "]"
          );
        }
        setParameter( parameter, date, temporalType );
        return this;
      }
View Full Code Here

  /**
   * {@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;
View Full Code Here

  /**
   * {@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;
View Full Code Here

TOP

Related Classes of javax.persistence.Parameter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.