use of org.springframework.dao.DataAccessException in project spring-boot by spring-projects.
the class AbstractDataSourcePoolMetadataTests method getPoolSizeNoConnection.
@Test
public void getPoolSizeNoConnection() {
// Make sure the pool is initialized
JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSourceMetadata().getDataSource());
jdbcTemplate.execute(new ConnectionCallback<Void>() {
@Override
public Void doInConnection(Connection connection) throws SQLException, DataAccessException {
return null;
}
});
assertThat(getDataSourceMetadata().getActive()).isEqualTo(Integer.valueOf(0));
assertThat(getDataSourceMetadata().getUsage()).isEqualTo(Float.valueOf(0));
}
use of org.springframework.dao.DataAccessException in project spring-boot by spring-projects.
the class AbstractDataSourcePoolMetadataTests method getPoolSizeOneConnection.
@Test
public void getPoolSizeOneConnection() {
JdbcTemplate jdbcTemplate = new JdbcTemplate(getDataSourceMetadata().getDataSource());
jdbcTemplate.execute(new ConnectionCallback<Void>() {
@Override
public Void doInConnection(Connection connection) throws SQLException, DataAccessException {
assertThat(getDataSourceMetadata().getActive()).isEqualTo(Integer.valueOf(1));
assertThat(getDataSourceMetadata().getUsage()).isEqualTo(Float.valueOf(0.5F));
return null;
}
});
}
use of org.springframework.dao.DataAccessException in project opennms by OpenNMS.
the class DefaultRrdGraphService method getInputStreamForCommand.
private InputStream getInputStreamForCommand(String command) {
boolean debug = true;
InputStream tempIn = null;
try {
LOG.debug("Executing RRD command: {}", command);
tempIn = m_rrdDao.createGraph(command);
} catch (final DataAccessException e) {
LOG.warn("Exception while creating graph.", e);
if (debug) {
throw e;
} else {
return returnErrorImage(s_rrdError);
}
}
return tempIn;
}
use of org.springframework.dao.DataAccessException in project opennms by OpenNMS.
the class UdpUuidSender method run.
/**
* <p>run</p>
*/
@Override
public void run() {
// get the context
m_context = Thread.currentThread();
Logging.putPrefix(m_logPrefix);
if (m_stop) {
LOG.debug("Stop flag set before thread started, exiting");
return;
} else {
LOG.debug("Thread context started");
}
/*
* This loop is labeled so that it can be
* exited quickly when the thread is interrupted.
*/
List<UdpReceivedEvent> eventHold = new ArrayList<UdpReceivedEvent>(30);
Map<UdpReceivedEvent, EventReceipt> receipts = new HashMap<UdpReceivedEvent, EventReceipt>();
RunLoop: while (!m_stop) {
LOG.debug("Waiting on event receipts to be generated");
synchronized (m_eventUuidsOut) {
// wait for an event to show up. wait in 1 second intervals
while (m_eventUuidsOut.isEmpty()) {
try {
// use wait instead of sleep to release the lock!
m_eventUuidsOut.wait(1000);
} catch (InterruptedException ie) {
LOG.debug("Thread context interrupted");
break RunLoop;
}
}
eventHold.addAll(m_eventUuidsOut);
m_eventUuidsOut.clear();
}
LOG.debug("Received {} event receipts to process", eventHold.size());
LOG.debug("Processing receipts");
// build an event-receipt
for (UdpReceivedEvent re : eventHold) {
for (Event e : re.getAckedEvents()) {
if (e.getUuid() != null) {
EventReceipt receipt = receipts.get(re);
if (receipt == null) {
receipt = new EventReceipt();
receipts.put(re, receipt);
}
receipt.addUuid(e.getUuid());
}
}
}
eventHold.clear();
LOG.debug("Event receipts sorted, transmitting receipts");
// turn them into XML and send it out the socket
for (Map.Entry<UdpReceivedEvent, EventReceipt> entry : receipts.entrySet()) {
UdpReceivedEvent re = entry.getKey();
EventReceipt receipt = entry.getValue();
StringWriter writer = new StringWriter();
try {
JaxbUtils.marshal(receipt, writer);
} catch (DataAccessException e) {
LOG.warn("Failed to build event receipt for agent {}:{}", InetAddressUtils.str(re.getSender()), re.getPort(), e);
}
String xml = writer.getBuffer().toString();
try {
byte[] xml_bytes = xml.getBytes(StandardCharsets.US_ASCII);
DatagramPacket pkt = new DatagramPacket(xml_bytes, xml_bytes.length, re.getSender(), re.getPort());
LOG.debug("Transmitting receipt to destination {}:{}", InetAddressUtils.str(re.getSender()), re.getPort());
m_dgSock.send(pkt);
synchronized (m_handlers) {
for (EventHandler handler : m_handlers) {
try {
handler.receiptSent(receipt);
} catch (Throwable t) {
LOG.warn("Error processing event receipt", t);
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("Receipt transmitted OK {");
LOG.debug(xml);
LOG.debug("}");
}
} catch (IOException e) {
LOG.warn("Failed to send packet to host {}:{}", InetAddressUtils.str(re.getSender()), re.getPort(), e);
}
}
receipts.clear();
}
LOG.debug("Context finished, returning");
}
use of org.springframework.dao.DataAccessException in project alf.io by alfio-event.
the class SpecialPriceTokenGenerator method generateCode.
private void generateCode(SpecialPrice specialPrice) {
TicketCategory ticketCategory = ticketCategoryRepository.getByIdAndActive(specialPrice.getTicketCategoryId()).orElseThrow(IllegalStateException::new);
Event event = eventRepository.findById(ticketCategory.getEventId());
int maxLength = configurationManager.getIntConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), ticketCategory.getId(), ConfigurationKeys.SPECIAL_PRICE_CODE_LENGTH), 6);
while (true) {
try {
log.trace("generate code for special price with id {}", specialPrice.getId());
specialPriceRepository.updateCode(nextValidCode(maxLength), specialPrice.getId());
log.trace("done.");
return;
} catch (DataAccessException e) {
log.warn("got a duplicate. Retrying...", e);
}
}
}
Aggregations