List of usage examples for org.springframework.transaction CannotCreateTransactionException toString
public String toString()
From source file:ca.nrc.cadc.vos.server.NodeDAO.java
/** * Change the busy stateof a node from a known state to another. * * @param node// w w w .j a v a 2 s. c o m * @param curState * @param newState */ public void setBusyState(DataNode node, NodeBusyState curState, NodeBusyState newState) throws TransientException { log.debug("setBusyState: " + node.getUri().getPath() + ", " + curState + " -> " + newState); expectPersistentNode(node); try { startTransaction(); prof.checkpoint("start.getSetBusyStateSQL"); String sql = getSetBusyStateSQL(node, curState, newState); log.debug(sql); int num = jdbc.update(sql); prof.checkpoint("getSetBusyStateSQL"); if (num != 1) throw new IllegalStateException( "setBusyState " + curState + " -> " + newState + " failed: " + node.getUri()); commitTransaction(); prof.checkpoint("commit.getSetBusyStateSQL"); } catch (CannotCreateTransactionException ex) { log.error("failed to create transaction: " + node.getUri().getPath(), ex); if (DBUtil.isTransientDBException(ex)) throw new TransientException("failed to get node: " + node.getUri().getPath(), ex); else throw new RuntimeException("failed to get node: " + node.getUri().getPath(), ex); } catch (IllegalStateException ex) { log.debug(ex.toString()); if (transactionStatus != null) try { rollbackTransaction(); prof.checkpoint("rollback.getSetBusyStateSQL"); } catch (Throwable oops) { log.error("failed to rollback transaction", oops); } throw ex; } catch (Throwable t) { log.error("Delete rollback for node: " + node.getUri().getPath(), t); if (transactionStatus != null) try { rollbackTransaction(); prof.checkpoint("rollback.getSetBusyStateSQL"); } catch (Throwable oops) { log.error("failed to rollback transaction", oops); } if (DBUtil.isTransientDBException(t)) throw new TransientException("failed to updateNodeMetadata " + node.getUri().getPath(), t); else throw new RuntimeException("failed to updateNodeMetadata " + node.getUri().getPath(), t); } finally { if (transactionStatus != null) try { log.warn("delete - BUG - transaction still open in finally... calling rollback"); rollbackTransaction(); } catch (Throwable oops) { log.error("failed to rollback transaction in finally", oops); } } }
From source file:ca.nrc.cadc.vos.server.NodeDAO.java
/** * Recursive delete of a node. This method irrevocably deletes a node and all * the child nodes below it./*from ww w . ja v a2 s . c om*/ * * @param node */ public void delete(Node node) throws TransientException { log.debug("delete: " + node.getUri().getPath() + ", " + node.getClass().getSimpleName()); expectPersistentNode(node); try { if (node instanceof ContainerNode) { ContainerNode dest = (ContainerNode) getPath(deletedNodePath); // need a unique name under /deletedPath String idName = getNodeID(node) + "-" + node.getName(); node.setName(idName); // move handles the transaction, container size changes, rename, and reparent move(node, dest); } else { startTransaction(); prof.checkpoint("start.delete"); // lock the child String sql = getUpdateLockSQL(node); jdbc.update(sql); prof.checkpoint("getUpdateLockSQL"); if (node instanceof DataNode) { // get the contentLength value sql = getSelectContentLengthForDeleteSQL(node); // Note: if node size is null, the jdbc template // will return zero. Long sizeDifference = jdbc.queryForLong(sql); prof.checkpoint("getSelectContentLengthSQL"); // delete the node only if it is not busy deleteNode(node, true); // apply the negative size difference to the parent sql = this.getApplySizeDiffSQL(node.getParent(), sizeDifference, false); log.debug(sql); jdbc.update(sql); prof.checkpoint("getApplySizeDiffSQL"); } else if (node instanceof LinkNode) { // delete the node deleteNode(node, false); } else throw new RuntimeException("BUG - unsupported node type: " + node.getClass()); commitTransaction(); prof.checkpoint("commit.delete"); } log.debug("Node deleted: " + node.getUri().getPath()); } catch (CannotCreateTransactionException ex) { log.error("failed to create transaction: " + node.getUri().getPath(), ex); if (DBUtil.isTransientDBException(ex)) throw new TransientException("failed to get node: " + node.getUri().getPath(), ex); else throw new RuntimeException("failed to get node: " + node.getUri().getPath(), ex); } catch (IllegalStateException ex) { log.debug(ex.toString()); if (transactionStatus != null) try { rollbackTransaction(); prof.checkpoint("rollback.delete"); } catch (Throwable oops) { log.error("failed to rollback transaction", oops); } throw ex; } catch (Throwable t) { log.error("delete rollback for node: " + node.getUri().getPath(), t); if (transactionStatus != null) try { rollbackTransaction(); prof.checkpoint("rollback.delete"); } catch (Throwable oops) { log.error("failed to rollback transaction", oops); } if (DBUtil.isTransientDBException(t)) throw new TransientException("failed to delete " + node.getUri().getPath(), t); else throw new RuntimeException("failed to delete " + node.getUri().getPath(), t); } finally { if (transactionStatus != null) try { log.warn("delete - BUG - transaction still open in finally... calling rollback"); rollbackTransaction(); } catch (Throwable oops) { log.error("failed to rollback transaction in finally", oops); } } }