use of org.springframework.dao.InvalidDataAccessApiUsageException in project spring-framework by spring-projects.
the class NamedParameterUtils method buildValueArray.
/**
* Convert a Map of named parameter values to a corresponding array.
* @param parsedSql the parsed SQL statement
* @param paramSource the source for named parameters
* @param declaredParams the List of declared SqlParameter objects
* (may be {@code null}). If specified, the parameter metadata will
* be built into the value array in the form of SqlParameterValue objects.
* @return the array of values
*/
public static Object[] buildValueArray(ParsedSql parsedSql, SqlParameterSource paramSource, List<SqlParameter> declaredParams) {
Object[] paramArray = new Object[parsedSql.getTotalParameterCount()];
if (parsedSql.getNamedParameterCount() > 0 && parsedSql.getUnnamedParameterCount() > 0) {
throw new InvalidDataAccessApiUsageException("Not allowed to mix named and traditional ? placeholders. You have " + parsedSql.getNamedParameterCount() + " named parameter(s) and " + parsedSql.getUnnamedParameterCount() + " traditional placeholder(s) in statement: " + parsedSql.getOriginalSql());
}
List<String> paramNames = parsedSql.getParameterNames();
for (int i = 0; i < paramNames.size(); i++) {
String paramName = paramNames.get(i);
try {
Object value = paramSource.getValue(paramName);
SqlParameter param = findParameter(declaredParams, paramName, i);
paramArray[i] = (param != null ? new SqlParameterValue(param, value) : value);
} catch (IllegalArgumentException ex) {
throw new InvalidDataAccessApiUsageException("No value supplied for the SQL parameter '" + paramName + "': " + ex.getMessage());
}
}
return paramArray;
}
use of org.springframework.dao.InvalidDataAccessApiUsageException in project spring-data-mongodb by spring-projects.
the class MongoRepositoryFactory method getRepositoryFragments.
/*
* (non-Javadoc)
* @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getRepositoryFragments(org.springframework.data.repository.core.RepositoryMetadata)
*/
@Override
protected RepositoryFragments getRepositoryFragments(RepositoryMetadata metadata) {
RepositoryFragments fragments = RepositoryFragments.empty();
boolean isQueryDslRepository = QUERY_DSL_PRESENT && QuerydslPredicateExecutor.class.isAssignableFrom(metadata.getRepositoryInterface());
if (isQueryDslRepository) {
if (metadata.isReactiveRepository()) {
throw new InvalidDataAccessApiUsageException("Cannot combine Querydsl and reactive repository support in a single interface");
}
MongoEntityInformation<?, Serializable> entityInformation = getEntityInformation(metadata.getDomainType(), metadata);
fragments = fragments.append(RepositoryFragment.implemented(getTargetRepositoryViaReflection(QuerydslMongoPredicateExecutor.class, entityInformation, operations)));
}
return fragments;
}
use of org.springframework.dao.InvalidDataAccessApiUsageException in project summerb by skarpushin.
the class AbstractJdbcUpdate method compile.
// -------------------------------------------------------------------------
// Methods handling compilation issues
// -------------------------------------------------------------------------
/**
* Compile this JdbcUpdate using provided parameters and meta data plus
* other settings. This finalizes the configuration for this object and
* subsequent attempts to compile are ignored. This will be implicitly
* called the first time an un-compiled update is executed.
*
* @throws org.springframework.dao.InvalidDataAccessApiUsageException
* if the object hasn't been correctly initialized, for example
* if no DataSource has been provided
*/
public final synchronized void compile() throws InvalidDataAccessApiUsageException {
if (!isCompiled()) {
if (getTableName() == null) {
throw new InvalidDataAccessApiUsageException("Table name is required");
}
try {
this.jdbcTemplate.afterPropertiesSet();
} catch (IllegalArgumentException ex) {
throw new InvalidDataAccessApiUsageException(ex.getMessage());
}
compileInternal();
this.compiled = true;
if (logger.isDebugEnabled()) {
logger.debug("JdbcUpdate for table [" + getTableName() + "] compiled");
}
}
}
use of org.springframework.dao.InvalidDataAccessApiUsageException in project irida by phac-nml.
the class AnalysisSubmissionServiceImpl method create.
/**
* {@inheritDoc}
*/
@Override
@PreAuthorize("hasRole('ROLE_USER')")
public AnalysisSubmission create(AnalysisSubmission analysisSubmission) throws ConstraintViolationException, EntityExistsException {
UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
User user = userRepository.loadUserByUsername(userDetails.getUsername());
analysisSubmission.setSubmitter(user);
try {
return super.create(analysisSubmission);
} catch (final InvalidDataAccessApiUsageException e) {
// if the exception is because we're using unsaved properties, try to wrap the exception with a sane-er message.
if (e.getCause() != null) {
final Throwable primaryCause = e.getCause();
if (primaryCause.getCause() != null && primaryCause.getCause() instanceof TransientPropertyValueException) {
final TransientPropertyValueException propertyException = (TransientPropertyValueException) primaryCause.getCause();
if (Objects.equals("namedParameters", propertyException.getPropertyName())) {
throw new UnsupportedOperationException("You must save the named properties *before* you use them in a submission.", e);
}
}
}
throw e;
}
}
use of org.springframework.dao.InvalidDataAccessApiUsageException in project ma-core-public by infiniteautomation.
the class DaoUtils method getIdKey.
@Deprecated
private Object getIdKey(GeneratedKeyHolder keyHolder) {
List<Map<String, Object>> keyList = keyHolder.getKeyList();
if (keyList.size() == 0)
return null;
if (keyList.size() > 1)
throw new InvalidDataAccessApiUsageException("Multiple key records returned from insert");
Map<String, Object> keys = keyList.get(0);
if (keys.size() == 0)
return null;
if (keys.size() == 1)
return keys.values().iterator().next();
// Look for "id"
Object key = keys.get("id");
if (key == null)
key = keys.get("ID");
if (key == null)
throw new InvalidDataAccessApiUsageException("No obvious id field found in keys: " + keys);
return key;
}
Aggregations