Top Description Fields Constructors Methods
org.springframework.jdbc.core.namedparam

public Class BeanPropertySqlParameterSource

extends AbstractSqlParameterSource
Class Inheritance
Imports
java.beans.PropertyDescriptor, java.util.ArrayList, .List, org.springframework.beans.BeanWrapper, .NotReadablePropertyException, .PropertyAccessor, .PropertyAccessorFactory, org.springframework.jdbc.core.StatementCreatorUtils, org.springframework.lang.NonNull, .Nullable, org.springframework.util.StringUtils

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. Supports components of record classes as well, with accessor methods matching parameter names.

Uses a Spring BeanWrapper for bean property access underneath.

Authors
Thomas Risberg, Juergen Hoeller
Since
2.0
See Also
NamedParameterJdbcTemplate, SimplePropertySqlParameterSource

Field Summary

Modifier and TypeField and Description
private final BeanWrapper
private String[]

Constructor Summary

AccessConstructor and Description
public
BeanPropertySqlParameterSource(Object
the bean instance to wrap
object
)

Create a new BeanPropertySqlParameterSource for the given bean.

Method Summary

Modifier and TypeMethod and Description
public String[]
getParameterNames()

Overrides default org.springframework.jdbc.core.namedparam.SqlParameterSource.getParameterNames.

Enumerate all available parameter names if possible.
public String[]

Returns:

an array containing all the known property names
getReadablePropertyNames
()

Provide access to the property names of the wrapped bean.

public int
getSqlType(String
the name of the parameter
paramName
)

Overrides org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource.getSqlType.

Overrides default org.springframework.jdbc.core.namedparam.SqlParameterSource.getSqlType.

Derives a default SQL type from the corresponding property type.
public Object
getValue(String
the name of the parameter
paramName
)

Implements org.springframework.jdbc.core.namedparam.SqlParameterSource.getValue.

Return the parameter value for the requested named parameter.
public boolean
hasValue(String
the name of the parameter
paramName
)

Implements org.springframework.jdbc.core.namedparam.SqlParameterSource.hasValue.

Determine whether there is a value for the specified named parameter.
Inherited from org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource:
getTypeNameregisterSqlTyperegisterTypeNametoString

Field Detail

beanWrapperback to summary
private final BeanWrapper beanWrapper
propertyNamesback to summary
private String[] propertyNames
Annotations
@Nullable

Constructor Detail

BeanPropertySqlParameterSourceback to summary
public BeanPropertySqlParameterSource(Object object)

Create a new BeanPropertySqlParameterSource for the given bean.

Parameters
object:Object

the bean instance to wrap

Method Detail

getParameterNamesback to summary
public String[] getParameterNames()

Overrides default org.springframework.jdbc.core.namedparam.SqlParameterSource.getParameterNames.

Doc from org.springframework.jdbc.core.namedparam.SqlParameterSource.getParameterNames.

Enumerate all available parameter names if possible.

This is an optional operation, primarily for use with org.springframework.jdbc.core.simple.SimpleJdbcInsert and org.springframework.jdbc.core.simple.SimpleJdbcCall.

Returns:String[]

the array of parameter names, or null if not determinable

Annotations
@Override
@NonNull
getReadablePropertyNamesback to summary
public String[] getReadablePropertyNames()

Provide access to the property names of the wrapped bean. Uses support provided in the PropertyAccessor interface.

Returns:String[]

an array containing all the known property names

getSqlTypeback to summary
public int getSqlType(String paramName)

Overrides org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource.getSqlType.

Overrides default org.springframework.jdbc.core.namedparam.SqlParameterSource.getSqlType.

Derives a default SQL type from the corresponding property type.

Parameters
paramName:String

Doc from org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource.getSqlType.

the name of the parameter

Returns:int

Doc from org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource.getSqlType.

the SQL type of the parameter, or TYPE_UNKNOWN if not registered

Annotations
@Override
See Also
org.springframework.jdbc.core.StatementCreatorUtils#javaTypeToSqlParameterType
getValueback to summary
public Object getValue(String paramName) throws IllegalArgumentException

Implements org.springframework.jdbc.core.namedparam.SqlParameterSource.getValue.

Doc from org.springframework.jdbc.core.namedparam.SqlParameterSource.getValue.

Return the parameter value for the requested named parameter.

Parameters
paramName:String

the name of the parameter

Returns:Object

the value of the specified parameter

Annotations
@Override
@Nullable
Exceptions
IllegalArgumentException:
if there is no value for the requested parameter
hasValueback to summary
public boolean hasValue(String paramName)

Implements org.springframework.jdbc.core.namedparam.SqlParameterSource.hasValue.

Doc from org.springframework.jdbc.core.namedparam.SqlParameterSource.hasValue.

Determine whether there is a value for the specified named parameter.

Parameters
paramName:String

the name of the parameter

Returns:boolean

whether there is a value defined

Annotations
@Override