Package org.springframework.jdbc.core.namedparam

# Class BeanPropertySqlParameterSource

java.lang.Object
org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource
org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource

All Implemented Interfaces:
  `SqlParameterSource`

public class BeanPropertySqlParameterSource extends AbstractSqlParameterSource
`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.

Since:
  2.0
Author:
  Thomas Risberg, Juergen Hoeller
See Also:
  - `NamedParameterJdbcTemplate`
  - `SimplePropertySqlParameterSource`

## Field Summary

### Fields inherited from interface org.springframework.jdbc.core.namedparam.SqlParameterSource

`TYPE_UNKNOWN`

## Constructor Summary

Constructors
Constructor
Description
`BeanPropertySqlParameterSource(Object object)`
Create a new BeanPropertySqlParameterSource for the given bean.

## Method Summary

Modifier and Type
Method
Description
`String[]`
`getParameterNames()`
Enumerate all available parameter names if possible.
`String[]`
`getReadablePropertyNames()`
Provide access to the property names of the wrapped bean.
`int`
`getSqlType(String paramName)`
Derives a default SQL type from the corresponding property type.
`Object`
`getValue(String paramName)`
Return the parameter value for the requested named parameter.
`boolean`
`hasValue(String paramName)`
Determine whether there is a value for the specified named parameter.

### Methods inherited from class org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource

`getTypeName, registerSqlType, registerTypeName, toString`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

## Constructor Details

### BeanPropertySqlParameterSource

public BeanPropertySqlParameterSource(Object object)
Create a new BeanPropertySqlParameterSource for the given bean.

Parameters:
  `object` - the bean instance to wrap

## Method Details

### hasValue

public boolean hasValue(String paramName)
Description copied from interface: `SqlParameterSource`
Determine 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

@Nullable public Object getValue(String paramName) throws IllegalArgumentException
Description copied from interface: `SqlParameterSource`
Return 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

public int getSqlType(String paramName)
Derives a default SQL type from the corresponding property type.

Specified by:
  `getSqlType` in interface `SqlParameterSource`
Overrides:
  `getSqlType` in class `AbstractSqlParameterSource`
Parameters:
  `paramName` - the name of the parameter
Returns:
  the SQL type of the parameter, or `TYPE_UNKNOWN` if not registered
See Also:
  - `StatementCreatorUtils.javaTypeToSqlParameterType(java.lang.Class<?>)`

### getParameterNames

@NonNull public String[] getParameterNames()
Description copied from interface: `SqlParameterSource`
Enumerate all available parameter names if possible.

This is an optional operation, primarily for use with `SimpleJdbcInsert` and `SimpleJdbcCall`.

Returns:
  the array of parameter names, or `null` if not determinable
See Also:
  - `SqlParameterSourceUtils.extractCaseInsensitiveParameterNames(org.springframework.jdbc.core.namedparam.SqlParameterSource)`

### getReadablePropertyNames

public String[] getReadablePropertyNames()
Provide access to the property names of the wrapped bean. Uses support provided in the `PropertyAccessor` interface.

Returns:
  an array containing all the known property names