com.databasesandlife.util.jdbc.DbMutex Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-common Show documentation
Show all versions of java-common Show documentation
Utility classes developed at Adrian Smith Software (A.S.S.)
package com.databasesandlife.util.jdbc;
import java.util.HashMap;
/**
* Maintains a table full of mutexes as described
* here
*
* To use this, create this table:
*
* CREATE TABLE mutex (name VARCHAR(100)) ENGINE=InnoDB;
*
*
* @author This source is copyright Adrian Smith and licensed under the LGPL 3.
* @see Project on GitHub
*/
@SuppressWarnings("serial")
public class DbMutex {
public String name;
public DbMutex(String name) { this.name = name; }
public void acquire(DbTransaction tx) {
tx.insertIgnoringUniqueConstraintViolations("mutex", new HashMap() {{ put("name", name); }});
tx.query("SELECT * FROM mutex WHERE name=? FOR UPDATE", name);
}
}