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"); extractFile("hibernate.cfg.xml");
sessionFactory = var configuration = new org.hibernate.cfg.Configuration()
new Configuration() .addAnnotatedClass(Server.class)
.configure(new File(this.getDataFolder().getAbsolutePath() + "/" + "hibernate.cfg.xml")) .addAnnotatedClass(Node.class)
.addAnnotatedClass(Server.class) .addAnnotatedClass(Allocation.class);
.addAnnotatedClass(Node.class)
.addAnnotatedClass(Allocation.class) if (getConfig().getBoolean("mysql.get-from-file")) {
.buildSessionFactory(); 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 // Initialize the controllers
serversController = new ServersController(sessionFactory); serversController = new ServersController(sessionFactory);

View File

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

View File

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

View File

@ -53,12 +53,11 @@ public class Server {
@JoinColumn(name = "node") @JoinColumn(name = "node")
private Node node; private Node node;
@Column(name = "allocations") @OneToMany(mappedBy = "server", fetch = FetchType.EAGER)
@OneToMany(mappedBy = "id", fetch = FetchType.EAGER)
private List<Allocation> allocations; private List<Allocation> allocations;
@JoinColumn(name = "default_allocation", referencedColumnName = "id") @JoinColumn(name = "default_allocation")
@OneToOne @OneToOne()
private Allocation defaultAllocation; 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: mysql:
hostname: 127.0.0.1 # Url of the MySQL server, in format: jdbc:mysql://<host>:<port>/<database>
username: web # Any additional options can be added at the end of url, such as:
password: webmaster # ?autoReconnect=true&useSSL=false?useUnicode=true&characterEncoding=UTF-8
database: PlayerServers url: "jdbc:mysql://localhost:3306/playerservers?useSSL=false&serverTimezone=UTC"
useSSL: true
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? # For how long should we keep Server Data cached?
cache-time: 20 cache-time: 20