-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
20 changed files
with
818 additions
and
128 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,3 +42,4 @@ test-deploy-token.txt | |
/test/ | ||
assets/resources/database.properties | ||
/logs/ | ||
/config/ |
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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
########## GUILD DATA ######### | ||
guild_data_insert = INSERT INTO `WatameBot`.`Guild` (GuildID, GuildProperties) VALUES (?, ?); | ||
guild_data_insert = INSERT INTO `WatameBot`.`Guild` (GuildID, GuildProperties) VALUES (?, '{}'); | ||
guild_data_get = SELECT * FROM `WatameBot`.`Guild`; | ||
guild_data_get_id = SELECT * FROM `WatameBot`.`Guild` WHERE GuildID = ?; | ||
|
||
########## GUILD JSON DATA ######### | ||
guild_json_select = SELECT JSON_EXTRACT(GuildProperties, ?) FROM `WatameBot`.`Guild` WHERE GuildID = ?; | ||
guild_json_update = UPDATE `WatameBot`.`Guild` SET GuildProperties = JSON_SET(GuildProperties, ?, ?) WHERE GuildID = ?; | ||
guild_json_remove = UPDATE `WatameBot`.`Guild` SET GuildProperties = JSON_REMOVE(GuildProperties, ?); | ||
guild_json_remove = UPDATE `WatameBot`.`Guild` SET GuildProperties = JSON_REMOVE(GuildProperties, ?) WHERE GuildID = ?; |
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 |
---|---|---|
|
@@ -3,37 +3,31 @@ | |
<groupId>net.foxgenesis.watame</groupId> | ||
<artifactId>watamebot</artifactId> | ||
<version>1.0.1</version> | ||
|
||
<name>WatameBot</name> | ||
<url>https://foxgenesis.net/watamebot</url> | ||
<description>A plugin based Discord bot written in Java.</description> | ||
|
||
<organization> | ||
<name>FoxGenesis</name> | ||
<url>https://foxgenesis.net</url> | ||
</organization> | ||
|
||
<licenses> | ||
<license> | ||
<name>GNU General Public License v2.0</name> | ||
<url>https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html</url> | ||
</license> | ||
</licenses> | ||
|
||
<developers> | ||
<developer> | ||
<id>FoxGenesis</id> | ||
<name>FoxGenesis</name> | ||
<email>[email protected]</email> | ||
</developer> | ||
</developers> | ||
|
||
<scm> | ||
<url>https://github.com/FoxGenesis/Watamebot/tree/main</url> | ||
<connection>scm:git:[email protected];FoxGenesis/Watamebot.git</connection> | ||
<developerConnection>scm:git:ssh://github.com;FoxGenesis/Watamebot.git</developerConnection> | ||
</scm> | ||
|
||
<build> | ||
<sourceDirectory>src</sourceDirectory> | ||
<resources> | ||
|
@@ -62,7 +56,6 @@ | |
<release>17</release> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
|
@@ -77,64 +70,60 @@ | |
<artifactId>JDA</artifactId> | ||
<version>5.0.0-alpha.18</version> | ||
</dependency> | ||
|
||
<!-- https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc --> | ||
<dependency> | ||
<groupId>org.xerial</groupId> | ||
<artifactId>sqlite-jdbc</artifactId> | ||
<version>3.39.2.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
<version>2.0.6</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<version>1.4.5</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.fusesource.jansi</groupId> | ||
<artifactId>jansi</artifactId> | ||
<version>2.4.0</version> | ||
</dependency> | ||
|
||
<!-- https://mvnrepository.com/artifact/org.json/json --> | ||
<dependency> | ||
<groupId>org.json</groupId> | ||
<artifactId>json</artifactId> | ||
<version>20220924</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.zaxxer</groupId> | ||
<artifactId>HikariCP</artifactId> | ||
<version>5.0.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.mysql</groupId> | ||
<artifactId>mysql-connector-j</artifactId> | ||
<version>8.0.31</version> | ||
</dependency> | ||
|
||
<!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils --> | ||
<dependency> | ||
<groupId>commons-beanutils</groupId> | ||
<artifactId>commons-beanutils</artifactId> | ||
<version>1.9.4</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-text</artifactId> | ||
<version>1.10.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-configuration2</artifactId> | ||
<version>2.8.0</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<profiles> | ||
<profile> | ||
<id>ci-cd1</id> | ||
|
@@ -163,7 +152,6 @@ | |
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
|
@@ -202,7 +190,6 @@ | |
</plugins> | ||
</build> | ||
</profile> | ||
|
||
<profile> | ||
<id>ci-cd2</id> | ||
<distributionManagement> | ||
|
@@ -232,7 +219,6 @@ | |
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
|
@@ -271,7 +257,6 @@ | |
</plugins> | ||
</build> | ||
</profile> | ||
|
||
<profile> | ||
<id>zip</id> | ||
<build> | ||
|
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 @@ | ||
/test/ |
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,84 @@ | ||
package net.foxgenesis.database; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.util.Objects; | ||
import java.util.Properties; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.CompletionException; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import net.dv8tion.jda.internal.utils.IOUtil; | ||
|
||
public abstract class AConnectionProvider implements AutoCloseable { | ||
|
||
protected final Logger logger; | ||
private final String name; | ||
protected final Properties properties; | ||
|
||
public AConnectionProvider(Properties properties, String name) { | ||
this.name = Objects.requireNonNull(name); | ||
this.logger = LoggerFactory.getLogger(name); | ||
this.properties = Objects.requireNonNull(properties); | ||
|
||
String type = properties.getProperty("databaseType", "mysql"); | ||
properties.remove("databaseType"); | ||
|
||
String ip = properties.getProperty("ip", "localhost"); | ||
properties.remove("ip"); | ||
|
||
String port = properties.getProperty("port", "3306"); | ||
properties.remove("port"); | ||
|
||
String database = properties.getProperty("database", "WatameBot"); | ||
properties.remove("database"); | ||
|
||
properties.put("jdbcUrl", "jdbc:%s://%s:%s/%s".formatted(type, ip, port, database)); | ||
|
||
properties.put("poolName", name); | ||
} | ||
|
||
protected abstract Connection openConnection() throws SQLException; | ||
|
||
protected <U> U openAutoClosedConnection(ConnectionConsumer<U> consumer, Consumer<Throwable> error) { | ||
try (Connection conn = openConnection()) { | ||
return consumer.applyConnection(conn); | ||
} catch (Exception e) { | ||
if (error != null) | ||
error.accept(e); | ||
return null; | ||
} | ||
} | ||
|
||
protected <U> CompletableFuture<U> asyncConnection(Function<Connection, U> function) { | ||
CompletableFuture<Connection> conn = CompletableFuture.supplyAsync(() -> { | ||
try { | ||
return openConnection(); | ||
} catch (SQLException e) { | ||
throw new CompletionException(e); | ||
} | ||
}); | ||
|
||
CompletableFuture<Connection> copy = conn.copy(); | ||
return conn.thenApplyAsync(function).whenCompleteAsync((result, error) -> { | ||
copy.thenAcceptAsync(IOUtil::silentClose); | ||
if (error != null) | ||
throw new CompletionException(error); | ||
}); | ||
} | ||
|
||
public final String getName() { return name; } | ||
|
||
@Override | ||
public void close() throws Exception { | ||
logger.debug("Shutting down {}", name); | ||
|
||
} | ||
|
||
@FunctionalInterface | ||
public interface ConnectionConsumer<U> { public U applyConnection(Connection connection) throws SQLException; } | ||
} |
Oops, something went wrong.