diff --git a/pandalib-db/pom.xml b/pandalib-db/pom.xml
index ef86f6e..df38184 100644
--- a/pandalib-db/pom.xml
+++ b/pandalib-db/pom.xml
@@ -19,7 +19,75 @@
pandalib-util
${project.version}
-
+
+ org.apache.commons
+ commons-dbcp2
+ 2.9.0
+
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.3.0
+
+
+ package
+
+ shade
+
+
+
+
+ org.apache.commons:commons-dbcp2
+ org.apache.commons:commons-pool2
+ commons-logging:commons-logging
+
+
+
+
+ org.apache.commons:commons-dbcp2
+
+ META-INF/MANIFEST.MF
+
+
+
+ org.apache.commons:commons-pool2
+
+ META-INF/MANIFEST.MF
+
+
+
+ commons-logging:commons-logging
+
+ META-INF/MANIFEST.MF
+
+
+
+
+
+ org.apache.commons
+ fr.pandacube.lib.db.shaded.commons
+
+
+ org.apache.commons
+ fr.pandacube.lib.db.shaded.commons
+
+
+
+
+
+
+ false
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pandalib-db/src/main/java/fr/pandacube/lib/db/DB.java b/pandalib-db/src/main/java/fr/pandacube/lib/db/DB.java
index 1d3b13c..6293ba0 100644
--- a/pandalib-db/src/main/java/fr/pandacube/lib/db/DB.java
+++ b/pandalib-db/src/main/java/fr/pandacube/lib/db/DB.java
@@ -1,5 +1,6 @@
package fr.pandacube.lib.db;
+import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -17,7 +18,7 @@ import fr.pandacube.lib.util.Log;
/**
* Static class to handle most of the database operations.
- *
+ *
* To use this database library, first call {@link #init(DBConnection, String)} with an appropriate {@link DBConnection},
* then you can initialize every table you need for your application, using {@link #initTable(Class)}.
*
@@ -25,370 +26,606 @@ import fr.pandacube.lib.util.Log;
*/
public final class DB {
- private static final List>> tables = new ArrayList<>();
- private static final Map>, String> tableNames = new HashMap<>();
+ private static final List>> tables = new ArrayList<>();
+ private static final Map>, String> tableNames = new HashMap<>();
- private static DBConnection connection;
- /* package */ static String tablePrefix = "";
+ private static DBConnection connection;
+ /* package */ static String tablePrefix = "";
- public static DBConnection getConnection() {
- return connection;
- }
+ /**
+ * Gets the {@link DBConnection}.
+ * @return the {@link DBConnection}.
+ */
+ public static DBConnection getConnection() {
+ return connection;
+ }
- public synchronized static void init(DBConnection conn, String tablePrefix) {
- connection = conn;
- DB.tablePrefix = Objects.requireNonNull(tablePrefix);
- }
+ /**
+ * Initialize with the provided connection.
+ * @param conn the database connection.
+ * @param tablePrefix determine a prefix for the table that will be initialized.
+ */
+ public synchronized static void init(DBConnection conn, String tablePrefix) {
+ connection = conn;
+ DB.tablePrefix = Objects.requireNonNull(tablePrefix);
+ }
- public static synchronized > void initTable(Class elemClass) throws DBInitTableException {
- if (connection == null) {
- throw new DBInitTableException(elemClass, "Database connection is not yet initialized.");
- }
- if (tables.contains(elemClass)) return;
- try {
- tables.add(elemClass);
- Log.debug("[DB] Start Init SQL table "+elemClass.getSimpleName());
- E instance = elemClass.getConstructor().newInstance();
- String tableName = tablePrefix + instance.tableName();
- tableNames.put(elemClass, tableName);
- if (!tableExistInDB(tableName)) createTable(instance);
- Log.debug("[DB] End init SQL table "+elemClass.getSimpleName());
- } catch (Exception|ExceptionInInitializerError e) {
- throw new DBInitTableException(elemClass, e);
- }
- }
+ /**
+ * Initialialize the table represented by the provided class.
+ * @param elemClass the class representing a table.
+ * @param the type representing the table.
+ * @throws DBInitTableException if the table failed to initialized.
+ */
+ public static synchronized > void initTable(Class elemClass) throws DBInitTableException {
+ if (connection == null) {
+ throw new DBInitTableException(elemClass, "Database connection is not yet initialized.");
+ }
+ if (tables.contains(elemClass)) return;
+ try {
+ tables.add(elemClass);
+ Log.debug("[DB] Start Init SQL table "+elemClass.getSimpleName());
+ E instance = elemClass.getConstructor().newInstance();
+ String tableName = tablePrefix + instance.tableName();
+ tableNames.put(elemClass, tableName);
+ if (!tableExistInDB(tableName)) createTable(instance);
+ Log.debug("[DB] End init SQL table "+elemClass.getSimpleName());
+ } catch (Exception|ExceptionInInitializerError e) {
+ throw new DBInitTableException(elemClass, e);
+ }
+ }
- private static > void createTable(E elem) throws SQLException {
-
- String tableName = tablePrefix + elem.tableName();
+ private static > void createTable(E elem) throws SQLException {
- StringBuilder sql = new StringBuilder("CREATE TABLE IF NOT EXISTS " + tableName + " (");
- List