Skip to content

Commit 7b17623

Browse files
committed
2.2.0-SNAPSHOT
1 parent d1f8c62 commit 7b17623

File tree

10 files changed

+229
-221
lines changed

10 files changed

+229
-221
lines changed

README.md

Lines changed: 66 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,17 @@
33
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
44
[![jitpack](https://jitpack.io/v/hteppl/DataManager.svg)](https://jitpack.io/#hteppl/DataManager)
55

6-
DataManager is a simple library plugin for Nukkit Minecraft Bedrock core (and forks), that will help you to create and
6+
DataManager is a simple library plugin for [PowerNukkitX](https://github.com/PowerNukkitX/PowerNukkitX) Minecraft
7+
Bedrock core, that will help you to create and
78
manage your SQL connections with ease.
89

9-
## Libraries
10-
11-
[**Nukkit**](https://github.com/CloudburstMC/Nukkit) is nuclear-powered server software for Minecraft: Pocket Edition
12-
(you can also use PowerNukkit or PowerNukkitX).
13-
14-
[**Sql2o**](https://github.com/aaberg/sql2o) is small useful framework that makes coding for database easy.
15-
16-
[**HikariCP**](https://github.com/brettwooldridge/HikariCP) is a "zero-overhead" production ready JDBC connection pool.
17-
At roughly 130Kb, the library is very light.
18-
19-
## Performance of SELECT
10+
## Build JAR File
2011

21-
Execute 1000 SELECT statements against a DB and map the data returned to a POJO.
22-
23-
| Method | Duration |
24-
|------------------------------------------|-------------------|
25-
| Hand coded <code>ResultSet</code> | 15ms |
26-
| [Sql2o](https://github.com/aaberg/sql2o) | 24ms (60% slower) |
12+
```shell
13+
$ git clone https://github.com/hteppl/DataManager
14+
$ cd DataManager
15+
$ mvn clean package
16+
```
2717

2818
## How to install
2919

@@ -45,7 +35,7 @@ enough. Also, you can configure some default database settings in `config.yml`.
4535
<dependency>
4636
<groupId>com.github.hteppl</groupId>
4737
<artifactId>DataManager</artifactId>
48-
<version>2.1.0-SNAPSHOT</version>
38+
<version>2.2.0-SNAPSHOT</version>
4939
</dependency>
5040
```
5141

@@ -61,7 +51,7 @@ allprojects {
6151

6252
```groovy
6353
dependencies {
64-
implementation 'com.github.hteppl:DataManager:2.1.0-SNAPSHOT'
54+
implementation 'com.github.hteppl:DataManager:2.2.0-SNAPSHOT'
6555
}
6656
```
6757

@@ -70,102 +60,106 @@ dependencies {
7060
Default plugin `config.yml` settings.
7161

7262
```yaml
73-
# sqlite path settings for method SQLiteDatabase(String database)
74-
sqlite:
75-
# use global folder for saving sqlite tables (near plugins, worlds, etc.) or plugin folder
76-
global: true
77-
# name for folder if "global" is set to true
78-
folder-name: "database"
79-
80-
# mysql settings
81-
mysql:
82-
# default mysql connection properties
83-
properties: "useSSL=false&autoReconnect=true&useUnicode=true&serverTimezone=UTC"
84-
# Hikari connection pool settings (https://github.com/brettwooldridge/HikariCP)
85-
hikari:
86-
auto-commit: true
87-
connection-timeout: 30000
88-
idle-timeout: 600000
89-
keepalive-time: 0
90-
max-lifetime: 1800000
91-
maximum-pool-size: 10
63+
# sqlite directory name for anonymous databases
64+
# set empty, for creating database file in plugin's folder by default
65+
sqlite-directory: "database"
66+
67+
# default mysql connection properties
68+
mysql-properties: "useSSL=false&autoReconnect=true&useUnicode=true&serverTimezone=UTC"
69+
70+
# Hikari connection pool settings (https://github.com/brettwooldridge/HikariCP)
71+
hikari:
72+
auto-commit: true
73+
connection-timeout: 30000
74+
idle-timeout: 600000
75+
keepalive-time: 0
76+
max-lifetime: 1800000
77+
maximum-pool-size: 10
9278
```
9379
9480
## How to use
9581
9682
Firstly we recommend to read:
9783
98-
- [*Sql2o Documentation*](https://github.com/aaberg/sql2o/wiki)
84+
- [*Jdbi Developer Guide*](http://jdbi.org/)
9985
- [*HikariCP Configuration*](https://github.com/brettwooldridge/HikariCP#gear-configuration-knobs-baby)
10086
101-
Here is very basic example of your MySQL database class:
87+
Very basic example of MySQL database class:
10288
10389
```java
10490
import me.hteppl.data.database.MySQLDatabase;
105-
import org.sql2o.Connection;
91+
import org.jdbi.v3.core.Handle;
10692

10793
public class MyDatabase extends MySQLDatabase {
10894

10995
public MyDatabase() {
11096
super("host", "database", "user", "password");
111-
// also you can execute your db scheme with
112-
this.executeScheme("CREATE TABLE IF NOT EXISTS ...");
113-
114-
// or use openConnection() method
115-
try (Connection connection = this.openConnection()) {
116-
connection.createQuery("SELECT ...").executeUpdate();
117-
}
11897

119-
// if you need disable auto commit, use beginTransaction() method
120-
try (Connection connection = this.beginTransaction()) {
121-
connection.createQuery("SELECT ...").executeUpdate();
98+
try (Handle handle = this.getHandle()) {
99+
handle.createUpdate("...")
100+
.bind("var1", "data1")
101+
.bind("var2", "data2")
102+
.execute();
122103
}
123104
}
124105
}
125106
```
126107

127-
or SQLite database class:
108+
Example of SQLite database class:
128109

129110
```java
130111
import me.hteppl.data.database.SQLiteDatabase;
131-
import org.sql2o.Connection;
112+
import org.jdbi.v3.core.Handle;
132113

133114
public class MyDatabase extends SQLiteDatabase {
134115

135116
public MyDatabase() {
136117
super("database");
137-
// also you can execute your db scheme with
138-
this.executeScheme("CREATE TABLE IF NOT EXISTS ...");
139-
140-
// or use openConnection() method
141-
try (Connection connection = this.openConnection()) {
142-
connection.createQuery("SELECT ...").executeUpdate();
143-
}
144118

145-
// if you need disable auto commit, use beginTransaction() method
146-
try (Connection connection = this.beginTransaction()) {
147-
connection.createQuery("SELECT ...").executeUpdate();
119+
try (Handle handle = this.getHandle()) {
120+
handle.createUpdate("...")
121+
.bind("var1", "data1")
122+
.bind("var2", "data2")
123+
.execute();
148124
}
149125
}
150126
}
151127
```
152128

153-
After that, you can easily do what you want with your [*Sql2o*](https://www.sql2o.org) connections:
129+
After that, you can easily do what you want with your [*Jdbi*](http://jdbi.org/) handles:
154130

155131
```java
156132
/* import your database class */
157133

158134
public class Main {
159135

160136
public static void main(String[] args) {
161-
MyDatabase db = new MyDatabase();
137+
MyDatabase database = new MyDatabase();
162138

163-
try (Connection connection = db.openConnection()) {
164-
connection.createQuery("SELECT ...");
139+
try (Handle handle = database.getHandle()) {
140+
handle.createUpdate("...")
141+
.bind("var1", "data1")
142+
.bind("var2", "data2")
143+
.execute();
165144
}
166-
167-
// also you can execute your db scheme with
168-
db.executeScheme("CREATE TABLE IF NOT EXISTS ...");
169145
}
170146
}
171-
```
147+
```
148+
149+
## Libraries
150+
151+
[**PowerNukkitX**](https://github.com/PowerNukkitX/PowerNukkitX) is a branch version based on PowerNukkit,
152+
developed and maintained by PowerNukkitX.
153+
154+
[**MariaDB Connector**](https://github.com/mariadb-corporation/mariadb-connector-j) MariaDB Connector/J is a Type 4 JDBC
155+
driver. It was developed specifically as a lightweight JDBC connector for use with MariaDB and MySQL database servers.
156+
157+
[**Jdbi**](https://github.com/jdbi/jdbi) The Jdbi library provides convenient, idiomatic access to relational databases
158+
in Java.
159+
160+
[**HikariCP**](https://github.com/brettwooldridge/HikariCP) is a "zero-overhead" production ready JDBC connection pool.
161+
At roughly 130Kb, the library is very light.
162+
163+
## License
164+
165+
This project is licensed under the [MIT License](https://opensource.org/licenses/MIT)

pom.xml

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,28 @@
66

77
<groupId>me.hteppl</groupId>
88
<artifactId>DataManager</artifactId>
9-
<version>2.1.0-SNAPSHOT</version>
9+
<version>2.2.0-SNAPSHOT</version>
1010

1111
<properties>
12-
<maven.compiler.source>8</maven.compiler.source>
13-
<maven.compiler.target>8</maven.compiler.target>
12+
<maven.compiler.source>17</maven.compiler.source>
13+
<maven.compiler.target>17</maven.compiler.target>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1616
</properties>
1717

18+
<developers>
19+
<developer>
20+
<id>hteppl</id>
21+
<name>Oleg Kraev</name>
22+
<url>https://github.com/hteppl</url>
23+
</developer>
24+
<developer>
25+
<id>IWareQ</id>
26+
<name>Dmitry Luk</name>
27+
<url>https://github.com/IWareQ</url>
28+
</developer>
29+
</developers>
30+
1831
<build>
1932
<resources>
2033
<resource>
@@ -35,10 +48,14 @@
3548
</resources>
3649
<defaultGoal>clean package</defaultGoal>
3750
<plugins>
51+
<plugin>
52+
<artifactId>maven-resources-plugin</artifactId>
53+
<version>3.3.1</version>
54+
</plugin>
3855
<plugin>
3956
<groupId>org.apache.maven.plugins</groupId>
4057
<artifactId>maven-compiler-plugin</artifactId>
41-
<version>3.10.1</version>
58+
<version>3.11.0</version>
4259
<configuration>
4360
<source>${maven.compiler.source}</source>
4461
<target>${maven.compiler.target}</target>
@@ -47,7 +64,7 @@
4764
<plugin>
4865
<groupId>org.apache.maven.plugins</groupId>
4966
<artifactId>maven-shade-plugin</artifactId>
50-
<version>3.4.1</version>
67+
<version>3.5.0</version>
5168
<configuration>
5269
<createDependencyReducedPom>false</createDependencyReducedPom>
5370
</configuration>
@@ -57,54 +74,54 @@
5774
<goals>
5875
<goal>shade</goal>
5976
</goals>
77+
<configuration>
78+
<minimizeJar>true</minimizeJar>
79+
<filters>
80+
<filter>
81+
<artifact>*:*</artifact>
82+
<excludes>
83+
<exclude>META-INF/**</exclude>
84+
</excludes>
85+
</filter>
86+
</filters>
87+
</configuration>
6088
</execution>
6189
</executions>
6290
</plugin>
6391
</plugins>
6492
</build>
6593

66-
<repositories>
67-
<repository>
68-
<id>opencollab-repo-snapshot</id>
69-
<url>https://repo.opencollab.dev/maven-snapshots/</url>
70-
</repository>
71-
<repository>
72-
<id>nukkitx</id>
73-
<url>https://repo.nukkitx.com/main/</url>
74-
</repository>
75-
</repositories>
76-
7794
<dependencies>
7895
<dependency>
79-
<groupId>cn.nukkit</groupId>
80-
<artifactId>nukkit</artifactId>
81-
<version>1.0-SNAPSHOT</version>
96+
<groupId>cn.powernukkitx</groupId>
97+
<artifactId>powernukkitx</artifactId>
98+
<version>1.20.10-r1</version>
8299
<scope>provided</scope>
83100
</dependency>
84101
<dependency>
85-
<groupId>org.sql2o</groupId>
86-
<artifactId>sql2o</artifactId>
87-
<version>1.6.0</version>
102+
<groupId>org.jdbi</groupId>
103+
<artifactId>jdbi3-core</artifactId>
104+
<version>3.41.0</version>
105+
</dependency>
106+
<dependency>
107+
<groupId>org.mariadb.jdbc</groupId>
108+
<artifactId>mariadb-java-client</artifactId>
109+
<version>3.2.0</version>
88110
</dependency>
89111
<dependency>
90112
<groupId>com.zaxxer</groupId>
91113
<artifactId>HikariCP</artifactId>
92114
<version>4.0.3</version>
93115
</dependency>
94-
<dependency>
95-
<groupId>com.mysql</groupId>
96-
<artifactId>mysql-connector-j</artifactId>
97-
<version>8.0.32</version>
98-
</dependency>
99116
<dependency>
100117
<groupId>org.xerial</groupId>
101118
<artifactId>sqlite-jdbc</artifactId>
102-
<version>3.40.1.0</version>
119+
<version>3.43.0.0</version>
103120
</dependency>
104121
<dependency>
105122
<groupId>org.projectlombok</groupId>
106123
<artifactId>lombok</artifactId>
107-
<version>1.18.26</version>
124+
<version>1.18.28</version>
108125
<scope>provided</scope>
109126
</dependency>
110127
</dependencies>

src/main/java/me/hteppl/data/DataManager.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66

77
public class DataManager extends PluginBase {
88

9-
@Getter
10-
private static DataManager instance;
119
@Getter
1210
private static Settings settings;
1311

1412
@Override
1513
public void onEnable() {
1614
this.saveDefaultConfig();
17-
instance = this;
18-
settings = new Settings(this.getConfig());
15+
settings = new Settings(this.getConfig(), this.getDataFolder().getPath());
1916
}
2017
}

0 commit comments

Comments
 (0)