use of org.springframework.dao.DataAccessException in project spring-framework by spring-projects.
the class SQLExceptionCustomTranslatorTests method dataAccessResourceException.
@Test
public void dataAccessResourceException() {
SQLException dataAccessResourceEx = SQLExceptionSubclassFactory.newSQLDataException("", "", 2);
DataAccessException dae = sext.translate("task", "SQL", dataAccessResourceEx);
assertEquals(dataAccessResourceEx, dae.getCause());
assertThat(dae, instanceOf(TransientDataAccessResourceException.class));
}
use of org.springframework.dao.DataAccessException in project spring-framework by spring-projects.
the class SQLStateSQLExceptionTranslatorTests method doTest.
private void doTest(String sqlState, Class<?> dataAccessExceptionType) {
SQLException ex = new SQLException(REASON, sqlState);
SQLExceptionTranslator translator = new SQLStateSQLExceptionTranslator();
DataAccessException dax = translator.translate(TASK, SQL, ex);
assertNotNull("Translation must *never* result in a null DataAccessException being returned.", dax);
assertEquals("Wrong DataAccessException type returned as the result of the translation", dataAccessExceptionType, dax.getClass());
assertNotNull("The original SQLException must be preserved in the translated DataAccessException", dax.getCause());
assertSame("The exact same original SQLException must be preserved in the translated DataAccessException", ex, dax.getCause());
}
use of org.springframework.dao.DataAccessException in project spring-framework by spring-projects.
the class JpaTransactionManager method doCommit.
@Override
protected void doCommit(DefaultTransactionStatus status) {
JpaTransactionObject txObject = (JpaTransactionObject) status.getTransaction();
if (status.isDebug()) {
logger.debug("Committing JPA transaction on EntityManager [" + txObject.getEntityManagerHolder().getEntityManager() + "]");
}
try {
EntityTransaction tx = txObject.getEntityManagerHolder().getEntityManager().getTransaction();
tx.commit();
} catch (RollbackException ex) {
if (ex.getCause() instanceof RuntimeException) {
DataAccessException dex = getJpaDialect().translateExceptionIfPossible((RuntimeException) ex.getCause());
if (dex != null) {
throw dex;
}
}
throw new TransactionSystemException("Could not commit JPA transaction", ex);
} catch (RuntimeException ex) {
// Assumably failed to flush changes to database.
throw DataAccessUtils.translateIfNecessary(ex, getJpaDialect());
}
}
use of org.springframework.dao.DataAccessException in project opennms by OpenNMS.
the class DefaultEventConfDao method reloadConfig.
private synchronized void reloadConfig() throws DataAccessException {
try {
// Load the root event file
Events events = JaxbUtils.unmarshal(Events.class, m_configResource);
// Hash the list of event files for efficient lookup
Set<String> eventFiles = new HashSet<>();
eventFiles.addAll(events.getEventFiles());
// if and only if they exist in the new root
for (String eventFile : m_events.getEventFiles()) {
if (!eventFiles.contains(eventFile)) {
m_lastModifiedEventFiles.remove(eventFile);
continue;
}
events.addLoadedEventFile(eventFile, m_events.getLoadEventsByFile(eventFile));
}
// Load/reload the event files as necessary
events.loadEventFilesIfModified(m_configResource, m_lastModifiedEventFiles);
// Order the events for efficient searching
events.initialize(m_partition, new EventOrdering());
m_events = events;
} catch (Exception e) {
throw new DataRetrievalFailureException("Unabled to load " + m_configResource, e);
}
}
use of org.springframework.dao.DataAccessException in project opennms by OpenNMS.
the class MockEventWriter method process.
private void process(final Event event) throws EventProcessorException {
LOG.debug("Writing event: {}", event);
final OnmsEvent oe = new OnmsEvent();
oe.setEventAutoAction((event.getAutoactionCount() > 0) ? AutoAction.format(event.getAutoaction(), EVENT_AUTOACTION_FIELD_SIZE) : null);
oe.setEventCorrelation((event.getCorrelation() != null) ? org.opennms.netmgt.dao.util.Correlation.format(event.getCorrelation(), EVENT_CORRELATION_FIELD_SIZE) : null);
oe.setEventCreateTime(event.getCreationTime());
oe.setId(event.getDbid());
oe.setEventDescr(event.getDescr());
try {
oe.setDistPoller(m_distPollerDao.get(event.getDistPoller()));
} catch (final DataAccessException e) {
throw new EventProcessorException(e);
}
oe.setEventHost(event.getHost());
oe.setEventForward((event.getForwardCount() > 0) ? org.opennms.netmgt.dao.util.Forward.format(event.getForward(), EVENT_FORWARD_FIELD_SIZE) : null);
oe.setIfIndex(event.getIfIndex());
oe.setIpAddr(event.getInterfaceAddress());
if (event.getLogmsg() != null) {
// set log message
oe.setEventLogMsg(EventDatabaseConstants.format(event.getLogmsg().getContent(), 0));
final String logdest = event.getLogmsg().getDest();
if (logdest.equals("logndisplay")) {
// if 'logndisplay' set both log and display column to yes
oe.setEventLog("Y");
oe.setEventDisplay("Y");
} else if (logdest.equals("logonly")) {
// if 'logonly' set log column to true
oe.setEventLog("Y");
oe.setEventDisplay("N");
} else if (logdest.equals("displayonly")) {
// if 'displayonly' set display column to true
oe.setEventLog("N");
oe.setEventDisplay("Y");
} else if (logdest.equals("suppress")) {
// if 'suppress' set both log and display to false
oe.setEventLog("N");
oe.setEventDisplay("N");
}
}
oe.setEventMouseOverText(event.getMouseovertext());
try {
oe.setNode(m_nodeDao.get(event.getNodeid().intValue()));
} catch (final DataAccessException e) {
throw new EventProcessorException(e);
}
if (event.getOperactionCount() > 0) {
final List<Operaction> a = new ArrayList<>();
final List<String> b = new ArrayList<>();
for (final Operaction eoa : event.getOperactionCollection()) {
a.add(eoa);
b.add(eoa.getMenutext());
}
oe.setEventOperAction(OperatorAction.format(a, EVENT_OPERACTION_FIELD_SIZE));
oe.setEventOperActionMenuText(EventDatabaseConstants.format(b, EVENT_OPERACTION_MENU_FIELD_SIZE));
}
oe.setEventOperInstruct(event.getOperinstruct());
oe.setEventParametersFromEvent(event);
oe.setEventPathOutage(event.getPathoutage());
try {
oe.setServiceType(m_serviceTypeDao.findByName(event.getService()));
} catch (final DataAccessException e) {
throw new EventProcessorException(e);
}
oe.setSeverityLabel(event.getSeverity());
oe.setEventSnmp(SnmpInfo.format(event.getSnmp(), EVENT_SNMP_FIELD_SIZE));
oe.setEventSnmpHost(EventDatabaseConstants.format(event.getSnmphost(), EVENT_SNMPHOST_FIELD_SIZE));
oe.setEventSource(event.getSource());
oe.setEventTime(event.getTime());
if (event.getTticket() != null) {
oe.setEventTTicket(EventDatabaseConstants.format(event.getTticket().getContent(), EVENT_TTICKET_FIELD_SIZE));
oe.setEventTTicketState(event.getTticket().getState().equals("on") ? 1 : 0);
}
oe.setEventUei(event.getUei());
m_eventDao.saveOrUpdate(oe);
}
Aggregations