# db-patterns
**Repository Path**: mirrors_bramp/db-patterns
## Basic Information
- **Project Name**: db-patterns
- **Description**: Some simple DB patterns implemented onto of MySQL
- **Primary Language**: Unknown
- **License**: BSD-2-Clause
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 1
- **Created**: 2020-08-08
- **Last Updated**: 2026-05-16
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
MySQL DB Patterns
=================
by [Andrew Brampton](http://bramp.net) 2013
Intro
-----
Some useful java code backed by JDBC that implements some common patterns.
So far a Condition object, and a Queue are implemented.
```maven
net.bramp.db-patterns
db-patterns
0.1.1
```
Condition
---------
A distributed Java Condition
```java
DataSource ds = ...
Condition condition = new MySQLSleepBasedCondition(ds, "lockname");
condition.await(); // Blocks until a notify
// on another thread (or process, or machine)
condition.notify();
```
The MySQLSleepBasedCondition is based on the MySQL ``SLEEP()`` and ``KILL QUERY``
The thread that is woken up is guaranteed to be the one that has waited the longest.
Queue
-----
A distributed MySQL backed Java BlockingQueue
```java
DataSource ds = ...
BlockingQueue queue = new MySQLBasedQueue(ds, "queue name", String.class);
queue.add("Some String");
// on another thread (or process, or machine)
String s = queue.poll(); // Non blocking
// or
String s = queue.take(); // Blocks until element available
```
The MySQLBasedQueue uses the MySQLSleepBasedCondition to help form a blocking
queue, that can work without polling the database for new work.
Build and Release
-----------------
To build this project use `mvn`.
To push a release to maven central use the standard maven release plugin, and Sonatype's OSS repo:
```bash
mvn release:prepare
mvn release:perform
```
Useful Articles
---------------
https://blog.engineyard.com/2011/5-subtle-ways-youre-using-mysql-as-a-queue-and-why-itll-bite-you