use of org.alfresco.service.transaction.ReadOnlyServerException 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