Package javax.persistence

Examples of javax.persistence.Parameter


     * @since Java Persistence 2.0
     */
    public <T> Parameter<T> getParameter(int position, Class<T> type) {
        try {
            entityManager.verifyOpen();
            Parameter param = (Parameter) getInternalParameters().get(String.valueOf(position));
            if (param == null) {
                throw new IllegalArgumentException(ExceptionLocalization.buildMessage("NO_PARAMETER_WITH_INDEX", new Object[] { position, this.databaseQuery }));

            }
            return param;
View Full Code Here


     * @since Java Persistence 2.0
     */
    public Parameter<?> getParameter(String name) {
        try {
            entityManager.verifyOpen();
            Parameter param = (Parameter) getInternalParameters().get(name);
            if (param == null) {
                throw new IllegalArgumentException(ExceptionLocalization.buildMessage("NO_PARAMETER_WITH_NAME", new Object[] { name, this.databaseQuery }));
            }
            return param;
        } catch (RuntimeException e) {
View Full Code Here

     * @since Java Persistence 2.0
     */
    public Parameter<?> getParameter(int position) {
        try {
            entityManager.verifyOpen();
            Parameter param = (Parameter) getInternalParameters().get(String.valueOf(position));
            if (param == null) {
                throw new IllegalArgumentException(ExceptionLocalization.buildMessage("NO_PARAMETER_WITH_INDEX", new Object[] { position, this.databaseQuery }));
            }
            return param;
        } catch (RuntimeException e) {
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

     * @since Java Persistence 2.0
     */
    public <T> Parameter<T> getParameter(String name, Class<T> type) {
        try {
            entityManager.verifyOpen();
            Parameter param = (Parameter) getInternalParameters().get(name);
            if (param == null) {
                throw new IllegalArgumentException(ExceptionLocalization.buildMessage("NO_PARAMETER_WITH_NAME", new Object[] { name, this.databaseQuery }));

            }
            return param;
View Full Code Here

     * @since Java Persistence 2.0
     */
    public <T> Parameter<T> getParameter(int position, Class<T> type) {
        try {
            entityManager.verifyOpen();
            Parameter param = (Parameter) getInternalParameters().get(String.valueOf(position));
            if (param == null) {
                throw new IllegalArgumentException(ExceptionLocalization.buildMessage("NO_PARAMETER_WITH_INDEX", new Object[] { position, this.databaseQuery }));

            }
            return param;
View Full Code Here

     * @since Java Persistence 2.0
     */
    public Parameter<?> getParameter(String name) {
        try {
            entityManager.verifyOpen();
            Parameter param = (Parameter) getInternalParameters().get(name);
            if (param == null) {
                throw new IllegalArgumentException(ExceptionLocalization.buildMessage("NO_PARAMETER_WITH_NAME", new Object[] { name, this.databaseQuery }));
            }
            return param;
        } catch (RuntimeException e) {
View Full Code Here

     * @since Java Persistence 2.0
     */
    public Parameter<?> getParameter(int position) {
        try {
            entityManager.verifyOpen();
            Parameter param = (Parameter) getInternalParameters().get(String.valueOf(position));
            if (param == null) {
                throw new IllegalArgumentException(ExceptionLocalization.buildMessage("NO_PARAMETER_WITH_INDEX", new Object[] { position, this.databaseQuery }));
            }
            return param;
        } catch (RuntimeException e) {
View Full Code Here

  @Override
  @SuppressWarnings("unchecked")
  public <T> Parameter<T> getParameter(String name, Class<T> type) {
    checkOpen( false );
    Parameter param = findParameterRegistration( 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 = findParameterRegistration( 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

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.