Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de2eceb
commit b7f9788
Showing
11 changed files
with
556 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.github.vladimir-bukhtoyarov</groupId> | ||
<artifactId>bucket4j-parent</artifactId> | ||
<version>7.2.0</version> | ||
<relativePath>../bucket4j-parent</relativePath> | ||
</parent> | ||
|
||
<artifactId>bucket4j-mysql</artifactId> | ||
<name>bucket4j-mysql</name> | ||
|
||
<repositories> | ||
<repository> | ||
<id>central</id> | ||
<name>Maven Central</name> | ||
<url>https://repo1.maven.org/maven2/</url> | ||
</repository> | ||
</repositories> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.github.vladimir-bukhtoyarov</groupId> | ||
<artifactId>bucket4j-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.github.vladimir-bukhtoyarov</groupId> | ||
<artifactId>bucket4j-core</artifactId> | ||
<version>${project.version}</version> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.testcontainers</groupId> | ||
<artifactId>mysql</artifactId> | ||
<version>1.16.3</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<version>8.0.28</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.zaxxer</groupId> | ||
<artifactId>HikariCP-java6</artifactId> | ||
<version>2.3.8</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
43 changes: 43 additions & 0 deletions
43
bucket4j-mysql/src/main/java/io/github/bucket4j/mysql/MySQLProxyConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.github.bucket4j.mysql; | ||
|
||
import io.github.bucket4j.distributed.jdbc.BucketTableSettings; | ||
import io.github.bucket4j.distributed.proxy.ClientSideConfig; | ||
|
||
import javax.sql.DataSource; | ||
|
||
public class MySQLProxyConfiguration { | ||
|
||
private final DataSource dataSource; | ||
private final ClientSideConfig clientSideConfig; | ||
private final BucketTableSettings tableSettings; | ||
|
||
public MySQLProxyConfiguration(DataSource dataSource) { | ||
this(dataSource, ClientSideConfig.getDefault(), BucketTableSettings.getDefault()); | ||
} | ||
|
||
public MySQLProxyConfiguration(DataSource dataSource, ClientSideConfig clientSideConfig, BucketTableSettings tableSettings) { | ||
this.dataSource = dataSource; | ||
this.clientSideConfig = clientSideConfig; | ||
this.tableSettings = tableSettings; | ||
} | ||
|
||
public String getIdName() { | ||
return tableSettings.getIdName(); | ||
} | ||
|
||
public String getStateName() { | ||
return tableSettings.getStateName(); | ||
} | ||
|
||
public String getTableName() { | ||
return tableSettings.getTableName(); | ||
} | ||
|
||
public DataSource getDataSource() { | ||
return dataSource; | ||
} | ||
|
||
public ClientSideConfig getClientSideConfig() { | ||
return clientSideConfig; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
bucket4j-mysql/src/main/java/io/github/bucket4j/mysql/MySQLProxyConfigurationBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package io.github.bucket4j.mysql; | ||
|
||
import io.github.bucket4j.BucketExceptions; | ||
import io.github.bucket4j.distributed.jdbc.BucketTableSettings; | ||
import io.github.bucket4j.distributed.proxy.ClientSideConfig; | ||
|
||
import javax.sql.DataSource; | ||
|
||
/** | ||
* @author Maxim Bartkov | ||
* The class to build {@link MySQLProxyConfiguration} | ||
*/ | ||
public final class MySQLProxyConfigurationBuilder { | ||
private ClientSideConfig clientSideConfig; | ||
private BucketTableSettings tableSettings; | ||
|
||
private MySQLProxyConfigurationBuilder() { | ||
} | ||
|
||
public static MySQLProxyConfigurationBuilder builder() { | ||
return new MySQLProxyConfigurationBuilder(); | ||
} | ||
|
||
/** | ||
* @param clientSideConfig {@link ClientSideConfig} client-side configuration for proxy-manager. | ||
* By default, under the hood uses {@link ClientSideConfig#getDefault} | ||
* @return {@link MySQLProxyConfigurationBuilder} | ||
*/ | ||
public MySQLProxyConfigurationBuilder 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 MySQLProxyConfigurationBuilder} | ||
*/ | ||
public MySQLProxyConfigurationBuilder addTableSettings(BucketTableSettings tableSettings) { | ||
this.tableSettings = tableSettings; | ||
return this; | ||
} | ||
|
||
/** | ||
* The method takes a {@link DataSource} as a required parameter | ||
* @param dataSource - a database configuration | ||
* @return {@link MySQLProxyConfiguration} | ||
*/ | ||
public MySQLProxyConfiguration build(DataSource dataSource) { | ||
if(dataSource == null) { | ||
throw new BucketExceptions.BucketExecutionException("DataSource cannot be null"); | ||
} | ||
if(tableSettings == null) { | ||
this.tableSettings = BucketTableSettings.getDefault(); | ||
} | ||
if(clientSideConfig == null) { | ||
this.clientSideConfig = ClientSideConfig.getDefault(); | ||
} | ||
return new MySQLProxyConfiguration(dataSource, clientSideConfig, tableSettings); | ||
} | ||
} |
Oops, something went wrong.