An open API service indexing awesome lists of open source software.

https://github.com/adorsys/lock-persistence


https://github.com/adorsys/lock-persistence

Last synced: 8 months ago
JSON representation

Awesome Lists containing this project

README

          

# lock-persistence

## Usage in spring boot

1. Add maven dependency:

```

de.adorsys.lock-persistence
lock-persistence-core
${lock-persistence.version}

```

### ... for relational databases

2. Add maven dependency:

```

de.adorsys.lock-persistence
lock-persistence-jpa
${lock-persistence.version}

```

3. Add `@EnableJpaLockPersistence` annotation to your spring boot configuration class

4. Make sure your database contains following table definition named `lock_persistence` within default schema:

```
CREATE TABLE lock_persistence (
id SERIAL PRIMARY KEY,
name VARCHAR(256),
value VARCHAR(36),
expires TIMESTAMP
);
```

(example for postgres)

continue with 5.

### ... for mongo

2. Add maven dependency:

```

de.adorsys.lock-persistence
lock-persistence-mongo
${lock-persistence.version}

```

3. Add `@EnableMongoLockPersistence` annotation to your spring boot configuration class

continue with 5.

### provide and use LockClient Bean

5. Make sure you're providing a Bean for a `LockClient` instance:

```
@Bean
LockClient lockClient(LockService lockService) {
return new SimpleLockClient("", lockService);
}
```

6. Use the injected `LockClient` instance in your code:

```
lockClient.executeIfOwned("", new Runnable() {
@Override
public void run() {
... your stuff to be locked for concurrent access ...
}
});
```