MySQL is now configurable through config, bugfixes

This commit is contained in:
OpenSource 2023-02-05 04:19:34 +01:00
parent 1f3b231b31
commit d98c5b347c
5 changed files with 50 additions and 27 deletions

View File

@ -48,13 +48,30 @@ public class PsHubCore extends JavaPlugin {
extractFile("hibernate.cfg.xml");
sessionFactory =
new Configuration()
.configure(new File(this.getDataFolder().getAbsolutePath() + "/" + "hibernate.cfg.xml"))
.addAnnotatedClass(Server.class)
.addAnnotatedClass(Node.class)
.addAnnotatedClass(Allocation.class)
.buildSessionFactory();
var configuration = new org.hibernate.cfg.Configuration()
.addAnnotatedClass(Server.class)
.addAnnotatedClass(Node.class)
.addAnnotatedClass(Allocation.class);
if (getConfig().getBoolean("mysql.get-from-file")) {
configuration
.configure(new File(this.getDataFolder().getAbsolutePath() + "/" + "hibernate.cfg.xml"));
} else {
configuration
.setProperty("hibernate.connection.url", getConfig().getString("mysql.url"))
.setProperty("hibernate.connection.username", getConfig().getString("mysql.username"))
.setProperty("hibernate.connection.password", getConfig().getString("mysql.password"))
.setProperty("hibernate.connection.driver_class", getConfig().getString("mysql.driver"))
.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect")
.setProperty("hibernate.connection.pool_size", "10")
.setProperty("hibernate.show_sql", String.valueOf(getConfig().getBoolean("mysql.debug")))
.setProperty("hibernate.format_sql",
String.valueOf(getConfig().getBoolean("mysql.debug")))
.setProperty("hibernate.current_session_context_class", "thread")
.setProperty("hibernate.hbm2ddl.auto", getConfig().getString("mysql.update-policy"));
}
sessionFactory = configuration.buildSessionFactory();
// Initialize the controllers
serversController = new ServersController(sessionFactory);

View File

@ -19,8 +19,7 @@ import lombok.Setter;
public class Allocation {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private long id;
@Column(name = "ip", nullable = false)
@ -33,8 +32,8 @@ public class Allocation {
@JoinColumn(name = "node")
private Node node;
@ManyToOne(optional = true)
@JoinColumn(name = "server_id", nullable = true)
@ManyToOne()
@JoinColumn(name = "server_id")
private Server server;
public String getFullAddress() {

View File

@ -25,23 +25,22 @@ import lombok.Setter;
public class Node {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "id", unique = true, nullable = false)
private Long id;
@Column(name = "name")
@Column(name = "name", nullable = false)
private String name;
@Column(name = "ip")
@Column(name = "ip", nullable = false)
private String ip;
@Column(name = "port")
@Column(name = "port", nullable = false)
private int port;
@Column(name = "max_online")
private Integer maxOnline;
@Column(name = "pterodactyl")
@Column(name = "pterodactyl", nullable = false)
private boolean pterodactyl = false;
@Column(name = "token")

View File

@ -53,12 +53,11 @@ public class Server {
@JoinColumn(name = "node")
private Node node;
@Column(name = "allocations")
@OneToMany(mappedBy = "id", fetch = FetchType.EAGER)
@OneToMany(mappedBy = "server", fetch = FetchType.EAGER)
private List<Allocation> allocations;
@JoinColumn(name = "default_allocation", referencedColumnName = "id")
@OneToOne
@JoinColumn(name = "default_allocation")
@OneToOne()
private Allocation defaultAllocation;
/**

View File

@ -1,9 +1,18 @@
# Please enter your MySQL information below. These need to be the same as for PlayerServers.
mysql:
hostname: 127.0.0.1
username: web
password: webmaster
database: PlayerServers
useSSL: true
# Url of the MySQL server, in format: jdbc:mysql://<host>:<port>/<database>
# Any additional options can be added at the end of url, such as:
# ?autoReconnect=true&useSSL=false?useUnicode=true&characterEncoding=UTF-8
url: "jdbc:mysql://localhost:3306/playerservers?useSSL=false&serverTimezone=UTC"
username: root
password: root
# Developer options, do not change unless you know what you are doing.
driver: "com.mysql.cj.jdbc.Driver"
update-policy: "update"
debug: false
get-from-file: false
# For how long should we keep Server Data cached?
cache-time: 20