Java Code Examples for javax.persistence.ParameterMode#IN
The following examples show how to use
javax.persistence.ParameterMode#IN .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ParameterBindImpl.java From lams with GNU General Public License v2.0 | 6 votes |
private void internalSetValue(T value) { if ( procedureParameter.getMode() != ParameterMode.IN && procedureParameter.getMode() != ParameterMode.INOUT ) { throw new IllegalStateException( "Can only bind values for IN/INOUT parameters : " + procedureParameter ); } if ( procedureParameter.getParameterType() != null ) { if ( value == null ) { if ( !procedureParameter.isPassNullsEnabled() ) { throw new IllegalArgumentException( "The parameter " + ( procedureParameter.getName() != null ? "named [" + procedureParameter.getName() + "]" : "at position [" + procedureParameter.getPosition() + "]" ) + " was null. You need to call ParameterRegistration#enablePassingNulls(true) in order to pass null parameters." ); } } else if ( !procedureParameter.getParameterType().isInstance( value ) && !procedureParameter.getHibernateType().getReturnedClass().isInstance( value ) ) { throw new IllegalArgumentException( "Bind value [" + value + "] was not of specified type [" + procedureParameter .getParameterType() ); } } this.value = value; this.isBound = true; }
Example 2
Source File: ProcedureParameterImpl.java From lams with GNU General Public License v2.0 | 4 votes |
@Override @SuppressWarnings("unchecked") public T extract(CallableStatement statement) { if ( mode == ParameterMode.IN ) { throw new ParameterMisuseException( "IN parameter not valid for output extraction" ); } try { if ( mode == ParameterMode.REF_CURSOR ) { if ( procedureCall.getParameterStrategy() == ParameterStrategy.NAMED ) { return (T) statement.getObject( name ); } else { return (T) statement.getObject( startIndex ); } } else { final Type hibernateType = determineHibernateType(); final int[] sqlTypes = hibernateType.sqlTypes( procedureCall.getSession().getFactory() ); // TODO: sqlTypesToUse.length > 1 does not seem to have a working use case (HHH-10769). // For now, if sqlTypes.length > 1 with a named parameter, then extract // parameter values by position (since we only have one name). final boolean useNamed = sqlTypes.length == 1 && procedureCall.getParameterStrategy() == ParameterStrategy.NAMED && canDoNameParameterBinding( hibernateType ); if ( ProcedureParameterExtractionAware.class.isInstance( hibernateType ) ) { if ( useNamed ) { return (T) ( (ProcedureParameterExtractionAware) hibernateType ).extract( statement, new String[] { getName() }, procedureCall.getSession() ); } else { return (T) ( (ProcedureParameterExtractionAware) hibernateType ).extract( statement, startIndex, procedureCall.getSession() ); } } else { if ( useNamed ) { return (T) statement.getObject( name ); } else { return (T) statement.getObject( startIndex ); } } } } catch (SQLException e) { throw procedureCall.getSession().getFactory().getSQLExceptionHelper().convert( e, "Unable to extract OUT/INOUT parameter value" ); } }