@Transactional(readOnly = false)
public boolean moveScheduleActionDown(ScheduleAction action)
{
synchronized (ScheduleAction.class)
{
HibernateTemplate htl = getHibernateTemplate();
Integer maxPosition = (Integer) htl.find("select max(position) from ScheduleAction where scheduleId = ?",
action.getScheduleId()).get(0);
if (action.getPosition() < maxPosition)
{
List<ScheduleAction> nextActions = htl.find(
"from ScheduleAction where scheduleId = ? and position = ?", new Object[]
{
action.getScheduleId(), action.getPosition() + 1
});
if (nextActions.size() > 0)
{
nextActions.get(0).setPosition(action.getPosition());
htl.update(nextActions.get(0));
}
action.setPosition(action.getPosition() + 1);
htl.update(action);
return true;
}
return false;