🛠️ Code cleanup & added many new features #1
@ -28,7 +28,7 @@ public class MySQLConnection {
|
||||
private String tablePrefixVariable = "";
|
||||
private String connectString = "";
|
||||
private Connection con;
|
||||
private TableFactory tableFactory = new TableFactory(this);
|
||||
private final TableFactory tableFactory = new TableFactory(this);
|
||||
|
||||
/**
|
||||
* Basic constructor for the connection
|
||||
@ -194,6 +194,7 @@ public class MySQLConnection {
|
||||
|
||||
/**
|
||||
* Gets the table factory
|
||||
*
|
||||
* @return the table factory
|
||||
*/
|
||||
public TableFactory getTableFactory() {
|
||||
@ -267,6 +268,7 @@ public class MySQLConnection {
|
||||
|
||||
/**
|
||||
* Get the current table Prefix
|
||||
*
|
||||
* @return the prefix
|
||||
*/
|
||||
public String getTablePrefix() {
|
||||
|
@ -9,7 +9,7 @@ public class TableFactory {
|
||||
|
||||
private final HashMap<Class<? extends SQLTable>, SQLTable> REGISTERED_TABLES = new HashMap<>();
|
||||
|
||||
private MySQLConnection connection;
|
||||
private final MySQLConnection connection;
|
||||
|
||||
public TableFactory(MySQLConnection connection) {
|
||||
this.connection = connection;
|
||||
@ -17,6 +17,7 @@ public class TableFactory {
|
||||
|
||||
/**
|
||||
* Registers and creates a sql table
|
||||
*
|
||||
* @param table The table you want to register
|
||||
* @return this class
|
||||
*/
|
||||
@ -28,6 +29,7 @@ public class TableFactory {
|
||||
|
||||
/**
|
||||
* Gets a registered table from the list
|
||||
*
|
||||
* @param tableClass The class of the table you want to get
|
||||
* @return the instance of the table
|
||||
*/
|
||||
|
@ -15,6 +15,7 @@ public class TableGenerator {
|
||||
|
||||
/**
|
||||
* Basic constructor for the TableGenerator
|
||||
*
|
||||
* @param tableName Name of the table
|
||||
*/
|
||||
public TableGenerator(MySQLConnection connection, String tableName) {
|
||||
@ -36,6 +37,7 @@ public class TableGenerator {
|
||||
|
||||
/**
|
||||
* Add a field to the Table
|
||||
*
|
||||
* @param type The type of the field you want to add
|
||||
* @param name The name of the field you want to add
|
||||
* @param length The length of the field you want to add
|
||||
@ -58,6 +60,7 @@ public class TableGenerator {
|
||||
|
||||
/**
|
||||
* Add a field to the Table
|
||||
*
|
||||
* @param type The type of the field you want to add
|
||||
* @param name The name of the field you want to add
|
||||
* @param length The length of the field you want to add
|
||||
@ -74,6 +77,7 @@ public class TableGenerator {
|
||||
|
||||
/**
|
||||
* Add a field to the Table
|
||||
*
|
||||
* @param type The type of the field you want to add
|
||||
* @param name The name of the field you want to add
|
||||
* @return this class
|
||||
@ -84,6 +88,7 @@ public class TableGenerator {
|
||||
|
||||
/**
|
||||
* Creates the table you wanted
|
||||
*
|
||||
* @return this class
|
||||
*/
|
||||
public TableGenerator create() {
|
||||
|
@ -22,6 +22,7 @@ public class DataBaseSelection {
|
||||
|
||||
/**
|
||||
* Basic constructor for selection
|
||||
*
|
||||
* @param connection The current Connection
|
||||
* @param tableName The table name
|
||||
*/
|
||||
@ -35,6 +36,7 @@ public class DataBaseSelection {
|
||||
|
||||
/**
|
||||
* Basic constructor for selection
|
||||
*
|
||||
* @param connection The current Connection
|
||||
*/
|
||||
public DataBaseSelection(MySQLConnection connection) {
|
||||
@ -46,6 +48,7 @@ public class DataBaseSelection {
|
||||
|
||||
/**
|
||||
* Get the temp-generated parameters
|
||||
*
|
||||
* @return ArrayList of parameters
|
||||
*/
|
||||
private ArrayList<Object> getTempParams() {
|
||||
@ -57,6 +60,7 @@ public class DataBaseSelection {
|
||||
|
||||
/**
|
||||
* Sets the table name
|
||||
*
|
||||
* @param tableName The table name
|
||||
* @return this class
|
||||
*/
|
||||
@ -67,6 +71,7 @@ public class DataBaseSelection {
|
||||
|
||||
/**
|
||||
* Adding another 'where'-statement
|
||||
*
|
||||
* @param column Table column name
|
||||
* @param value Table value name
|
||||
* @return this class
|
||||
@ -78,6 +83,7 @@ public class DataBaseSelection {
|
||||
|
||||
/**
|
||||
* Sets the limit of the rows
|
||||
*
|
||||
* @param limit The new limit
|
||||
* @return this class
|
||||
*/
|
||||
@ -88,6 +94,7 @@ public class DataBaseSelection {
|
||||
|
||||
/**
|
||||
* Sets the limit of the rows
|
||||
*
|
||||
* @param limit The new limit
|
||||
* @return this class
|
||||
*/
|
||||
@ -98,6 +105,7 @@ public class DataBaseSelection {
|
||||
|
||||
/**
|
||||
* Get the ResultManager
|
||||
*
|
||||
* @return ResultManager
|
||||
*/
|
||||
public ResultManager getResult() {
|
||||
@ -106,6 +114,7 @@ public class DataBaseSelection {
|
||||
|
||||
/**
|
||||
* Get the ResultSet
|
||||
*
|
||||
* @return ResultSet
|
||||
*/
|
||||
public ResultSet getResultSet() {
|
||||
@ -114,6 +123,7 @@ public class DataBaseSelection {
|
||||
|
||||
/**
|
||||
* Debug the current Statement
|
||||
*
|
||||
* @return this class
|
||||
*/
|
||||
public DataBaseSelection printStatement() {
|
||||
@ -121,15 +131,19 @@ public class DataBaseSelection {
|
||||
messageBuilder.append(processStatement());
|
||||
messageBuilder.append(" | params» ");
|
||||
AtomicBoolean added = new AtomicBoolean(false);
|
||||
getTempParams().forEach(v -> { messageBuilder.append((added.get()) ? ", " : "").append(v);added.set(true); });
|
||||
getTempParams().forEach(v -> {
|
||||
messageBuilder.append((added.get()) ? ", " : "").append(v);
|
||||
added.set(true);
|
||||
});
|
||||
StackTraceElement[] st = Thread.currentThread().getStackTrace();
|
||||
StackTraceElement stack = st[st.length - 1];
|
||||
LOG.debug("DEBUG <" + stack.getFileName()+":"+stack.getLineNumber() + "> Statement: " + messageBuilder.toString());
|
||||
LOG.debug("DEBUG <" + stack.getFileName() + ":" + stack.getLineNumber() + "> Statement: " + messageBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adding another factors
|
||||
*
|
||||
* @param query MySQL Query
|
||||
* @param params Optional parameters for the Query
|
||||
* @return this class
|
||||
@ -142,13 +156,19 @@ public class DataBaseSelection {
|
||||
|
||||
/**
|
||||
* Get the current statement query
|
||||
*
|
||||
* @return the current statement query
|
||||
*/
|
||||
private String processStatement() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("SELECT * FROM ").append(tableName).append(" ");
|
||||
AtomicBoolean used = new AtomicBoolean(false);
|
||||
whereList.forEach((k, v) -> { if (!used.get()) sb.append("WHERE ");else sb.append("AND ");used.set(true);sb.append(k).append(" = ? "); });
|
||||
whereList.forEach((k, v) -> {
|
||||
if (!used.get()) sb.append("WHERE ");
|
||||
else sb.append("AND ");
|
||||
used.set(true);
|
||||
sb.append(k).append(" = ? ");
|
||||
});
|
||||
if (limit != 0) sb.append("LIMIT ").append(limit);
|
||||
optionalQuery.forEach(v -> sb.append(" ").append(v).append(" "));
|
||||
return sb.toString();
|
||||
|
@ -7,12 +7,13 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public class InsertManager {
|
||||
|
||||
private MySQLConnection connection;
|
||||
private final MySQLConnection connection;
|
||||
private String tableName;
|
||||
private HashMap<String, Object> values;
|
||||
private final HashMap<String, Object> values;
|
||||
|
||||
/**
|
||||
* Basic constructor for the InsertManager
|
||||
*
|
||||
* @param connection The current connection
|
||||
*/
|
||||
public InsertManager(MySQLConnection connection) {
|
||||
@ -22,6 +23,7 @@ public class InsertManager {
|
||||
|
||||
/**
|
||||
* Constructor with direct tableName integration
|
||||
*
|
||||
* @param connection The current connection
|
||||
* @param tableName The name of the table
|
||||
*/
|
||||
@ -33,6 +35,7 @@ public class InsertManager {
|
||||
|
||||
/**
|
||||
* Optionally add the tableName / Change the name of the table
|
||||
*
|
||||
* @param tableName The name of the table
|
||||
*/
|
||||
public void from(String tableName) {
|
||||
@ -41,6 +44,7 @@ public class InsertManager {
|
||||
|
||||
/**
|
||||
* Query value
|
||||
*
|
||||
* @param fieldName The name of the column
|
||||
* @param value The value of the object you want to insert
|
||||
* @return this class
|
||||
@ -52,6 +56,7 @@ public class InsertManager {
|
||||
|
||||
/**
|
||||
* Prepares the SQL Query
|
||||
*
|
||||
* @return the SQL Query
|
||||
*/
|
||||
public String prepareStatement() {
|
||||
@ -77,6 +82,7 @@ public class InsertManager {
|
||||
|
||||
/**
|
||||
* Execute the current SQL query
|
||||
*
|
||||
* @return this class
|
||||
*/
|
||||
public InsertManager execute() {
|
||||
|
@ -16,6 +16,7 @@ public class ResultManager {
|
||||
|
||||
/**
|
||||
* Basic constructor for the ResultManager
|
||||
*
|
||||
* @param resultSet Existing ResultSet
|
||||
*/
|
||||
public ResultManager(ResultSet resultSet) {
|
||||
@ -24,6 +25,7 @@ public class ResultManager {
|
||||
|
||||
/**
|
||||
* Getting the ResultSet
|
||||
*
|
||||
* @return ResultSet
|
||||
*/
|
||||
public ResultSet getResultSet() {
|
||||
@ -32,92 +34,140 @@ public class ResultManager {
|
||||
|
||||
/**
|
||||
* Get the Object of an Result
|
||||
*
|
||||
* @param column Table column
|
||||
* @return Object
|
||||
*/
|
||||
public Object getObject(String column) {
|
||||
try { while (resultSet.next()) { return resultSet.getObject(column); }
|
||||
} catch (Exception err) { LOG.error(err.getMessage()); }
|
||||
try {
|
||||
while (resultSet.next()) {
|
||||
return resultSet.getObject(column);
|
||||
}
|
||||
} catch (Exception err) {
|
||||
LOG.error(err.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the String of an Result
|
||||
*
|
||||
* @param column Table column
|
||||
* @return String
|
||||
*/
|
||||
public String getString(String column) {
|
||||
try { while (resultSet.next()) { return resultSet.getString(column); }
|
||||
} catch (Exception err) { LOG.error(err.getMessage()); }
|
||||
try {
|
||||
while (resultSet.next()) {
|
||||
return resultSet.getString(column);
|
||||
}
|
||||
} catch (Exception err) {
|
||||
LOG.error(err.getMessage());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Integer of an Result
|
||||
*
|
||||
* @param column Table column
|
||||
* @return Integer
|
||||
*/
|
||||
public Integer getInteger(String column) {
|
||||
try { while (resultSet.next()) { return resultSet.getInt(column); }
|
||||
} catch (Exception err) { LOG.error(err.getMessage()); }
|
||||
try {
|
||||
while (resultSet.next()) {
|
||||
return resultSet.getInt(column);
|
||||
}
|
||||
} catch (Exception err) {
|
||||
LOG.error(err.getMessage());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the Boolean of an Result
|
||||
*
|
||||
* @param column Table column
|
||||
* @return Boolean
|
||||
*/
|
||||
public Boolean getBoolean(String column) {
|
||||
try { while (resultSet.next()) { return resultSet.getBoolean(column); }
|
||||
} catch (Exception err) { LOG.error(err.getMessage()); }
|
||||
try {
|
||||
while (resultSet.next()) {
|
||||
return resultSet.getBoolean(column);
|
||||
}
|
||||
} catch (Exception err) {
|
||||
LOG.error(err.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Timestamp getTimestamp(String column) {
|
||||
try { while (resultSet.next()) { return resultSet.getTimestamp(column); }
|
||||
} catch (Exception err) { LOG.error(err.getMessage()); }
|
||||
try {
|
||||
while (resultSet.next()) {
|
||||
return resultSet.getTimestamp(column);
|
||||
}
|
||||
} catch (Exception err) {
|
||||
LOG.error(err.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the count of the Result
|
||||
*
|
||||
* @return Integer (Count)
|
||||
*/
|
||||
public Integer getRowCount() {
|
||||
int count = 0;
|
||||
try { while (resultSet.next()) { count++; } } catch (Exception err) { LOG.error(err.getMessage()); }
|
||||
try {
|
||||
while (resultSet.next()) {
|
||||
count++;
|
||||
}
|
||||
} catch (Exception err) {
|
||||
LOG.error(err.getMessage());
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a List of all Results
|
||||
*
|
||||
* @param column Table column
|
||||
* @return ArrayList of Result
|
||||
*/
|
||||
public ArrayList<String> getList(String column) {
|
||||
ArrayList<String> results = new ArrayList<>();
|
||||
try { while (resultSet.next()) { results.add(resultSet.getString(column)); }
|
||||
} catch (Exception err) { LOG.error(err.getMessage()); }
|
||||
try {
|
||||
while (resultSet.next()) {
|
||||
results.add(resultSet.getString(column));
|
||||
}
|
||||
} catch (Exception err) {
|
||||
LOG.error(err.getMessage());
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a List of all Results for 2 columns
|
||||
*
|
||||
* @param column Table column #1
|
||||
* @param column2 Table column #2
|
||||
* @return HashMap of Result
|
||||
*/
|
||||
public HashMap<String, String> getMultipleList(String column, String column2) {
|
||||
HashMap<String, String> results = new HashMap<>();
|
||||
try { while (resultSet.next()) {
|
||||
results.put(resultSet.getString(column), resultSet.getString(column2)); }
|
||||
} catch (Exception err) { LOG.error(err.getMessage()); }
|
||||
try {
|
||||
while (resultSet.next()) {
|
||||
results.put(resultSet.getString(column), resultSet.getString(column2));
|
||||
}
|
||||
} catch (Exception err) {
|
||||
LOG.error(err.getMessage());
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all results with all columns
|
||||
*
|
||||
* @return ArrayList with the result
|
||||
*/
|
||||
public ArrayList<HashMap<String, Object>> getList() {
|
||||
@ -131,7 +181,9 @@ public class ResultManager {
|
||||
}
|
||||
results.add(result);
|
||||
}
|
||||
} catch (Exception err) { LOG.error(err.getMessage()); }
|
||||
} catch (Exception err) {
|
||||
LOG.error(err.getMessage());
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
|
@ -12,13 +12,14 @@ public class UpdateManager {
|
||||
|
||||
private final Logger LOG = MySQLConnection.LOG;
|
||||
|
||||
private MySQLConnection connection;
|
||||
private final MySQLConnection connection;
|
||||
private String tableName;
|
||||
private HashMap<String, Object> whereList;
|
||||
private HashMap<String, Object> setList;
|
||||
private final HashMap<String, Object> whereList;
|
||||
private final HashMap<String, Object> setList;
|
||||
|
||||
/**
|
||||
* Basic constructor for the UpdateManager
|
||||
*
|
||||
* @param connection Existing MySQL connection
|
||||
*/
|
||||
public UpdateManager(MySQLConnection connection) {
|
||||
@ -29,6 +30,7 @@ public class UpdateManager {
|
||||
|
||||
/**
|
||||
* Basic constructor for the UpdateManager
|
||||
*
|
||||
* @param connection Existing MySQL connection
|
||||
* @param tableName Table name
|
||||
*/
|
||||
@ -41,6 +43,7 @@ public class UpdateManager {
|
||||
|
||||
/**
|
||||
* Get the parameters for the SQL statement
|
||||
*
|
||||
* @return the parameters
|
||||
*/
|
||||
private ArrayList<Object> getTempParams() {
|
||||
@ -52,6 +55,7 @@ public class UpdateManager {
|
||||
|
||||
/**
|
||||
* Get the current connection
|
||||
*
|
||||
* @return MySQL connection
|
||||
*/
|
||||
public MySQLConnection getConnection() {
|
||||
@ -60,6 +64,7 @@ public class UpdateManager {
|
||||
|
||||
/**
|
||||
* Print the deletion statement
|
||||
*
|
||||
* @return this class
|
||||
*/
|
||||
public UpdateManager printDeleteStatement() {
|
||||
@ -67,15 +72,19 @@ public class UpdateManager {
|
||||
messageBuilder.append(processDeleteStatement());
|
||||
messageBuilder.append(" | params» ");
|
||||
AtomicBoolean added = new AtomicBoolean(false);
|
||||
whereList.values().forEach(v -> { messageBuilder.append((added.get()) ? ", " : "").append(v);added.set(true); });
|
||||
whereList.values().forEach(v -> {
|
||||
messageBuilder.append((added.get()) ? ", " : "").append(v);
|
||||
added.set(true);
|
||||
});
|
||||
StackTraceElement[] st = Thread.currentThread().getStackTrace();
|
||||
StackTraceElement stack = st[st.length - 1];
|
||||
LOG.debug("DEBUG <" + stack.getFileName()+":"+stack.getLineNumber() + "> Statement: " + messageBuilder.toString());
|
||||
LOG.debug("DEBUG <" + stack.getFileName() + ":" + stack.getLineNumber() + "> Statement: " + messageBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the update statement
|
||||
*
|
||||
* @return this class
|
||||
*/
|
||||
public UpdateManager printUpdateStatement() {
|
||||
@ -83,15 +92,19 @@ public class UpdateManager {
|
||||
messageBuilder.append(processUpdateStatement());
|
||||
messageBuilder.append(" | params» ");
|
||||
AtomicBoolean added = new AtomicBoolean(false);
|
||||
getTempParams().forEach(v -> { messageBuilder.append((added.get()) ? ", " : "").append(v);added.set(true); });
|
||||
getTempParams().forEach(v -> {
|
||||
messageBuilder.append((added.get()) ? ", " : "").append(v);
|
||||
added.set(true);
|
||||
});
|
||||
StackTraceElement[] st = Thread.currentThread().getStackTrace();
|
||||
StackTraceElement stack = st[st.length - 1];
|
||||
LOG.debug("DEBUG <" + stack.getFileName()+":"+stack.getLineNumber() + "> Statement: " + messageBuilder.toString());
|
||||
LOG.debug("DEBUG <" + stack.getFileName() + ":" + stack.getLineNumber() + "> Statement: " + messageBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the tableName
|
||||
*
|
||||
* @param tableName New tableName
|
||||
* @return this class
|
||||
*/
|
||||
@ -102,6 +115,7 @@ public class UpdateManager {
|
||||
|
||||
/**
|
||||
* Add a 'where'-clause
|
||||
*
|
||||
* @param column Table column
|
||||
* @param value Value of the column
|
||||
* @return this class
|
||||
@ -113,6 +127,7 @@ public class UpdateManager {
|
||||
|
||||
/**
|
||||
* Add a 'set'-clause
|
||||
*
|
||||
* @param column Table column
|
||||
* @param value Value of the column
|
||||
* @return this class
|
||||
@ -124,6 +139,7 @@ public class UpdateManager {
|
||||
|
||||
/**
|
||||
* Delete the entries with your current conditions
|
||||
*
|
||||
* @return this class
|
||||
*/
|
||||
public UpdateManager delete() {
|
||||
@ -133,6 +149,7 @@ public class UpdateManager {
|
||||
|
||||
/**
|
||||
* Update the entries with your current conditions
|
||||
*
|
||||
* @return this class
|
||||
*/
|
||||
public UpdateManager update() {
|
||||
@ -142,6 +159,7 @@ public class UpdateManager {
|
||||
|
||||
/**
|
||||
* Get the Query of the 'update'-Statement
|
||||
*
|
||||
* @return the Statement
|
||||
*/
|
||||
private String processUpdateStatement() {
|
||||
@ -166,6 +184,7 @@ public class UpdateManager {
|
||||
|
||||
/**
|
||||
* Get the Query of the 'delete'-Statement
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String processDeleteStatement() {
|
||||
@ -184,6 +203,7 @@ public class UpdateManager {
|
||||
|
||||
/**
|
||||
* Generate a new Table (with prefilled tableName)
|
||||
*
|
||||
* @param tableName Name of the new table
|
||||
* @return the de.gnmyt.SQLToolkit.generator
|
||||
*/
|
||||
@ -193,6 +213,7 @@ public class UpdateManager {
|
||||
|
||||
/**
|
||||
* Generate a new Table
|
||||
*
|
||||
* @return the de.gnmyt.SQLToolkit.generator
|
||||
*/
|
||||
public TableGenerator generateTable() {
|
||||
|
@ -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,6 +26,7 @@ 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 defaultValue The default value of the string you want to add (leave empty if you don't want to use one)
|
||||
@ -36,6 +38,7 @@ 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>
|
||||
@ -48,6 +51,7 @@ 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 defaultValue The default value of the integer you want to add (leave empty if you don't want to use one)
|
||||
@ -59,6 +63,7 @@ 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>
|
||||
@ -71,6 +76,7 @@ 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 defaultValue The default value of the boolean you want to add (leave empty if you don't want to use one)
|
||||
@ -82,6 +88,7 @@ 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>
|
||||
@ -94,6 +101,7 @@ 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
|
||||
@ -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() {
|
||||
|
@ -15,6 +15,7 @@ public enum LoginParam {
|
||||
|
||||
/**
|
||||
* Basic constructor for the LoginParam enum
|
||||
*
|
||||
* @param value JDBC parameter
|
||||
*/
|
||||
LoginParam(String value) {
|
||||
@ -23,6 +24,7 @@ public enum LoginParam {
|
||||
|
||||
/**
|
||||
* Get the JDBC value
|
||||
*
|
||||
* @return the value
|
||||
*/
|
||||
public String getValue() {
|
||||
|
@ -12,6 +12,7 @@ public enum SQLType {
|
||||
|
||||
/**
|
||||
* Basic constructor for the SQLType enum
|
||||
*
|
||||
* @param value MySQL data type
|
||||
*/
|
||||
SQLType(String value) {
|
||||
@ -20,6 +21,7 @@ public enum SQLType {
|
||||
|
||||
/**
|
||||
* Get the value of the chosen enum
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getValue() {
|
||||
|
@ -11,6 +11,7 @@ public class TableField {
|
||||
|
||||
/**
|
||||
* Basic constructor of the {@link TableField}
|
||||
*
|
||||
* @param name The name of the field
|
||||
* @param type The type of the field
|
||||
* @param length The length of the field
|
||||
@ -27,6 +28,7 @@ public class TableField {
|
||||
|
||||
/**
|
||||
* Simple constructor of the {@link TableField}
|
||||
*
|
||||
* @param name The name of the field
|
||||
*/
|
||||
public TableField(String name) {
|
||||
@ -42,38 +44,98 @@ public class TableField {
|
||||
|
||||
/**
|
||||
* Gets the name of the field
|
||||
*
|
||||
* @return the name of the field
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the field
|
||||
*
|
||||
* @param name The new name of the field
|
||||
* @return this class
|
||||
*/
|
||||
public TableField setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the type of the field
|
||||
*
|
||||
* @return the type of the field
|
||||
*/
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of the field
|
||||
*
|
||||
* @param type The new type of the field
|
||||
* @return this class
|
||||
*/
|
||||
public TableField setType(String type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of the field (with a sql type)
|
||||
*
|
||||
* @param type The new type of the field
|
||||
* @return this class
|
||||
*/
|
||||
public TableField setType(SQLType type) {
|
||||
this.type = type.getValue();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the length of the field
|
||||
*
|
||||
* @return the length of the field
|
||||
*/
|
||||
public int getLength() {
|
||||
return length != 0 ? length : 255;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the length of the field
|
||||
*
|
||||
* @param length The new length of the field
|
||||
* @return this class
|
||||
*/
|
||||
public TableField setLength(int length) {
|
||||
this.length = length;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the extra of the field
|
||||
*
|
||||
* @return the extra of the field
|
||||
*/
|
||||
public String[] getExtra() {
|
||||
return extra;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the extras of the field
|
||||
*
|
||||
* @param extra The new extras of the field
|
||||
* @return this class
|
||||
*/
|
||||
public TableField setExtra(String[] extra) {
|
||||
this.extra = extra;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the extras of the field as a string
|
||||
*
|
||||
* @return the extras of the field as a string
|
||||
*/
|
||||
public String getExtras() {
|
||||
@ -85,6 +147,7 @@ public class TableField {
|
||||
|
||||
/**
|
||||
* Gets the allowNull variable as sql string
|
||||
*
|
||||
* @return the allowNull variable as sql string
|
||||
*/
|
||||
public String getNullAsSQL() {
|
||||
@ -93,72 +156,16 @@ public class TableField {
|
||||
|
||||
/**
|
||||
* Gets the default value of the field
|
||||
*
|
||||
* @return the default value of the field
|
||||
*/
|
||||
public String getDefaultValue() {
|
||||
return !defaultValue.isEmpty() ? "DEFAULT '" + defaultValue + "'" : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the field is allowed to have a <b>NULL</b>
|
||||
* @return <code>true</code> if the field is <b>NULL</b>, otherwise <code>false</code>
|
||||
*/
|
||||
public boolean isAllowNull() {
|
||||
return allowNull;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name of the field
|
||||
* @param name The new name of the field
|
||||
* @return this class
|
||||
*/
|
||||
public TableField setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of the field
|
||||
* @param type The new type of the field
|
||||
* @return this class
|
||||
*/
|
||||
public TableField setType(String type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the type of the field (with a sql type)
|
||||
* @param type The new type of the field
|
||||
* @return this class
|
||||
*/
|
||||
public TableField setType(SQLType type) {
|
||||
this.type = type.getValue();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the length of the field
|
||||
* @param length The new length of the field
|
||||
* @return this class
|
||||
*/
|
||||
public TableField setLength(int length) {
|
||||
this.length = length;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the allowNull variable of the field
|
||||
* @param allowNull <code>true</code> if you want to allow a <b>NULL</b> in the field, otherwise <code>false</code>
|
||||
* @return this class
|
||||
*/
|
||||
public TableField setAllowNull(boolean allowNull) {
|
||||
this.allowNull = allowNull;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the default value of the field
|
||||
*
|
||||
* @param defaultValue The new default value of the field
|
||||
* @return this class
|
||||
*/
|
||||
@ -168,17 +175,28 @@ public class TableField {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the extras of the field
|
||||
* @param extra The new extras of the field
|
||||
* Checks if the field is allowed to have a <b>NULL</b>
|
||||
*
|
||||
* @return <code>true</code> if the field is <b>NULL</b>, otherwise <code>false</code>
|
||||
*/
|
||||
public boolean isAllowNull() {
|
||||
return allowNull;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the allowNull variable of the field
|
||||
*
|
||||
* @param allowNull <code>true</code> if you want to allow a <b>NULL</b> in the field, otherwise <code>false</code>
|
||||
* @return this class
|
||||
*/
|
||||
public TableField setExtra(String[] extra) {
|
||||
this.extra = extra;
|
||||
public TableField setAllowNull(boolean allowNull) {
|
||||
this.allowNull = allowNull;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the generated sql row
|
||||
*
|
||||
* @return the generated sql row
|
||||
*/
|
||||
public String generateSQLRow() {
|
||||
|
Reference in New Issue
Block a user