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

public Class MapSqlParameterSource

extends AbstractSqlParameterSource
Class Inheritance
Imports
java.util.Collections, .LinkedHashMap, .Map, org.springframework.jdbc.core.SqlParameterValue, org.springframework.lang.NonNull, .Nullable, org.springframework.util.Assert, .StringUtils

SqlParameterSource implementation that holds a given Map of parameters.

This class is intended for passing in a simple Map of parameter values to the methods of the NamedParameterJdbcTemplate class.

The addValue methods on this class will make adding several values easier. The methods return a reference to the MapSqlParameterSource itself, so you can chain several method calls together within a single statement.

Authors
Thomas Risberg, Juergen Hoeller
Since
2.0
See Also
addValue(String, Object), addValue(String, Object, int), registerSqlType, NamedParameterJdbcTemplate

Field Summary

Modifier and TypeField and Description
private final Map<String, Object>

Constructor Summary

AccessConstructor and Description
public
MapSqlParameterSource()

Create an empty MapSqlParameterSource, with values to be added via addValue.

public
MapSqlParameterSource(String
the name of the parameter
paramName
,
Object
the value of the parameter
value
)

Create a new MapSqlParameterSource, with one value comprised of the supplied arguments.

public
MapSqlParameterSource(Map<String, ?>
a Map holding existing parameter values (can be null)
values
)

Create a new MapSqlParameterSource based on a Map.

Method Summary

Modifier and TypeMethod and Description
public MapSqlParameterSource

Returns:

a reference to this parameter source, so it's possible to chain several calls together
addValue
(String
the name of the parameter
paramName
,
Object
the value of the parameter
value
)

Add a parameter to this parameter source.

public MapSqlParameterSource

Returns:

a reference to this parameter source, so it's possible to chain several calls together
addValue
(String
the name of the parameter
paramName
,
Object
the value of the parameter
value
,
int
the SQL type of the parameter
sqlType
)

Add a parameter to this parameter source.

public MapSqlParameterSource

Returns:

a reference to this parameter source, so it's possible to chain several calls together
addValue
(String
the name of the parameter
paramName
,
Object
the value of the parameter
value
,
int
the SQL type of the parameter
sqlType
,
String
the type name of the parameter
typeName
)

Add a parameter to this parameter source.

public MapSqlParameterSource

Returns:

a reference to this parameter source, so it's possible to chain several calls together
addValues
(Map<String, ?>
a Map holding existing parameter values (can be null)
values
)

Add a Map of parameters to this parameter source.

public String[]
getParameterNames()

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

Enumerate all available parameter names if possible.
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 Map<String, Object>
getValues()

Expose the current parameter values as read-only Map.

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.
public boolean
hasValues()

Return whether this parameter source has been configured with any values.

Inherited from org.springframework.jdbc.core.namedparam.AbstractSqlParameterSource:
getSqlTypegetTypeNameregisterSqlTyperegisterTypeNametoString

Field Detail

valuesback to summary
private final Map<String, Object> values

Constructor Detail

MapSqlParameterSourceback to summary
public MapSqlParameterSource()

Create an empty MapSqlParameterSource, with values to be added via addValue.

See Also
addValue(String, Object)
MapSqlParameterSourceback to summary
public MapSqlParameterSource(String paramName, Object value)

Create a new MapSqlParameterSource, with one value comprised of the supplied arguments.

Parameters
paramName:String

the name of the parameter

value:Object

the value of the parameter

See Also
addValue(String, Object)
MapSqlParameterSourceback to summary
public MapSqlParameterSource(Map<String, ?> values)

Create a new MapSqlParameterSource based on a Map.

Parameters
values:Map<String, ?>

a Map holding existing parameter values (can be null)

Method Detail

addValueback to summary
public MapSqlParameterSource addValue(String paramName, Object value)

Add a parameter to this parameter source.

Parameters
paramName:String

the name of the parameter

value:Object

the value of the parameter

Returns:MapSqlParameterSource

a reference to this parameter source, so it's possible to chain several calls together

addValueback to summary
public MapSqlParameterSource addValue(String paramName, Object value, int sqlType)

Add a parameter to this parameter source.

Parameters
paramName:String

the name of the parameter

value:Object

the value of the parameter

sqlType:int

the SQL type of the parameter

Returns:MapSqlParameterSource

a reference to this parameter source, so it's possible to chain several calls together

addValueback to summary
public MapSqlParameterSource addValue(String paramName, Object value, int sqlType, String typeName)

Add a parameter to this parameter source.

Parameters
paramName:String

the name of the parameter

value:Object

the value of the parameter

sqlType:int

the SQL type of the parameter

typeName:String

the type name of the parameter

Returns:MapSqlParameterSource

a reference to this parameter source, so it's possible to chain several calls together

addValuesback to summary
public MapSqlParameterSource addValues(Map<String, ?> values)

Add a Map of parameters to this parameter source.

Parameters
values:Map<String, ?>

a Map holding existing parameter values (can be null)

Returns:MapSqlParameterSource

a reference to this parameter source, so it's possible to chain several calls together

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
getValueback to summary
public Object getValue(String paramName)

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
getValuesback to summary
public Map<String, Object> getValues()

Expose the current parameter values as read-only Map.

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
hasValuesback to summary
public boolean hasValues()

Return whether this parameter source has been configured with any values.

Since
6.1