use of org.springframework.dao.InvalidDataAccessApiUsageException in project spring-framework by spring-projects.
the class RdbmsOperation method compile.
/**
* Compile this query.
* Ignores subsequent attempts to compile.
* @throws InvalidDataAccessApiUsageException if the object hasn't
* been correctly initialized, for example if no DataSource has been provided
*/
public final void compile() throws InvalidDataAccessApiUsageException {
if (!isCompiled()) {
if (getSql() == null) {
throw new InvalidDataAccessApiUsageException("Property 'sql' is required");
}
try {
this.jdbcTemplate.afterPropertiesSet();
} catch (IllegalArgumentException ex) {
throw new InvalidDataAccessApiUsageException(ex.getMessage());
}
compileInternal();
this.compiled = true;
if (logger.isDebugEnabled()) {
logger.debug("RdbmsOperation with SQL [" + getSql() + "] compiled");
}
}
}
use of org.springframework.dao.InvalidDataAccessApiUsageException in project spring-framework by spring-projects.
the class RdbmsOperation method validateNamedParameters.
/**
* Validate the named 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 parameter Map supplied (may be {@code null})
* @throws InvalidDataAccessApiUsageException if the parameters are invalid
*/
protected void validateNamedParameters(@Nullable Map<String, ?> parameters) throws InvalidDataAccessApiUsageException {
checkCompiled();
Map<String, ?> paramsToUse = (parameters != null ? parameters : Collections.<String, Object>emptyMap());
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");
}
if (param.getName() != null && !paramsToUse.containsKey(param.getName())) {
throw new InvalidDataAccessApiUsageException("The parameter named '" + param.getName() + "' was not among the parameters supplied: " + paramsToUse.keySet());
}
declaredInParameters++;
}
}
validateParameterCount(paramsToUse.size(), declaredInParameters);
}
use of org.springframework.dao.InvalidDataAccessApiUsageException in project spring-framework by spring-projects.
the class EntityManagerFactoryUtilsTests method testTranslatesIllegalArgumentException.
@Test
public void testTranslatesIllegalArgumentException() {
IllegalArgumentException iae = new IllegalArgumentException();
DataAccessException dex = EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(iae);
assertThat(dex.getCause()).isSameAs(iae);
boolean condition = dex instanceof InvalidDataAccessApiUsageException;
assertThat(condition).isTrue();
}
use of org.springframework.dao.InvalidDataAccessApiUsageException in project alfresco-repository by Alfresco.
the class TransactionServiceImplTest method testReadOnlyTxn.
@Test
public void testReadOnlyTxn() throws Exception {
// start a read-only transaction
transactionService.setAllowWrite(false, vetoName);
UserTransaction txn = transactionService.getUserTransaction();
txn.begin();
// do some writing
try {
nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + "_" + System.currentTimeMillis());
txn.commit();
fail("Read-only transaction wasn't detected");
} catch (ReadOnlyServerException e) {
// This is now thrown at the lower layers, but it *is* possible for one of the later
// exceptions to get through: Fixed ALF-3884: Share does not report access denied exceptions correctly
@SuppressWarnings("unused") int i = 0;
} catch (InvalidDataAccessApiUsageException e) {
// expected this ...
@SuppressWarnings("unused") int i = 0;
} catch (TransientDataAccessResourceException e) {
// or this - for MySQL (java.sql.SQLException: Connection is read-only. Queries leading to data modification are not allowed.)
@SuppressWarnings("unused") int i = 0;
} catch (IllegalStateException e) {
// or this - for MS SQLServer, Oracle (via AbstractNodeDAOImpl.getCurrentTransaction)
@SuppressWarnings("unused") int i = 0;
} catch (UncategorizedSQLException e) {
// or this - for PostgreSQL (org.postgresql.util.PSQLException: ERROR: transaction is read-only)
if (dialect instanceof PostgreSQLDialect) {
// ALF-4226
@SuppressWarnings("unused") int i = 0;
} else {
throw e;
}
} finally {
transactionService.setAllowWrite(true, vetoName);
try {
txn.rollback();
} catch (Throwable e) {
}
}
}
Aggregations