use of org.springframework.jdbc.core.SqlParameter in project musiccabinet by hakko.
the class JdbcUserLovedTracksDao method batchInsert.
private void batchInsert(String lastFmUsername, List<Track> lovedTracks) {
String sql = "insert into music.lovedtrack_import" + " (lastfm_user, artist_name, track_name) values (?,?,?)";
BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
batchUpdate.setBatchSize(1000);
batchUpdate.declareParameter(new SqlParameter("lastfm_user", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("artist_name", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("track_name", Types.VARCHAR));
for (Track track : lovedTracks) {
batchUpdate.update(new Object[] { lastFmUsername, track.getArtist().getName(), track.getName() });
}
batchUpdate.flush();
}
use of org.springframework.jdbc.core.SqlParameter in project musiccabinet by hakko.
the class JdbcUserRecommendedArtistsDao method batchInsert.
private void batchInsert(List<RecommendedArtist> artists, LastFmUser user) {
String sql = "insert into music.userrecommendedartist_import" + " (lastfm_user, artist_name, rank, contextartist1_name, contextartist2_name)" + " values (?,?,?,?,?)";
BatchSqlUpdate batchUpdate = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
batchUpdate.setBatchSize(1000);
batchUpdate.declareParameter(new SqlParameter("lastfm_user", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("artist_name", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("rank", Types.INTEGER));
batchUpdate.declareParameter(new SqlParameter("contextartist1_name", Types.VARCHAR));
batchUpdate.declareParameter(new SqlParameter("contextartist2_name", Types.VARCHAR));
for (int i = 0; i < artists.size(); i++) {
RecommendedArtist rec = artists.get(i);
batchUpdate.update(new Object[] { user.getLastFmUsername(), rec.getArtist().getName(), i, name(rec.getContextArtist1()), name(rec.getContextArtist2()) });
}
batchUpdate.flush();
}
use of org.springframework.jdbc.core.SqlParameter in project spring-framework by spring-projects.
the class CallMetaDataContext method matchInParameterValuesWithCallParameters.
/**
* Match input parameter values with the parameters declared to be used in the call.
* @param inParameters the input values
* @return a Map containing the matched parameter names with the value taken from the input
*/
public Map<String, ?> matchInParameterValuesWithCallParameters(Map<String, ?> inParameters) {
if (!this.metaDataProvider.isProcedureColumnMetaDataUsed()) {
return inParameters;
}
Map<String, String> callParameterNames = new HashMap<>(this.callParameters.size());
for (SqlParameter parameter : this.callParameters) {
if (parameter.isInputValueProvided()) {
String parameterName = parameter.getName();
String parameterNameToMatch = this.metaDataProvider.parameterNameToUse(parameterName);
if (parameterNameToMatch != null) {
callParameterNames.put(parameterNameToMatch.toLowerCase(), parameterName);
}
}
}
Map<String, Object> matchedParameters = new HashMap<>(inParameters.size());
for (String parameterName : inParameters.keySet()) {
String parameterNameToMatch = this.metaDataProvider.parameterNameToUse(parameterName);
String callParameterName = callParameterNames.get(parameterNameToMatch.toLowerCase());
if (callParameterName == null) {
if (logger.isDebugEnabled()) {
Object value = inParameters.get(parameterName);
if (value instanceof SqlParameterValue) {
value = ((SqlParameterValue) value).getValue();
}
if (value != null) {
logger.debug("Unable to locate the corresponding IN or IN-OUT parameter for \"" + parameterName + "\" in the parameters used: " + callParameterNames.keySet());
}
}
} else {
matchedParameters.put(callParameterName, inParameters.get(parameterName));
}
}
if (matchedParameters.size() < callParameterNames.size()) {
for (String parameterName : callParameterNames.keySet()) {
String parameterNameToMatch = this.metaDataProvider.parameterNameToUse(parameterName);
String callParameterName = callParameterNames.get(parameterNameToMatch.toLowerCase());
if (!matchedParameters.containsKey(callParameterName)) {
logger.warn("Unable to locate the corresponding parameter value for '" + parameterName + "' within the parameter values provided: " + inParameters.keySet());
}
}
}
if (logger.isDebugEnabled()) {
logger.debug("Matching " + inParameters.keySet() + " with " + callParameterNames.values());
logger.debug("Found match for " + matchedParameters.keySet());
}
return matchedParameters;
}
use of org.springframework.jdbc.core.SqlParameter in project spring-framework by spring-projects.
the class CallMetaDataContext method matchInParameterValuesWithCallParameters.
public Map<String, ?> matchInParameterValuesWithCallParameters(Object[] parameterValues) {
Map<String, Object> matchedParameters = new HashMap<>(parameterValues.length);
int i = 0;
for (SqlParameter parameter : this.callParameters) {
if (parameter.isInputValueProvided()) {
String parameterName = parameter.getName();
matchedParameters.put(parameterName, parameterValues[i++]);
}
}
return matchedParameters;
}
use of org.springframework.jdbc.core.SqlParameter in project spring-framework by spring-projects.
the class RdbmsOperation method validateParameters.
/**
* Validate the parameters passed to an execute method based on declared parameters.
* Subclasses should invoke this method before every {@code executeQuery()}
* or {@code update()} method.
* @param parameters parameters supplied (may be {@code null})
* @throws InvalidDataAccessApiUsageException if the parameters are invalid
*/
protected void validateParameters(Object[] parameters) throws InvalidDataAccessApiUsageException {
checkCompiled();
int declaredInParameters = 0;
for (SqlParameter param : this.declaredParameters) {
if (param.isInputValueProvided()) {
if (!supportsLobParameters() && (param.getSqlType() == Types.BLOB || param.getSqlType() == Types.CLOB)) {
throw new InvalidDataAccessApiUsageException("BLOB or CLOB parameters are not allowed for this kind of operation");
}
declaredInParameters++;
}
}
validateParameterCount((parameters != null ? parameters.length : 0), declaredInParameters);
}
Aggregations