Skip to content

Commit

Permalink
#120 documentation for Microsoft SQL Server integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladimir Buhtoyarov committed Nov 5, 2023
1 parent 8107459 commit f3761bc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 27 deletions.
11 changes: 6 additions & 5 deletions README.md
Expand Up @@ -81,11 +81,12 @@ In addition to local in-memory buckets, the Bucket4j supports clustered usage sc
| ```Redis/Lettuce``` | Yes | Yes | [bucket4j-redis/Lettuce](https://bucket4j.com/8.6.0/toc.html#example-of-bucket-instantiation-via-lettucebasedproxymanager) |

### JDBC back-ends
| Back-end | Documentation link |
| :--- |:---------------------------------------------------------------------------------:|
| ```MySQL``` | [bucket4j-mysql](https://bucket4j.com/8.6.0/toc.html#mysql-integration) |
| ```PostgreSQL``` | [bucket4j-postgresql](https://bucket4j.com/8.6.0/toc.html#postgresql-integration) |
| ```Oracle``` | [bucket4j-oracle](https://bucket4j.com/8.6.0/toc.html#oracle-integration) |
| Back-end | Documentation link |
|:---------------------------|:------------------------------------------------------------------------------------:|
| ```MySQL``` | [bucket4j-mysql](https://bucket4j.com/8.6.0/toc.html#mysql-integration) |
| ```PostgreSQL``` | [bucket4j-postgresql](https://bucket4j.com/8.6.0/toc.html#postgresql-integration) |
| ```Oracle``` | [bucket4j-oracle](https://bucket4j.com/8.6.0/toc.html#oracle-integration) |
| ```Microsoft SQL Server``` | [bucket4j-mssql](https://bucket4j.com/8.6.0/toc.html#microsoftsqlserver-integration) |


### Local caches support
Expand Down
Expand Up @@ -17,33 +17,28 @@ CREATE TABLE IF NOT EXISTS buckets(id BIGINT PRIMARY KEY, state BYTEA);
CREATE TABLE IF NOT EXISTS buckets(id BIGINT PRIMARY KEY, state BLOB);
----

==== Configuring custom settings of SQLProxyManager
.Oracle
[,sql]
----
CREATE TABLE bucket(id NUMBER NOT NULL PRIMARY KEY, state RAW(255));
----

* Each proxy manager takes `SQLProxyConfiguration` to customize work with database
.Microsoft SQL Server
[,sql]
----
CREATE TABLE bucket(id INT NOT NULL PRIMARY KEY, state BINARY(256))
----

* To do that, you should use `SQLProxyConfigurationBuilder`, which includes the next parameters:
==== Configuring custom settings of SQLProxyManager
* Each proxy manager takes `SQLProxyConfiguration` to customize work with database

* To do that, you should use `SQLProxyConfigurationBuilder`, which allows to configure data-source and names for table and columns:
[source, java]
----
/**
* @param clientSideConfig {@link ClientSideConfig} client-side configuration for proxy-manager.
* By default, under the hood uses {@link ClientSideConfig#getDefault}
* @return {@link SQLProxyConfigurationBuilder}
*/
public SQLProxyConfigurationBuilder addClientSideConfig(ClientSideConfig clientSideConfig) {
this.clientSideConfig = clientSideConfig;
return this;
}
/**
* @param tableSettings {@link BucketTableSettings} define a configuration of the table to use as a Buckets store.
* By default, under the hood uses {@link BucketTableSettings#getDefault}
* @return {@link SQLProxyConfigurationBuilder}
*/
public SQLProxyConfigurationBuilder addTableSettings(BucketTableSettings tableSettings) {
this.tableSettings = tableSettings;
return this;
}
SQLProxyConfiguration configuration = SQLProxyConfiguration.builder()
.withTableSettings(tableSettings)
.build(dataSource);
proxyManager = new MSSQLSelectForUpdateBasedProxyManager<>(configuration);
----

==== Overriding table configuration
Expand Down Expand Up @@ -175,3 +170,30 @@ To use Bucket4j extension for MySQL you need to add following dependency:
.build();
BucketProxy bucket = proxyManager.builder().build(key, bucketConfiguration);
----

==== MicrosoftSQLServer integration
===== Dependencies
To use Bucket4j extension for Microsoft SQL Server you need to add following dependency:

[,xml,subs=attributes+]
----
<dependency>
<groupId>com.bucket4j</groupId>
<artifactId>bucket4j-mssql</artifactId>
<version>{revnumber}</version>
</dependency>
----

===== Example of Bucket instantiation

----
SQLProxyConfiguration<Long> sqlProxyConfiguration = SQLProxyConfiguration.builder()
.withTableSettings(tableSettings)
.build(dataSource);
MSSQLSelectForUpdateBasedProxyManager<Long> proxyManager = new MSSQLSelectForUpdateBasedProxyManager<>(sqlProxyConfiguration);
...
BucketConfiguration bucketConfiguration = BucketConfiguration.builder()
.addLimit(limit -> limit.capacity(10).refillGreedy(10, ofSeconds(1)))
.build();
BucketProxy bucket = proxyManager.builder().build(key, bucketConfiguration);
----

0 comments on commit f3761bc

Please sign in to comment.