List of usage examples for java.lang RuntimeException getCause
public synchronized Throwable getCause()
From source file:name.livitski.tools.persista.AbstractDAO.java
/** * Loads properties from a map into an entity object. *///from w w w. j a va 2 s . co m public void loadProperties(Entity object, Map<String, Object> properties) { try { for (Map.Entry<String, Object> property : properties.entrySet()) { Method setter = mutator(property.getKey()); setter.invoke(object, property.getValue()); } } catch (RuntimeException e) { throw e; } catch (InvocationTargetException e) { Throwable cause = e.getCause(); if (cause instanceof RuntimeException) throw (RuntimeException) cause; else throw new RuntimeException("Could not load properties into an object of " + entityClass, e); } catch (Exception e) { throw new UnsupportedOperationException("Could not load properties into an object of " + entityClass, e); } }
From source file:org.kuali.rice.kew.routeheader.service.impl.RouteHeaderServiceImpl.java
public DocumentRouteHeaderValue saveRouteHeader(DocumentRouteHeaderValue routeHeader) { if (LOG.isDebugEnabled()) { LOG.debug("About to Save the route Header: " + routeHeader.getDocumentId() + " / version=" + routeHeader.getVersionNumber()); DocumentRouteHeaderValue currHeader = getDataObjectService().find(DocumentRouteHeaderValue.class, routeHeader.getDocumentId()); if (currHeader != null) { LOG.debug("Current Header Version: " + currHeader.getVersionNumber()); } else {/* ww w. ja va 2 s.co m*/ LOG.debug("Current Header: null"); } LOG.debug(ExceptionUtils.getStackTrace(new Throwable())); } try { // before saving, copy off the document content, since it's transient it will get erased during a JPA merge DocumentRouteHeaderValueContent content = routeHeader.getDocumentContent(); DocumentRouteHeaderValue drvPersisted = dataObjectService.save(routeHeader, PersistenceOption.FLUSH); // now let's save the content and reattach it to our document content.setDocumentId(drvPersisted.getDocumentId()); content = dataObjectService.save(content); drvPersisted.setDocumentContent(content); return drvPersisted; } catch (RuntimeException ex) { if (ex.getCause() instanceof OptimisticLockException) { LOG.error("Optimistic Locking Exception saving document header or content. Offending object: " + ex.getCause() + "; DocumentId = " + routeHeader.getDocumentId() + " ; Version Number = " + routeHeader.getVersionNumber()); } LOG.error("Unable to save document header or content. Route Header: " + routeHeader, ex); throw ex; } }
From source file:org.broadleafcommerce.openadmin.server.service.DynamicEntityRemoteService.java
@Override public PersistenceResponse add(final PersistencePackage persistencePackage) throws ServiceException { final PersistenceResponse[] response = new PersistenceResponse[1]; try {// ww w . j a va 2 s. c om transUtil.runTransactionalOperation(new StreamCapableTransactionalOperationAdapter() { @Override public void execute() throws Throwable { response[0] = nonTransactionalAdd(persistencePackage); } @Override public boolean shouldRetryOnTransactionLockAcquisitionFailure() { return super.shouldRetryOnTransactionLockAcquisitionFailure(); } }, RuntimeException.class); } catch (RuntimeException e) { if (e.getCause() instanceof ServiceException) { throw (ServiceException) e.getCause(); } throw e; } return response[0]; }
From source file:org.broadleafcommerce.openadmin.server.service.DynamicEntityRemoteService.java
@Override public PersistenceResponse update(final PersistencePackage persistencePackage) throws ServiceException { final PersistenceResponse[] response = new PersistenceResponse[1]; try {//from w w w . j av a 2s. c o m transUtil.runTransactionalOperation(new StreamCapableTransactionalOperationAdapter() { @Override public void execute() throws Throwable { response[0] = nonTransactionalUpdate(persistencePackage); } @Override public boolean shouldRetryOnTransactionLockAcquisitionFailure() { return super.shouldRetryOnTransactionLockAcquisitionFailure(); } }, RuntimeException.class); } catch (RuntimeException e) { if (e.getCause() instanceof ServiceException) { throw (ServiceException) e.getCause(); } throw e; } return response[0]; }
From source file:org.broadleafcommerce.openadmin.server.service.DynamicEntityRemoteService.java
@Override public PersistenceResponse remove(final PersistencePackage persistencePackage) throws ServiceException { final PersistenceResponse[] response = new PersistenceResponse[1]; try {/* w w w . jav a 2 s. co m*/ transUtil.runTransactionalOperation(new StreamCapableTransactionalOperationAdapter() { @Override public void execute() throws Throwable { response[0] = nonTransactionalRemove(persistencePackage); } @Override public boolean shouldRetryOnTransactionLockAcquisitionFailure() { return super.shouldRetryOnTransactionLockAcquisitionFailure(); } }, RuntimeException.class); } catch (RuntimeException e) { if (e.getCause() instanceof ServiceException) { throw (ServiceException) e.getCause(); } throw e; } return response[0]; }
From source file:name.livitski.tools.persista.AbstractDAO.java
public Object getProperty(Object objectOrMap, String property) { Method getter = accessor(property); if (null == objectOrMap) throw new NullPointerException("Cannot access property \"" + property + "\" of a null object"); if (entityClass.isInstance(objectOrMap)) { try {//from w w w . ja v a2s. c o m return getter.invoke(objectOrMap); } catch (RuntimeException e) { throw e; } catch (InvocationTargetException e) { Throwable cause = e.getCause(); if (cause instanceof RuntimeException) throw (RuntimeException) cause; else throw new RuntimeException( "Could not read property \"" + property + "\" on an object of " + entityClass, e); } catch (Exception e) { throw new UnsupportedOperationException( "Could not read property \"" + property + "\" on an object of " + entityClass, e); } } else if (objectOrMap instanceof Map<?, ?>) { @SuppressWarnings("unchecked") final Map<String, Object> map = (Map<String, Object>) objectOrMap; return map.get(property); } else throw new IllegalArgumentException(objectOrMap + " is neither a map nor a " + entityClass.getName()); }
From source file:name.livitski.tools.persista.AbstractDAO.java
/** * Sets a property on an entity object or a map of properties. * @param objectOrMap an entity object, a map of properties, * or <code>null</code>/*ww w .j av a 2 s .co m*/ * @param property the name of a property to set * @param value the value of a property to set * @return the same entity object or map with the new property * value, or a new map if <code>objectOrMap</code> was * <code>null</code> */ public Object setProperty(Object objectOrMap, String property, Object value) { Method setter = mutator(property); if (null == objectOrMap) objectOrMap = new HashMap<String, Object>(); if (entityClass.isInstance(objectOrMap)) { try { setter.invoke(objectOrMap, value); } catch (RuntimeException e) { throw e; } catch (InvocationTargetException e) { Throwable cause = e.getCause(); if (cause instanceof RuntimeException) throw (RuntimeException) cause; else throw new RuntimeException( "Could not set property \"" + property + "\" on an object of " + entityClass, e); } catch (Exception e) { throw new UnsupportedOperationException( "Could not set property \"" + property + "\" on an object of " + entityClass, e); } } else if (objectOrMap instanceof Map<?, ?>) { @SuppressWarnings("unchecked") final Map<String, Object> map = (Map<String, Object>) objectOrMap; map.put(property, value); } else throw new IllegalArgumentException(objectOrMap + " is neither a map nor a " + entityClass.getName()); return objectOrMap; }
From source file:org.apache.hadoop.hdfs.server.namenode.TestNameNodeReconfigure.java
/** * Test that we can change the block placement policy through the * reconfigurable API./*from w w w . ja v a2s. c om*/ */ @Test public void testChangeBlockPlacementPolicy() throws IOException, ReconfigurationException { setUp(); AtomicInteger callCounter = new AtomicInteger(0); MockPlacementPolicy.setCallCounter(callCounter); DFSTestUtil util = new DFSTestUtil("", 2, 1, 512); // write some files with the default block placement policy util.createFiles(fs, "/reconfdat1", (short) 3); util.waitReplication(fs, "/reconfdat1", (short) 3); assertTrue("calls already made to MockPlacementPolicy", callCounter.get() == 0); // switch over to the mock placement policy cluster.getNameNode().reconfigureProperty("dfs.block.replicator.classname", "org.apache.hadoop.hdfs.server." + "namenode." + "TestNameNodeReconfigure$" + "MockPlacementPolicy"); // write some files with the mock placement policy util.createFiles(fs, "/reconfdat2", (short) 3); util.waitReplication(fs, "/reconfdat2", (short) 3); int callsMade1 = callCounter.get(); // check that calls were made to mock placement policy assertTrue("no calls made to MockPlacementPolicy", callsMade1 > 0); LOG.info("" + callsMade1 + " calls made to MockPlacementPolicy"); // now try to change it to a non-existent class try { cluster.getNameNode().reconfigureProperty("dfs.block.replicator.classname", "does.not.exist"); fail("ReconfigurationException expected"); } catch (RuntimeException expected) { assertTrue("exception should have cause", expected.getCause() != null); assertTrue("exception's cause should have cause", expected.getCause().getCause() != null); assertTrue( "ClassNotFoundException expected but got " + expected.getCause().getCause().getClass().getCanonicalName(), expected.getCause().getCause() instanceof ClassNotFoundException); } // write some files, they should still go to the mock placemeny policy util.createFiles(fs, "/reconfdat3", (short) 3); util.waitReplication(fs, "/reconfdat3", (short) 3); int callsMade2 = callCounter.get(); // check that more calls were made to mock placement policy assertTrue("no calls made to MockPlacementPolicy", callsMade2 > callsMade1); LOG.info("" + (callsMade2 - callsMade1) + " calls made to MockPlacementPolicy"); // now revert back to the default policy cluster.getNameNode().reconfigureProperty("dfs.block.replicator.classname", null); // write some files with the default block placement policy util.createFiles(fs, "/reconfdat4", (short) 3); util.waitReplication(fs, "/reconfdat4", (short) 3); // make sure that no more calls were made to mock placement policy assertTrue("more calls made to MockPlacementPolicy", callCounter.get() == callsMade2); util.cleanup(fs, "/reconfdat1"); util.cleanup(fs, "/reconfdat2"); util.cleanup(fs, "/reconfdat3"); util.cleanup(fs, "/reconfdat4"); }
From source file:com.rackspacecloud.blueflood.io.SerializationTest.java
@Test(expected = SerializationException.class) public void testSerializeStringFails() throws Throwable { try {//from w ww .ja v a 2s .c om NumericSerializer.get(Granularity.FULL).toByteBuffer("words"); } catch (RuntimeException e) { throw e.getCause(); } }
From source file:com.rackspacecloud.blueflood.io.SerializationTest.java
@Test(expected = SerializationException.class) public void testVersion2FullDeserializeBadType() throws Throwable { byte[] buf = new byte[] { 0, 2 }; try {//ww w. ja v a 2s . c om NumericSerializer.get(Granularity.FULL).fromByteBuffer(ByteBuffer.wrap(buf)); } catch (RuntimeException e) { throw e.getCause(); } }