All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.databasesandlife.util.jdbc.DbMutex Maven / Gradle / Ivy

There is a newer version: 21.0.1
Show newest version
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); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy