use of org.springframework.transaction.support.TransactionCallbackWithoutResult in project ma-core-public by infiniteautomation.
the class EventHandlerDao method saveEventHandler.
private AbstractEventHandlerVO<?> saveEventHandler(final String typeName, final String subtypeName, final int typeRef1, final int typeRef2, final AbstractEventHandlerVO<?> handler) {
getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
if (handler.getId() == Common.NEW_ID)
insertEventHandler(typeName, subtypeName, typeRef1, typeRef2, handler);
else
updateEventHandler(handler);
if (handler.getAddedEventTypes() != null)
for (EventType et : handler.getAddedEventTypes()) EventHandlerDao.instance.addEventHandlerMappingIfMissing(handler.getId(), et);
}
});
return getEventHandler(handler.getId());
}
use of org.springframework.transaction.support.TransactionCallbackWithoutResult in project neo-java by coranos.
the class BlockDbH2Impl method deleteBlockAtHeight.
/**
* used to get blocks unstuck, during debugging.
*
* @param blockHeight
* the block height to remove.
*/
public void deleteBlockAtHeight(final long blockHeight) {
final byte[] blockHeightBa = BlockUtil.getBlockHeightBa(blockHeight);
final DataSourceTransactionManager tsMan = new DataSourceTransactionManager(ds);
final TransactionTemplate txTemplate = new TransactionTemplate(tsMan);
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
try {
txTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(final TransactionStatus ts) {
try {
final JdbcTemplate t = new JdbcTemplate(ds);
executeSqlGroup(t, "deleteBlockAtHeight", blockHeightBa);
} catch (final Exception e) {
if (LOG.isErrorEnabled()) {
LOG.error("deleteBlockAtHeight sql exception", e);
}
}
}
});
} catch (final DataAccessException e) {
if (LOG.isErrorEnabled()) {
LOG.error("deleteBlockAtHeight data access exception", e);
}
}
}
use of org.springframework.transaction.support.TransactionCallbackWithoutResult in project collect by openforis.
the class CollectRDBMonitor method runInTransaction.
private void runInTransaction(final Runnable task) {
TransactionTemplate tmpl = new TransactionTemplate(transactionManager);
tmpl.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
task.run();
}
});
}
use of org.springframework.transaction.support.TransactionCallbackWithoutResult in project spring-session by spring-projects.
the class JdbcOperationsSessionRepository method save.
@Override
public void save(final JdbcSession session) {
if (session.isNew()) {
this.transactionOperations.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
JdbcOperationsSessionRepository.this.jdbcOperations.update(JdbcOperationsSessionRepository.this.createSessionQuery, ps -> {
ps.setString(1, session.primaryKey);
ps.setString(2, session.getId());
ps.setLong(3, session.getCreationTime().toEpochMilli());
ps.setLong(4, session.getLastAccessedTime().toEpochMilli());
ps.setInt(5, (int) session.getMaxInactiveInterval().getSeconds());
ps.setLong(6, session.getExpiryTime().toEpochMilli());
ps.setString(7, session.getPrincipalName());
});
if (!session.getAttributeNames().isEmpty()) {
final List<String> attributeNames = new ArrayList<>(session.getAttributeNames());
JdbcOperationsSessionRepository.this.jdbcOperations.batchUpdate(JdbcOperationsSessionRepository.this.createSessionAttributeQuery, new BatchPreparedStatementSetter() {
@Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
String attributeName = attributeNames.get(i);
ps.setString(1, session.primaryKey);
ps.setString(2, attributeName);
serialize(ps, 3, session.getAttribute(attributeName));
}
@Override
public int getBatchSize() {
return attributeNames.size();
}
});
}
}
});
} else {
this.transactionOperations.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
if (session.isChanged()) {
JdbcOperationsSessionRepository.this.jdbcOperations.update(JdbcOperationsSessionRepository.this.updateSessionQuery, ps -> {
ps.setString(1, session.getId());
ps.setLong(2, session.getLastAccessedTime().toEpochMilli());
ps.setInt(3, (int) session.getMaxInactiveInterval().getSeconds());
ps.setLong(4, session.getExpiryTime().toEpochMilli());
ps.setString(5, session.getPrincipalName());
ps.setString(6, session.primaryKey);
});
}
Map<String, Object> delta = session.getDelta();
if (!delta.isEmpty()) {
for (final Map.Entry<String, Object> entry : delta.entrySet()) {
if (entry.getValue() == null) {
JdbcOperationsSessionRepository.this.jdbcOperations.update(JdbcOperationsSessionRepository.this.deleteSessionAttributeQuery, ps -> {
ps.setString(1, session.primaryKey);
ps.setString(2, entry.getKey());
});
} else {
int updatedCount = JdbcOperationsSessionRepository.this.jdbcOperations.update(JdbcOperationsSessionRepository.this.updateSessionAttributeQuery, ps -> {
serialize(ps, 1, entry.getValue());
ps.setString(2, session.primaryKey);
ps.setString(3, entry.getKey());
});
if (updatedCount == 0) {
JdbcOperationsSessionRepository.this.jdbcOperations.update(JdbcOperationsSessionRepository.this.createSessionAttributeQuery, ps -> {
ps.setString(1, session.primaryKey);
ps.setString(2, entry.getKey());
serialize(ps, 3, entry.getValue());
});
}
}
}
}
}
});
}
session.clearChangeFlags();
}
use of org.springframework.transaction.support.TransactionCallbackWithoutResult in project ma-modules-public by infiniteautomation.
the class ScheduledEventDao method deleteScheduledEvent.
public void deleteScheduledEvent(final int scheduledEventId) {
ScheduledEventVO se = getScheduledEvent(scheduledEventId);
final ExtendedJdbcTemplate ejt2 = ejt;
if (se != null) {
getTransactionTemplate().execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
ejt2.update("delete from eventHandlersMapping where eventTypeName=? and eventTypeRef1=?", new Object[] { ScheduledEventType.TYPE_NAME, scheduledEventId });
ejt2.update("delete from scheduledEvents where id=?", new Object[] { scheduledEventId });
}
});
AuditEventType.raiseDeletedEvent(AuditEvent.TYPE_NAME, se);
this.countMonitor.decrement();
}
}
Aggregations