[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.FormDataParam;
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.options.Condition;
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
/** Upload some datas */
private static long tmpFolderId = 1;
protected final DBAccess da = DBAccess.createInterface();
private static void createFolder(final String path) throws IOException {
if (!Files.exists(java.nio.file.Path.of(path))) {
@ -122,7 +121,7 @@ public class DataResource {
public Data getWithSha512(final String sha512) {
LOGGER.info("find sha512 = {}", sha512);
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) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -133,7 +132,7 @@ public class DataResource {
public Data getWithId(final long id) {
LOGGER.info("find id = {}", id);
try {
return this.da.get(Data.class, id);
return DataAccess.get(Data.class, id);
} catch (final Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -162,7 +161,7 @@ public class DataResource {
injectedData.size = Files.size(Paths.get(tmpPath));
try {
injectedData = this.da.insert(injectedData);
injectedData = DataAccess.insert(injectedData);
} catch (final Exception e) {
e.printStackTrace();
return null;
@ -255,7 +254,7 @@ public class DataResource {
public Data getSmall(final UUID id) {
try {
return this.da.get(Data.class, id);
return DataAccess.get(Data.class, id);
} catch (final Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -502,7 +501,7 @@ public class DataResource {
}
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.List;
import org.kar.archidata.GlobalConfiguration;
import org.kar.archidata.annotation.AnnotationTools;
import org.kar.archidata.dataAccess.options.Condition;
import org.kar.archidata.dataAccess.options.FilterValue;
import org.kar.archidata.dataAccess.options.Limit;
import org.kar.archidata.dataAccess.options.QueryOption;
import org.kar.archidata.dataAccess.options.TransmitKey;
import org.kar.archidata.db.DBConfig;
import org.kar.archidata.db.DBInterfaceFactory;
import org.kar.archidata.db.DbInterface;
import org.kar.archidata.db.DbInterfaceMorphia;
import org.kar.archidata.db.DbInterfaceSQL;
import org.kar.archidata.db.DbConfig;
import org.kar.archidata.db.DbIo;
import org.kar.archidata.db.DbIoFactory;
import org.kar.archidata.db.DbIoMorphia;
import org.kar.archidata.db.DbIoSql;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -35,48 +34,42 @@ import jakarta.ws.rs.InternalServerErrorException;
* back-end. */
public abstract class DBAccess implements Closeable {
final static Logger LOGGER = LoggerFactory.getLogger(DBAccess.class);
public static final DBAccess createInterface() {
try {
return DBAccess.createInterface(GlobalConfiguration.getDbconfig());
} catch (InternalServerErrorException | IOException e) {
LOGGER.error("Fail to initialize connection of the DB");
e.printStackTrace();
}
return null;
public static final DBAccess createInterface()
throws InternalServerErrorException, IOException, DataAccessException {
return DBAccess.createInterface(DbIoFactory.create());
}
public static final DBAccess createInterface(final DBConfig config)
public static final DBAccess createInterface(final DbConfig config)
throws InternalServerErrorException, IOException {
final DBInterfaceFactory entry = DBInterfaceFactory.create(config);
return DBAccess.createInterface(entry.getDbInterface());
return DBAccess.createInterface(DbIoFactory.create(config));
}
public static final DBAccess createInterface(final DbInterface io) throws InternalServerErrorException {
if (io instanceof final DbInterfaceMorphia ioMorphia) {
public static final DBAccess createInterface(final DbIo io) throws InternalServerErrorException {
if (io instanceof final DbIoMorphia ioMorphia) {
return new DBAccessMorphia(ioMorphia);
} else if (io instanceof final DbInterfaceSQL ioSQL) {
} else if (io instanceof final DbIoSql ioSQL) {
return new DBAccessSQL(ioSQL);
}
throw new InternalServerErrorException("unknow DB interface ... ");
}
public boolean isDBExist(final String name, final QueryOption... option) throws InternalServerErrorException {
throw new InternalServerErrorException("Can Not manage the DB-access");
}
public boolean createDB(final String name) {
throw new InternalServerErrorException("Can Not manage the DB-access");
}
public void deleteDB(final String name) {
throw new InternalServerErrorException("Can Not manage the DB-access");
}
public boolean isTableExist(final String name, final QueryOption... option) throws InternalServerErrorException {
throw new InternalServerErrorException("Can Not manage the DB-access");
}
public <ID_TYPE> QueryCondition getTableIdCondition(final Class<?> clazz, final ID_TYPE idKey)
throws DataAccessException {
// Find the ID field type ....
@ -99,7 +92,7 @@ public abstract class DBAccess implements Closeable {
}
return new QueryCondition(AnnotationTools.getFieldName(idField), "=", idKey);
}
// TODO: manage insert batch...
public <T> List<T> insertMultiple(final List<T> data, final QueryOption... options) throws Exception {
final List<T> out = new ArrayList<>();
@ -109,9 +102,9 @@ public abstract class DBAccess implements Closeable {
}
return out;
}
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...
public <T> T insertWithJson(final Class<T> clazz, final String jsonData) throws Exception {
final ObjectMapper mapper = new ObjectMapper();
@ -119,7 +112,7 @@ public abstract class DBAccess implements Closeable {
final T data = mapper.readValue(jsonData, clazz);
return insert(data);
}
/** Update an object with the inserted json data
*
* @param <T> Type of the object to insert
@ -139,7 +132,7 @@ public abstract class DBAccess implements Closeable {
options.add(new TransmitKey(id));
return updateWhereWithJson(clazz, jsonData, options.getAllArray());
}
public <T> long updateWhereWithJson(final Class<T> clazz, final String jsonData, final QueryOption... option)
throws Exception {
final QueryOptions options = new QueryOptions(option);
@ -157,11 +150,11 @@ public abstract class DBAccess implements Closeable {
options.add(new FilterValue(keys));
return updateWhere(data, options.getAllArray());
}
public <T, ID_TYPE> long update(final T data, final ID_TYPE id) throws Exception {
return update(data, id, AnnotationTools.getFieldsNames(data.getClass()));
}
/** @param <T>
* @param data
* @param id
@ -179,14 +172,14 @@ public abstract class DBAccess implements Closeable {
options.add(new TransmitKey(id));
return updateWhere(data, options);
}
public <T> long updateWhere(final T data, final QueryOption... option) throws Exception {
final QueryOptions options = new QueryOptions(option);
return updateWhere(data, options);
}
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 {
options.add(new Limit(1));
final List<T> values = getsWhere(clazz, options);
@ -195,17 +188,17 @@ public abstract class DBAccess implements Closeable {
}
return values.get(0);
}
public <T> T getWhere(final Class<T> clazz, final QueryOption... option) throws Exception {
final QueryOptions options = new QueryOptions(option);
return getWhere(clazz, options);
}
public <T> List<T> getsWhere(final Class<T> clazz, final QueryOption... option) throws Exception {
final QueryOptions options = new QueryOptions(option);
return getsWhere(clazz, options);
}
public Condition conditionFusionOrEmpty(final QueryOptions options, final boolean throwIfEmpty)
throws DataAccessException {
if (options == null) {
@ -231,37 +224,37 @@ public abstract class DBAccess implements Closeable {
}
return condition;
}
abstract public <T> List<T> getsWhere(final Class<T> clazz, final QueryOptions options)
throws DataAccessException, IOException;
public <ID_TYPE> long count(final Class<?> clazz, final ID_TYPE id, final QueryOption... option) throws Exception {
final QueryOptions options = new QueryOptions(option);
options.add(new Condition(getTableIdCondition(clazz, id)));
return countWhere(clazz, options);
}
public long countWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
final QueryOptions options = new QueryOptions(option);
return countWhere(clazz, options);
}
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 {
final QueryOptions options = new QueryOptions(option);
options.add(new Condition(getTableIdCondition(clazz, id)));
return getWhere(clazz, options.getAllArray());
}
public <T> List<T> gets(final Class<T> clazz) throws Exception {
return getsWhere(clazz);
}
public <T> List<T> gets(final Class<T> clazz, final QueryOption... option) throws Exception {
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).
* @param <ID_TYPE> Type of the reference @Id
* @param clazz Data model that might remove element
@ -277,7 +270,7 @@ public abstract class DBAccess implements Closeable {
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).
* @param clazz Data model that might remove element.
* @param condition Condition to remove elements.
@ -291,40 +284,40 @@ public abstract class DBAccess implements Closeable {
return deleteHardWhere(clazz, option);
}
}
public <ID_TYPE> long deleteHard(final Class<?> clazz, final ID_TYPE id, final QueryOption... option)
throws Exception {
final QueryOptions options = new QueryOptions(option);
options.add(new Condition(getTableIdCondition(clazz, id)));
return deleteHardWhere(clazz, options.getAllArray());
}
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)
throws Exception {
final QueryOptions options = new QueryOptions(option);
options.add(new Condition(getTableIdCondition(clazz, id)));
return deleteSoftWhere(clazz, options.getAllArray());
}
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 {
return unsetDeleteWhere(clazz, new Condition(getTableIdCondition(clazz, id)));
}
public <ID_TYPE> long unsetDelete(final Class<?> clazz, final ID_TYPE id, final QueryOption... option)
throws DataAccessException {
final QueryOptions options = new QueryOptions(option);
options.add(new Condition(getTableIdCondition(clazz, id)));
return unsetDeleteWhere(clazz, options.getAllArray());
}
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 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.OrderBy;
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.tools.UuidUtils;
import org.slf4j.Logger;
@ -74,13 +74,13 @@ public class DBAccessMorphia extends DBAccess {
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;
}
public DbInterfaceMorphia getInterface() {
public DbIoMorphia getInterface() {
return this.db;
}
@ -120,7 +120,7 @@ public class DBAccessMorphia extends DBAccess {
return groups;
}
protected <T> void setValuedb(
final Class<?> type,
final T data,
@ -349,7 +349,7 @@ public class DBAccessMorphia extends DBAccess {
return;
//throw new ArchiveException("wrong type of field [" + fieldName + "]: " + doc.toJson());
}
protected Object convertDefaultField(String data, final Field field) throws Exception {
if (data.startsWith("'") && data.endsWith("'")) {
data = data.substring(1, data.length() - 1);
@ -939,6 +939,6 @@ public class DBAccessMorphia extends DBAccess {
@Override
public void close() throws IOException {
// 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.QueryOption;
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.tools.ConfigBaseVariable;
import org.kar.archidata.tools.DateTools;
@ -73,9 +73,9 @@ public class DBAccessSQL extends DBAccess {
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;
}
@ -1616,7 +1616,7 @@ public class DBAccessSQL extends DBAccess {
}
return outs;
}
@Override
public void close() throws IOException {
// 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
* back-end. */
public class DataAccess {
static final Logger LOGGER = LoggerFactory.getLogger(DataAccess.class);
private static final Logger LOGGER = LoggerFactory.getLogger(DataAccess.class);
public DataAccess() {
}
public static boolean isDBExist(final String name, final QueryOption... options)
throws InternalServerErrorException, IOException {
throws InternalServerErrorException, IOException, DataAccessException {
try (DBAccess db = DBAccess.createInterface()) {
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()) {
return db.createDB(name);
}
}
public static boolean isTableExist(final String name, final QueryOption... options)
throws InternalServerErrorException, IOException {
throws InternalServerErrorException, IOException, DataAccessException {
try (DBAccess db = DBAccess.createInterface()) {
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)
throws DataAccessException, IOException {
try (DBAccess db = DBAccess.createInterface()) {

View File

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

View File

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

View File

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

View File

@ -39,8 +39,7 @@ public class QueryOr implements QueryItem {
}
@Override
public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
throws Exception {
public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii) throws Exception {
for (final QueryItem elem : this.childs) {
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);
if (AnnotationTools.isPrimaryKey(field)) {
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,
"This is a '@Id' (primaryKey) ==> can not be change");
});
}
if (AnnotationTools.getConstraintsNotNull(field)) {
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) {
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)) {
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");
});
}
@ -420,11 +408,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
if (AnnotationTools.isUnique(field)) {
// Create the request ...
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);
Object other = null;
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)
throws Exception {
public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii) throws Exception {
if (this.condition != null) {
this.condition.injectQuery(ioDb, ps, iii);
}

View File

@ -16,8 +16,7 @@ public class Limit extends QueryOption {
query.append(" LIMIT ? \n");
}
public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
throws Exception {
public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii) throws Exception {
ioDb.addElement(ps, this.limit, iii);
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;
import java.util.List;
import org.kar.archidata.dataAccess.DBAccess;
import org.kar.archidata.exception.DataAccessException;
import org.kar.archidata.tools.ConfigBaseVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DBConfig {
public class DbConfig {
static final Logger LOGGER = LoggerFactory.getLogger(DBAccess.class);
private final String type;
private final String hostname;
@ -14,9 +17,17 @@ public class DBConfig {
private final String password;
private final String dbName;
private final boolean keepConnected;
private final List<Class<?>> classes;
public DBConfig(final String type, final String hostname, final Integer port, final String login,
final String password, final String dbName, final boolean keepConnected) throws DataAccessException {
public DbConfig() 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) {
this.type = "mysql";
} else {
@ -43,6 +54,7 @@ public class DBConfig {
this.password = password;
this.dbName = dbName;
this.keepConnected = keepConnected;
this.classes = classes;
}
@ -81,6 +93,10 @@ public class DBConfig {
return this.keepConnected;
}
public List<Class<?>> getClasses() {
return this.classes;
}
public String getUrl() {
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.Morphia;
public class DbInterfaceMorphia extends DbInterface implements Closeable {
private final static Logger LOGGER = LoggerFactory.getLogger(DbInterfaceMorphia.class);
private final MongoClient mongoClient;
private final Datastore datastore;
public class DbIoMorphia extends DbIo implements Closeable {
private final static Logger LOGGER = LoggerFactory.getLogger(DbIoMorphia.class);
private MongoClient mongoClient = null;
private Datastore datastore = null;
public DbInterfaceMorphia(final DBConfig config, final Class<?>... classes) throws IOException {
this(config.getUrl(), config.getDbName(), classes);
public DbIoMorphia(final DbConfig config) throws IOException {
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):
// final MongoClient mongoClient = MongoClients.create(dbUrl);
LOGGER.info("Connect on the DB: {}", dbUrl);
@ -61,18 +80,4 @@ public class DbInterfaceMorphia extends DbInterface implements Closeable {
// Ensure indexes
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.LoggerFactory;
public class DbInterfaceSQL extends DbInterface implements Closeable {
final static Logger LOGGER = LoggerFactory.getLogger(DbInterfaceSQL.class);
public class DbIoSql extends DbIo implements Closeable {
final static Logger LOGGER = LoggerFactory.getLogger(DbIoSql.class);
private Connection connection = null;
public DbInterfaceSQL(final DBConfig config) throws IOException {
this(config.getUrl(), config.getLogin(), config.getPassword());
public DbIoSql(final DbConfig config) throws IOException {
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 {
this.connection = DriverManager.getConnection(dbUrl, login, password);
} catch (final SQLException ex) {
@ -27,12 +38,12 @@ public class DbInterfaceSQL extends DbInterface implements Closeable {
}
}
public Connection getConnection() {
return this.connection;
}
@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 {
this.connection.close();
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.DataFactory;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.ws.rs.InternalServerErrorException;
public class MigrationEngine {
final static Logger LOGGER = LoggerFactory.getLogger(MigrationEngine.class);
@ -26,6 +28,10 @@ public class MigrationEngine {
protected final DBAccess da;
public MigrationEngine() throws InternalServerErrorException, IOException, DataAccessException {
this(DBAccess.createInterface());
}
/** Migration engine constructor (empty). */
public MigrationEngine(final DBAccess da) {
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.
* @param config SQL connection for 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 {
migrateErrorThrow(config);
} catch (final Exception ex) {
@ -110,7 +116,7 @@ public class MigrationEngine {
* @throws IOException Error if access on the DB */
@SuppressFBWarnings({ "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING",
"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]");
// check the integrity of the migrations:
LOGGER.info("List of availlable Migration: ");

View File

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

View File

@ -17,6 +17,7 @@ public class ConfigBaseVariable {
static public String eMailFrom;
static public String eMailLogin;
static public String eMailPassword;
static public Class<?>[] dbInterfacesClasses;
// For test only
public static void clearAllValue() {
@ -36,6 +37,7 @@ public class ConfigBaseVariable {
eMailFrom = System.getenv("EMAIL_FROM");
eMailLogin = System.getenv("EMAIL_LOGIN");
eMailPassword = System.getenv("EMAIL_PASSWORD");
dbInterfacesClasses = new Class<?>[0];
}
static {
@ -70,14 +72,17 @@ public class ConfigBaseVariable {
return dbHost;
}
public static String getDBPort() {
public static Short getDBPort() {
if (dbPort == null) {
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() {
@ -142,4 +147,11 @@ public class ConfigBaseVariable {
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.util.List;
import org.kar.archidata.GlobalConfiguration;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.dataAccess.model.SerializeAsJson;
import test.kar.archidata.dataAccess.model.SerializeListAsJson;
import test.kar.archidata.dataAccess.model.SimpleTable;
@ -36,8 +37,9 @@ import test.kar.archidata.dataAccess.model.TypesTable;
public class ConfigureDb {
final static private Logger LOGGER = LoggerFactory.getLogger(ConfigureDb.class);
final static private String modeTestForced = null;//"MONGO";
public static void configure() throws IOException {
static DBAccess dba = null;
public static void configure() throws IOException, InternalServerErrorException, DataAccessException {
String modeTest = System.getenv("TEST_E2E_MODE");
if (modeTest == null || modeTest.isEmpty() || "false".equalsIgnoreCase(modeTest)) {
modeTest = "SQLITE-MEMORY";
@ -97,17 +99,12 @@ public class ConfigureDb {
ConfigBaseVariable.dbUser = "root";
}
// Connect the dataBase...
final DBInterfaceFactory entry = DBInterfaceFactory.create(GlobalConfiguration.getDbconfig(),
listObject.toArray(new Class<?>[0]));
entry.connect();
dba = DBAccess.createInterface();
removeDB();
}
public static void removeDB() {
final DBAccess da = DBAccess.createInterface();
String modeTest = System.getenv("TEST_E2E_MODE");
if (modeTest == null || modeTest.isEmpty() || "false".equalsIgnoreCase(modeTest)) {
modeTest = "SQLITE-MEMORY";
@ -121,19 +118,19 @@ public class ConfigureDb {
if ("SQLITE-MEMORY".equalsIgnoreCase(modeTest)) {
// nothing to do ...
} else if ("SQLITE".equalsIgnoreCase(modeTest)) {
da.deleteDB(ConfigBaseVariable.bdDatabase);
dba.deleteDB(ConfigBaseVariable.bdDatabase);
} else if ("MY-SQL".equalsIgnoreCase(modeTest)) {
da.deleteDB(ConfigBaseVariable.bdDatabase);
dba.deleteDB(ConfigBaseVariable.bdDatabase);
} else if ("MONGO".equalsIgnoreCase(modeTest)) {
da.deleteDB(ConfigBaseVariable.bdDatabase);
dba.deleteDB(ConfigBaseVariable.bdDatabase);
} else {}
}
public static void clear() throws IOException {
LOGGER.info("Remove the test db");
removeDB();
DBInterfaceFactory.closeAllForceMode();
DbIoFactory.closeAllForceMode();
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.media.multipart.MultiPartFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.kar.archidata.GlobalConfiguration;
import org.kar.archidata.UpdateJwtPublicKey;
import org.kar.archidata.api.DataResource;
import org.kar.archidata.api.ProxyResource;
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.OptionFilter;
import org.kar.archidata.migration.MigrationEngine;
@ -33,11 +33,7 @@ public class WebLauncher {
protected UpdateJwtPublicKey keyUpdater = null;
protected HttpServer server = null;
private final DBAccess da;
public WebLauncher() {
this.da = DBAccess.createInterface();
}
public WebLauncher() {}
private static URI getBaseURI() {
return UriBuilder.fromUri(ConfigBaseVariable.getlocalAddress()).build();
@ -45,13 +41,13 @@ public class WebLauncher {
public void migrateDB() throws Exception {
WebLauncher.LOGGER.info("Create migration engine");
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
final MigrationEngine migrationEngine = new MigrationEngine();
WebLauncher.LOGGER.info("Add initialization");
//migrationEngine.setInit(new Initialization());
WebLauncher.LOGGER.info("Add migration since last version");
//migrationEngine.add(new Migration20231126());
WebLauncher.LOGGER.info("Migrate the DB [START]");
migrationEngine.migrateWaitAdmin(GlobalConfiguration.getDbconfig());
migrationEngine.migrateWaitAdmin(new DbConfig());
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();
plop("jpeg");
@ -127,8 +123,8 @@ public class WebLauncher {
// System.out.println(" getDBLogin: '" + ConfigVariable.getDBLogin() + "'");
// System.out.println(" getDBPassword: '" + ConfigVariable.getDBPassword() + "'");
// System.out.println(" getDBName: '" + ConfigVariable.getDBName() + "'");
System.out.println(" ==> " + GlobalConfiguration.getDbconfig());
System.out.println("OAuth service " + getBaseURI());
LOGGER.info(" ==> {}", new DbConfig());
LOGGER.info("OAuth service {}", getBaseURI());
this.server = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc);
final HttpServer serverLink = this.server;
Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {

View File

@ -1,14 +1,10 @@
package test.kar.archidata.apiExtern;
import java.io.IOException;
import org.kar.archidata.tools.ConfigBaseVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import test.kar.archidata.ConfigureDb;
public class WebLauncherTest extends WebLauncher {
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).
ConfigBaseVariable.testMode = "true";
// 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.AsyncType;
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.LoggerFactory;
@ -27,40 +27,39 @@ import test.kar.archidata.dataAccess.model.SimpleTable;
public class TestResourceSample {
private static final Logger LOGGER = LoggerFactory.getLogger(TestResource.class);
private final DBAccess da = DBAccess.createInterface();
@GET
@PermitAll
public List<SimpleTable> gets() throws Exception {
return this.da.gets(SimpleTable.class);
return DataAccess.gets(SimpleTable.class);
}
@GET
@Path("{id}")
@PermitAll
public SimpleTable get(@PathParam("id") final Long id) throws Exception {
return this.da.get(SimpleTable.class, id);
return DataAccess.get(SimpleTable.class, id);
}
@ARCHIVE
@Path("{id}")
@PermitAll
public SimpleTable archive(@PathParam("id") final Long id) throws Exception {
return this.da.get(SimpleTable.class, id);
return DataAccess.get(SimpleTable.class, id);
}
@RESTORE
@Path("{id}")
@PermitAll
public SimpleTable restore(@PathParam("id") final Long id) throws Exception {
return this.da.get(SimpleTable.class, id);
return DataAccess.get(SimpleTable.class, id);
}
@POST
@PermitAll
@Consumes(MediaType.APPLICATION_JSON)
public SimpleTable post(final SimpleTable data) throws Exception {
return this.da.insert(data);
return DataAccess.insert(data);
}
@PATCH
@ -69,8 +68,8 @@ public class TestResourceSample {
@Consumes(MediaType.APPLICATION_JSON)
public SimpleTable patch(@PathParam("id") final Long id, @AsyncType(SimpleTable.class) final String jsonRequest)
throws Exception {
this.da.updateWithJson(SimpleTable.class, id, jsonRequest);
return this.da.get(SimpleTable.class, id);
DataAccess.updateWithJson(SimpleTable.class, id, jsonRequest);
return DataAccess.get(SimpleTable.class, id);
}
@PUT
@ -78,15 +77,15 @@ public class TestResourceSample {
@PermitAll
@Consumes(MediaType.APPLICATION_JSON)
public SimpleTable put(@PathParam("id") final Long id, final SimpleTable data) throws Exception {
this.da.update(data, id);
return this.da.get(SimpleTable.class, id);
DataAccess.update(data, id);
return DataAccess.get(SimpleTable.class, id);
}
@DELETE
@Path("{id}")
@PermitAll
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.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.SerializeAsJson;
@ -39,7 +41,7 @@ public class TestJson {
ConfigureDb.clear();
}
public TestJson() {
public TestJson() throws InternalServerErrorException, IOException, DataAccessException {
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.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.SerializeListAsJson;
@ -39,7 +41,7 @@ public class TestListJson {
ConfigureDb.clear();
}
public TestListJson() {
public TestListJson() throws InternalServerErrorException, IOException, DataAccessException {
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.DataFactory;
import org.kar.archidata.dataAccess.addOnSQL.AddOnManyToMany;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.TypeManyToManyRemote;
@ -41,7 +43,7 @@ public class TestManyToMany {
ConfigureDb.clear();
}
public TestManyToMany() {
public TestManyToMany() throws InternalServerErrorException, IOException, DataAccessException {
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.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.TypeManyToOneRemote;
@ -43,7 +45,7 @@ public class TestManyToOne {
ConfigureDb.clear();
}
public TestManyToOne() {
public TestManyToOne() throws InternalServerErrorException, IOException, DataAccessException {
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.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.TypeOneToManyRemote;
@ -43,7 +45,7 @@ public class TestOneToMany {
ConfigureDb.clear();
}
public TestOneToMany() {
public TestOneToMany() throws InternalServerErrorException, IOException, DataAccessException {
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.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.TypesTable;
@ -38,7 +40,7 @@ public class TestRawQuery {
ConfigureDb.clear();
}
public TestRawQuery() {
public TestRawQuery() throws InternalServerErrorException, IOException, DataAccessException {
this.da = DBAccess.createInterface();
if (this.da instanceof final DBAccessSQL daSQL) {
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.DataFactory;
import org.kar.archidata.dataAccess.QueryOptions;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.SimpleTable;
@ -49,7 +51,7 @@ public class TestSimpleTable {
ConfigureDb.clear();
}
public TestSimpleTable() {
public TestSimpleTable() throws InternalServerErrorException, IOException, DataAccessException {
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.DataFactory;
import org.kar.archidata.dataAccess.QueryOptions;
import org.kar.archidata.exception.DataAccessException;
import org.kar.archidata.tools.ConfigBaseVariable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.SimpleTableSoftDelete;
@ -51,7 +53,7 @@ public class TestSimpleTableSoftDelete {
ConfigureDb.clear();
}
public TestSimpleTableSoftDelete() {
public TestSimpleTableSoftDelete() throws InternalServerErrorException, IOException, DataAccessException {
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.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.Enum1ForTest;
@ -39,7 +41,7 @@ public class TestTypeEnum1 {
ConfigureDb.clear();
}
public TestTypeEnum1() {
public TestTypeEnum1() throws InternalServerErrorException, IOException, DataAccessException {
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.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.Enum2ForTest;
@ -39,7 +41,7 @@ public class TestTypeEnum2 {
ConfigureDb.clear();
}
public TestTypeEnum2() {
public TestTypeEnum2() throws InternalServerErrorException, IOException, DataAccessException {
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.DBAccessSQL;
import org.kar.archidata.dataAccess.DataFactory;
import org.kar.archidata.exception.DataAccessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.dataAccess.model.TypesTable;
@ -43,7 +45,7 @@ public class TestTypes {
ConfigureDb.clear();
}
public TestTypes() {
public TestTypes() throws InternalServerErrorException, IOException, DataAccessException {
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.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.kar.archidata.GlobalConfiguration;
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.MigrationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.migration.model.TypesMigrationInitialisationFirst;
@ -28,7 +30,7 @@ public class TestMigrationFail {
private DBAccess da = null;
public TestMigrationFail() {
public TestMigrationFail() throws InternalServerErrorException, IOException, DataAccessException {
this.da = DBAccess.createInterface();
}
@ -48,7 +50,7 @@ public class TestMigrationFail {
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
// add initialization:
migrationEngine.setInit(new InitializationFirst());
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig());
migrationEngine.migrateErrorThrow(new DbConfig());
final TypesMigrationInitialisationFirst test = new TypesMigrationInitialisationFirst();
test.testData = 95.0;
@ -66,7 +68,7 @@ public class TestMigrationFail {
migrationEngine.add(new Migration1());
migrationEngine.add(new MigrationFail());
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.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.kar.archidata.GlobalConfiguration;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.migration.model.TypesMigrationInitialisationCurrent;
@ -28,7 +30,7 @@ public class TestMigrationFirstInit {
private DBAccess da = null;
public TestMigrationFirstInit() {
public TestMigrationFirstInit() throws InternalServerErrorException, IOException, DataAccessException {
this.da = DBAccess.createInterface();
}
@ -48,7 +50,7 @@ public class TestMigrationFirstInit {
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
// add initialization:
migrationEngine.setInit(new InitializationFirst());
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig());
migrationEngine.migrateErrorThrow(new DbConfig());
final TypesMigrationInitialisationFirst test = new TypesMigrationInitialisationFirst();
test.testData = 95.0;
@ -63,7 +65,7 @@ public class TestMigrationFirstInit {
final MigrationEngine migrationEngine = new MigrationEngine(this.da);
// add initialization:
migrationEngine.setInit(new InitializationFirst());
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig());
migrationEngine.migrateErrorThrow(new DbConfig());
final TypesMigrationInitialisationFirst test = new TypesMigrationInitialisationFirst();
test.testData = 99.0;
@ -80,7 +82,7 @@ public class TestMigrationFirstInit {
migrationEngine.setInit(new InitializationCurrent());
migrationEngine.add(new Migration1());
migrationEngine.add(new Migration2());
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig());
migrationEngine.migrateErrorThrow(new DbConfig());
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
test.testDataMigration2 = 125.0;
@ -97,7 +99,7 @@ public class TestMigrationFirstInit {
migrationEngine.setInit(new InitializationCurrent());
migrationEngine.add(new Migration1());
migrationEngine.add(new Migration2());
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig());
migrationEngine.migrateErrorThrow(new DbConfig());
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
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.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.kar.archidata.GlobalConfiguration;
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.model.Migration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import jakarta.ws.rs.InternalServerErrorException;
import test.kar.archidata.ConfigureDb;
import test.kar.archidata.StepwiseExtension;
import test.kar.archidata.migration.model.TypesMigrationInitialisationCurrent;
@ -29,7 +31,7 @@ public class TestMigrationFirstInitWithMigration {
private DBAccess da = null;
public TestMigrationFirstInitWithMigration() {
public TestMigrationFirstInitWithMigration() throws InternalServerErrorException, IOException, DataAccessException {
this.da = DBAccess.createInterface();
}
@ -52,7 +54,7 @@ public class TestMigrationFirstInitWithMigration {
// add migration for old version
migrationEngine.add(new Migration1());
migrationEngine.add(new Migration2());
Assertions.assertDoesNotThrow(() -> migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig()));
Assertions.assertDoesNotThrow(() -> migrationEngine.migrateErrorThrow(new DbConfig()));
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
test.testDataMigration2 = 95.0;
@ -76,7 +78,7 @@ public class TestMigrationFirstInitWithMigration {
// add migration for old version
migrationEngine.add(new Migration1());
migrationEngine.add(new Migration2());
migrationEngine.migrateErrorThrow(GlobalConfiguration.getDbconfig());
migrationEngine.migrateErrorThrow(new DbConfig());
final TypesMigrationInitialisationCurrent test = new TypesMigrationInitialisationCurrent();
test.testDataMigration2 = 99.0;