[FEAT] refacto the configuration method

This commit is contained in:
Edouard DUPIN 2024-12-15 08:22:43 +01:00
parent 4d99835a6a
commit 0e88823094
41 changed files with 404 additions and 355 deletions

View File

@ -1,28 +0,0 @@
package org.kar.archidata;
import org.kar.archidata.db.DBConfig;
import org.kar.archidata.exception.DataAccessException;
import org.kar.archidata.tools.ConfigBaseVariable;
public class GlobalConfiguration {
private static final DBConfig dbConfig;
static {
DBConfig dbConfigTmp = null;
try {
dbConfigTmp = new DBConfig(ConfigBaseVariable.getDBType(), ConfigBaseVariable.getDBHost(),
Integer.parseInt(ConfigBaseVariable.getDBPort()), ConfigBaseVariable.getDBLogin(),
ConfigBaseVariable.getDBPassword(), ConfigBaseVariable.getDBName(),
ConfigBaseVariable.getDBKeepConnected());
} catch (NumberFormatException | DataAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Fail to configure db access ... in static GlobalConfiguration");
}
dbConfig = dbConfigTmp;
}
public static DBConfig getDbconfig() {
return dbConfig;
}
}

View File

@ -24,7 +24,7 @@ import javax.imageio.ImageIO;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam; import org.glassfish.jersey.media.multipart.FormDataParam;
import org.kar.archidata.annotation.security.PermitTokenInURI; import org.kar.archidata.annotation.security.PermitTokenInURI;
import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.DataAccess;
import org.kar.archidata.dataAccess.QueryCondition; import org.kar.archidata.dataAccess.QueryCondition;
import org.kar.archidata.dataAccess.options.Condition; import org.kar.archidata.dataAccess.options.Condition;
import org.kar.archidata.exception.FailException; import org.kar.archidata.exception.FailException;
@ -64,7 +64,6 @@ public class DataResource {
private final static int CHUNK_SIZE_IN = 50 * 1024 * 1024; // 1MB chunks private final static int CHUNK_SIZE_IN = 50 * 1024 * 1024; // 1MB chunks
/** Upload some datas */ /** Upload some datas */
private static long tmpFolderId = 1; private static long tmpFolderId = 1;
protected final DBAccess da = DBAccess.createInterface();
private static void createFolder(final String path) throws IOException { private static void createFolder(final String path) throws IOException {
if (!Files.exists(java.nio.file.Path.of(path))) { if (!Files.exists(java.nio.file.Path.of(path))) {
@ -122,7 +121,7 @@ public class DataResource {
public Data getWithSha512(final String sha512) { public Data getWithSha512(final String sha512) {
LOGGER.info("find sha512 = {}", sha512); LOGGER.info("find sha512 = {}", sha512);
try { try {
return this.da.getWhere(Data.class, new Condition(new QueryCondition("sha512", "=", sha512))); return DataAccess.getWhere(Data.class, new Condition(new QueryCondition("sha512", "=", sha512)));
} catch (final Exception e) { } catch (final Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -133,7 +132,7 @@ public class DataResource {
public Data getWithId(final long id) { public Data getWithId(final long id) {
LOGGER.info("find id = {}", id); LOGGER.info("find id = {}", id);
try { try {
return this.da.get(Data.class, id); return DataAccess.get(Data.class, id);
} catch (final Exception e) { } catch (final Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -162,7 +161,7 @@ public class DataResource {
injectedData.size = Files.size(Paths.get(tmpPath)); injectedData.size = Files.size(Paths.get(tmpPath));
try { try {
injectedData = this.da.insert(injectedData); injectedData = DataAccess.insert(injectedData);
} catch (final Exception e) { } catch (final Exception e) {
e.printStackTrace(); e.printStackTrace();
return null; return null;
@ -255,7 +254,7 @@ public class DataResource {
public Data getSmall(final UUID id) { public Data getSmall(final UUID id) {
try { try {
return this.da.get(Data.class, id); return DataAccess.get(Data.class, id);
} catch (final Exception e) { } catch (final Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
@ -502,7 +501,7 @@ public class DataResource {
} }
public void undelete(final Long id) throws Exception { public void undelete(final Long id) throws Exception {
this.da.unsetDelete(Data.class, id); DataAccess.unsetDelete(Data.class, id);
} }
} }

View File

@ -6,18 +6,17 @@ import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.kar.archidata.GlobalConfiguration;
import org.kar.archidata.annotation.AnnotationTools; import org.kar.archidata.annotation.AnnotationTools;
import org.kar.archidata.dataAccess.options.Condition; import org.kar.archidata.dataAccess.options.Condition;
import org.kar.archidata.dataAccess.options.FilterValue; import org.kar.archidata.dataAccess.options.FilterValue;
import org.kar.archidata.dataAccess.options.Limit; import org.kar.archidata.dataAccess.options.Limit;
import org.kar.archidata.dataAccess.options.QueryOption; import org.kar.archidata.dataAccess.options.QueryOption;
import org.kar.archidata.dataAccess.options.TransmitKey; import org.kar.archidata.dataAccess.options.TransmitKey;
import org.kar.archidata.db.DBConfig; import org.kar.archidata.db.DbConfig;
import org.kar.archidata.db.DBInterfaceFactory; import org.kar.archidata.db.DbIo;
import org.kar.archidata.db.DbInterface; import org.kar.archidata.db.DbIoFactory;
import org.kar.archidata.db.DbInterfaceMorphia; import org.kar.archidata.db.DbIoMorphia;
import org.kar.archidata.db.DbInterfaceSQL; import org.kar.archidata.db.DbIoSql;
import org.kar.archidata.exception.DataAccessException; import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -35,48 +34,42 @@ import jakarta.ws.rs.InternalServerErrorException;
* back-end. */ * back-end. */
public abstract class DBAccess implements Closeable { public abstract class DBAccess implements Closeable {
final static Logger LOGGER = LoggerFactory.getLogger(DBAccess.class); final static Logger LOGGER = LoggerFactory.getLogger(DBAccess.class);
public static final DBAccess createInterface() { public static final DBAccess createInterface()
try { throws InternalServerErrorException, IOException, DataAccessException {
return DBAccess.createInterface(GlobalConfiguration.getDbconfig()); return DBAccess.createInterface(DbIoFactory.create());
} catch (InternalServerErrorException | IOException e) {
LOGGER.error("Fail to initialize connection of the DB");
e.printStackTrace();
}
return null;
} }
public static final DBAccess createInterface(final DBConfig config) public static final DBAccess createInterface(final DbConfig config)
throws InternalServerErrorException, IOException { throws InternalServerErrorException, IOException {
final DBInterfaceFactory entry = DBInterfaceFactory.create(config); return DBAccess.createInterface(DbIoFactory.create(config));
return DBAccess.createInterface(entry.getDbInterface());
} }
public static final DBAccess createInterface(final DbInterface io) throws InternalServerErrorException { public static final DBAccess createInterface(final DbIo io) throws InternalServerErrorException {
if (io instanceof final DbInterfaceMorphia ioMorphia) { if (io instanceof final DbIoMorphia ioMorphia) {
return new DBAccessMorphia(ioMorphia); return new DBAccessMorphia(ioMorphia);
} else if (io instanceof final DbInterfaceSQL ioSQL) { } else if (io instanceof final DbIoSql ioSQL) {
return new DBAccessSQL(ioSQL); return new DBAccessSQL(ioSQL);
} }
throw new InternalServerErrorException("unknow DB interface ... "); throw new InternalServerErrorException("unknow DB interface ... ");
} }
public boolean isDBExist(final String name, final QueryOption... option) throws InternalServerErrorException { public boolean isDBExist(final String name, final QueryOption... option) throws InternalServerErrorException {
throw new InternalServerErrorException("Can Not manage the DB-access"); throw new InternalServerErrorException("Can Not manage the DB-access");
} }
public boolean createDB(final String name) { public boolean createDB(final String name) {
throw new InternalServerErrorException("Can Not manage the DB-access"); throw new InternalServerErrorException("Can Not manage the DB-access");
} }
public void deleteDB(final String name) { public void deleteDB(final String name) {
throw new InternalServerErrorException("Can Not manage the DB-access"); throw new InternalServerErrorException("Can Not manage the DB-access");
} }
public boolean isTableExist(final String name, final QueryOption... option) throws InternalServerErrorException { public boolean isTableExist(final String name, final QueryOption... option) throws InternalServerErrorException {
throw new InternalServerErrorException("Can Not manage the DB-access"); throw new InternalServerErrorException("Can Not manage the DB-access");
} }
public <ID_TYPE> QueryCondition getTableIdCondition(final Class<?> clazz, final ID_TYPE idKey) public <ID_TYPE> QueryCondition getTableIdCondition(final Class<?> clazz, final ID_TYPE idKey)
throws DataAccessException { throws DataAccessException {
// Find the ID field type .... // Find the ID field type ....
@ -99,7 +92,7 @@ public abstract class DBAccess implements Closeable {
} }
return new QueryCondition(AnnotationTools.getFieldName(idField), "=", idKey); return new QueryCondition(AnnotationTools.getFieldName(idField), "=", idKey);
} }
// TODO: manage insert batch... // TODO: manage insert batch...
public <T> List<T> insertMultiple(final List<T> data, final QueryOption... options) throws Exception { public <T> List<T> insertMultiple(final List<T> data, final QueryOption... options) throws Exception {
final List<T> out = new ArrayList<>(); final List<T> out = new ArrayList<>();
@ -109,9 +102,9 @@ public abstract class DBAccess implements Closeable {
} }
return out; return out;
} }
abstract public <T> T insert(final T data, final QueryOption... option) throws Exception; abstract public <T> T insert(final T data, final QueryOption... option) throws Exception;
// seems a good idea, but very dangerous if we not filter input data... if set an id it can be complicated... // seems a good idea, but very dangerous if we not filter input data... if set an id it can be complicated...
public <T> T insertWithJson(final Class<T> clazz, final String jsonData) throws Exception { public <T> T insertWithJson(final Class<T> clazz, final String jsonData) throws Exception {
final ObjectMapper mapper = new ObjectMapper(); final ObjectMapper mapper = new ObjectMapper();
@ -119,7 +112,7 @@ public abstract class DBAccess implements Closeable {
final T data = mapper.readValue(jsonData, clazz); final T data = mapper.readValue(jsonData, clazz);
return insert(data); return insert(data);
} }
/** Update an object with the inserted json data /** Update an object with the inserted json data
* *
* @param <T> Type of the object to insert * @param <T> Type of the object to insert
@ -139,7 +132,7 @@ public abstract class DBAccess implements Closeable {
options.add(new TransmitKey(id)); options.add(new TransmitKey(id));
return updateWhereWithJson(clazz, jsonData, options.getAllArray()); return updateWhereWithJson(clazz, jsonData, options.getAllArray());
} }
public <T> long updateWhereWithJson(final Class<T> clazz, final String jsonData, final QueryOption... option) public <T> long updateWhereWithJson(final Class<T> clazz, final String jsonData, final QueryOption... option)
throws Exception { throws Exception {
final QueryOptions options = new QueryOptions(option); final QueryOptions options = new QueryOptions(option);
@ -157,11 +150,11 @@ public abstract class DBAccess implements Closeable {
options.add(new FilterValue(keys)); options.add(new FilterValue(keys));
return updateWhere(data, options.getAllArray()); return updateWhere(data, options.getAllArray());
} }
public <T, ID_TYPE> long update(final T data, final ID_TYPE id) throws Exception { public <T, ID_TYPE> long update(final T data, final ID_TYPE id) throws Exception {
return update(data, id, AnnotationTools.getFieldsNames(data.getClass())); return update(data, id, AnnotationTools.getFieldsNames(data.getClass()));
} }
/** @param <T> /** @param <T>
* @param data * @param data
* @param id * @param id
@ -179,14 +172,14 @@ public abstract class DBAccess implements Closeable {
options.add(new TransmitKey(id)); options.add(new TransmitKey(id));
return updateWhere(data, options); return updateWhere(data, options);
} }
public <T> long updateWhere(final T data, final QueryOption... option) throws Exception { public <T> long updateWhere(final T data, final QueryOption... option) throws Exception {
final QueryOptions options = new QueryOptions(option); final QueryOptions options = new QueryOptions(option);
return updateWhere(data, options); return updateWhere(data, options);
} }
public abstract <T> long updateWhere(final T data, QueryOptions options) throws Exception; public abstract <T> long updateWhere(final T data, QueryOptions options) throws Exception;
public <T> T getWhere(final Class<T> clazz, final QueryOptions options) throws Exception { public <T> T getWhere(final Class<T> clazz, final QueryOptions options) throws Exception {
options.add(new Limit(1)); options.add(new Limit(1));
final List<T> values = getsWhere(clazz, options); final List<T> values = getsWhere(clazz, options);
@ -195,17 +188,17 @@ public abstract class DBAccess implements Closeable {
} }
return values.get(0); return values.get(0);
} }
public <T> T getWhere(final Class<T> clazz, final QueryOption... option) throws Exception { public <T> T getWhere(final Class<T> clazz, final QueryOption... option) throws Exception {
final QueryOptions options = new QueryOptions(option); final QueryOptions options = new QueryOptions(option);
return getWhere(clazz, options); return getWhere(clazz, options);
} }
public <T> List<T> getsWhere(final Class<T> clazz, final QueryOption... option) throws Exception { public <T> List<T> getsWhere(final Class<T> clazz, final QueryOption... option) throws Exception {
final QueryOptions options = new QueryOptions(option); final QueryOptions options = new QueryOptions(option);
return getsWhere(clazz, options); return getsWhere(clazz, options);
} }
public Condition conditionFusionOrEmpty(final QueryOptions options, final boolean throwIfEmpty) public Condition conditionFusionOrEmpty(final QueryOptions options, final boolean throwIfEmpty)
throws DataAccessException { throws DataAccessException {
if (options == null) { if (options == null) {
@ -231,37 +224,37 @@ public abstract class DBAccess implements Closeable {
} }
return condition; return condition;
} }
abstract public <T> List<T> getsWhere(final Class<T> clazz, final QueryOptions options) abstract public <T> List<T> getsWhere(final Class<T> clazz, final QueryOptions options)
throws DataAccessException, IOException; throws DataAccessException, IOException;
public <ID_TYPE> long count(final Class<?> clazz, final ID_TYPE id, final QueryOption... option) throws Exception { public <ID_TYPE> long count(final Class<?> clazz, final ID_TYPE id, final QueryOption... option) throws Exception {
final QueryOptions options = new QueryOptions(option); final QueryOptions options = new QueryOptions(option);
options.add(new Condition(getTableIdCondition(clazz, id))); options.add(new Condition(getTableIdCondition(clazz, id)));
return countWhere(clazz, options); return countWhere(clazz, options);
} }
public long countWhere(final Class<?> clazz, final QueryOption... option) throws Exception { public long countWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
final QueryOptions options = new QueryOptions(option); final QueryOptions options = new QueryOptions(option);
return countWhere(clazz, options); return countWhere(clazz, options);
} }
public abstract long countWhere(final Class<?> clazz, final QueryOptions options) throws Exception; public abstract long countWhere(final Class<?> clazz, final QueryOptions options) throws Exception;
public <T, ID_TYPE> T get(final Class<T> clazz, final ID_TYPE id, final QueryOption... option) throws Exception { public <T, ID_TYPE> T get(final Class<T> clazz, final ID_TYPE id, final QueryOption... option) throws Exception {
final QueryOptions options = new QueryOptions(option); final QueryOptions options = new QueryOptions(option);
options.add(new Condition(getTableIdCondition(clazz, id))); options.add(new Condition(getTableIdCondition(clazz, id)));
return getWhere(clazz, options.getAllArray()); return getWhere(clazz, options.getAllArray());
} }
public <T> List<T> gets(final Class<T> clazz) throws Exception { public <T> List<T> gets(final Class<T> clazz) throws Exception {
return getsWhere(clazz); return getsWhere(clazz);
} }
public <T> List<T> gets(final Class<T> clazz, final QueryOption... option) throws Exception { public <T> List<T> gets(final Class<T> clazz, final QueryOption... option) throws Exception {
return getsWhere(clazz, option); return getsWhere(clazz, option);
} }
/** Delete items with the specific Id (cf @Id) and some options. If the Entity is manage as a softDeleted model, then it is flag as removed (if not already done before). /** Delete items with the specific Id (cf @Id) and some options. If the Entity is manage as a softDeleted model, then it is flag as removed (if not already done before).
* @param <ID_TYPE> Type of the reference @Id * @param <ID_TYPE> Type of the reference @Id
* @param clazz Data model that might remove element * @param clazz Data model that might remove element
@ -277,7 +270,7 @@ public abstract class DBAccess implements Closeable {
return deleteHard(clazz, id, options); return deleteHard(clazz, id, options);
} }
} }
/** Delete items with the specific condition and some options. If the Entity is manage as a softDeleted model, then it is flag as removed (if not already done before). /** Delete items with the specific condition and some options. If the Entity is manage as a softDeleted model, then it is flag as removed (if not already done before).
* @param clazz Data model that might remove element. * @param clazz Data model that might remove element.
* @param condition Condition to remove elements. * @param condition Condition to remove elements.
@ -291,40 +284,40 @@ public abstract class DBAccess implements Closeable {
return deleteHardWhere(clazz, option); return deleteHardWhere(clazz, option);
} }
} }
public <ID_TYPE> long deleteHard(final Class<?> clazz, final ID_TYPE id, final QueryOption... option) public <ID_TYPE> long deleteHard(final Class<?> clazz, final ID_TYPE id, final QueryOption... option)
throws Exception { throws Exception {
final QueryOptions options = new QueryOptions(option); final QueryOptions options = new QueryOptions(option);
options.add(new Condition(getTableIdCondition(clazz, id))); options.add(new Condition(getTableIdCondition(clazz, id)));
return deleteHardWhere(clazz, options.getAllArray()); return deleteHardWhere(clazz, options.getAllArray());
} }
public abstract long deleteHardWhere(final Class<?> clazz, final QueryOption... option) throws Exception; public abstract long deleteHardWhere(final Class<?> clazz, final QueryOption... option) throws Exception;
public <ID_TYPE> long deleteSoft(final Class<?> clazz, final ID_TYPE id, final QueryOption... option) public <ID_TYPE> long deleteSoft(final Class<?> clazz, final ID_TYPE id, final QueryOption... option)
throws Exception { throws Exception {
final QueryOptions options = new QueryOptions(option); final QueryOptions options = new QueryOptions(option);
options.add(new Condition(getTableIdCondition(clazz, id))); options.add(new Condition(getTableIdCondition(clazz, id)));
return deleteSoftWhere(clazz, options.getAllArray()); return deleteSoftWhere(clazz, options.getAllArray());
} }
public abstract long deleteSoftWhere(final Class<?> clazz, final QueryOption... option) throws Exception; public abstract long deleteSoftWhere(final Class<?> clazz, final QueryOption... option) throws Exception;
public <ID_TYPE> long unsetDelete(final Class<?> clazz, final ID_TYPE id) throws DataAccessException { public <ID_TYPE> long unsetDelete(final Class<?> clazz, final ID_TYPE id) throws DataAccessException {
return unsetDeleteWhere(clazz, new Condition(getTableIdCondition(clazz, id))); return unsetDeleteWhere(clazz, new Condition(getTableIdCondition(clazz, id)));
} }
public <ID_TYPE> long unsetDelete(final Class<?> clazz, final ID_TYPE id, final QueryOption... option) public <ID_TYPE> long unsetDelete(final Class<?> clazz, final ID_TYPE id, final QueryOption... option)
throws DataAccessException { throws DataAccessException {
final QueryOptions options = new QueryOptions(option); final QueryOptions options = new QueryOptions(option);
options.add(new Condition(getTableIdCondition(clazz, id))); options.add(new Condition(getTableIdCondition(clazz, id)));
return unsetDeleteWhere(clazz, options.getAllArray()); return unsetDeleteWhere(clazz, options.getAllArray());
} }
public abstract long unsetDeleteWhere(final Class<?> clazz, final QueryOption... option) throws DataAccessException; public abstract long unsetDeleteWhere(final Class<?> clazz, final QueryOption... option) throws DataAccessException;
public abstract void drop(final Class<?> clazz, final QueryOption... option) throws Exception; public abstract void drop(final Class<?> clazz, final QueryOption... option) throws Exception;
public abstract void cleanAll(final Class<?> clazz, final QueryOption... option) throws Exception; public abstract void cleanAll(final Class<?> clazz, final QueryOption... option) throws Exception;
} }

View File

@ -29,7 +29,7 @@ import org.kar.archidata.dataAccess.options.FilterValue;
import org.kar.archidata.dataAccess.options.Limit; import org.kar.archidata.dataAccess.options.Limit;
import org.kar.archidata.dataAccess.options.OrderBy; import org.kar.archidata.dataAccess.options.OrderBy;
import org.kar.archidata.dataAccess.options.QueryOption; import org.kar.archidata.dataAccess.options.QueryOption;
import org.kar.archidata.db.DbInterfaceMorphia; import org.kar.archidata.db.DbIoMorphia;
import org.kar.archidata.exception.DataAccessException; import org.kar.archidata.exception.DataAccessException;
import org.kar.archidata.tools.UuidUtils; import org.kar.archidata.tools.UuidUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -74,13 +74,13 @@ public class DBAccessMorphia extends DBAccess {
DBAccessMorphia.addOn.add(addOn); DBAccessMorphia.addOn.add(addOn);
} }
private final DbInterfaceMorphia db; private final DbIoMorphia db;
public DBAccessMorphia(final DbInterfaceMorphia db) { public DBAccessMorphia(final DbIoMorphia db) {
this.db = db; this.db = db;
} }
public DbInterfaceMorphia getInterface() { public DbIoMorphia getInterface() {
return this.db; return this.db;
} }
@ -120,7 +120,7 @@ public class DBAccessMorphia extends DBAccess {
return groups; return groups;
} }
protected <T> void setValuedb( protected <T> void setValuedb(
final Class<?> type, final Class<?> type,
final T data, final T data,
@ -349,7 +349,7 @@ public class DBAccessMorphia extends DBAccess {
return; return;
//throw new ArchiveException("wrong type of field [" + fieldName + "]: " + doc.toJson()); //throw new ArchiveException("wrong type of field [" + fieldName + "]: " + doc.toJson());
} }
protected Object convertDefaultField(String data, final Field field) throws Exception { protected Object convertDefaultField(String data, final Field field) throws Exception {
if (data.startsWith("'") && data.endsWith("'")) { if (data.startsWith("'") && data.endsWith("'")) {
data = data.substring(1, data.length() - 1); data = data.substring(1, data.length() - 1);
@ -939,6 +939,6 @@ public class DBAccessMorphia extends DBAccess {
@Override @Override
public void close() throws IOException { public void close() throws IOException {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
} }

View File

@ -37,7 +37,7 @@ import org.kar.archidata.dataAccess.options.Limit;
import org.kar.archidata.dataAccess.options.OrderBy; import org.kar.archidata.dataAccess.options.OrderBy;
import org.kar.archidata.dataAccess.options.QueryOption; import org.kar.archidata.dataAccess.options.QueryOption;
import org.kar.archidata.dataAccess.options.TransmitKey; import org.kar.archidata.dataAccess.options.TransmitKey;
import org.kar.archidata.db.DbInterfaceSQL; import org.kar.archidata.db.DbIoSql;
import org.kar.archidata.exception.DataAccessException; import org.kar.archidata.exception.DataAccessException;
import org.kar.archidata.tools.ConfigBaseVariable; import org.kar.archidata.tools.ConfigBaseVariable;
import org.kar.archidata.tools.DateTools; import org.kar.archidata.tools.DateTools;
@ -73,9 +73,9 @@ public class DBAccessSQL extends DBAccess {
DBAccessSQL.addOn.add(addOn); DBAccessSQL.addOn.add(addOn);
} }
private final DbInterfaceSQL db; private final DbIoSql db;
public DBAccessSQL(final DbInterfaceSQL db) { public DBAccessSQL(final DbIoSql db) {
this.db = db; this.db = db;
} }
@ -1616,7 +1616,7 @@ public class DBAccessSQL extends DBAccess {
} }
return outs; return outs;
} }
@Override @Override
public void close() throws IOException { public void close() throws IOException {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View File

@ -19,27 +19,28 @@ import jakarta.ws.rs.InternalServerErrorException;
/** Data access is an abstraction class that permit to access on the DB with a function wrapping that permit to minimize the SQL writing of SQL code. This interface support the SQL and SQLite /** Data access is an abstraction class that permit to access on the DB with a function wrapping that permit to minimize the SQL writing of SQL code. This interface support the SQL and SQLite
* back-end. */ * back-end. */
public class DataAccess { public class DataAccess {
static final Logger LOGGER = LoggerFactory.getLogger(DataAccess.class); private static final Logger LOGGER = LoggerFactory.getLogger(DataAccess.class);
public DataAccess() { public DataAccess() {
} }
public static boolean isDBExist(final String name, final QueryOption... options) public static boolean isDBExist(final String name, final QueryOption... options)
throws InternalServerErrorException, IOException { throws InternalServerErrorException, IOException, DataAccessException {
try (DBAccess db = DBAccess.createInterface()) { try (DBAccess db = DBAccess.createInterface()) {
return db.isDBExist(name, options); return db.isDBExist(name, options);
} }
} }
public static boolean createDB(final String name) throws IOException { public static boolean createDB(final String name)
throws IOException, InternalServerErrorException, DataAccessException {
try (DBAccess db = DBAccess.createInterface()) { try (DBAccess db = DBAccess.createInterface()) {
return db.createDB(name); return db.createDB(name);
} }
} }
public static boolean isTableExist(final String name, final QueryOption... options) public static boolean isTableExist(final String name, final QueryOption... options)
throws InternalServerErrorException, IOException { throws InternalServerErrorException, IOException, DataAccessException {
try (DBAccess db = DBAccess.createInterface()) { try (DBAccess db = DBAccess.createInterface()) {
return db.isTableExist(name, options); return db.isTableExist(name, options);
} }
@ -160,7 +161,6 @@ public class DataAccess {
} }
} }
@SuppressWarnings("unchecked")
public static <T> List<T> getsWhere(final Class<T> clazz, final QueryOptions options) public static <T> List<T> getsWhere(final Class<T> clazz, final QueryOptions options)
throws DataAccessException, IOException { throws DataAccessException, IOException {
try (DBAccess db = DBAccess.createInterface()) { try (DBAccess db = DBAccess.createInterface()) {

View File

@ -45,8 +45,7 @@ public class QueryAnd implements QueryItem {
} }
@Override @Override
public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii) public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii) throws Exception {
throws Exception {
for (final QueryItem elem : this.childs) { for (final QueryItem elem : this.childs) {
elem.injectQuery(ioDb, ps, iii); elem.injectQuery(ioDb, ps, iii);
} }

View File

@ -40,8 +40,7 @@ public class QueryCondition implements QueryItem {
} }
@Override @Override
public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii) public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii) throws Exception {
throws Exception {
ioDb.addElement(ps, this.value, iii); ioDb.addElement(ps, this.value, iii);
iii.inc(); iii.inc();
} }

View File

@ -48,8 +48,7 @@ public class QueryInList<T> implements QueryItem {
} }
@Override @Override
public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii) public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii) throws Exception {
throws Exception {
for (final Object elem : this.value) { for (final Object elem : this.value) {
ioDb.addElement(ps, elem, iii); ioDb.addElement(ps, elem, iii);
iii.inc(); iii.inc();

View File

@ -39,8 +39,7 @@ public class QueryOr implements QueryItem {
} }
@Override @Override
public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii) public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii) throws Exception {
throws Exception {
for (final QueryItem elem : this.childs) { for (final QueryItem elem : this.childs) {
elem.injectQuery(ioDb, ps, iii); elem.injectQuery(ioDb, ps, iii);
} }

View File

@ -68,22 +68,14 @@ public class CheckJPA<T> implements CheckFunctionInterface {
final String fieldName = field.getName(); // AnnotationTools.getFieldName(field); final String fieldName = field.getName(); // AnnotationTools.getFieldName(field);
if (AnnotationTools.isPrimaryKey(field)) { if (AnnotationTools.isPrimaryKey(field)) {
add(fieldName, add(fieldName,
( (final DBAccess ioDb, final String baseName, final T data, final QueryOptions options) -> {
final DBAccess ioDb,
final String baseName,
final T data,
final QueryOptions options) -> {
throw new InputException(baseName + fieldName, throw new InputException(baseName + fieldName,
"This is a '@Id' (primaryKey) ==> can not be change"); "This is a '@Id' (primaryKey) ==> can not be change");
}); });
} }
if (AnnotationTools.getConstraintsNotNull(field)) { if (AnnotationTools.getConstraintsNotNull(field)) {
add(fieldName, add(fieldName,
( (final DBAccess ioDb, final String baseName, final T data, final QueryOptions options) -> {
final DBAccess ioDb,
final String baseName,
final T data,
final QueryOptions options) -> {
if (field.get(data) == null) { if (field.get(data) == null) {
throw new InputException(baseName + fieldName, "Can not be null"); throw new InputException(baseName + fieldName, "Can not be null");
} }
@ -91,11 +83,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
} }
if (AnnotationTools.isCreatedAtField(field) || AnnotationTools.isUpdateAtField(field)) { if (AnnotationTools.isCreatedAtField(field) || AnnotationTools.isUpdateAtField(field)) {
add(fieldName, add(fieldName,
( (final DBAccess ioDb, final String baseName, final T data, final QueryOptions options) -> {
final DBAccess ioDb,
final String baseName,
final T data,
final QueryOptions options) -> {
throw new InputException(baseName + fieldName, "It is forbidden to change this field"); throw new InputException(baseName + fieldName, "It is forbidden to change this field");
}); });
} }
@ -420,11 +408,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
if (AnnotationTools.isUnique(field)) { if (AnnotationTools.isUnique(field)) {
// Create the request ... // Create the request ...
add(fieldName, add(fieldName,
( (final DBAccess ioDb, final String baseName, final T data, final QueryOptions options) -> {
final DBAccess ioDb,
final String baseName,
final T data,
final QueryOptions options) -> {
final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class); final List<ConditionChecker> condCheckers = options.get(ConditionChecker.class);
Object other = null; Object other = null;
if (condCheckers.isEmpty()) { if (condCheckers.isEmpty()) {

View File

@ -30,8 +30,7 @@ public class Condition extends QueryOption {
} }
} }
public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii) public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii) throws Exception {
throws Exception {
if (this.condition != null) { if (this.condition != null) {
this.condition.injectQuery(ioDb, ps, iii); this.condition.injectQuery(ioDb, ps, iii);
} }

View File

@ -16,8 +16,7 @@ public class Limit extends QueryOption {
query.append(" LIMIT ? \n"); query.append(" LIMIT ? \n");
} }
public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii) public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii) throws Exception {
throws Exception {
ioDb.addElement(ps, this.limit, iii); ioDb.addElement(ps, this.limit, iii);
iii.inc(); iii.inc();
} }

View File

@ -1,76 +0,0 @@
package org.kar.archidata.db;
import java.io.Closeable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DBInterfaceFactory implements Closeable {
final static Logger LOGGER = LoggerFactory.getLogger(DBInterfaceFactory.class);
private final DBConfig config;
private DbInterface ioDb;
private Class<?> classes[] = {};
private static List<DBInterfaceFactory> stored = new ArrayList<>();
private DBInterfaceFactory(final DBConfig config, final Class<?>... classes) throws IOException {
this.config = config;
this.classes = classes;
connect();
}
public static DBInterfaceFactory create(final DBConfig config, final Class<?>... classes) throws IOException {
if (config.getKeepConnected()) {
for (final DBInterfaceFactory elem : stored) {
if (elem == null) {
continue;
}
if (elem.config.getUrl().equals(config.getUrl())) {
return elem;
}
}
final DBInterfaceFactory tmp = new DBInterfaceFactory(config);
stored.add(tmp);
return tmp;
} else {
return new DBInterfaceFactory(config, classes);
}
}
public void connect() throws IOException {
if ("mysql".equals(this.config.getType())) {
this.ioDb = new DbInterfaceSQL(this.config);
} else if ("sqlite".equals(this.config.getType())) {
this.ioDb = new DbInterfaceSQL(this.config);
} else if ("mongo".equals(this.config.getType())) {
this.ioDb = new DbInterfaceMorphia(this.config, this.classes);
} else {
throw new IOException("DB type: '" + this.config.getType() + "'is not managed");
}
}
@Override
public void close() throws IOException {
if (this.config.getKeepConnected()) {
return;
}
closeForce();
}
public void closeForce() throws IOException {
this.ioDb.close();
}
public DbInterface getDbInterface() {
return this.ioDb;
}
public static void closeAllForceMode() throws IOException {
for (final DBInterfaceFactory entry : stored) {
entry.closeForce();
}
stored = new ArrayList<>();
}
}

View File

@ -1,11 +1,14 @@
package org.kar.archidata.db; package org.kar.archidata.db;
import java.util.List;
import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.exception.DataAccessException; import org.kar.archidata.exception.DataAccessException;
import org.kar.archidata.tools.ConfigBaseVariable;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class DBConfig { public class DbConfig {
static final Logger LOGGER = LoggerFactory.getLogger(DBAccess.class); static final Logger LOGGER = LoggerFactory.getLogger(DBAccess.class);
private final String type; private final String type;
private final String hostname; private final String hostname;
@ -14,9 +17,17 @@ public class DBConfig {
private final String password; private final String password;
private final String dbName; private final String dbName;
private final boolean keepConnected; private final boolean keepConnected;
private final List<Class<?>> classes;
public DBConfig(final String type, final String hostname, final Integer port, final String login, public DbConfig() throws DataAccessException {
final String password, final String dbName, final boolean keepConnected) throws DataAccessException { this(ConfigBaseVariable.getDBType(), ConfigBaseVariable.getDBHost(), ConfigBaseVariable.getDBPort(),
ConfigBaseVariable.getDBLogin(), ConfigBaseVariable.getDBPassword(), ConfigBaseVariable.getDBName(),
ConfigBaseVariable.getDBKeepConnected(), List.of(ConfigBaseVariable.getBbInterfacesClasses()));
}
public DbConfig(final String type, final String hostname, final Short port, final String login,
final String password, final String dbName, final boolean keepConnected, final List<Class<?>> classes)
throws DataAccessException {
if (type == null) { if (type == null) {
this.type = "mysql"; this.type = "mysql";
} else { } else {
@ -43,6 +54,7 @@ public class DBConfig {
this.password = password; this.password = password;
this.dbName = dbName; this.dbName = dbName;
this.keepConnected = keepConnected; this.keepConnected = keepConnected;
this.classes = classes;
} }
@ -81,6 +93,10 @@ public class DBConfig {
return this.keepConnected; return this.keepConnected;
} }
public List<Class<?>> getClasses() {
return this.classes;
}
public String getUrl() { public String getUrl() {
return getUrl(false); return getUrl(false);
} }

View File

@ -1,16 +0,0 @@
package org.kar.archidata.db;
import java.io.Closeable;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DbInterface implements Closeable {
private final static Logger LOGGER = LoggerFactory.getLogger(DbInterface.class);
@Override
public void close() throws IOException {
LOGGER.error("Check db interface close implementation !!! " + this.getClass().getCanonicalName());
}
}

View File

@ -0,0 +1,75 @@
package org.kar.archidata.db;
import java.io.Closeable;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public abstract class DbIo implements Closeable {
private final static Logger LOGGER = LoggerFactory.getLogger(DbIo.class);
// we count the number of connection in the system to prevent disconnection in a middle of a stream.
private int count = 0;
protected final DbConfig config;
protected DbIo(final DbConfig config) throws IOException {
this.config = config;
// If we want to stay connected, we instantiate a basic connection (only force close can remove it).
if (this.config.getKeepConnected()) {
open();
}
}
@Override
public synchronized final void close() throws IOException {
if (this.count <= 0) {
LOGGER.error("Request one more close: {}", this.getClass().getCanonicalName());
return;
}
this.count--;
if (this.count == 0) {
LOGGER.warn("close: {}", this.getClass().getCanonicalName());
closeImplement();
} else {
LOGGER.debug("postponed close: {}", this.getClass().getCanonicalName());
}
}
public synchronized final void closeForce() throws IOException {
LOGGER.warn("Request Force close: {}", this.getClass().getCanonicalName());
if (this.count == 0) {
LOGGER.info("Nothing to do in force close, DB is already closed");
return;
}
if (this.config.getKeepConnected()) {
if (this.count >= 2) {
LOGGER.error("close: {} with {} connection on it", this.getClass().getCanonicalName(), this.count - 1);
}
} else if (this.count >= 1) {
LOGGER.error("close: {} with {} connection on it", this.getClass().getCanonicalName(), this.count);
}
this.count = 0;
LOGGER.warn("close: {}", this.getClass().getCanonicalName());
closeImplement();
}
public synchronized final void open() throws IOException {
if (this.count == 0) {
LOGGER.warn("open: {}", this.getClass().getCanonicalName());
openImplement();
} else {
LOGGER.debug("already open: {}", this.getClass().getCanonicalName());
}
this.count++;
}
protected abstract void closeImplement() throws IOException;
protected abstract void openImplement() throws IOException;
public boolean compatible(final DbConfig config) {
return config.equals(config);
}
}

View File

@ -0,0 +1,65 @@
package org.kar.archidata.db;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DbIoFactory {
final static Logger LOGGER = LoggerFactory.getLogger(DbIoFactory.class);
private static List<DbIo> stored = new ArrayList<>();
private DbIoFactory() throws IOException {}
public static DbIo create() throws IOException, DataAccessException {
// Find the global configuration of the system.
return create(new DbConfig());
}
public static DbIo create(final DbConfig config) throws IOException {
for (final DbIo elem : stored) {
if (elem == null) {
continue;
}
if (elem.compatible(config)) {
elem.open();
return elem;
}
}
final DbIo tmp = createInstance(config);
if (config.getKeepConnected()) {
stored.add(tmp);
}
tmp.open();
return tmp;
}
private static DbIo createInstance(final DbConfig config) throws IOException {
switch (config.getType()) {
case "mysql":
return new DbIoSql(config);
case "sqlite":
return new DbIoSql(config);
case "mongo":
return new DbIoMorphia(config);
}
throw new IOException("DB type: '" + config.getType() + "'is not managed");
}
public static void close() throws IOException {
for (final DbIo entry : stored) {
entry.close();
}
}
public static void closeAllForceMode() throws IOException {
for (final DbIo entry : stored) {
entry.closeForce();
}
stored = new ArrayList<>();
}
}

View File

@ -19,16 +19,35 @@ import com.mongodb.client.MongoClients;
import dev.morphia.Datastore; import dev.morphia.Datastore;
import dev.morphia.Morphia; import dev.morphia.Morphia;
public class DbInterfaceMorphia extends DbInterface implements Closeable { public class DbIoMorphia extends DbIo implements Closeable {
private final static Logger LOGGER = LoggerFactory.getLogger(DbInterfaceMorphia.class); private final static Logger LOGGER = LoggerFactory.getLogger(DbIoMorphia.class);
private final MongoClient mongoClient; private MongoClient mongoClient = null;
private final Datastore datastore; private Datastore datastore = null;
public DbInterfaceMorphia(final DBConfig config, final Class<?>... classes) throws IOException { public DbIoMorphia(final DbConfig config) throws IOException {
this(config.getUrl(), config.getDbName(), classes); super(config);
} }
public DbInterfaceMorphia(final String dbUrl, final String dbName, final Class<?>... classes) { public Datastore getDatastore() {
return this.datastore;
}
public MongoClient getClient() {
return this.mongoClient;
}
@Override
synchronized public void closeImplement() throws IOException {
this.mongoClient.close();
this.mongoClient = null;
this.datastore = null;
}
@Override
synchronized public void openImplement() throws IOException {
final Class<?>[] classes = this.config.getClasses().toArray(new Class<?>[0]);
final String dbUrl = this.config.getUrl();
final String dbName = this.config.getDbName();
// Connect to MongoDB (simple form): // Connect to MongoDB (simple form):
// final MongoClient mongoClient = MongoClients.create(dbUrl); // final MongoClient mongoClient = MongoClients.create(dbUrl);
LOGGER.info("Connect on the DB: {}", dbUrl); LOGGER.info("Connect on the DB: {}", dbUrl);
@ -61,18 +80,4 @@ public class DbInterfaceMorphia extends DbInterface implements Closeable {
// Ensure indexes // Ensure indexes
this.datastore.ensureIndexes(); this.datastore.ensureIndexes();
} }
public Datastore getDatastore() {
return this.datastore;
}
public MongoClient getClient() {
return this.mongoClient;
}
@Override
public void close() throws IOException {
this.mongoClient.close();
}
} }

View File

@ -9,16 +9,27 @@ import java.sql.SQLException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class DbInterfaceSQL extends DbInterface implements Closeable { public class DbIoSql extends DbIo implements Closeable {
final static Logger LOGGER = LoggerFactory.getLogger(DbInterfaceSQL.class); final static Logger LOGGER = LoggerFactory.getLogger(DbIoSql.class);
private Connection connection = null; private Connection connection = null;
public DbInterfaceSQL(final DBConfig config) throws IOException { public DbIoSql(final DbConfig config) throws IOException {
this(config.getUrl(), config.getLogin(), config.getPassword()); super(config);
} }
public DbInterfaceSQL(final String dbUrl, final String login, final String password) throws IOException { public Connection getConnection() {
if (this.connection == null) {
LOGGER.error("Request closed connection !!!");
}
return this.connection;
}
@Override
synchronized public void openImplement() throws IOException {
final String dbUrl = this.config.getUrl();
final String login = this.config.getLogin();
final String password = this.config.getPassword();
try { try {
this.connection = DriverManager.getConnection(dbUrl, login, password); this.connection = DriverManager.getConnection(dbUrl, login, password);
} catch (final SQLException ex) { } catch (final SQLException ex) {
@ -27,12 +38,12 @@ public class DbInterfaceSQL extends DbInterface implements Closeable {
} }
} }
public Connection getConnection() {
return this.connection;
}
@Override @Override
public void close() throws IOException { synchronized public void closeImplement() throws IOException {
if (this.connection == null) {
LOGGER.error("Request close of un-open connection !!!");
return;
}
try { try {
this.connection.close(); this.connection.close();
this.connection = null; this.connection = null;

View File

@ -9,12 +9,14 @@ import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.dataAccess.DBAccessSQL; import org.kar.archidata.dataAccess.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory; import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.dataAccess.QueryOptions; import org.kar.archidata.dataAccess.QueryOptions;
import org.kar.archidata.db.DBConfig; import org.kar.archidata.db.DbConfig;
import org.kar.archidata.exception.DataAccessException;
import org.kar.archidata.migration.model.Migration; import org.kar.archidata.migration.model.Migration;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.ws.rs.InternalServerErrorException;
public class MigrationEngine { public class MigrationEngine {
final static Logger LOGGER = LoggerFactory.getLogger(MigrationEngine.class); final static Logger LOGGER = LoggerFactory.getLogger(MigrationEngine.class);
@ -26,6 +28,10 @@ public class MigrationEngine {
protected final DBAccess da; protected final DBAccess da;
public MigrationEngine() throws InternalServerErrorException, IOException, DataAccessException {
this(DBAccess.createInterface());
}
/** Migration engine constructor (empty). */ /** Migration engine constructor (empty). */
public MigrationEngine(final DBAccess da) { public MigrationEngine(final DBAccess da) {
this(da, new ArrayList<>(), null); this(da, new ArrayList<>(), null);
@ -90,7 +96,7 @@ public class MigrationEngine {
/** Process the automatic migration of the system The function wait the Administrator intervention to correct the bug. /** Process the automatic migration of the system The function wait the Administrator intervention to correct the bug.
* @param config SQL connection for the migration. * @param config SQL connection for the migration.
* @throws InterruptedException user interrupt the migration */ * @throws InterruptedException user interrupt the migration */
public void migrateWaitAdmin(final DBConfig config) throws InterruptedException { public void migrateWaitAdmin(final DbConfig config) throws InterruptedException {
try { try {
migrateErrorThrow(config); migrateErrorThrow(config);
} catch (final Exception ex) { } catch (final Exception ex) {
@ -110,7 +116,7 @@ public class MigrationEngine {
* @throws IOException Error if access on the DB */ * @throws IOException Error if access on the DB */
@SuppressFBWarnings({ "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING", @SuppressFBWarnings({ "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING",
"SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE" }) "SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE" })
public void migrateErrorThrow(final DBConfig config) throws MigrationException { public void migrateErrorThrow(final DbConfig config) throws MigrationException {
LOGGER.info("Execute migration ... [BEGIN]"); LOGGER.info("Execute migration ... [BEGIN]");
// check the integrity of the migrations: // check the integrity of the migrations:
LOGGER.info("List of availlable Migration: "); LOGGER.info("List of availlable Migration: ");

View File

@ -70,8 +70,7 @@ public class MigrationSqlStep implements MigrationInterface {
} }
@Override @Override
public boolean applyMigration(final DBAccess da, final StringBuilder log, final Migration model) public boolean applyMigration(final DBAccess da, final StringBuilder log, final Migration model) throws Exception {
throws Exception {
if (!this.isGenerated) { if (!this.isGenerated) {
this.isGenerated = true; this.isGenerated = true;
generateStep(); generateStep();

View File

@ -17,6 +17,7 @@ public class ConfigBaseVariable {
static public String eMailFrom; static public String eMailFrom;
static public String eMailLogin; static public String eMailLogin;
static public String eMailPassword; static public String eMailPassword;
static public Class<?>[] dbInterfacesClasses;
// For test only // For test only
public static void clearAllValue() { public static void clearAllValue() {
@ -36,6 +37,7 @@ public class ConfigBaseVariable {
eMailFrom = System.getenv("EMAIL_FROM"); eMailFrom = System.getenv("EMAIL_FROM");
eMailLogin = System.getenv("EMAIL_LOGIN"); eMailLogin = System.getenv("EMAIL_LOGIN");
eMailPassword = System.getenv("EMAIL_PASSWORD"); eMailPassword = System.getenv("EMAIL_PASSWORD");
dbInterfacesClasses = new Class<?>[0];
} }
static { static {
@ -70,14 +72,17 @@ public class ConfigBaseVariable {
return dbHost; return dbHost;
} }
public static String getDBPort() { public static Short getDBPort() {
if (dbPort == null) { if (dbPort == null) {
if (getDBType().equals("mongo")) { if (getDBType().equals("mongo")) {
return "27017"; return 27017;
} }
return "3306"; return 3306;
} }
return dbPort; if (dbPort == null) {
return null;
}
return Short.parseShort(dbPort);
} }
public static String getDBLogin() { public static String getDBLogin() {
@ -142,4 +147,11 @@ public class ConfigBaseVariable {
return new EMailConfig(eMailFrom, eMailLogin, eMailPassword); return new EMailConfig(eMailFrom, eMailLogin, eMailPassword);
} }
public static Class<?>[] getBbInterfacesClasses() {
return dbInterfacesClasses;
}
public static void setBbInterfacesClasses(final Class<?>[] data) {
dbInterfacesClasses = data;
}
} }

View File

@ -3,13 +3,14 @@ package test.kar.archidata;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import org.kar.archidata.GlobalConfiguration;
import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.db.DBInterfaceFactory; import org.kar.archidata.db.DbIoFactory;
import org.kar.archidata.exception.DataAccessException;
import org.kar.archidata.tools.ConfigBaseVariable; import org.kar.archidata.tools.ConfigBaseVariable;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.dataAccess.model.SerializeAsJson; import test.kar.archidata.dataAccess.model.SerializeAsJson;
import test.kar.archidata.dataAccess.model.SerializeListAsJson; import test.kar.archidata.dataAccess.model.SerializeListAsJson;
import test.kar.archidata.dataAccess.model.SimpleTable; import test.kar.archidata.dataAccess.model.SimpleTable;
@ -36,8 +37,9 @@ import test.kar.archidata.dataAccess.model.TypesTable;
public class ConfigureDb { public class ConfigureDb {
final static private Logger LOGGER = LoggerFactory.getLogger(ConfigureDb.class); final static private Logger LOGGER = LoggerFactory.getLogger(ConfigureDb.class);
final static private String modeTestForced = null;//"MONGO"; final static private String modeTestForced = null;//"MONGO";
static DBAccess dba = null;
public static void configure() throws IOException {
public static void configure() throws IOException, InternalServerErrorException, DataAccessException {
String modeTest = System.getenv("TEST_E2E_MODE"); String modeTest = System.getenv("TEST_E2E_MODE");
if (modeTest == null || modeTest.isEmpty() || "false".equalsIgnoreCase(modeTest)) { if (modeTest == null || modeTest.isEmpty() || "false".equalsIgnoreCase(modeTest)) {
modeTest = "SQLITE-MEMORY"; modeTest = "SQLITE-MEMORY";
@ -97,17 +99,12 @@ public class ConfigureDb {
ConfigBaseVariable.dbUser = "root"; ConfigBaseVariable.dbUser = "root";
} }
// Connect the dataBase... // Connect the dataBase...
final DBInterfaceFactory entry = DBInterfaceFactory.create(GlobalConfiguration.getDbconfig(), dba = DBAccess.createInterface();
listObject.toArray(new Class<?>[0]));
entry.connect();
removeDB(); removeDB();
} }
public static void removeDB() { public static void removeDB() {
final DBAccess da = DBAccess.createInterface();
String modeTest = System.getenv("TEST_E2E_MODE"); String modeTest = System.getenv("TEST_E2E_MODE");
if (modeTest == null || modeTest.isEmpty() || "false".equalsIgnoreCase(modeTest)) { if (modeTest == null || modeTest.isEmpty() || "false".equalsIgnoreCase(modeTest)) {
modeTest = "SQLITE-MEMORY"; modeTest = "SQLITE-MEMORY";
@ -121,19 +118,19 @@ public class ConfigureDb {
if ("SQLITE-MEMORY".equalsIgnoreCase(modeTest)) { if ("SQLITE-MEMORY".equalsIgnoreCase(modeTest)) {
// nothing to do ... // nothing to do ...
} else if ("SQLITE".equalsIgnoreCase(modeTest)) { } else if ("SQLITE".equalsIgnoreCase(modeTest)) {
da.deleteDB(ConfigBaseVariable.bdDatabase); dba.deleteDB(ConfigBaseVariable.bdDatabase);
} else if ("MY-SQL".equalsIgnoreCase(modeTest)) { } else if ("MY-SQL".equalsIgnoreCase(modeTest)) {
da.deleteDB(ConfigBaseVariable.bdDatabase); dba.deleteDB(ConfigBaseVariable.bdDatabase);
} else if ("MONGO".equalsIgnoreCase(modeTest)) { } else if ("MONGO".equalsIgnoreCase(modeTest)) {
da.deleteDB(ConfigBaseVariable.bdDatabase); dba.deleteDB(ConfigBaseVariable.bdDatabase);
} else {} } else {}
} }
public static void clear() throws IOException { public static void clear() throws IOException {
LOGGER.info("Remove the test db"); LOGGER.info("Remove the test db");
removeDB(); removeDB();
DBInterfaceFactory.closeAllForceMode(); DbIoFactory.closeAllForceMode();
ConfigBaseVariable.clearAllValue(); ConfigBaseVariable.clearAllValue();
} }
} }

View File

@ -12,12 +12,12 @@ import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.jackson.JacksonFeature; import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.media.multipart.MultiPartFeature; import org.glassfish.jersey.media.multipart.MultiPartFeature;
import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.server.ResourceConfig;
import org.kar.archidata.GlobalConfiguration;
import org.kar.archidata.UpdateJwtPublicKey; import org.kar.archidata.UpdateJwtPublicKey;
import org.kar.archidata.api.DataResource; import org.kar.archidata.api.DataResource;
import org.kar.archidata.api.ProxyResource; import org.kar.archidata.api.ProxyResource;
import org.kar.archidata.catcher.GenericCatcher; import org.kar.archidata.catcher.GenericCatcher;
import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.db.DbConfig;
import org.kar.archidata.exception.DataAccessException;
import org.kar.archidata.filter.CORSFilter; import org.kar.archidata.filter.CORSFilter;
import org.kar.archidata.filter.OptionFilter; import org.kar.archidata.filter.OptionFilter;
import org.kar.archidata.migration.MigrationEngine; import org.kar.archidata.migration.MigrationEngine;
@ -33,11 +33,7 @@ public class WebLauncher {
protected UpdateJwtPublicKey keyUpdater = null; protected UpdateJwtPublicKey keyUpdater = null;
protected HttpServer server = null; protected HttpServer server = null;
private final DBAccess da; public WebLauncher() {}
public WebLauncher() {
this.da = DBAccess.createInterface();
}
private static URI getBaseURI() { private static URI getBaseURI() {
return UriBuilder.fromUri(ConfigBaseVariable.getlocalAddress()).build(); return UriBuilder.fromUri(ConfigBaseVariable.getlocalAddress()).build();
@ -45,13 +41,13 @@ public class WebLauncher {
public void migrateDB() throws Exception { public void migrateDB() throws Exception {
WebLauncher.LOGGER.info("Create migration engine"); WebLauncher.LOGGER.info("Create migration engine");
final MigrationEngine migrationEngine = new MigrationEngine(this.da); final MigrationEngine migrationEngine = new MigrationEngine();
WebLauncher.LOGGER.info("Add initialization"); WebLauncher.LOGGER.info("Add initialization");
//migrationEngine.setInit(new Initialization()); //migrationEngine.setInit(new Initialization());
WebLauncher.LOGGER.info("Add migration since last version"); WebLauncher.LOGGER.info("Add migration since last version");
//migrationEngine.add(new Migration20231126()); //migrationEngine.add(new Migration20231126());
WebLauncher.LOGGER.info("Migrate the DB [START]"); WebLauncher.LOGGER.info("Migrate the DB [START]");
migrationEngine.migrateWaitAdmin(GlobalConfiguration.getDbconfig()); migrationEngine.migrateWaitAdmin(new DbConfig());
WebLauncher.LOGGER.info("Migrate the DB [STOP]"); WebLauncher.LOGGER.info("Migrate the DB [STOP]");
} }
@ -89,7 +85,7 @@ public class WebLauncher {
} }
} }
public void process() throws InterruptedException { public void process() throws InterruptedException, DataAccessException {
ImageIO.scanForPlugins(); ImageIO.scanForPlugins();
plop("jpeg"); plop("jpeg");
@ -127,8 +123,8 @@ public class WebLauncher {
// System.out.println(" getDBLogin: '" + ConfigVariable.getDBLogin() + "'"); // System.out.println(" getDBLogin: '" + ConfigVariable.getDBLogin() + "'");
// System.out.println(" getDBPassword: '" + ConfigVariable.getDBPassword() + "'"); // System.out.println(" getDBPassword: '" + ConfigVariable.getDBPassword() + "'");
// System.out.println(" getDBName: '" + ConfigVariable.getDBName() + "'"); // System.out.println(" getDBName: '" + ConfigVariable.getDBName() + "'");
System.out.println(" ==> " + GlobalConfiguration.getDbconfig()); LOGGER.info(" ==> {}", new DbConfig());
System.out.println("OAuth service " + getBaseURI()); LOGGER.info("OAuth service {}", getBaseURI());
this.server = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc); this.server = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc);
final HttpServer serverLink = this.server; final HttpServer serverLink = this.server;
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

View File

@ -1,14 +1,10 @@
package test.kar.archidata.apiExtern; package test.kar.archidata.apiExtern;
import java.io.IOException;
import org.kar.archidata.tools.ConfigBaseVariable; import org.kar.archidata.tools.ConfigBaseVariable;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import test.kar.archidata.ConfigureDb;
public class WebLauncherTest extends WebLauncher { public class WebLauncherTest extends WebLauncher {
final private static Logger LOGGER = LoggerFactory.getLogger(WebLauncherTest.class); final private static Logger LOGGER = LoggerFactory.getLogger(WebLauncherTest.class);
@ -19,11 +15,5 @@ public class WebLauncherTest extends WebLauncher {
// Enable the test mode permit to access to the test token (never use it in production). // Enable the test mode permit to access to the test token (never use it in production).
ConfigBaseVariable.testMode = "true"; ConfigBaseVariable.testMode = "true";
// ConfigBaseVariable.dbPort = "3306"; // ConfigBaseVariable.dbPort = "3306";
try {
ConfigureDb.configure();
} catch (final IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} }
} }

View File

@ -5,7 +5,7 @@ import java.util.List;
import org.kar.archidata.annotation.ARCHIVE; import org.kar.archidata.annotation.ARCHIVE;
import org.kar.archidata.annotation.AsyncType; import org.kar.archidata.annotation.AsyncType;
import org.kar.archidata.annotation.RESTORE; import org.kar.archidata.annotation.RESTORE;
import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.DataAccess;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -27,40 +27,39 @@ import test.kar.archidata.dataAccess.model.SimpleTable;
public class TestResourceSample { public class TestResourceSample {
private static final Logger LOGGER = LoggerFactory.getLogger(TestResource.class); private static final Logger LOGGER = LoggerFactory.getLogger(TestResource.class);
private final DBAccess da = DBAccess.createInterface();
@GET @GET
@PermitAll @PermitAll
public List<SimpleTable> gets() throws Exception { public List<SimpleTable> gets() throws Exception {
return this.da.gets(SimpleTable.class); return DataAccess.gets(SimpleTable.class);
} }
@GET @GET
@Path("{id}") @Path("{id}")
@PermitAll @PermitAll
public SimpleTable get(@PathParam("id") final Long id) throws Exception { public SimpleTable get(@PathParam("id") final Long id) throws Exception {
return this.da.get(SimpleTable.class, id); return DataAccess.get(SimpleTable.class, id);
} }
@ARCHIVE @ARCHIVE
@Path("{id}") @Path("{id}")
@PermitAll @PermitAll
public SimpleTable archive(@PathParam("id") final Long id) throws Exception { public SimpleTable archive(@PathParam("id") final Long id) throws Exception {
return this.da.get(SimpleTable.class, id); return DataAccess.get(SimpleTable.class, id);
} }
@RESTORE @RESTORE
@Path("{id}") @Path("{id}")
@PermitAll @PermitAll
public SimpleTable restore(@PathParam("id") final Long id) throws Exception { public SimpleTable restore(@PathParam("id") final Long id) throws Exception {
return this.da.get(SimpleTable.class, id); return DataAccess.get(SimpleTable.class, id);
} }
@POST @POST
@PermitAll @PermitAll
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public SimpleTable post(final SimpleTable data) throws Exception { public SimpleTable post(final SimpleTable data) throws Exception {
return this.da.insert(data); return DataAccess.insert(data);
} }
@PATCH @PATCH
@ -69,8 +68,8 @@ public class TestResourceSample {
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public SimpleTable patch(@PathParam("id") final Long id, @AsyncType(SimpleTable.class) final String jsonRequest) public SimpleTable patch(@PathParam("id") final Long id, @AsyncType(SimpleTable.class) final String jsonRequest)
throws Exception { throws Exception {
this.da.updateWithJson(SimpleTable.class, id, jsonRequest); DataAccess.updateWithJson(SimpleTable.class, id, jsonRequest);
return this.da.get(SimpleTable.class, id); return DataAccess.get(SimpleTable.class, id);
} }
@PUT @PUT
@ -78,15 +77,15 @@ public class TestResourceSample {
@PermitAll @PermitAll
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public SimpleTable put(@PathParam("id") final Long id, final SimpleTable data) throws Exception { public SimpleTable put(@PathParam("id") final Long id, final SimpleTable data) throws Exception {
this.da.update(data, id); DataAccess.update(data, id);
return this.da.get(SimpleTable.class, id); return DataAccess.get(SimpleTable.class, id);
} }
@DELETE @DELETE
@Path("{id}") @Path("{id}")
@PermitAll @PermitAll
public void remove(@PathParam("id") final Long id) throws Exception { public void remove(@PathParam("id") final Long id) throws Exception {
this.da.delete(SimpleTable.class, id); DataAccess.delete(SimpleTable.class, id);
} }
} }

View File

@ -14,9 +14,11 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.dataAccess.DBAccessSQL; import org.kar.archidata.dataAccess.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory; import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb; import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension; import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.SerializeAsJson; import test.kar.archidata.dataAccess.model.SerializeAsJson;
@ -39,7 +41,7 @@ public class TestJson {
ConfigureDb.clear(); ConfigureDb.clear();
} }
public TestJson() { public TestJson() throws InternalServerErrorException, IOException, DataAccessException {
this.da = DBAccess.createInterface(); this.da = DBAccess.createInterface();
} }

View File

@ -15,9 +15,11 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.dataAccess.DBAccessSQL; import org.kar.archidata.dataAccess.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory; import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb; import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension; import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.SerializeListAsJson; import test.kar.archidata.dataAccess.model.SerializeListAsJson;
@ -39,7 +41,7 @@ public class TestListJson {
ConfigureDb.clear(); ConfigureDb.clear();
} }
public TestListJson() { public TestListJson() throws InternalServerErrorException, IOException, DataAccessException {
this.da = DBAccess.createInterface(); this.da = DBAccess.createInterface();
} }

View File

@ -15,9 +15,11 @@ import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.dataAccess.DBAccessSQL; import org.kar.archidata.dataAccess.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory; import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.dataAccess.addOnSQL.AddOnManyToMany; import org.kar.archidata.dataAccess.addOnSQL.AddOnManyToMany;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb; import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension; import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.TypeManyToManyRemote; import test.kar.archidata.dataAccess.model.TypeManyToManyRemote;
@ -41,7 +43,7 @@ public class TestManyToMany {
ConfigureDb.clear(); ConfigureDb.clear();
} }
public TestManyToMany() { public TestManyToMany() throws InternalServerErrorException, IOException, DataAccessException {
this.da = DBAccess.createInterface(); this.da = DBAccess.createInterface();
} }

View File

@ -14,9 +14,11 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.dataAccess.DBAccessSQL; import org.kar.archidata.dataAccess.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory; import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb; import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension; import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.TypeManyToOneRemote; import test.kar.archidata.dataAccess.model.TypeManyToOneRemote;
@ -43,7 +45,7 @@ public class TestManyToOne {
ConfigureDb.clear(); ConfigureDb.clear();
} }
public TestManyToOne() { public TestManyToOne() throws InternalServerErrorException, IOException, DataAccessException {
this.da = DBAccess.createInterface(); this.da = DBAccess.createInterface();
} }

View File

@ -14,9 +14,11 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.dataAccess.DBAccessSQL; import org.kar.archidata.dataAccess.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory; import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb; import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension; import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.TypeOneToManyRemote; import test.kar.archidata.dataAccess.model.TypeOneToManyRemote;
@ -43,7 +45,7 @@ public class TestOneToMany {
ConfigureDb.clear(); ConfigureDb.clear();
} }
public TestOneToMany() { public TestOneToMany() throws InternalServerErrorException, IOException, DataAccessException {
this.da = DBAccess.createInterface(); this.da = DBAccess.createInterface();
} }

View File

@ -14,9 +14,11 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.dataAccess.DBAccessSQL; import org.kar.archidata.dataAccess.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory; import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb; import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension; import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.TypesTable; import test.kar.archidata.dataAccess.model.TypesTable;
@ -38,7 +40,7 @@ public class TestRawQuery {
ConfigureDb.clear(); ConfigureDb.clear();
} }
public TestRawQuery() { public TestRawQuery() throws InternalServerErrorException, IOException, DataAccessException {
this.da = DBAccess.createInterface(); this.da = DBAccess.createInterface();
if (this.da instanceof final DBAccessSQL daSQL) { if (this.da instanceof final DBAccessSQL daSQL) {
LOGGER.error("lkjddlkj"); LOGGER.error("lkjddlkj");

View File

@ -18,9 +18,11 @@ import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.dataAccess.DBAccessSQL; import org.kar.archidata.dataAccess.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory; import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.dataAccess.QueryOptions; import org.kar.archidata.dataAccess.QueryOptions;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb; import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension; import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.SimpleTable; import test.kar.archidata.dataAccess.model.SimpleTable;
@ -49,7 +51,7 @@ public class TestSimpleTable {
ConfigureDb.clear(); ConfigureDb.clear();
} }
public TestSimpleTable() { public TestSimpleTable() throws InternalServerErrorException, IOException, DataAccessException {
this.da = DBAccess.createInterface(); this.da = DBAccess.createInterface();
} }

View File

@ -18,10 +18,12 @@ import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.dataAccess.DBAccessSQL; import org.kar.archidata.dataAccess.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory; import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.dataAccess.QueryOptions; import org.kar.archidata.dataAccess.QueryOptions;
import org.kar.archidata.exception.DataAccessException;
import org.kar.archidata.tools.ConfigBaseVariable; import org.kar.archidata.tools.ConfigBaseVariable;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb; import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension; import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.SimpleTableSoftDelete; import test.kar.archidata.dataAccess.model.SimpleTableSoftDelete;
@ -51,7 +53,7 @@ public class TestSimpleTableSoftDelete {
ConfigureDb.clear(); ConfigureDb.clear();
} }
public TestSimpleTableSoftDelete() { public TestSimpleTableSoftDelete() throws InternalServerErrorException, IOException, DataAccessException {
this.da = DBAccess.createInterface(); this.da = DBAccess.createInterface();
} }

View File

@ -14,9 +14,11 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.dataAccess.DBAccessSQL; import org.kar.archidata.dataAccess.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory; import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb; import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension; import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.Enum1ForTest; import test.kar.archidata.dataAccess.model.Enum1ForTest;
@ -39,7 +41,7 @@ public class TestTypeEnum1 {
ConfigureDb.clear(); ConfigureDb.clear();
} }
public TestTypeEnum1() { public TestTypeEnum1() throws InternalServerErrorException, IOException, DataAccessException {
this.da = DBAccess.createInterface(); this.da = DBAccess.createInterface();
} }

View File

@ -14,9 +14,11 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.dataAccess.DBAccessSQL; import org.kar.archidata.dataAccess.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory; import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb; import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension; import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.Enum2ForTest; import test.kar.archidata.dataAccess.model.Enum2ForTest;
@ -39,7 +41,7 @@ public class TestTypeEnum2 {
ConfigureDb.clear(); ConfigureDb.clear();
} }
public TestTypeEnum2() { public TestTypeEnum2() throws InternalServerErrorException, IOException, DataAccessException {
this.da = DBAccess.createInterface(); this.da = DBAccess.createInterface();
} }

View File

@ -19,9 +19,11 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.dataAccess.DBAccessSQL; import org.kar.archidata.dataAccess.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory; import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb; import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension; import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.TypesTable; import test.kar.archidata.dataAccess.model.TypesTable;
@ -43,7 +45,7 @@ public class TestTypes {
ConfigureDb.clear(); ConfigureDb.clear();
} }
public TestTypes() { public TestTypes() throws InternalServerErrorException, IOException, DataAccessException {
this.da = DBAccess.createInterface(); this.da = DBAccess.createInterface();
} }

View File

@ -10,13 +10,15 @@ import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.kar.archidata.GlobalConfiguration;
import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.db.DbConfig;
import org.kar.archidata.exception.DataAccessException;
import org.kar.archidata.migration.MigrationEngine; import org.kar.archidata.migration.MigrationEngine;
import org.kar.archidata.migration.MigrationException; import org.kar.archidata.migration.MigrationException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb; import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension; import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.migration.model.TypesMigrationInitialisationFirst; import test.kar.archidata.migration.model.TypesMigrationInitialisationFirst;
@ -28,7 +30,7 @@ public class TestMigrationFail {
private DBAccess da = null; private DBAccess da = null;
public TestMigrationFail() { public TestMigrationFail() throws InternalServerErrorException, IOException, DataAccessException {
this.da = DBAccess.createInterface(); this.da = DBAccess.createInterface();
} }
@ -48,7 +50,7 @@ public class TestMigrationFail {
final MigrationEngine migrationEngine = new MigrationEngine(this.da); final MigrationEngine migrationEngine = new MigrationEngine(this.da);
// add initialization: // add initialization:
migrationEngine.setInit(new InitializationFirst()); migrationEngine.setInit(new InitializationFirst());
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig()); migrationEngine.migrateErrorThrow(new DbConfig());
final TypesMigrationInitialisationFirst test = new TypesMigrationInitialisationFirst(); final TypesMigrationInitialisationFirst test = new TypesMigrationInitialisationFirst();
test.testData = 95.0; test.testData = 95.0;
@ -66,7 +68,7 @@ public class TestMigrationFail {
migrationEngine.add(new Migration1()); migrationEngine.add(new Migration1());
migrationEngine.add(new MigrationFail()); migrationEngine.add(new MigrationFail());
Assertions.assertThrows(MigrationException.class, () -> { Assertions.assertThrows(MigrationException.class, () -> {
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig()); migrationEngine.migrateErrorThrow(new DbConfig());
}); });
} }

View File

@ -10,12 +10,14 @@ import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.kar.archidata.GlobalConfiguration;
import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.db.DbConfig;
import org.kar.archidata.exception.DataAccessException;
import org.kar.archidata.migration.MigrationEngine; import org.kar.archidata.migration.MigrationEngine;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb; import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension; import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.migration.model.TypesMigrationInitialisationCurrent; import test.kar.archidata.migration.model.TypesMigrationInitialisationCurrent;
@ -28,7 +30,7 @@ public class TestMigrationFirstInit {
private DBAccess da = null; private DBAccess da = null;
public TestMigrationFirstInit() { public TestMigrationFirstInit() throws InternalServerErrorException, IOException, DataAccessException {
this.da = DBAccess.createInterface(); this.da = DBAccess.createInterface();
} }
@ -48,7 +50,7 @@ public class TestMigrationFirstInit {
final MigrationEngine migrationEngine = new MigrationEngine(this.da); final MigrationEngine migrationEngine = new MigrationEngine(this.da);
// add initialization: // add initialization:
migrationEngine.setInit(new InitializationFirst()); migrationEngine.setInit(new InitializationFirst());
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig()); migrationEngine.migrateErrorThrow(new DbConfig());
final TypesMigrationInitialisationFirst test = new TypesMigrationInitialisationFirst(); final TypesMigrationInitialisationFirst test = new TypesMigrationInitialisationFirst();
test.testData = 95.0; test.testData = 95.0;
@ -63,7 +65,7 @@ public class TestMigrationFirstInit {
final MigrationEngine migrationEngine = new MigrationEngine(this.da); final MigrationEngine migrationEngine = new MigrationEngine(this.da);
// add initialization: // add initialization:
migrationEngine.setInit(new InitializationFirst()); migrationEngine.setInit(new InitializationFirst());
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig()); migrationEngine.migrateErrorThrow(new DbConfig());
final TypesMigrationInitialisationFirst test = new TypesMigrationInitialisationFirst(); final TypesMigrationInitialisationFirst test = new TypesMigrationInitialisationFirst();
test.testData = 99.0; test.testData = 99.0;
@ -80,7 +82,7 @@ public class TestMigrationFirstInit {
migrationEngine.setInit(new InitializationCurrent()); migrationEngine.setInit(new InitializationCurrent());
migrationEngine.add(new Migration1()); migrationEngine.add(new Migration1());
migrationEngine.add(new Migration2()); migrationEngine.add(new Migration2());
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig()); migrationEngine.migrateErrorThrow(new DbConfig());
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent(); final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
test.testDataMigration2 = 125.0; test.testDataMigration2 = 125.0;
@ -97,7 +99,7 @@ public class TestMigrationFirstInit {
migrationEngine.setInit(new InitializationCurrent()); migrationEngine.setInit(new InitializationCurrent());
migrationEngine.add(new Migration1()); migrationEngine.add(new Migration1());
migrationEngine.add(new Migration2()); migrationEngine.add(new Migration2());
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig()); migrationEngine.migrateErrorThrow(new DbConfig());
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent(); final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
test.testDataMigration2 = 2563.0; test.testDataMigration2 = 2563.0;

View File

@ -11,13 +11,15 @@ import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.kar.archidata.GlobalConfiguration;
import org.kar.archidata.dataAccess.DBAccess; import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.db.DbConfig;
import org.kar.archidata.exception.DataAccessException;
import org.kar.archidata.migration.MigrationEngine; import org.kar.archidata.migration.MigrationEngine;
import org.kar.archidata.migration.model.Migration; import org.kar.archidata.migration.model.Migration;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb; import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension; import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.migration.model.TypesMigrationInitialisationCurrent; import test.kar.archidata.migration.model.TypesMigrationInitialisationCurrent;
@ -29,7 +31,7 @@ public class TestMigrationFirstInitWithMigration {
private DBAccess da = null; private DBAccess da = null;
public TestMigrationFirstInitWithMigration() { public TestMigrationFirstInitWithMigration() throws InternalServerErrorException, IOException, DataAccessException {
this.da = DBAccess.createInterface(); this.da = DBAccess.createInterface();
} }
@ -52,7 +54,7 @@ public class TestMigrationFirstInitWithMigration {
// add migration for old version // add migration for old version
migrationEngine.add(new Migration1()); migrationEngine.add(new Migration1());
migrationEngine.add(new Migration2()); migrationEngine.add(new Migration2());
Assertions.assertDoesNotThrow(() -> migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig())); Assertions.assertDoesNotThrow(() -> migrationEngine.migrateErrorThrow(new DbConfig()));
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent(); final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
test.testDataMigration2 = 95.0; test.testDataMigration2 = 95.0;
@ -76,7 +78,7 @@ public class TestMigrationFirstInitWithMigration {
// add migration for old version // add migration for old version
migrationEngine.add(new Migration1()); migrationEngine.add(new Migration1());
migrationEngine.add(new Migration2()); migrationEngine.add(new Migration2());
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig()); migrationEngine.migrateErrorThrow(new DbConfig());
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent(); final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
test.testDataMigration2 = 99.0; test.testDataMigration2 = 99.0;