Class BeanPropertySqlParameterSource
java.lang.Object
org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource
org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource
- All Implemented Interfaces:
SqlParameterSource
SqlParameterSource implementation that obtains parameter values
from bean properties of a given JavaBean object. The names of the bean
properties have to match the parameter names.
Uses a Spring BeanWrapper for bean property access underneath.
- Since:
- 2.0
- Author:
- Thomas Risberg, Juergen Hoeller
- See Also:
-
Field Summary
Fields inherited from interface org.springframework.jdbc.core.namedparam.SqlParameterSource
TYPE_UNKNOWN -
Constructor Summary
ConstructorsConstructorDescriptionBeanPropertySqlParameterSource(Object object) Create a new BeanPropertySqlParameterSource for the given bean. -
Method Summary
Modifier and TypeMethodDescriptionString[]Enumerate all available parameter names if possible.String[]Provide access to the property names of the wrapped bean.intgetSqlType(String paramName) Derives a default SQL type from the corresponding property type.Return the parameter value for the requested named parameter.booleanDetermine whether there is a value for the specified named parameter.Methods inherited from class org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource
getTypeName, registerSqlType, registerTypeName, toString
-
Constructor Details
-
BeanPropertySqlParameterSource
Create a new BeanPropertySqlParameterSource for the given bean.- Parameters:
object- the bean instance to wrap
-
-
Method Details
-
hasValue
Description copied from interface:SqlParameterSourceDetermine whether there is a value for the specified named parameter.- Parameters:
paramName- the name of the parameter- Returns:
- whether there is a value defined
-
getValue
Description copied from interface:SqlParameterSourceReturn the parameter value for the requested named parameter.- Parameters:
paramName- the name of the parameter- Returns:
- the value of the specified parameter
- Throws:
IllegalArgumentException- if there is no value for the requested parameter
-
getSqlType
Derives a default SQL type from the corresponding property type.- Specified by:
getSqlTypein interfaceSqlParameterSource- Overrides:
getSqlTypein classAbstractSqlParameterSource- Parameters:
paramName- the name of the parameter- Returns:
- the SQL type of the parameter,
or
TYPE_UNKNOWNif not registered - See Also:
-
getParameterNames
Description copied from interface:SqlParameterSourceEnumerate all available parameter names if possible.This is an optional operation, primarily for use with
SimpleJdbcInsertandSimpleJdbcCall.- Returns:
- the array of parameter names, or
nullif not determinable - See Also:
-
getReadablePropertyNames
Provide access to the property names of the wrapped bean. Uses support provided in thePropertyAccessorinterface.- Returns:
- an array containing all the known property names
-