Cleaned up code

This commit is contained in:
2021-08-19 16:44:15 +02:00
parent 961778bb0e
commit 2fecd3b402
11 changed files with 301 additions and 161 deletions

View File

@ -8,11 +8,12 @@ import java.util.ArrayList;
public abstract class SQLTable {
private MySQLConnection connection;
private final MySQLConnection connection;
private ArrayList<TableField> tableFields;
/**
* The basic constructor of the {@link SQLTable}
*
* @param connection The mysql connection you want to use
*/
public SQLTable(MySQLConnection connection) {
@ -25,10 +26,11 @@ public abstract class SQLTable {
/**
* Adds a string to the table (without allowNull)
* @param name The name of the string you want to add
* @param length The length of the string you want to add
*
* @param name The name of the string you want to add
* @param length The length of the string you want to add
* @param defaultValue The default value of the string you want to add (leave empty if you don't want to use one)
* @param extras The extras you want to add to the string
* @param extras The extras you want to add to the string
*/
protected void string(String name, int length, String defaultValue, String... extras) {
custom(SQLType.STRING.getValue(), name, length, false, defaultValue, extras);
@ -36,11 +38,12 @@ public abstract class SQLTable {
/**
* Adds a string to the table (with allowNull)
* @param name The name of the string you want to add
* @param length The length of the string you want to add
* @param allowNull <code>true</code> if you want to allow a <b>NULL</b> in the field, otherwise <code>false</code>
*
* @param name The name of the string you want to add
* @param length The length of the string you want to add
* @param allowNull <code>true</code> if you want to allow a <b>NULL</b> in the field, otherwise <code>false</code>
* @param defaultValue The default value of the string you want to add (leave empty if you don't want to use one)
* @param extras The extras you want to add to the string
* @param extras The extras you want to add to the string
*/
protected void string(String name, int length, boolean allowNull, String defaultValue, String... extras) {
custom(SQLType.STRING.getValue(), name, length, allowNull, defaultValue, extras);
@ -48,10 +51,11 @@ public abstract class SQLTable {
/**
* Adds an integer to the table (without allowNull)
* @param name The name of the integer you want to add
* @param length The length of the integer you want to add
*
* @param name The name of the integer you want to add
* @param length The length of the integer you want to add
* @param defaultValue The default value of the integer you want to add (leave empty if you don't want to use one)
* @param extras The extras you want to add to the integer
* @param extras The extras you want to add to the integer
*/
protected void integer(String name, int length, String defaultValue, String... extras) {
custom(SQLType.INTEGER.getValue(), name, length, false, defaultValue, extras);
@ -59,11 +63,12 @@ public abstract class SQLTable {
/**
* Adds an integer to the table (with allowNull)
* @param name The name of the integer you want to add
* @param length The length of the integer you want to add
* @param allowNull <code>true</code> if you want to allow a <b>NULL</b> in the field, otherwise <code>false</code>
*
* @param name The name of the integer you want to add
* @param length The length of the integer you want to add
* @param allowNull <code>true</code> if you want to allow a <b>NULL</b> in the field, otherwise <code>false</code>
* @param defaultValue The default value of the integer you want to add (leave empty if you don't want to use one)
* @param extras The extras you want to add to the integer
* @param extras The extras you want to add to the integer
*/
protected void integer(String name, int length, boolean allowNull, String defaultValue, String... extras) {
custom(SQLType.INTEGER.getValue(), name, length, allowNull, defaultValue, extras);
@ -71,10 +76,11 @@ public abstract class SQLTable {
/**
* Adds a boolean to the table (without allowNull)
* @param name The name of the boolean you want to add
* @param length The length of the boolean you want to add
*
* @param name The name of the boolean you want to add
* @param length The length of the boolean you want to add
* @param defaultValue The default value of the boolean you want to add (leave empty if you don't want to use one)
* @param extras The extras you want to add to the boolean
* @param extras The extras you want to add to the boolean
*/
protected void bool(String name, int length, String defaultValue, String... extras) {
custom(SQLType.BOOLEAN.getValue(), name, length, false, defaultValue, extras);
@ -82,11 +88,12 @@ public abstract class SQLTable {
/**
* Adds a boolean to the table (with allowNull)
* @param name The name of the boolean you want to add
* @param length The length of the boolean you want to add
* @param allowNull <code>true</code> if you want to allow a <b>NULL</b> in the field, otherwise <code>false</code>
*
* @param name The name of the boolean you want to add
* @param length The length of the boolean you want to add
* @param allowNull <code>true</code> if you want to allow a <b>NULL</b> in the field, otherwise <code>false</code>
* @param defaultValue The default value of the boolean you want to add (leave empty if you don't want to use one)
* @param extras The extras you want to add to the boolean
* @param extras The extras you want to add to the boolean
*/
protected void bool(String name, int length, boolean allowNull, String defaultValue, String... extras) {
custom(SQLType.BOOLEAN.getValue(), name, length, allowNull, defaultValue, extras);
@ -94,12 +101,13 @@ public abstract class SQLTable {
/**
* Adds a custom field to the table
* @param type The type of the field
* @param name The name of the field
* @param length The length of the field
* @param allowNull <code>true</code> if you want to allow a <b>NULL</b> in the field, otherwise <code>false</code>
*
* @param type The type of the field
* @param name The name of the field
* @param length The length of the field
* @param allowNull <code>true</code> if you want to allow a <b>NULL</b> in the field, otherwise <code>false</code>
* @param defaultValue The default value of the field
* @param extras The extras that you want to add
* @param extras The extras that you want to add
*/
protected void custom(String type, String name, int length, boolean allowNull, String defaultValue, String... extras) {
custom(new TableField(name, type, length, allowNull, defaultValue).setExtra(extras));
@ -107,6 +115,7 @@ public abstract class SQLTable {
/**
* Adds a table field to the table
*
* @param tableField The table field you want to add
*/
protected void custom(TableField tableField) {
@ -115,6 +124,7 @@ public abstract class SQLTable {
/**
* Generates the table sql
*
* @return the table sql
*/
public String generateSQL() {