10 Commits
1.2.1 ... 1.3.1

Author SHA1 Message Date
Govindas
6e1e3ce14b Add Java 8 support 2021-05-12 12:20:13 +03:00
Govindas
aa65a4e7e8 set api version to 1.13
I think this will help with performance in 1.13+ version, but will keep working in 1.9+
2021-05-07 15:42:01 +03:00
Govindas
d00fc2b6a0 Merge pull request #10 from ham1255/master
Fixed Govindas weirdness on project files (maven fix)
2021-05-04 14:02:42 +00:00
mohammed jasem alaajel
a72da39839 Fixed Govindas weirdness on project files 2021-05-04 18:00:16 +04:00
Govindas
d98bc34b38 partially fixed pom.xml 2021-05-04 16:46:46 +03:00
Govindas
ce64eda9e2 Fix pom.xml & update HikariCP 2021-04-30 11:50:23 +03:00
Govindass
d9f95ac101 make sql auto sync if not main thread 2021-03-16 15:05:26 +02:00
Govindass
fbb35937e6 Preparations for quicker queries (no 50ms delay) feature 2021-03-03 14:27:09 +02:00
Govindas
852e5e0477 Update README.md 2021-02-12 12:44:58 +02:00
Govindass
7620da85f1 remove thread pool config option & Use CachedThreadPool to make sure all threads are used properly
CachedThreadPool automatically creates threads on demand and automatically deletes unused threads after 60 seconds of no usage, so we can remove config option
2021-02-12 12:43:57 +02:00
14 changed files with 128 additions and 41 deletions

1
.gitignore vendored
View File

@@ -6,3 +6,4 @@
*.iml
out/
target
compile/

View File

@@ -5,7 +5,7 @@
### Difference from original skript-db
- Fixed local variables disappearance in newer Skript versions (very hacky fix, but it works, so that's good!)
- Thread-pool size is now configurable
- Thread-pool size is now automatically increasing on demand to use of CachedThreadPool, instead of a fixed hard-coded number
- Uses a newer version of HikariCP
- Only meant to be used by newer Minecraft versions (1.8 is not supported)

26
pom.xml
View File

@@ -6,7 +6,7 @@
<groupId>com.btk5h</groupId>
<artifactId>skript-db</artifactId>
<version>1.2.1</version>
<version>1.3.1</version>
<packaging>jar</packaging>
<repositories>
@@ -45,11 +45,27 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>10</source>
<target>10</target>
<source>8</source>
<target>8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
@@ -65,7 +81,7 @@
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>4.0.1</version>
<version>4.0.3</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -89,4 +105,4 @@
</dependency>
</dependencies>
</project>
</project>

View File

@@ -1,3 +1,3 @@
Manifest-Version: 1.0
Main-Class: com.btk5h.skriptdb.SkriptDB
Manifest-Version: 1.0
Main-Class: com.btk5h.skriptdb.SkriptDB

View File

@@ -73,13 +73,9 @@ public final class SkriptDB extends JavaPlugin {
}
try {
if (out == null) return;
out.write("# How many connections can be awaited for simultaneously, may be useful to increase if mysql database is hosted on a separate machine to account for ping.\n");
out.write("# If it is hosted within the same machine, set it to the count of cores your processor has or the count of threads your processor can process at once.\n");
out.write("thread-pool-size: " + (Runtime.getRuntime().availableProcessors() + 1) + "\n");
out.write("# Only change this if you wish to use a different driver than Java's default, like MariaDB driver.\n");
out.write("# If you use MariaDB, its driver is shaded together with skript-db, so you can just specify:" + "\"org.mariadb.jdbc.Driver\"" + ".\n");
out.write("sql-driver-class-name:" + "\"default\"" + "\n");
out.write("sql-driver-class-name: " + "\"default\"" + "\n");
} catch (IOException e) {
e.printStackTrace();
}

View File

@@ -0,0 +1,34 @@
package com.btk5h.skriptdb.events;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class SQLQueryCompleteEvent extends Event {
private final static HandlerList HANDLERS = new HandlerList();
private String argument;
private Object variables;
public SQLQueryCompleteEvent(String argument) {
super(true);
this.argument = argument;
// this.variables = variables;
}
@Override
public String getEventName() {
return super.getEventName();
}
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
public static HandlerList getHandlerList() {
return HANDLERS;
}
public String getArgument() {
return argument;
}
// public String getVariables() {return;}
}

View File

@@ -8,6 +8,7 @@ import ch.njol.util.Kleenean;
import ch.njol.util.Pair;
import com.btk5h.skriptdb.SkriptDB;
import com.btk5h.skriptdb.SkriptUtil;
import com.btk5h.skriptdb.events.SQLQueryCompleteEvent;
import com.zaxxer.hikari.HikariDataSource;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
@@ -51,7 +52,7 @@ public class EffExecuteStatement extends Effect {
static String lastError;
private static final ExecutorService threadPool =
Executors.newFixedThreadPool(SkriptDB.getInstance().getConfig().getInt("thread-pool-size", 2));
Executors.newCachedThreadPool();
private Expression<String> query;
private Expression<HikariDataSource> dataSource;
@@ -79,14 +80,12 @@ public class EffExecuteStatement extends Effect {
String baseVariable = var != null ? var.toString(e).toLowerCase(Locale.ENGLISH) : null;
//if data source isn't set
if (ds == null)
return;
if (ds == null) return;
if (isSync) {
Object populatedVariables = executeStatement(ds, baseVariable, query);
continueScriptExecution(e, populatedVariables);
} else {
boolean sync = false;
if (!Bukkit.isPrimaryThread()) {
sync = true;
}
Object locals = Variables.removeLocals(e);
//execute SQL statement
@@ -94,12 +93,9 @@ public class EffExecuteStatement extends Effect {
CompletableFuture.supplyAsync(() -> executeStatement(ds, baseVariable, query), threadPool);
//when SQL statement is completed
sql.whenComplete((res, err) -> {
if (err != null) {
err.printStackTrace();
}
Bukkit.getScheduler().runTask(SkriptDB.getInstance(), () -> {
boolean finalSync = sync;
sql.whenComplete((res, err) -> {
if (err != null) { err.printStackTrace(); }
//handle last error syntax data
lastError = null;
@@ -110,28 +106,42 @@ public class EffExecuteStatement extends Effect {
if (getNext() != null) {
//if local variables are present
if (locals != null)
//bring back local variables
Variables.setLocalVariables(e, locals);
//populate SQL data into variables
if (!(res instanceof String)) {
((Map<String, Object>) res).forEach((name, value) -> setVariable(e, name, value));
//also set variables in the sql query complete event
SQLQueryCompleteEvent event = new SQLQueryCompleteEvent("something");
((Map<String, Object>) res).forEach((name, value) -> setVariable(event, name, value));
SkriptDB.getPlugin(SkriptDB.class).getServer().getPluginManager().callEvent(event);
}
if (isSync || finalSync) {
Variables.setLocalVariables(e, locals);
if (!(res instanceof String)) { ((Map<String, Object>) res).forEach((name, value) -> setVariable(e, name, value)); }
TriggerItem.walk(getNext(), e);
Variables.removeLocals(e);
} else {
Bukkit.getScheduler().runTask(SkriptDB.getInstance(), () -> {
Variables.setLocalVariables(e, locals);
if (!(res instanceof String)) { ((Map<String, Object>) res).forEach((name, value) -> setVariable(e, name, value)); }
TriggerItem.walk(getNext(), e);
//the line below is required to prevent memory leaks
//no functionality difference notice with it being removed from my test, but the memory gets filled with leaks
//so it must be kept
Variables.removeLocals(e);
});
}
TriggerItem.walk(getNext(), e);
//the line below is required to prevent memory leaks
//no functionality difference notice with it being removed from my test, but the memory gets filled with leaks
//so it must be kept
Variables.removeLocals(e);
}
});
});
}
}
@Override
protected TriggerItem walk(Event e) {
debug(e, true);
//I think no longer needed as of 1.3.0, uncomment if something breaks
if (!isSync) {
Delay.addDelayedEvent(e);
}

View File

@@ -0,0 +1,29 @@
package com.btk5h.skriptdb.skript;
import ch.njol.skript.Skript;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptEvent;
import ch.njol.skript.lang.SkriptParser;
import com.btk5h.skriptdb.events.SQLQueryCompleteEvent;
import org.bukkit.event.Event;
import org.eclipse.jdt.annotation.Nullable;
public class EvtSQLQueryComplete extends SkriptEvent {
static {
Skript.registerEvent("complete of sql query", EvtSQLQueryComplete.class, SQLQueryCompleteEvent.class, "complete of [(sql|database)] query");
}
@Override
public boolean init(final Literal<?>[] literals, final int i, final SkriptParser.ParseResult parseResult) {
return true;
}
@Override
public boolean check(Event event) {
return (event instanceof SQLQueryCompleteEvent);
}
@Override
public String toString(@Nullable Event event, boolean debug) {
return "complete of sql query";
}
}

View File

@@ -14,7 +14,7 @@ public class Types {
static {
Classes.registerClass(new ClassInfo<>(HikariDataSource.class, "datasource")
.user("datasources?")
.parser(new Parser<>() {
.parser(new Parser<HikariDataSource>() {
@Override
public HikariDataSource parse(String s, ParseContext context) {
return null;
@@ -35,7 +35,7 @@ public class Types {
return "jdbc:.+";
}
})
.serializer(new Serializer<>() {
.serializer(new Serializer<HikariDataSource>() {
@Override
public Fields serialize(HikariDataSource o) {
Fields fields = new Fields();

View File

@@ -1,5 +1,6 @@
name: skript-db
version: 1.2.0
version: 1.3.1
main: com.btk5h.skriptdb.SkriptDB
depend: [Skript]
authors: [btk5h, FranKusmiruk, Govindas]
api-version: 1.13