01: package org.outerj.daisy.sync.dao;
02:
03: import org.outerj.daisy.sync.SystemState;
04: import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
05:
06: public class LockerDBImpl implements Locker {
07: private final String getLock = "select propvalue from sync_system where propname = 'lockstate'";
08: private final String updateLock = "update sync_system set propvalue = ? where propname = 'lockstate' and propvalue = ?";
09:
10: private SimpleJdbcTemplate jdbcTemplate;
11:
12: public LockerDBImpl(SimpleJdbcTemplate template) {
13: this .jdbcTemplate = template;
14: }
15:
16: public boolean changeLockState(SystemState oldState,
17: SystemState newState) {
18: String oldvalue = new Integer(oldState.getValue()).toString();
19: String newvalue = new Integer(newState.getValue()).toString();
20: return jdbcTemplate.update(updateLock, new Object[] { newvalue,
21: oldvalue }) == 1;
22: }
23:
24: public SystemState getLockState() {
25: String stateStringValue = jdbcTemplate.queryForObject(getLock,
26: String.class, new Object[0]);
27: return SystemState.ValueOf(Integer.parseInt(stateStringValue));
28: }
29:
30: }
|