use of org.motechproject.mds.domain.SchemaChangeLock in project motech by motech.
the class SchemaChangeLockManager method releaseLock.
@Transactional(propagation = Propagation.MANDATORY)
public void releaseLock(String comment) {
LOGGER.info("Releasing lock for: {}", comment);
final PersistenceManager pm = getPersistenceManager();
final Boolean originalSerializedRead = pm.currentTransaction().getSerializeRead();
try {
pm.currentTransaction().setSerializeRead(true);
SchemaChangeLock lock = getLock(pm);
lock.setComment(null);
lock.setTimestamp(null);
LOGGER.info("Lock released for: {}", comment);
} finally {
pm.currentTransaction().setSerializeRead(originalSerializedRead);
}
}
use of org.motechproject.mds.domain.SchemaChangeLock in project motech by motech.
the class SchemaChangeLockManager method getLock.
private SchemaChangeLock getLock(PersistenceManager pm) {
Query query = pm.newQuery(SchemaChangeLock.class);
query.setUnique(true);
return (SchemaChangeLock) query.execute();
}
use of org.motechproject.mds.domain.SchemaChangeLock in project motech by motech.
the class SchemaChangeLockManager method acquireLock.
@Transactional(propagation = Propagation.MANDATORY)
public void acquireLock(String comment) {
LOGGER.info("Attempting to acquire lock for: {}", comment);
final PersistenceManager pm = getPersistenceManager();
final Boolean originalSerializedRead = pm.currentTransaction().getSerializeRead();
try {
pm.currentTransaction().setSerializeRead(true);
final DateTime waitStartTime = DateUtil.now();
SchemaChangeLock lock = null;
while (lock == null && beforeTimeout(waitStartTime)) {
// we keep retrying until timeout is reached
try {
LOGGER.info("Waiting for lock...");
lock = getLock(pm);
} catch (JDOException e) {
LOGGER.debug("Exception thrown while waiting for lock, probably timed out", e);
}
}
if (lock == null) {
throw new IllegalStateException("Unable to acquire schema change lock for: " + comment);
}
lock.setComment(comment);
lock.setTimestamp(DateUtil.now());
LOGGER.info("Lock acquired for: {}", comment);
} finally {
pm.currentTransaction().setSerializeRead(originalSerializedRead);
}
}
Aggregations