Init code push.
This commit is contained in:
parent
664f81d941
commit
ce8596f52a
91
NekoRIP.iml
Normal file
91
NekoRIP.iml
Normal file
|
@ -0,0 +1,91 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
||||||
|
<output url="file://$MODULE_DIR$/target/classes" />
|
||||||
|
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.6" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.google.guava:guava:30.1.1-jre" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.google.guava:failureaccess:1.0.1" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.google.code.findbugs:jsr305:3.0.2" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.checkerframework:checker-qual:3.8.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.google.errorprone:error_prone_annotations:2.5.1" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.google.j2objc:j2objc-annotations:1.3" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.sparkjava:spark-core:2.9.3" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.25" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-server:9.4.31.v20200723" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: javax.servlet:javax.servlet-api:3.1.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-http:9.4.31.v20200723" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-util:9.4.31.v20200723" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-io:9.4.31.v20200723" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-webapp:9.4.31.v20200723" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-xml:9.4.31.v20200723" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-servlet:9.4.31.v20200723" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-security:9.4.31.v20200723" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-server:9.4.31.v20200723" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-common:9.4.31.v20200723" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-client:9.4.31.v20200723" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.eclipse.jetty:jetty-client:9.4.31.v20200723" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-servlet:9.4.31.v20200723" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.eclipse.jetty.websocket:websocket-api:9.4.31.v20200723" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.15" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: commons-io:commons-io:2.8.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:8.0.23" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.google.protobuf:protobuf-java:3.11.4" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.json:json:20201115" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.apache.clerezza.ext:org.json.simple:0.4" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.jsoup:jsoup:1.13.1" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.28" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.realityforge.org.jetbrains.annotations:org.jetbrains.annotations:1.7.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.projectlombok:lombok:1.18.18" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.diogonunes:JColor:5.0.1" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: net.java.dev.jna:jna:5.5.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: net.java.dev.jna:jna-platform:5.5.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.tomlj:tomlj:1.0.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.antlr:antlr4-runtime:4.7.2" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.freemarker:freemarker:2.3.31" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: redis.clients:jedis:3.5.2" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.apache.commons:commons-pool2:2.6.2" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: commons-validator:commons-validator:1.7" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.9.4" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: commons-digester:commons-digester:2.1" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: commons-collections:commons-collections:3.2.2" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.slf4j:slf4j-simple:1.7.30" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.9" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.11" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.inversoft:prime-transformer:2.1.5" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.paypal.sdk:merchantsdk:2.15.122" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.paypal.sdk:paypal-core:1.7.2" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: net.sargue:mailgun:1.10.0" level="project" />
|
||||||
|
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.jersey.core:jersey-client:2.25" level="project" />
|
||||||
|
<orderEntry type="library" scope="RUNTIME" name="Maven: javax.ws.rs:javax.ws.rs-api:2.0.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.jersey.core:jersey-common:2.25" level="project" />
|
||||||
|
<orderEntry type="library" scope="RUNTIME" name="Maven: javax.annotation:javax.annotation-api:1.2" level="project" />
|
||||||
|
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.jersey.bundles.repackaged:jersey-guava:2.25" level="project" />
|
||||||
|
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.hk2:osgi-resource-locator:1.0.1" level="project" />
|
||||||
|
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.hk2:hk2-api:2.5.0-b30" level="project" />
|
||||||
|
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.hk2:hk2-utils:2.5.0-b30" level="project" />
|
||||||
|
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.hk2.external:aopalliance-repackaged:2.5.0-b30" level="project" />
|
||||||
|
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.hk2.external:javax.inject:2.5.0-b30" level="project" />
|
||||||
|
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.hk2:hk2-locator:2.5.0-b30" level="project" />
|
||||||
|
<orderEntry type="library" scope="RUNTIME" name="Maven: org.javassist:javassist:3.20.0-GA" level="project" />
|
||||||
|
<orderEntry type="library" scope="RUNTIME" name="Maven: org.glassfish.jersey.media:jersey-media-multipart:2.25" level="project" />
|
||||||
|
<orderEntry type="library" scope="RUNTIME" name="Maven: org.jvnet.mimepull:mimepull:1.9.6" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: club.minnced:discord-webhooks:0.5.6" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.14.9" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.squareup.okio:okio:1.17.2" level="project" />
|
||||||
|
<orderEntry type="library" scope="RUNTIME" name="Maven: org.jetbrains:annotations:16.0.1" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
143
pom.xml
Normal file
143
pom.xml
Normal file
|
@ -0,0 +1,143 @@
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<groupId>net.horizoncode.nekorip</groupId>
|
||||||
|
<artifactId>NekoRIP</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>8</source>
|
||||||
|
<target>8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.8.6</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
<version>30.1.1-jre</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.sparkjava</groupId>
|
||||||
|
<artifactId>spark-core</artifactId>
|
||||||
|
<version>2.9.3</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-codec</groupId>
|
||||||
|
<artifactId>commons-codec</artifactId>
|
||||||
|
<version>1.15</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
<version>2.8.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-logging</groupId>
|
||||||
|
<artifactId>commons-logging</artifactId>
|
||||||
|
<version>1.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>mysql</groupId>
|
||||||
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
|
<version>8.0.23</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.json</groupId>
|
||||||
|
<artifactId>json</artifactId>
|
||||||
|
<version>20201115</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.clerezza.ext</groupId>
|
||||||
|
<artifactId>org.json.simple</artifactId>
|
||||||
|
<version>0.4</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jsoup</groupId>
|
||||||
|
<artifactId>jsoup</artifactId>
|
||||||
|
<version>1.13.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
<version>1.28</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.realityforge.org.jetbrains.annotations</groupId>
|
||||||
|
<artifactId>org.jetbrains.annotations</artifactId>
|
||||||
|
<version>1.7.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.18</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.diogonunes</groupId>
|
||||||
|
<artifactId>JColor</artifactId>
|
||||||
|
<version>5.0.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.tomlj</groupId>
|
||||||
|
<artifactId>tomlj</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.freemarker</groupId>
|
||||||
|
<artifactId>freemarker</artifactId>
|
||||||
|
<version>2.3.31</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>redis.clients</groupId>
|
||||||
|
<artifactId>jedis</artifactId>
|
||||||
|
<version>3.5.2</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-validator</groupId>
|
||||||
|
<artifactId>commons-validator</artifactId>
|
||||||
|
<version>1.7</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-simple</artifactId>
|
||||||
|
<version>1.7.30</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-text</artifactId>
|
||||||
|
<version>1.9</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.inversoft</groupId>
|
||||||
|
<artifactId>prime-transformer</artifactId>
|
||||||
|
<version>2.1.5</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.paypal.sdk</groupId>
|
||||||
|
<artifactId>merchantsdk</artifactId>
|
||||||
|
<version>2.15.122</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.sargue</groupId>
|
||||||
|
<artifactId>mailgun</artifactId>
|
||||||
|
<version>1.10.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>club.minnced</groupId>
|
||||||
|
<artifactId>discord-webhooks</artifactId>
|
||||||
|
<version>0.5.6</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
54
src/main/java/net/horizoncode/nekorip/NekoRIP.java
Normal file
54
src/main/java/net/horizoncode/nekorip/NekoRIP.java
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
package net.horizoncode.nekorip;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.horizoncode.nekorip.config.Config;
|
||||||
|
import net.horizoncode.nekorip.mysql.MySQLAPI;
|
||||||
|
import org.apache.commons.lang3.Validate;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by HorizonCode at 10/05/2021
|
||||||
|
*
|
||||||
|
* @author HorizonCode
|
||||||
|
* @since 10/05/2021
|
||||||
|
**/
|
||||||
|
@Getter
|
||||||
|
public class NekoRIP {
|
||||||
|
|
||||||
|
private static NekoRIP instance;
|
||||||
|
|
||||||
|
private Config config;
|
||||||
|
private MySQLAPI mySQL;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new NekoRIP().init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
Validate.isTrue(instance == null, "Instance is already initialized.");
|
||||||
|
instance = this;
|
||||||
|
|
||||||
|
File config = new File("config.toml");
|
||||||
|
this.config = new Config(config);
|
||||||
|
|
||||||
|
if(this.config.isJustCreated()){
|
||||||
|
System.out.println("No config found, created one. Please edit the config!");
|
||||||
|
System.gc();
|
||||||
|
System.exit(0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String host = this.config.getStringOrDefault("mysql.host", "");
|
||||||
|
int port = this.config.getIntOrDefault("mysql.port", 3306);
|
||||||
|
String database = this.config.getStringOrDefault("mysql.database", "nekorip");
|
||||||
|
String username = this.config.getStringOrDefault("mysql.username", "root");
|
||||||
|
String password = this.config.getStringOrDefault("mysql.password", "");
|
||||||
|
|
||||||
|
mySQL = MySQLAPI.getInstance();
|
||||||
|
if(!mySQL.connect(host, port, username, password, database))
|
||||||
|
System.out.println("Failed to connect to mysql.");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
70
src/main/java/net/horizoncode/nekorip/config/Config.java
Normal file
70
src/main/java/net/horizoncode/nekorip/config/Config.java
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
package net.horizoncode.nekorip.config;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.Getter;
|
||||||
|
import net.horizoncode.nekorip.NekoRIP;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.tomlj.Toml;
|
||||||
|
import org.tomlj.TomlParseResult;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class Config {
|
||||||
|
|
||||||
|
@Getter(AccessLevel.NONE)
|
||||||
|
private final File configFile;
|
||||||
|
|
||||||
|
@Getter(AccessLevel.PACKAGE)
|
||||||
|
private TomlParseResult toml;
|
||||||
|
|
||||||
|
private boolean justCreated;
|
||||||
|
|
||||||
|
|
||||||
|
public Config(File cfg) {
|
||||||
|
configFile = cfg;
|
||||||
|
if (!configFile.exists()) {
|
||||||
|
try {
|
||||||
|
FileUtils.copyInputStreamToFile(NekoRIP.class.getResourceAsStream("/" + cfg.getName()), configFile);
|
||||||
|
justCreated = true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (configFile.isDirectory()) {
|
||||||
|
try {
|
||||||
|
FileUtils.copyInputStreamToFile(NekoRIP.class.getResourceAsStream("/" + cfg.getName()), configFile);
|
||||||
|
justCreated = true;
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (justCreated)
|
||||||
|
return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
toml = Toml.parse(configFile.toPath());
|
||||||
|
if (toml.hasErrors()) {
|
||||||
|
toml.errors().forEach(error -> System.err.println(error.toString()));
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIntOrDefault(String key, int defaultValue) {
|
||||||
|
return getToml().contains(key) && getToml().get(key) instanceof Integer ? (int) getToml().get(key) : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getBooleanOrDefault(String key, boolean defaultValue) {
|
||||||
|
return getToml().contains(key) && getToml().get(key) instanceof Boolean ? getToml().getBoolean(key) : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStringOrDefault(String key, String defaultValue) {
|
||||||
|
return getToml().contains(key) ? getToml().getString(key) : defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
116
src/main/java/net/horizoncode/nekorip/mysql/MySQLAPI.java
Normal file
116
src/main/java/net/horizoncode/nekorip/mysql/MySQLAPI.java
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
package net.horizoncode.nekorip.mysql;
|
||||||
|
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class MySQLAPI {
|
||||||
|
private static final MySQLAPI INSTANCE;
|
||||||
|
|
||||||
|
static {
|
||||||
|
INSTANCE = new MySQLAPI();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String host;
|
||||||
|
private int port;
|
||||||
|
private String user;
|
||||||
|
private String password;
|
||||||
|
private String database;
|
||||||
|
private Connection connection;
|
||||||
|
|
||||||
|
private MySQLAPI() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MySQLAPI getInstance() {
|
||||||
|
return MySQLAPI.INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean connect(final String host, final int port, final String user, final String password, final String database) {
|
||||||
|
this.host = host;
|
||||||
|
this.port = port;
|
||||||
|
this.user = user;
|
||||||
|
this.password = password;
|
||||||
|
this.database = database;
|
||||||
|
return this.openConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean openConnection() {
|
||||||
|
try {
|
||||||
|
if (this.connection != null) {
|
||||||
|
this.connection.close();
|
||||||
|
}
|
||||||
|
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||||
|
this.connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.user, this.password);
|
||||||
|
establishConnection();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("MySQL error while trying connecting to " + this.host + ":" + this.port + "/" + this.database + ": " + e.getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
System.out.println("MySQL connected to " + this.host + ":" + this.port + "/" + this.database);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void establishConnection() {
|
||||||
|
ScheduledExecutorService scheduleTaskExecutor = Executors.newScheduledThreadPool(5);
|
||||||
|
|
||||||
|
scheduleTaskExecutor.scheduleAtFixedRate(() -> {
|
||||||
|
try {
|
||||||
|
Statement s = getConnection().createStatement();
|
||||||
|
s.executeQuery("SELECT 1+1");
|
||||||
|
s.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}, 0, 10, TimeUnit.MINUTES);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeConnection() {
|
||||||
|
try {
|
||||||
|
System.out.println("MySQL connection closed!");
|
||||||
|
connection.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeRessources(final ResultSet rs, final PreparedStatement st, final Statement s) {
|
||||||
|
if (rs != null) {
|
||||||
|
try {
|
||||||
|
rs.close();
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (st != null) {
|
||||||
|
try {
|
||||||
|
st.close();
|
||||||
|
} catch (SQLException ex2) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (s != null) {
|
||||||
|
try {
|
||||||
|
s.close();
|
||||||
|
} catch (SQLException ex2) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeRessources(final ResultSet rs) {
|
||||||
|
this.closeRessources(rs, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeRessources(final PreparedStatement st) {
|
||||||
|
this.closeRessources(null, st, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeRessources(final Statement s) {
|
||||||
|
this.closeRessources(null, null, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Connection getConnection() {
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
9
src/main/resources/config.toml
Normal file
9
src/main/resources/config.toml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
[web]
|
||||||
|
port = 62011
|
||||||
|
|
||||||
|
[mysql]
|
||||||
|
host = ""
|
||||||
|
port = 3306
|
||||||
|
database = ""
|
||||||
|
username = ""
|
||||||
|
password = ""
|
Reference in New Issue
Block a user