diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 0000000..086dfce
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1 @@
+ko_fi: gnmyt
\ No newline at end of file
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..fdb2371
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,17 @@
+name: Java CI
+
+on: [push]
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v2
+ - name: Set up JDK
+ uses: actions/setup-java@v2
+ with:
+ java-version: '11'
+ distribution: 'adopt'
+ - name: Build with Maven
+ run: mvn --batch-mode --update-snapshots verify
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index bcbe4c5..c4016ca 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
/sqltoolkit.iml
/.idea/
+/target
\ No newline at end of file
diff --git a/README.md b/README.md
index b915628..898afc3 100644
--- a/README.md
+++ b/README.md
@@ -15,116 +15,128 @@
MySQL Toolkit
## About The Project
-This is a small project for quickly managing a MySQL database in Java. It makes everyday life with a database much easier.
-### Installation
-1. Clone the repo
- ```sh
- git clone https://github.com/gnmyt/sqltoolkit.git
+This is a small project for quickly managing a MySQL database in Java. It makes your everyday life with a database much
+easier.
+
+### Installation
+
+1. Add the jitpack repository to your `pom.xml`
+ ```xml
+
+
+ jitpack.io
+ https://jitpack.io
+
+
+ ```
+2. Add the dependency to your `pom.xml`
+ ```xml
+
+ com.github.gnmyt
+ sqltoolkit
+ master-SNAPSHOT
+
```
-2. Move the project into a package of your project (in most cases "sql")
-3. Ready! Have fun
-#### Maven coming soon
### Usage Examples
+
1. Create a connection
- - Example of a constructor without optional specifications
+ - Example of creating a connection
```java
MySQLConnection connection = new MySQLConnection(hostname, username, password, database).connect();
```
- - Example of a constructor with setting the logging level
- ```java
- MySQLConnection connection = new MySQLConnection(hostname, username, password, database, LogLevelType.ALL).connect();
- ```
- - Example of a constructor with optional login parameters
- ```java
- MySQLConnection connection = new MySQLConnection(hostname, username, password, database, LoginParam.AUTO_RECONNECT, LoginParam.NO_SSL).connect();
- ```
- #### Logging Levels
- - NONE - Sends nothing
- - LOW - Sends Warnings & Errors
- - ALL - Sends Infos, Warnings & Errors
- #### Login Parameters
- - DEFAULT *(useSSL=false&autoReconnect=true&useUnicode=yes&characterEncoding=UTF-8&useTimezone=true&serverTimezone=UTC)*
- - NO_SSL *(useSSL=false)*
- - USE_SSL *(useSSL=true)*
- - AUTO_RECONNECT *(autoReconnect=true)*
- - UTF8_ENCODING *(characterEncoding=UTF-8)*
- - USE_UNICODE *(useUnicode=yes)*
- - USE_TIMEZONE *(useTimezone=true)*
- - TIMEZONE_UTC *(serverTimezone=UTC)*
-2. Perform a standard SQL query
- - Get a ResultSet
- ```java
- connection.getResultSet("default query", "parameters");
- ```
- - Perform an update
- ```java
- connection.update("query", "parameters");
- ```
+2. Perform a default SQL query
+ - Get a ResultSet
+ ```java
+ connection.getResultSet("SELECT * FROM example WHERE test = ?", "test1");
+ ```
+ - Perform an update
+ ```java
+ connection.update("UPDATE example SET test = ? WHERE abc = ?", "test1", "test2");
+ ```
3. Get something from a table with managers
- 1. Getting a Result (For one result)
- ```java
- String value = connection.getResult("query", "parameters")
- .getString("column");
- ```
- 2. Getting Results (For more than one)
- ```java
- ArrayList list = connection.getResult("query", "parameters")
- .getList("column");
- ```
- 3. Choosing Results
- ```java
- connection
- .selectFrom("table")
- .where("column", "value")
- .limit(10)
- .getResult();
- ```
- 4. Choosing Results + Print the current statement
- ```java
- connection.select()
- .from("table")
+ 1. Getting a string from the table
+ ```java
+ String value = connection.getResult("query", "parameters")
+ .getString("column");
+ ```
+ 2. Getting a list from the table
+ ```java
+ ArrayList list = connection.getResult("query", "parameters")
+ .getList("column");
+ ```
+ or
+ ```java
+ ArrayList> list = connection.getResult("query", "parameters")
+ .getList();
+ ```
+ 4. Choosing Results
+ ```java
+ connection
+ .selectFrom("table")
.where("column", "value")
- .add("LIMIT 2,5")
- .printStatement();
- ```
+ .limit(10)
+ .getResult();
+ ```
4. Perform an update using managers
- 1. Update a Table
- ```java
- connection
- .update()
- .toTable("table")
- .where("column", "value")
- .set("column", "newValue")
- .update();
- ```
- 2. Generate a Table
- ```java
- connection
- .update()
- .generateTable("table")
- .useID()
- .addField(new SQLField(SQLType.STRING, "column", 999))
- .addField(new SQLField(SQLType.STRING, "column2", 25))
- .create();
- ```
-
-
+ 1. Update a Table
+ ```java
+ connection
+ .updateTo("table")
+ .where("column", "value")
+ .set("column", "newValue")
+ .execute();
+ ```
+ 2. Generate a Table
+ ```java
+ connection
+ .generateTable("table")
+ .addField(SQLType.STRING, "column")
+ .addField(SQLType.INTEGER, "column2", 2)
+ .create();
+ ```
+ 3. Delete something from a table
+ ```java
+ connection
+ .deleteFrom("table")
+ .where("column", "value")
+ .execute();
+ ```
+ 4. Insert something into a table
+ ```java
+ connection
+ .insertTo("table")
+ .value("username", "GNM")
+ .value("email", "germannewsmaker@gmail.com")
+ .execute();
+ ```
+You can find other examples in the [examples directory](src/examples/java).
+
## License
Distributed under the MIT License. See `LICENSE` for more information.
## End
-Currently there are not many features yet, so feel free to write me some suggestions!
+
+Currently, there are not many features, so feel free to write me some suggestions!
[contributors-shield]: https://img.shields.io/github/contributors/gnmyt/sqltoolkit.svg?style=for-the-badge
+
[contributors-url]: https://github.com/gnmyt/sqltoolkit/graphs/contributors
+
[forks-shield]: https://img.shields.io/github/forks/gnmyt/sqltoolkit.svg?style=for-the-badge
+
[forks-url]: https://github.com/gnmyt/sqltoolkit/network/members
+
[stars-shield]: https://img.shields.io/github/stars/gnmyt/sqltoolkit.svg?style=for-the-badge
+
[stars-url]: https://github.com/gnmyt/sqltoolkit/stargazers
+
[issues-shield]: https://img.shields.io/github/issues/gnmyt/sqltoolkit.svg?style=for-the-badge
+
[issues-url]: https://github.com/gnmyt/sqltoolkit/issues
+
[license-shield]: https://img.shields.io/github/license/gnmyt/sqltoolkit.svg?style=for-the-badge
-[license-url]: https://github.com/gnmyt/sqltoolkit/blob/master/LICENSE.txt
+
+[license-url]: https://github.com/gnmyt/sqltoolkit/blob/master/LICENSE
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 8ef4ba1..c856848 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
de.gnmyt
SQLToolkit
- 1.0
+ 2.0
8
@@ -14,11 +14,28 @@
+
+
mysql
mysql-connector-java
8.0.25
+
+
+
+ org.slf4j
+ slf4j-api
+ 1.7.32
+
+
+
+
+ org.slf4j
+ slf4j-simple
+ 1.7.32
+
+
\ No newline at end of file
diff --git a/src/examples/java/LoginExample.java b/src/examples/java/LoginExample.java
new file mode 100644
index 0000000..5534e19
--- /dev/null
+++ b/src/examples/java/LoginExample.java
@@ -0,0 +1,26 @@
+import de.gnmyt.sqltoolkit.drivers.MySQLConnection;
+
+public class LoginExample {
+
+ public static void main(String[] args) {
+
+ // First we can define the mysql server data into some variables
+ String hostname = "localhost";
+ String username = "root";
+ String password = "password";
+ String database = "database";
+
+ // Then we need to create a connection
+ MySQLConnection connection = new MySQLConnection(hostname, username, password, database); // Here you need to provide your mysql server data
+
+ // You can now set the settings of the connection (before connecting)
+ connection.updateSettings()
+ .useSSL(true) // You can set for example the ssl property
+ .customProperty("example", "value"); // You can also set a custom property
+
+
+ // Now you can connect to the database
+ connection.connect();
+ }
+
+}
diff --git a/src/examples/java/QueryExample.java b/src/examples/java/QueryExample.java
new file mode 100644
index 0000000..572c3e9
--- /dev/null
+++ b/src/examples/java/QueryExample.java
@@ -0,0 +1,60 @@
+import de.gnmyt.sqltoolkit.drivers.MySQLConnection;
+import de.gnmyt.sqltoolkit.queries.DeletionQuery;
+import de.gnmyt.sqltoolkit.queries.InsertQuery;
+import de.gnmyt.sqltoolkit.queries.SelectionQuery;
+import de.gnmyt.sqltoolkit.querybuilder.QueryParameter;
+import de.gnmyt.sqltoolkit.querybuilder.SQLQuery;
+
+import java.util.HashMap;
+
+public class QueryExample {
+
+ public static void main(String[] args) {
+
+ // First we need to connect to our database
+ MySQLConnection connection = new MySQLConnection("localhost", "root", "password", "database");
+
+ // We then can create a hashmap with all where-parameters
+ HashMap whereList = new HashMap<>();
+
+ // Now we can add some values to the 'where'-list
+ whereList.put("username", "GNM");
+ whereList.put("email", "germannewsmaker@gmail.com");
+
+ // Now we can create an example 'select'-query
+ SQLQuery query = connection.createQuery(SelectionQuery.class) // Here you can provide which query you want to create
+ .addParameter(QueryParameter.TABLE_NAME, "example_table") // Now we can pass in the table name
+ .addParameter(QueryParameter.WHERE_LIST, whereList) // And the list of 'where'-parameters
+ .build(); // Then we build the query
+
+ // You can then execute it
+ connection.getResult(query);
+
+ // Or print it
+ System.out.println(query);
+
+ // You can also create a 'delete'-query
+
+ SQLQuery deleteQuery = connection.createQuery(DeletionQuery.class) // Now we try the deletion query
+ .addParameter(QueryParameter.TABLE_NAME, "example_table") // Here you can pass in the table name
+ .addParameter(QueryParameter.WHERE_LIST, whereList) // For the example we are using the same list as before
+ .build(); // And now we build the query
+
+ // You can also create for example a 'insert'-query
+
+ // Because we want to insert values into a table we first need to create the list of values
+ HashMap insertValues = new HashMap<>();
+
+ // Now we can put add some values to the 'insert'-list
+ insertValues.put("username", "GNM");
+ insertValues.put("email", "germannewsmaker@gmail.com");
+ insertValues.put("password", "example123!");
+
+ // And then we can create the query
+ SQLQuery insertQuery = connection.createQuery(InsertQuery.class) // Now we try the insert query
+ .addParameter(QueryParameter.TABLE_NAME, "example_table") // Here you can pass in the table name
+ .addParameter(QueryParameter.VALUE_LIST, insertValues) // And now we pass in the value list
+ .build();
+ }
+
+}
diff --git a/src/examples/java/StorageMediumExample.java b/src/examples/java/StorageMediumExample.java
new file mode 100644
index 0000000..28610aa
--- /dev/null
+++ b/src/examples/java/StorageMediumExample.java
@@ -0,0 +1,80 @@
+import de.gnmyt.sqltoolkit.drivers.MySQLConnection;
+import de.gnmyt.sqltoolkit.storage.SQLStorageMedium;
+
+public class StorageMediumExample {
+
+ public static void main(String[] args) {
+
+ // First we need to connect to the mysql database
+ MySQLConnection connection = new MySQLConnection("localhost", "root", "password", "database").connect();
+
+ // Then we can register our user table
+ connection.getTableFactory().register(new StorageMediumExample.ConfigurationStorage(connection));
+
+ // Now we can get the storage from our table factory
+ ConfigurationStorage storage = (ConfigurationStorage) connection.getTableFactory().getStorage(ConfigurationStorage.class);
+
+ // Here we can use the methods that we created in the storage
+ storage.updateLanguage("en");
+ storage.updateVersion("1.0");
+
+ // We can also get a value by using the storage medium
+ String version = storage.getVersion();
+
+ // If you want to you can list all entries from the current storage
+ storage.getEntries().forEach(entry ->
+ System.out.println(entry.get("keyName") + " -> " + entry.get("value")));
+ }
+
+
+ public static class ConfigurationStorage extends SQLStorageMedium {
+
+ public ConfigurationStorage(MySQLConnection connection) {
+ super(connection);
+ }
+
+ @Override
+ protected String tableName() {
+ return "config_storage";
+ }
+
+ // Here we can add some example methods to test the storage medium
+
+ /**
+ * Updates the language of the configuration storage
+ *
+ * @param newLanguage The new language
+ */
+ public void updateLanguage(String newLanguage) {
+ insertOrUpdate("language", newLanguage);
+ }
+
+ /**
+ * Gets the current language of the configuration storage
+ *
+ * @return The current language of the configuration storage
+ */
+ public String getLanguage() {
+ return get("language");
+ }
+
+ /**
+ * Updates the version of the configuration storage
+ *
+ * @param newVersion The new version
+ */
+ public void updateVersion(String newVersion) {
+ insertOrUpdate("version", newVersion);
+ }
+
+ /**
+ * Gets the current version of the configuration storage
+ *
+ * @return The current version of the configuration storage
+ */
+ public String getVersion() {
+ return get("version");
+ }
+ }
+
+}
diff --git a/src/examples/java/TableExample.java b/src/examples/java/TableExample.java
new file mode 100644
index 0000000..7e60ce5
--- /dev/null
+++ b/src/examples/java/TableExample.java
@@ -0,0 +1,96 @@
+import de.gnmyt.sqltoolkit.drivers.MySQLConnection;
+import de.gnmyt.sqltoolkit.storage.SQLTable;
+import de.gnmyt.sqltoolkit.types.SQLType;
+import de.gnmyt.sqltoolkit.types.TableField;
+
+public class TableExample {
+
+ private static MySQLConnection connection;
+
+ public static void main(String[] args) {
+
+ // First we need to connect to the mysql database
+ connection = new MySQLConnection("localhost", "root", "password", "database").connect();
+
+ // Then we can register our user table
+ connection.getTableFactory().register(new UserTable(connection));
+
+ // Now let's create some users
+ createUser("GNM", "germannewsmaker@gmail.com", "Mathias");
+
+ createUser("delete_me", "deleteme@example.com", "DeleteMe");
+
+ // Here we can get the email of our user before we delete him
+ String email = getUserMail("delete_me");
+
+ // Now we can delete this user
+ deleteUser("delete_me");
+ }
+
+ /**
+ * Creates a user in the user table
+ *
+ * @param username The name of the user (nickname)
+ * @param email The email of the user
+ * @param first_name The first name of the user
+ */
+ public static void createUser(String username, String email, String first_name) {
+ SQLTable userTable = connection.getTableFactory().getTable(UserTable.class);
+
+ userTable.insert()
+ .value("username", username)
+ .value("email", email)
+ .value("first_name", first_name)
+ .execute();
+ }
+
+ /**
+ * Deletes a user from the user table
+ *
+ * @param username The name of the user
+ */
+ public static void deleteUser(String username) {
+ SQLTable userTable = connection.getTableFactory().getTable(UserTable.class);
+
+ userTable.delete()
+ .where("username", username)
+ .execute();
+ }
+
+ /**
+ * Gets the email of the user
+ *
+ * @param username The name of the user
+ * @return the email of the user
+ */
+ public static String getUserMail(String username) {
+ SQLTable userTable = connection.getTableFactory().getTable(UserTable.class);
+
+ return userTable.select()
+ .where("username", username)
+ .getResult()
+ .getString("email");
+ }
+
+ public static class UserTable extends SQLTable {
+
+ public UserTable(MySQLConnection connection) {
+ super(connection);
+ }
+
+ @Override
+ protected String tableName() {
+ return "users";
+ }
+
+ @Override
+ protected void tableFields() {
+ string("username", 255, "");
+ custom(new TableField().setType(SQLType.STRING).setName("email").setLength(25).setDefaultValue("test@example.com"));
+ custom("password").type(SQLType.STRING).allowNull(true).length(80).add();
+ custom().name("first_name").add();
+ }
+
+ }
+
+}
diff --git a/src/main/java/de/gnmyt/SQLToolkit/api/SQLConsumer.java b/src/main/java/de/gnmyt/SQLToolkit/api/SQLConsumer.java
deleted file mode 100644
index c37ee53..0000000
--- a/src/main/java/de/gnmyt/SQLToolkit/api/SQLConsumer.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package de.gnmyt.SQLToolkit.api;
-
-import java.sql.SQLException;
-
-/********************************
- * @author Mathias Wagner
- * Created 25.12.2020
- *******************************/
-
-@FunctionalInterface
-public interface SQLConsumer {
- void accept(T t) throws SQLException;
-}
diff --git a/src/main/java/de/gnmyt/SQLToolkit/drivers/MySQLConnection.java b/src/main/java/de/gnmyt/SQLToolkit/drivers/MySQLConnection.java
deleted file mode 100755
index 896685f..0000000
--- a/src/main/java/de/gnmyt/SQLToolkit/drivers/MySQLConnection.java
+++ /dev/null
@@ -1,286 +0,0 @@
-package de.gnmyt.SQLToolkit.drivers;
-
-import de.gnmyt.SQLToolkit.api.SQLConsumer;
-import de.gnmyt.SQLToolkit.manager.InsertManager;
-import de.gnmyt.SQLToolkit.manager.ResultManager;
-import de.gnmyt.SQLToolkit.manager.DataBaseSelection;
-import de.gnmyt.SQLToolkit.manager.UpdateManager;
-import de.gnmyt.SQLToolkit.types.LogLevelType;
-import de.gnmyt.SQLToolkit.types.LoginParam;
-
-import java.sql.*;
-
-/********************************
- * @author Mathias Wagner
- * Created 23.12.2020
- ********************************/
-
-public class MySQLConnection {
-
- private final String hostname;
- private final String username;
- private final String password;
- private final String database;
- private String tablePrefix = "";
- private String tablePrefixVariable = "";
- private String connectString = "";
- public static Connection con;
- private final SqlLogManager sqlLogManager;
-
- /**
- * Update the Connection String
- * @param loginParams New login parameters
- * @return this class
- */
- public MySQLConnection updateConnectString(LoginParam... loginParams) {
- this.connectString = getConnectionString(loginParams);
- return this;
- }
-
- /**
- * Set the Connection String
- * @param tablePrefixVariable New table prefix variable
- * @return this class
- */
- public MySQLConnection setTablePrefixVariable(String tablePrefixVariable) {
- this.tablePrefixVariable = tablePrefixVariable;
- return this;
- }
-
- /**
- * Set the current table Prefix
- * @param tablePrefix New table prefix
- * @return this class
- */
- public MySQLConnection setTablePrefix(String tablePrefix) {
- this.tablePrefix = tablePrefix;
- return this;
- }
-
- /**
- * Get the current table Prefix
- * @return the prefix
- */
- public String getTablePrefix() {
- return tablePrefix;
- }
-
- /**
- * Get the current jdbc connection string for mysql
- * @param loginParams login parameters
- * @return the string
- */
- private String getConnectionString(LoginParam[] loginParams) {
- boolean used = false;StringBuilder currentString = new StringBuilder();
- for (LoginParam param : loginParams) {
- String currentChar = (used) ? "&" : "?";used = true;
- currentString.append(currentChar).append(param.getValue());
- }
- return currentString.toString();
- }
-
- /**
- * Check if you are connected
- * @return status of the connection
- */
- public boolean isConnected() {
- return (con != null);
- }
-
- /**
- * Get the SQL Log Manager and adjust it how you like it
- * @return the SQL Log Manager
- */
- public SqlLogManager getLogManager() {
- return sqlLogManager;
- }
-
- /**
- * Basic constructor for the Connection
- * @param hostname MySQL server hostname
- * @param username MySQL server username
- * @param password MySQL server password
- * @param database MySQL server database
- * @param logLevel Logging level
- * @param loginParams Login parameters
- */
- public MySQLConnection(String hostname, String username, String password, String database, LogLevelType logLevel, LoginParam... loginParams) {
- this.hostname = hostname;
- this.username = username;
- this.password = password;
- this.database = database;
- this.sqlLogManager = new SqlLogManager();
- updateConnectString(loginParams);
- setLogLevelType(logLevel);
- }
-
- /**
- * Basic constructor for the Connection
- * @param hostname MySQL server hostname
- * @param username MySQL server username
- * @param password MySQL server password
- * @param database MySQL server database
- * @param loginParams Login parameters
- */
- public MySQLConnection(String hostname, String username, String password, String database, LoginParam... loginParams) {
- this.hostname = hostname;
- this.username = username;
- this.password = password;
- this.database = database;
- this.sqlLogManager = new SqlLogManager();
- updateConnectString(loginParams);
- setLogLevelType(LogLevelType.NONE);
- }
-
- /**
- * Set a new logging level
- * @param logLevelType New logging level
- * @return this class
- */
- public MySQLConnection setLogLevelType(LogLevelType logLevelType) {
- this.sqlLogManager.setLogLevelType(logLevelType);
- return this;
- }
-
- /**
- * Get a result from your server
- * @param query Search query
- * @param params Optional parameters
- * @return ResultSet
- */
- public ResultSet getResultSet(String query, Object... params) {
- query = (tablePrefix.isEmpty()) ? query : query.replace((tablePrefixVariable.isEmpty()) ? "$tp" : tablePrefixVariable, tablePrefix);
- try { int start = 1;
- PreparedStatement ps = con.prepareStatement(query);
- for (Object current : params) { ps.setObject(start, current);start++; }
- return ps.executeQuery();
- } catch (Exception err) {
- sqlLogManager.sendError(err.getMessage());
- }
- return null;
- }
-
- /**
- * Get a result from your server (get the Manager)
- * @param query Search query
- * @param params Optional parameters
- * @return ResultManager
- */
- public ResultManager getResult(String query, Object... params) {
- return new ResultManager(getResultSet(query, params), sqlLogManager);
- }
-
- /**
- * Run a action with a result from your server
- * @param query Search query
- * @param consumer consumer
- * @param params Optional parameters
- */
- public void getResult(String query, SQLConsumer consumer, Object... params) {
- try {
- ResultSet resultSet = getResultSet(query, params);
- consumer.accept(resultSet);
- resultSet.close();
- } catch (Exception ignored) {}
- }
-
- /**
- * Update something on your server by query
- * @param query Update query
- * @param params Optional parameters
- * @return this class
- */
- public MySQLConnection update(String query, Object... params) {
- query = (tablePrefix.isEmpty()) ? query : query.replace((tablePrefixVariable.isEmpty()) ? "$tp" : tablePrefixVariable, tablePrefix);
- try { int start = 1;
- PreparedStatement ps = con.prepareStatement(query);
- for (Object current : params) { ps.setObject(start, current);start++; }
- ps.executeUpdate();
- } catch (Exception err) { err.printStackTrace(); }
- return this;
- }
-
- /**
- * Get the update de.gnmyt.SQLToolkit.manager for easier updating
- * @return Update de.gnmyt.SQLToolkit.manager
- */
- public UpdateManager update() {
- return new UpdateManager(this);
- }
-
- /**
- * Get the update de.gnmyt.SQLToolkit.manager for easier updating (pre filled table)
- * @param tableName The name of the table
- * @return Update de.gnmyt.SQLToolkit.manager
- */
- public UpdateManager updateTable(String tableName) {
- return new UpdateManager(this, tableName);
- }
-
- /**
- * Get the Database Selection for easier selection of tables (pre filled table)
- * @param tableName The name of the table
- * @return DatabaseSelection
- */
- public DataBaseSelection selectFrom(String tableName) {
- return new DataBaseSelection(this, tableName);
- }
-
- /**
- * Get the Database Selection for easier selection of tables
- * @return DatabaseSelection
- */
- public DataBaseSelection select() {
- return new DataBaseSelection(this);
- }
-
- /**
- * Get the InsertManager for easier inserting to a table
- * @return InsertManager
- */
- public InsertManager insert() {
- return new InsertManager(this);
- }
-
- /**
- * Get the InsertManager for easier inserting to a table
- * @param tableName The name of the table you want to insert a object
- * @return InsertManager
- */
- public InsertManager insertTo(String tableName) {
- return new InsertManager(this, tableName);
- }
-
- /**
- * Connect with your MySQL server
- * @return this class
- */
- public MySQLConnection connect() {
- if (!isConnected()) { try {
- sqlLogManager.sendInfo("Connecting to " + hostname + " with user " + username + " to database " + database);
- Class.forName("com.mysql.cj.jdbc.Driver");
- con = DriverManager.getConnection("jdbc:mysql://" + hostname + "/" + database + connectString, username, password);
- sqlLogManager.sendInfo("Connection established");
- } catch (Exception exception) {
- if (exception.getMessage().contains("jdbc.Driver"))
- sqlLogManager.sendError("MySQL driver not found! Check your dependencies or install the JDBC Mysql Driver from https://dev.mysql.com/downloads/file/?id=498587");
- else if (exception.getMessage().contains("has not received any packets")) sqlLogManager.sendError("No packets received from the server.");
- else if (exception.getMessage().contains("denied for user")) sqlLogManager.sendError("Wrong username/password");
- else sqlLogManager.sendError(exception.getMessage());
- }
- } else sqlLogManager.sendWarning("Already connected");
- return this;
- }
-
- /**
- * Disconnect from your MySQL Server
- * @return this class
- */
- public MySQLConnection disconnect() {
- if (isConnected()) { try { con.close();con = null;sqlLogManager.sendInfo("Connection closed");
- } catch (Exception err) { sqlLogManager.sendError(err.getMessage()); }
- } else sqlLogManager.sendWarning("Not connected. Please connect first");
- return this;
- }
-
-}
diff --git a/src/main/java/de/gnmyt/SQLToolkit/drivers/SqlLogManager.java b/src/main/java/de/gnmyt/SQLToolkit/drivers/SqlLogManager.java
deleted file mode 100755
index 8cfc8f0..0000000
--- a/src/main/java/de/gnmyt/SQLToolkit/drivers/SqlLogManager.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package de.gnmyt.SQLToolkit.drivers;
-
-import de.gnmyt.SQLToolkit.types.LogLevelType;
-
-import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
-
-/********************************
- * @author Mathias Wagner
- * Created 23.12.2020
- ********************************/
-
-public class SqlLogManager {
-
- private LogLevelType logLevelType;
- private String logFormat = "[%date » MySQL %type] %msg";
-
- /**
- * Sets the Log Level
- * @param logLevelType Logging Level
- */
- public void setLogLevelType(LogLevelType logLevelType) {
- this.logLevelType = logLevelType;
- }
-
- /**
- * Format for the Message
- * @param logFormat The Formatted String
- */
- public void setLogFormat(String logFormat) {
- this.logFormat = logFormat;
- }
-
- /**
- * Getting the Logging Level
- * @return LogLevelType
- */
- public LogLevelType getLogLevelType() {
- return logLevelType;
- }
-
- /**
- * Send an information
- * @param msg The provided message
- */
- public void sendInfo(String msg) {
- if (logLevelType == LogLevelType.ALL)
- sendLog("Info", msg);
- }
-
- /**
- * Send an Warning
- * @param msg The provided message
- */
- public void sendWarning(String msg) {
- if (logLevelType == LogLevelType.ALL || logLevelType == LogLevelType.LOW)
- sendLog("Warning", msg);
- }
-
- /**
- * Send an Error
- * @param msg The provided message
- */
- public void sendError(String msg) {
- if (logLevelType == LogLevelType.ALL || logLevelType == LogLevelType.LOW) {
- StackTraceElement[] st = Thread.currentThread().getStackTrace();
- StackTraceElement stack = st[st.length-1];
- sendLog("Error", "<"+stack.getFileName()+":"+stack.getLineNumber()+"> "+msg);
- }
- }
-
- /**
- * Intern Logging Feature
- * @param prefix Logging Prefix
- * @param msg The provided message
- */
- private void sendLog(String prefix, String msg) {
- String formatted = logFormat.replace("%type", prefix).replace("%date", getDate()).replace("%msg", msg);
- System.out.println(formatted);
- }
-
- /**
- * Getting the date
- * @return Datetime
- */
- private String getDate() {
- DateTimeFormatter dtf = DateTimeFormatter.ofPattern("H:m:s");
- LocalDateTime dt = LocalDateTime.now();
- return dtf.format(dt);
- }
-
-}
diff --git a/src/main/java/de/gnmyt/SQLToolkit/fields/SQLField.java b/src/main/java/de/gnmyt/SQLToolkit/fields/SQLField.java
deleted file mode 100644
index 1fb48c0..0000000
--- a/src/main/java/de/gnmyt/SQLToolkit/fields/SQLField.java
+++ /dev/null
@@ -1,110 +0,0 @@
-package de.gnmyt.SQLToolkit.fields;
-
-import de.gnmyt.SQLToolkit.types.SQLType;
-
-/********************************
- * @author Mathias Wagner
- * Created 23.12.2020
- ********************************/
-
-public class SQLField {
-
- private String name = "";
- private String defaultValue = "";
- private String optionalParameter = "";
- private Integer length = 0;
- private SQLType sqlType;
-
- /**
- * Basic constructor for the SQL field
- * @param sqlType Type of the SQL field
- * @param name Name of the SQL field
- * @param length Length of the SQL field
- */
- public SQLField(SQLType sqlType, String name, Integer length) {
- this.name = name;
- this.sqlType = sqlType;
- this.length = length;
- }
-
- /**
- * Set the default value for the SQL field
- * @param defaultValue New default value
- * @return this class
- */
- public SQLField setDefaultValue(String defaultValue) {
- this.defaultValue = defaultValue;
- return this;
- }
-
- /**
- * Set optional parameter for the SQL field
- * @param optionalParameter New optional parameter
- * @return this class
- */
- public SQLField setOptionalParameter(String optionalParameter) {
- this.optionalParameter = optionalParameter;
- return this;
- }
-
- /**
- * Set the length of the SQL field
- * @param length New length
- * @return this class
- */
- public SQLField setLength(Integer length) {
- this.length = length;
- return this;
- }
-
- /**
- * Set the name of the SQL field
- * @param name New name
- * @return this class
- */
- public SQLField setName(String name) {
- this.name = name;
- return this;
- }
-
- /**
- * Get the length of the SQL Field
- * @return length
- */
- public Integer getLength() {
- return length;
- }
-
- /**
- * Get the default value of the SQL Field
- * @return default value
- */
- public String getDefaultValue() {
- return defaultValue;
- }
-
- /**
- * Get the optional parameters of the SQL Field
- * @return this class
- */
- public String getOptionalParameter() {
- return optionalParameter;
- }
-
- /**
- * Get the name of the SQL Field
- * @return name
- */
- public String getName() {
- return name;
- }
-
- /**
- * Get the SQL Type of the SQL Field
- * @return SQL Type
- */
- public SQLType getSqlType() {
- return sqlType;
- }
-
-}
diff --git a/src/main/java/de/gnmyt/SQLToolkit/generator/TableGenerator.java b/src/main/java/de/gnmyt/SQLToolkit/generator/TableGenerator.java
deleted file mode 100644
index 13dd9bb..0000000
--- a/src/main/java/de/gnmyt/SQLToolkit/generator/TableGenerator.java
+++ /dev/null
@@ -1,84 +0,0 @@
-package de.gnmyt.SQLToolkit.generator;
-
-import de.gnmyt.SQLToolkit.drivers.MySQLConnection;
-import de.gnmyt.SQLToolkit.fields.SQLField;
-import de.gnmyt.SQLToolkit.manager.UpdateManager;
-
-import java.util.ArrayList;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/********************************
- * @author Mathias Wagner
- * Created 23.12.2020
- ********************************/
-
-public class TableGenerator {
-
- private UpdateManager updateManager;
- private ArrayList fields;
- private boolean useID;
- private String tableName;
- MySQLConnection connection;
-
- /**
- * Basic constructor for the TableGenerator
- * @param updateManager Existing update de.gnmyt.SQLToolkit.manager
- * @param tableName Name of the table
- */
- public TableGenerator(UpdateManager updateManager, String tableName) {
- this.updateManager = updateManager;
- this.tableName = tableName;
- this.fields = new ArrayList<>();
- connection = updateManager.getConnection();
- }
-
- /**
- * Add an 'id' field to the Table
- * @return this class
- */
- public TableGenerator useID() {
- this.useID = true;
- return this;
- }
-
- /**
- * Add a field to the Table
- * @param field String of the field
- * @return this class
- */
- public TableGenerator addField(String field) {
- fields.add(field);
- return this;
- }
-
- /**
- * Add a field to the Table
- * @param field Existing SQL Field
- * @return this class
- */
- public TableGenerator addField(SQLField field) {
- String temp = "";
- temp += "`" + field.getName() + "` " + field.getSqlType().getValue() + "(" + field.getLength() + ")";
- temp += !field.getDefaultValue().isEmpty() ? " DEFAULT '" + field.getDefaultValue() + "'" : "";
- temp += !field.getOptionalParameter().isEmpty() ? " " + field.getOptionalParameter() : "";
- fields.add(temp);
- return this;
- }
-
- /**
- * Create the table you wanted
- * @return this class
- */
- public TableGenerator create() {
- StringBuilder sb = new StringBuilder();
- sb.append("CREATE TABLE IF NOT EXISTS " + tableName + " ( ");
- AtomicBoolean used = new AtomicBoolean(false);
- if (useID) sb.append(used.get() ? ", " : "").append("`id` INT(255) NOT NULL AUTO_INCREMENT");used.set(true);
- fields.forEach(string -> { sb.append(used.get() ? ", " : "").append(string);used.set(true); });
- if (useID) sb.append(used.get() ? ", " : "").append("PRIMARY KEY (`id`)");used.set(true);
- sb.append(" ) ENGINE = InnoDB;");
- connection.update(sb.toString());
- return this;
- }
-
-}
diff --git a/src/main/java/de/gnmyt/SQLToolkit/manager/DataBaseSelection.java b/src/main/java/de/gnmyt/SQLToolkit/manager/DataBaseSelection.java
deleted file mode 100644
index dd22b42..0000000
--- a/src/main/java/de/gnmyt/SQLToolkit/manager/DataBaseSelection.java
+++ /dev/null
@@ -1,160 +0,0 @@
-package de.gnmyt.SQLToolkit.manager;
-
-import de.gnmyt.SQLToolkit.drivers.MySQLConnection;
-
-import java.sql.ResultSet;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/********************************
- * @author Mathias Wagner
- * Created 23.12.2020
- ********************************/
-
-public class DataBaseSelection {
-
- private final MySQLConnection connection;
- private final HashMap whereList;
- private final ArrayList