Compare commits
2 Commits
78dfb481fa
...
4d99835a6a
Author | SHA1 | Date | |
---|---|---|---|
4d99835a6a | |||
22b17972dc |
@ -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.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.QueryCondition;
|
||||
import org.kar.archidata.dataAccess.options.Condition;
|
||||
import org.kar.archidata.exception.FailException;
|
||||
@ -64,7 +64,7 @@ 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 DataAccess da = DataAccess.createInterface();
|
||||
protected final DBAccess da = DBAccess.createInterface();
|
||||
|
||||
private static void createFolder(final String path) throws IOException {
|
||||
if (!Files.exists(java.nio.file.Path.of(path))) {
|
||||
|
330
src/org/kar/archidata/dataAccess/DBAccess.java
Normal file
330
src/org/kar/archidata/dataAccess/DBAccess.java
Normal file
@ -0,0 +1,330 @@
|
||||
package org.kar.archidata.dataAccess;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
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.exception.DataAccessException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import jakarta.ws.rs.InternalServerErrorException;
|
||||
|
||||
/* TODO list:
|
||||
- Manage to group of SQL action to permit to commit only at the end.
|
||||
*/
|
||||
|
||||
/** 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 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(final DBConfig config)
|
||||
throws InternalServerErrorException, IOException {
|
||||
final DBInterfaceFactory entry = DBInterfaceFactory.create(config);
|
||||
return DBAccess.createInterface(entry.getDbInterface());
|
||||
}
|
||||
|
||||
public static final DBAccess createInterface(final DbInterface io) throws InternalServerErrorException {
|
||||
if (io instanceof final DbInterfaceMorphia ioMorphia) {
|
||||
return new DBAccessMorphia(ioMorphia);
|
||||
} else if (io instanceof final DbInterfaceSQL 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 ....
|
||||
final Field idField = AnnotationTools.getIdField(clazz);
|
||||
if (idField == null) {
|
||||
throw new DataAccessException(
|
||||
"The class have no annotation @Id ==> can not determine the default type searching");
|
||||
}
|
||||
// check the compatibility of the id and the declared ID
|
||||
final Class<?> typeClass = idField.getType();
|
||||
if (idKey == null) {
|
||||
throw new DataAccessException("Try to identify the ID type and object was null.");
|
||||
}
|
||||
if (idKey.getClass() != typeClass) {
|
||||
if (idKey.getClass() == Condition.class) {
|
||||
throw new DataAccessException(
|
||||
"Try to identify the ID type on a condition 'close' internal API error use xxxWhere(...) instead.");
|
||||
}
|
||||
throw new DataAccessException("Request update with the wrong type ...");
|
||||
}
|
||||
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<>();
|
||||
for (final T elem : data) {
|
||||
final T tmp = insert(elem, options);
|
||||
out.add(tmp);
|
||||
}
|
||||
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();
|
||||
// parse the object to be sure the data are valid:
|
||||
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
|
||||
* @param <ID_TYPE> Master key on the object manage with @Id
|
||||
* @param clazz Class reference of the insertion model
|
||||
* @param id Key to insert data
|
||||
* @param jsonData Json data (partial) values to update
|
||||
* @return the number of object updated
|
||||
* @throws Exception */
|
||||
public <T, ID_TYPE> long updateWithJson(
|
||||
final Class<T> clazz,
|
||||
final ID_TYPE id,
|
||||
final String jsonData,
|
||||
final QueryOption... option) throws Exception {
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
options.add(new Condition(getTableIdCondition(clazz, id)));
|
||||
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);
|
||||
if (options.get(Condition.class).size() == 0) {
|
||||
throw new DataAccessException("request a updateWhereWithJson without any condition");
|
||||
}
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
// parse the object to be sure the data are valid:
|
||||
final T data = mapper.readValue(jsonData, clazz);
|
||||
// Read the tree to filter injection of data:
|
||||
final JsonNode root = mapper.readTree(jsonData);
|
||||
final List<String> keys = new ArrayList<>();
|
||||
final var iterator = root.fieldNames();
|
||||
iterator.forEachRemaining(e -> keys.add(e));
|
||||
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
|
||||
* @param filterValue
|
||||
* @return the affected rows.
|
||||
* @throws Exception */
|
||||
public <T, ID_TYPE> long update(
|
||||
final T data,
|
||||
final ID_TYPE id,
|
||||
final List<String> updateColomn,
|
||||
final QueryOption... option) throws Exception {
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
options.add(new Condition(getTableIdCondition(data.getClass(), id)));
|
||||
options.add(new FilterValue(updateColomn));
|
||||
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);
|
||||
if (values.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
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) {
|
||||
return new Condition();
|
||||
}
|
||||
final List<Condition> conditions = options.get(Condition.class);
|
||||
if (conditions.size() == 0) {
|
||||
if (throwIfEmpty) {
|
||||
throw new DataAccessException("request a gets without any condition");
|
||||
} else {
|
||||
return new Condition();
|
||||
}
|
||||
}
|
||||
Condition condition = null;
|
||||
if (conditions.size() == 1) {
|
||||
condition = conditions.get(0);
|
||||
} else {
|
||||
final QueryAnd andCondition = new QueryAnd();
|
||||
for (final Condition cond : conditions) {
|
||||
andCondition.add(cond.condition);
|
||||
}
|
||||
condition = new Condition(andCondition);
|
||||
}
|
||||
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
|
||||
* @param id Unique Id of the model
|
||||
* @param options (Optional) Options of the request
|
||||
* @return Number of element that is removed. */
|
||||
public <ID_TYPE> long delete(final Class<?> clazz, final ID_TYPE id, final QueryOption... options)
|
||||
throws Exception {
|
||||
final String hasDeletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||
if (hasDeletedFieldName != null) {
|
||||
return deleteSoft(clazz, id, options);
|
||||
} else {
|
||||
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.
|
||||
* @param options (Optional) Options of the request.
|
||||
* @return Number of element that is removed. */
|
||||
public long deleteWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
||||
final String hasDeletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||
if (hasDeletedFieldName != null) {
|
||||
return deleteSoftWhere(clazz, option);
|
||||
} else {
|
||||
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;
|
||||
|
||||
}
|
@ -3,9 +3,6 @@ package org.kar.archidata.dataAccess;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
@ -34,7 +31,6 @@ import org.kar.archidata.dataAccess.options.OrderBy;
|
||||
import org.kar.archidata.dataAccess.options.QueryOption;
|
||||
import org.kar.archidata.db.DbInterfaceMorphia;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.kar.archidata.tools.DateTools;
|
||||
import org.kar.archidata.tools.UuidUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -59,8 +55,8 @@ 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 DataAccessMorphia extends DataAccess {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(DataAccessMorphia.class);
|
||||
public class DBAccessMorphia extends DBAccess {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(DBAccessMorphia.class);
|
||||
// by default we manage some add-on that permit to manage non-native model (like json serialization, List of external key as String list...)
|
||||
static final List<DataAccessAddOn> addOn = new ArrayList<>();
|
||||
|
||||
@ -75,12 +71,12 @@ public class DataAccessMorphia extends DataAccess {
|
||||
* @param addOn instantiate object on the Add-on
|
||||
*/
|
||||
public static void addAddOn(final DataAccessAddOn addOn) {
|
||||
DataAccessMorphia.addOn.add(addOn);
|
||||
DBAccessMorphia.addOn.add(addOn);
|
||||
}
|
||||
|
||||
private final DbInterfaceMorphia db;
|
||||
|
||||
public DataAccessMorphia(final DbInterfaceMorphia db) {
|
||||
public DBAccessMorphia(final DbInterfaceMorphia db) {
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
@ -111,44 +107,6 @@ public class DataAccessMorphia extends DataAccess {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Extract a list of Long with "-" separated element from a SQL input data.
|
||||
* @param rs Result Set of the BDD
|
||||
* @param iii Id in the result set
|
||||
* @return The list of Long value
|
||||
* @throws SQLException if an error is generated in the SQL request. */
|
||||
public List<Long> getListOfIds(final ResultSet rs, final int iii, final String separator) throws SQLException {
|
||||
final String trackString = rs.getString(iii);
|
||||
if (rs.wasNull()) {
|
||||
return null;
|
||||
}
|
||||
final List<Long> out = new ArrayList<>();
|
||||
final String[] elements = trackString.split(separator);
|
||||
for (final String elem : elements) {
|
||||
final Long tmp = Long.parseLong(elem);
|
||||
out.add(tmp);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Extract a list of UUID with "-" separated element from a SQL input data.
|
||||
* @param rs Result Set of the BDD
|
||||
* @param iii Id in the result set
|
||||
* @return The list of Long value
|
||||
* @throws SQLException if an error is generated in the SQL request. */
|
||||
public List<UUID> getListOfUUIDs(final ResultSet rs, final int iii, final String separator) throws SQLException {
|
||||
final String trackString = rs.getString(iii);
|
||||
if (rs.wasNull()) {
|
||||
return null;
|
||||
}
|
||||
final List<UUID> out = new ArrayList<>();
|
||||
final String[] elements = trackString.split(separator);
|
||||
for (final String elem : elements) {
|
||||
final UUID tmp = UUID.fromString(elem);
|
||||
out.add(tmp);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public byte[][] splitIntoGroupsOf16Bytes(final byte[] input) {
|
||||
final int inputLength = input.length;
|
||||
final int numOfGroups = (inputLength + 15) / 16; // Calculate the number of groups needed
|
||||
@ -162,29 +120,7 @@ public class DataAccessMorphia extends DataAccess {
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
public List<UUID> getListOfRawUUIDs(final ResultSet rs, final int iii) throws SQLException, DataAccessException {
|
||||
final byte[] trackString = rs.getBytes(iii);
|
||||
if (rs.wasNull()) {
|
||||
return null;
|
||||
}
|
||||
final byte[][] elements = splitIntoGroupsOf16Bytes(trackString);
|
||||
final List<UUID> out = new ArrayList<>();
|
||||
for (final byte[] elem : elements) {
|
||||
final UUID tmp = UuidUtils.asUuid(elem);
|
||||
out.add(tmp);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public UUID getListOfRawUUID(final ResultSet rs, final int iii) throws SQLException, DataAccessException {
|
||||
final byte[] elem = rs.getBytes(iii);
|
||||
if (rs.wasNull()) {
|
||||
return null;
|
||||
}
|
||||
return UuidUtils.asUuid(elem);
|
||||
}
|
||||
|
||||
|
||||
protected <T> void setValuedb(
|
||||
final Class<?> type,
|
||||
final T data,
|
||||
@ -413,221 +349,7 @@ public class DataAccessMorphia extends DataAccess {
|
||||
return;
|
||||
//throw new ArchiveException("wrong type of field [" + fieldName + "]: " + doc.toJson());
|
||||
}
|
||||
|
||||
// TODO: this function will replace the previous one !!!
|
||||
protected RetreiveFromDB createSetValueFromDbCallback(final int count, final Field field) throws Exception {
|
||||
final Class<?> type = field.getType();
|
||||
if (type == UUID.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
|
||||
final byte[] tmp = rs.getBytes(count);
|
||||
// final UUID tmp = rs.getObject(count, UUID.class);
|
||||
if (rs.wasNull()) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
// field.set(obj, tmp);
|
||||
final UUID uuid = UuidUtils.asUuid(tmp);
|
||||
field.set(obj, uuid);
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == Long.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final Long tmp = rs.getLong(count);
|
||||
if (rs.wasNull()) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, tmp);
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == long.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final Long tmp = rs.getLong(count);
|
||||
if (rs.wasNull()) {
|
||||
// field.set(data, null);
|
||||
} else {
|
||||
field.setLong(obj, tmp);
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == Integer.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final Integer tmp = rs.getInt(count);
|
||||
if (rs.wasNull()) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, tmp);
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == int.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final Integer tmp = rs.getInt(count);
|
||||
if (rs.wasNull()) {
|
||||
// field.set(obj, null);
|
||||
} else {
|
||||
field.setInt(obj, tmp);
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == Float.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final Float tmp = rs.getFloat(count);
|
||||
if (rs.wasNull()) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, tmp);
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == float.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final Float tmp = rs.getFloat(count);
|
||||
if (rs.wasNull()) {
|
||||
// field.set(obj, null);
|
||||
} else {
|
||||
field.setFloat(obj, tmp);
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == Double.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final Double tmp = rs.getDouble(count);
|
||||
if (rs.wasNull()) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, tmp);
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == double.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final Double tmp = rs.getDouble(count);
|
||||
if (rs.wasNull()) {
|
||||
// field.set(obj, null);
|
||||
} else {
|
||||
field.setDouble(obj, tmp);
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == Boolean.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final Boolean tmp = rs.getBoolean(count);
|
||||
if (rs.wasNull()) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, tmp);
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == boolean.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final Boolean tmp = rs.getBoolean(count);
|
||||
if (rs.wasNull()) {
|
||||
// field.set(obj, null);
|
||||
} else {
|
||||
field.setBoolean(obj, tmp);
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == Timestamp.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final Timestamp tmp = rs.getTimestamp(count);
|
||||
if (rs.wasNull()) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, tmp);
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == Date.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
try {
|
||||
final Timestamp tmp = rs.getTimestamp(count);
|
||||
if (rs.wasNull()) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, Date.from(tmp.toInstant()));
|
||||
}
|
||||
} catch (final SQLException ex) {
|
||||
final String tmp = rs.getString(count);
|
||||
LOGGER.error("Fail to parse the SQL time !!! {}", tmp);
|
||||
if (rs.wasNull()) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
final Date date = DateTools.parseDate(tmp);
|
||||
LOGGER.error("Fail to parse the SQL time !!! {}", date);
|
||||
field.set(obj, date);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == Instant.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final String tmp = rs.getString(count);
|
||||
if (rs.wasNull()) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, Instant.parse(tmp));
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == LocalDate.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final java.sql.Date tmp = rs.getDate(count);
|
||||
if (rs.wasNull()) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, tmp.toLocalDate());
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == LocalTime.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final java.sql.Time tmp = rs.getTime(count);
|
||||
if (rs.wasNull()) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, tmp.toLocalTime());
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type == String.class) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final String tmp = rs.getString(count);
|
||||
if (rs.wasNull()) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
field.set(obj, tmp);
|
||||
}
|
||||
};
|
||||
}
|
||||
if (type.isEnum()) {
|
||||
return (final ResultSet rs, final Object obj) -> {
|
||||
final String tmp = rs.getString(count);
|
||||
if (rs.wasNull()) {
|
||||
field.set(obj, null);
|
||||
} else {
|
||||
boolean find = false;
|
||||
final Object[] arr = type.getEnumConstants();
|
||||
for (final Object elem : arr) {
|
||||
if (elem.toString().equals(tmp)) {
|
||||
field.set(obj, elem);
|
||||
find = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!find) {
|
||||
throw new DataAccessException("Enum value does not exist in the Model: '" + tmp + "'");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
throw new DataAccessException("Unknown Field Type");
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected Object convertDefaultField(String data, final Field field) throws Exception {
|
||||
if (data.startsWith("'") && data.endsWith("'")) {
|
||||
data = data.substring(1, data.length() - 1);
|
||||
@ -912,7 +634,7 @@ public class DataAccessMorphia extends DataAccess {
|
||||
LOGGER.info("updateWhere with value: {}", actions.toJson());
|
||||
final UpdateResult ret = collection.updateMany(filters, actions);
|
||||
return ret.getModifiedCount();
|
||||
} catch (final SQLException ex) {
|
||||
} catch (final Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
for (final LazyGetter action : asyncActions) {
|
||||
@ -921,55 +643,6 @@ public class DataAccessMorphia extends DataAccess {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addElement(final PreparedStatement ps, final Object value, final CountInOut iii) throws Exception {
|
||||
if (value instanceof final UUID tmp) {
|
||||
final byte[] dataByte = UuidUtils.asBytes(tmp);
|
||||
ps.setBytes(iii.value, dataByte);
|
||||
} else if (value instanceof final Long tmp) {
|
||||
LOGGER.debug("Inject Long => {}", tmp);
|
||||
ps.setLong(iii.value, tmp);
|
||||
} else if (value instanceof final Integer tmp) {
|
||||
LOGGER.debug("Inject Integer => {}", tmp);
|
||||
ps.setInt(iii.value, tmp);
|
||||
} else if (value instanceof final String tmp) {
|
||||
LOGGER.debug("Inject String => {}", tmp);
|
||||
ps.setString(iii.value, tmp);
|
||||
} else if (value instanceof final Short tmp) {
|
||||
LOGGER.debug("Inject Short => {}", tmp);
|
||||
ps.setShort(iii.value, tmp);
|
||||
} else if (value instanceof final Byte tmp) {
|
||||
LOGGER.debug("Inject Byte => {}", tmp);
|
||||
ps.setByte(iii.value, tmp);
|
||||
} else if (value instanceof final Float tmp) {
|
||||
LOGGER.debug("Inject Float => {}", tmp);
|
||||
ps.setFloat(iii.value, tmp);
|
||||
} else if (value instanceof final Double tmp) {
|
||||
LOGGER.debug("Inject Double => {}", tmp);
|
||||
ps.setDouble(iii.value, tmp);
|
||||
} else if (value instanceof final Boolean tmp) {
|
||||
LOGGER.debug("Inject Boolean => {}", tmp);
|
||||
ps.setBoolean(iii.value, tmp);
|
||||
} else if (value instanceof final Timestamp tmp) {
|
||||
LOGGER.debug("Inject Timestamp => {}", tmp);
|
||||
ps.setTimestamp(iii.value, tmp);
|
||||
} else if (value instanceof final Date tmp) {
|
||||
LOGGER.debug("Inject Date => {}", tmp);
|
||||
ps.setTimestamp(iii.value, java.sql.Timestamp.from((tmp).toInstant()));
|
||||
} else if (value instanceof final LocalDate tmp) {
|
||||
LOGGER.debug("Inject LocalDate => {}", tmp);
|
||||
ps.setDate(iii.value, java.sql.Date.valueOf(tmp));
|
||||
} else if (value instanceof final LocalTime tmp) {
|
||||
LOGGER.debug("Inject LocalTime => {}", tmp);
|
||||
ps.setTime(iii.value, java.sql.Time.valueOf(tmp));
|
||||
} else if (value.getClass().isEnum()) {
|
||||
LOGGER.debug("Inject ENUM => {}", value.toString());
|
||||
ps.setString(iii.value, value.toString());
|
||||
} else {
|
||||
throw new DataAccessException("Not manage type ==> need to add it ...");
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> generateSelectField(final Class<?> clazz, final QueryOptions options) throws Exception {
|
||||
// TODO: list of user select fields.
|
||||
final boolean readAllfields = QueryOptions.readAllColomn(options);
|
||||
@ -1083,9 +756,6 @@ public class DataAccessMorphia extends DataAccess {
|
||||
elem.doRequest();
|
||||
}
|
||||
}
|
||||
} catch (final SQLException ex) {
|
||||
ex.printStackTrace();
|
||||
throw new DataAccessException("Catch a SQL Exception: " + ex.getMessage());
|
||||
} catch (final Exception ex) {
|
||||
ex.printStackTrace();
|
||||
throw new DataAccessException("Catch an Exception: " + ex.getMessage());
|
||||
@ -1198,7 +868,8 @@ public class DataAccessMorphia extends DataAccess {
|
||||
return retFind.getDeletedCount();
|
||||
}
|
||||
|
||||
private <ID_TYPE> long deleteSoft(final Class<?> clazz, final ID_TYPE id, final QueryOption... option)
|
||||
@Override
|
||||
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)));
|
||||
@ -1264,4 +935,10 @@ public class DataAccessMorphia extends DataAccess {
|
||||
final MongoCollection<Document> collection = this.db.getDatastore().getDatabase().getCollection(collectionName);
|
||||
collection.deleteMany(new Document());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
@ -55,8 +55,8 @@ 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 DataAccessSQL extends DataAccess {
|
||||
final static Logger LOGGER = LoggerFactory.getLogger(DataAccessSQL.class);
|
||||
public class DBAccessSQL extends DBAccess {
|
||||
final static Logger LOGGER = LoggerFactory.getLogger(DBAccessSQL.class);
|
||||
// by default we manage some add-on that permit to manage non-native model (like json serialization, List of external key as String list...)
|
||||
final static List<DataAccessAddOn> addOn = new ArrayList<>();
|
||||
|
||||
@ -70,12 +70,12 @@ public class DataAccessSQL extends DataAccess {
|
||||
/** Add a new add-on on the current management.
|
||||
* @param addOn instantiate object on the Add-on */
|
||||
public static void addAddOn(final DataAccessAddOn addOn) {
|
||||
DataAccessSQL.addOn.add(addOn);
|
||||
DBAccessSQL.addOn.add(addOn);
|
||||
}
|
||||
|
||||
private final DbInterfaceSQL db;
|
||||
|
||||
public DataAccessSQL(final DbInterfaceSQL db) {
|
||||
public DBAccessSQL(final DbInterfaceSQL db) {
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
@ -1121,7 +1121,6 @@ public class DataAccessSQL extends DataAccess {
|
||||
return 0L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addElement(final PreparedStatement ps, final Object value, final CountInOut iii) throws Exception {
|
||||
if (value instanceof final UUID tmp) {
|
||||
final byte[] dataByte = UuidUtils.asBytes(tmp);
|
||||
@ -1617,4 +1616,10 @@ public class DataAccessSQL extends DataAccess {
|
||||
}
|
||||
return outs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
@ -1,36 +1,15 @@
|
||||
package org.kar.archidata.dataAccess;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
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.DBEntry;
|
||||
import org.kar.archidata.db.DbInterface;
|
||||
import org.kar.archidata.db.DbInterfaceMorphia;
|
||||
import org.kar.archidata.db.DbInterfaceSQL;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.kar.archidata.tools.UuidUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
||||
import jakarta.ws.rs.InternalServerErrorException;
|
||||
|
||||
/* TODO list:
|
||||
@ -39,91 +18,59 @@ 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 abstract class DataAccess {
|
||||
final static Logger LOGGER = LoggerFactory.getLogger(DataAccess.class);
|
||||
public class DataAccess {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(DataAccess.class);
|
||||
|
||||
public DataAccess() {
|
||||
|
||||
public static final DataAccess createInterface() {
|
||||
try {
|
||||
return DataAccess.createInterface(GlobalConfiguration.getDbconfig());
|
||||
} catch (InternalServerErrorException | IOException e) {
|
||||
LOGGER.error("Fail to initialize connection of the DB");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static final DataAccess createInterface(final DBConfig config)
|
||||
public static boolean isDBExist(final String name, final QueryOption... options)
|
||||
throws InternalServerErrorException, IOException {
|
||||
final DBEntry entry = DBEntry.createInterface(config);
|
||||
return DataAccess.createInterface(entry.getDbInterface());
|
||||
}
|
||||
|
||||
public static final DataAccess createInterface(final DbInterface io) throws InternalServerErrorException {
|
||||
if (io instanceof final DbInterfaceMorphia ioMorphia) {
|
||||
return new DataAccessMorphia(ioMorphia);
|
||||
} else if (io instanceof final DbInterfaceSQL ioSQL) {
|
||||
return new DataAccessSQL(ioSQL);
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.isDBExist(name, options);
|
||||
}
|
||||
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 ....
|
||||
final Field idField = AnnotationTools.getIdField(clazz);
|
||||
if (idField == null) {
|
||||
throw new DataAccessException(
|
||||
"The class have no annotation @Id ==> can not determine the default type searching");
|
||||
public static boolean createDB(final String name) throws IOException {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.createDB(name);
|
||||
}
|
||||
// check the compatibility of the id and the declared ID
|
||||
final Class<?> typeClass = idField.getType();
|
||||
if (idKey == null) {
|
||||
throw new DataAccessException("Try to identify the ID type and object was null.");
|
||||
}
|
||||
|
||||
public static boolean isTableExist(final String name, final QueryOption... options)
|
||||
throws InternalServerErrorException, IOException {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.isTableExist(name, options);
|
||||
}
|
||||
if (idKey.getClass() != typeClass) {
|
||||
if (idKey.getClass() == Condition.class) {
|
||||
throw new DataAccessException(
|
||||
"Try to identify the ID type on a condition 'close' internal API error use xxxWhere(...) instead.");
|
||||
}
|
||||
throw new DataAccessException("Request update with the wrong type ...");
|
||||
}
|
||||
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<>();
|
||||
for (final T elem : data) {
|
||||
final T tmp = insert(elem, options);
|
||||
out.add(tmp);
|
||||
public static <T> List<T> insertMultiple(final List<T> data, final QueryOption... options) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.insertMultiple(data, options);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
abstract public <T> T insert(final T data, final QueryOption... option) throws Exception;
|
||||
@SuppressFBWarnings("SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING")
|
||||
public static <T> T insert(final T data, final QueryOption... options) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.insert(data, options);
|
||||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
// parse the object to be sure the data are valid:
|
||||
final T data = mapper.readValue(jsonData, clazz);
|
||||
return insert(data);
|
||||
public static <T> T insertWithJson(final Class<T> clazz, final String jsonData) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.insertWithJson(clazz, jsonData);
|
||||
}
|
||||
}
|
||||
|
||||
public static <ID_TYPE> QueryCondition getTableIdCondition(final Class<?> clazz, final ID_TYPE idKey)
|
||||
throws DataAccessException, IOException {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.getTableIdCondition(clazz, idKey);
|
||||
}
|
||||
}
|
||||
|
||||
/** Update an object with the inserted json data
|
||||
@ -135,37 +82,29 @@ public abstract class DataAccess {
|
||||
* @param jsonData Json data (partial) values to update
|
||||
* @return the number of object updated
|
||||
* @throws Exception */
|
||||
public <T, ID_TYPE> long updateWithJson(
|
||||
public static <T, ID_TYPE> long updateWithJson(
|
||||
final Class<T> clazz,
|
||||
final ID_TYPE id,
|
||||
final String jsonData,
|
||||
final QueryOption... option) throws Exception {
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
options.add(new Condition(getTableIdCondition(clazz, id)));
|
||||
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);
|
||||
if (options.get(Condition.class).size() == 0) {
|
||||
throw new DataAccessException("request a updateWhereWithJson without any condition");
|
||||
final QueryOption... options) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.updateWithJson(clazz, id, jsonData, options);
|
||||
}
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
// parse the object to be sure the data are valid:
|
||||
final T data = mapper.readValue(jsonData, clazz);
|
||||
// Read the tree to filter injection of data:
|
||||
final JsonNode root = mapper.readTree(jsonData);
|
||||
final List<String> keys = new ArrayList<>();
|
||||
final var iterator = root.fieldNames();
|
||||
iterator.forEachRemaining(e -> keys.add(e));
|
||||
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()));
|
||||
public static <T> long updateWhereWithJson(
|
||||
final Class<T> clazz,
|
||||
final String jsonData,
|
||||
final QueryOption... options) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.updateWhereWithJson(clazz, jsonData, options);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T, ID_TYPE> long update(final T data, final ID_TYPE id) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.update(data, id);
|
||||
}
|
||||
}
|
||||
|
||||
/** @param <T>
|
||||
@ -174,146 +113,97 @@ public abstract class DataAccess {
|
||||
* @param filterValue
|
||||
* @return the affected rows.
|
||||
* @throws Exception */
|
||||
public <T, ID_TYPE> long update(
|
||||
public static <T, ID_TYPE> long update(
|
||||
final T data,
|
||||
final ID_TYPE id,
|
||||
final List<String> updateColomn,
|
||||
final QueryOption... option) throws Exception {
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
options.add(new Condition(getTableIdCondition(data.getClass(), id)));
|
||||
options.add(new FilterValue(updateColomn));
|
||||
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 void addElement(final PreparedStatement ps, final Object value, final CountInOut iii) throws Exception {
|
||||
if (value instanceof final UUID tmp) {
|
||||
final byte[] dataByte = UuidUtils.asBytes(tmp);
|
||||
ps.setBytes(iii.value, dataByte);
|
||||
} else if (value instanceof final Long tmp) {
|
||||
LOGGER.debug("Inject Long => {}", tmp);
|
||||
ps.setLong(iii.value, tmp);
|
||||
} else if (value instanceof final Integer tmp) {
|
||||
LOGGER.debug("Inject Integer => {}", tmp);
|
||||
ps.setInt(iii.value, tmp);
|
||||
} else if (value instanceof final String tmp) {
|
||||
LOGGER.debug("Inject String => {}", tmp);
|
||||
ps.setString(iii.value, tmp);
|
||||
} else if (value instanceof final Short tmp) {
|
||||
LOGGER.debug("Inject Short => {}", tmp);
|
||||
ps.setShort(iii.value, tmp);
|
||||
} else if (value instanceof final Byte tmp) {
|
||||
LOGGER.debug("Inject Byte => {}", tmp);
|
||||
ps.setByte(iii.value, tmp);
|
||||
} else if (value instanceof final Float tmp) {
|
||||
LOGGER.debug("Inject Float => {}", tmp);
|
||||
ps.setFloat(iii.value, tmp);
|
||||
} else if (value instanceof final Double tmp) {
|
||||
LOGGER.debug("Inject Double => {}", tmp);
|
||||
ps.setDouble(iii.value, tmp);
|
||||
} else if (value instanceof final Boolean tmp) {
|
||||
LOGGER.debug("Inject Boolean => {}", tmp);
|
||||
ps.setBoolean(iii.value, tmp);
|
||||
} else if (value instanceof final Timestamp tmp) {
|
||||
LOGGER.debug("Inject Timestamp => {}", tmp);
|
||||
ps.setTimestamp(iii.value, tmp);
|
||||
} else if (value instanceof final Date tmp) {
|
||||
LOGGER.debug("Inject Date => {}", tmp);
|
||||
ps.setTimestamp(iii.value, java.sql.Timestamp.from((tmp).toInstant()));
|
||||
} else if (value instanceof final LocalDate tmp) {
|
||||
LOGGER.debug("Inject LocalDate => {}", tmp);
|
||||
ps.setDate(iii.value, java.sql.Date.valueOf(tmp));
|
||||
} else if (value instanceof final LocalTime tmp) {
|
||||
LOGGER.debug("Inject LocalTime => {}", tmp);
|
||||
ps.setTime(iii.value, java.sql.Time.valueOf(tmp));
|
||||
} else if (value.getClass().isEnum()) {
|
||||
LOGGER.debug("Inject ENUM => {}", value.toString());
|
||||
ps.setString(iii.value, value.toString());
|
||||
} else {
|
||||
throw new DataAccessException("Not manage type ==> need to add it ...");
|
||||
final QueryOption... options) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.update(data, id, updateColomn, options);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
if (values.size() == 0) {
|
||||
return null;
|
||||
public static <T> long updateWhere(final T data, final QueryOption... options) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.updateWhere(data, options);
|
||||
}
|
||||
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) {
|
||||
return new Condition();
|
||||
public static <T> long updateWhere(final T data, final QueryOptions options) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.updateWhere(data, options);
|
||||
}
|
||||
final List<Condition> conditions = options.get(Condition.class);
|
||||
if (conditions.size() == 0) {
|
||||
if (throwIfEmpty) {
|
||||
throw new DataAccessException("request a gets without any condition");
|
||||
} else {
|
||||
return new Condition();
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T getWhere(final Class<T> clazz, final QueryOptions options) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.getWhere(clazz, options);
|
||||
}
|
||||
Condition condition = null;
|
||||
if (conditions.size() == 1) {
|
||||
condition = conditions.get(0);
|
||||
} else {
|
||||
final QueryAnd andCondition = new QueryAnd();
|
||||
for (final Condition cond : conditions) {
|
||||
andCondition.add(cond.condition);
|
||||
}
|
||||
condition = new Condition(andCondition);
|
||||
}
|
||||
|
||||
public static <T> T getWhere(final Class<T> clazz, final QueryOption... options) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.getWhere(clazz, options);
|
||||
}
|
||||
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 static <T> List<T> getsWhere(final Class<T> clazz, final QueryOption... options) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.getsWhere(clazz, options);
|
||||
}
|
||||
}
|
||||
|
||||
public long countWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
return countWhere(clazz, options);
|
||||
public static Condition conditionFusionOrEmpty(final QueryOptions options, final boolean throwIfEmpty)
|
||||
throws DataAccessException, IOException {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.conditionFusionOrEmpty(options, throwIfEmpty);
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> List<T> getsWhere(final Class<T> clazz, final QueryOptions options)
|
||||
throws DataAccessException, IOException {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.getsWhere(clazz, options);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> List<T> gets(final Class<T> clazz) throws Exception {
|
||||
return getsWhere(clazz);
|
||||
public static <ID_TYPE> long count(final Class<?> clazz, final ID_TYPE id, final QueryOption... options)
|
||||
throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.count(clazz, id, options);
|
||||
}
|
||||
}
|
||||
|
||||
public <T> List<T> gets(final Class<T> clazz, final QueryOption... option) throws Exception {
|
||||
return getsWhere(clazz, option);
|
||||
public static long countWhere(final Class<?> clazz, final QueryOption... options) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.countWhere(clazz, options);
|
||||
}
|
||||
}
|
||||
|
||||
public static long countWhere(final Class<?> clazz, final QueryOptions options) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.countWhere(clazz, options);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T, ID_TYPE> T get(final Class<T> clazz, final ID_TYPE id, final QueryOption... options)
|
||||
throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.get(clazz, id, options);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> List<T> gets(final Class<T> clazz) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.gets(clazz);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> List<T> gets(final Class<T> clazz, final QueryOption... options) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.gets(clazz, options);
|
||||
}
|
||||
}
|
||||
|
||||
/** 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).
|
||||
@ -322,13 +212,10 @@ public abstract class DataAccess {
|
||||
* @param id Unique Id of the model
|
||||
* @param options (Optional) Options of the request
|
||||
* @return Number of element that is removed. */
|
||||
public <ID_TYPE> long delete(final Class<?> clazz, final ID_TYPE id, final QueryOption... options)
|
||||
public static <ID_TYPE> long delete(final Class<?> clazz, final ID_TYPE id, final QueryOption... options)
|
||||
throws Exception {
|
||||
final String hasDeletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||
if (hasDeletedFieldName != null) {
|
||||
return deleteSoft(clazz, id, options);
|
||||
} else {
|
||||
return deleteHard(clazz, id, options);
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.delete(clazz, id, options);
|
||||
}
|
||||
}
|
||||
|
||||
@ -337,48 +224,69 @@ public abstract class DataAccess {
|
||||
* @param condition Condition to remove elements.
|
||||
* @param options (Optional) Options of the request.
|
||||
* @return Number of element that is removed. */
|
||||
public long deleteWhere(final Class<?> clazz, final QueryOption... option) throws Exception {
|
||||
final String hasDeletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||
if (hasDeletedFieldName != null) {
|
||||
return deleteSoftWhere(clazz, option);
|
||||
} else {
|
||||
return deleteHardWhere(clazz, option);
|
||||
public static long deleteWhere(final Class<?> clazz, final QueryOption... options) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.deleteWhere(clazz, options);
|
||||
}
|
||||
}
|
||||
|
||||
public <ID_TYPE> long deleteHard(final Class<?> clazz, final ID_TYPE id, final QueryOption... option)
|
||||
public static <ID_TYPE> long deleteHard(final Class<?> clazz, final ID_TYPE id, final QueryOption... options)
|
||||
throws Exception {
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
options.add(new Condition(getTableIdCondition(clazz, id)));
|
||||
return deleteHardWhere(clazz, options.getAllArray());
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.deleteHard(clazz, id, options);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract long deleteHardWhere(final Class<?> clazz, final QueryOption... option) throws Exception;
|
||||
public static long deleteHardWhere(final Class<?> clazz, final QueryOption... options) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.deleteHardWhere(clazz, options);
|
||||
}
|
||||
}
|
||||
|
||||
private <ID_TYPE> long deleteSoft(final Class<?> clazz, final ID_TYPE id, final QueryOption... option)
|
||||
public static <ID_TYPE> long deleteSoft(final Class<?> clazz, final ID_TYPE id, final QueryOption... options)
|
||||
throws Exception {
|
||||
final QueryOptions options = new QueryOptions(option);
|
||||
options.add(new Condition(getTableIdCondition(clazz, id)));
|
||||
return deleteSoftWhere(clazz, options.getAllArray());
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.deleteSoft(clazz, id, options);
|
||||
}
|
||||
}
|
||||
|
||||
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 static long deleteSoftWhere(final Class<?> clazz, final QueryOption... options) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.deleteSoftWhere(clazz, options);
|
||||
}
|
||||
}
|
||||
|
||||
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 static <ID_TYPE> long unsetDelete(final Class<?> clazz, final ID_TYPE id)
|
||||
throws DataAccessException, IOException {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.unsetDelete(clazz, id);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract long unsetDeleteWhere(final Class<?> clazz, final QueryOption... option) throws DataAccessException;
|
||||
public static <ID_TYPE> long unsetDelete(final Class<?> clazz, final ID_TYPE id, final QueryOption... options)
|
||||
throws DataAccessException, IOException {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.unsetDelete(clazz, id, options);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void drop(final Class<?> clazz, final QueryOption... option) throws Exception;
|
||||
public static long unsetDeleteWhere(final Class<?> clazz, final QueryOption... options)
|
||||
throws DataAccessException, IOException {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
return db.unsetDeleteWhere(clazz, options);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void cleanAll(final Class<?> clazz, final QueryOption... option) throws Exception;
|
||||
public static void drop(final Class<?> clazz, final QueryOption... options) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
db.drop(clazz, options);
|
||||
}
|
||||
}
|
||||
|
||||
public static void cleanAll(final Class<?> clazz, final QueryOption... options) throws Exception {
|
||||
try (DBAccess db = DBAccess.createInterface()) {
|
||||
db.cleanAll(clazz, options);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ public class DataExport {
|
||||
}
|
||||
|
||||
public static TableQuery queryTable(
|
||||
final DataAccessSQL ioDb,
|
||||
final DBAccessSQL ioDb,
|
||||
final List<TableQueryTypes> headers,
|
||||
final String query,
|
||||
final List<Object> parameters,
|
||||
@ -254,7 +254,7 @@ public class DataExport {
|
||||
}
|
||||
|
||||
public static TableQuery queryTable(
|
||||
final DataAccessSQL ioDb,
|
||||
final DBAccessSQL ioDb,
|
||||
final List<TableQueryTypes> headers,
|
||||
final String queryBase,
|
||||
final List<Object> parameters,
|
||||
|
@ -387,8 +387,8 @@ public class DataFactory {
|
||||
}
|
||||
alreadyAdded.add(dataName);
|
||||
LOGGER.trace(" + '{}'", elem.getName());
|
||||
if (DataAccessSQL.isAddOnField(elem)) {
|
||||
final DataAccessAddOn addOn = DataAccessSQL.findAddOnforField(elem);
|
||||
if (DBAccessSQL.isAddOnField(elem)) {
|
||||
final DataAccessAddOn addOn = DBAccessSQL.findAddOnforField(elem);
|
||||
LOGGER.trace("Create type for: {} ==> {} (ADD-ON)", AnnotationTools.getFieldName(elem),
|
||||
elem.getType());
|
||||
if (addOn != null) {
|
||||
|
@ -45,7 +45,7 @@ public class QueryAnd implements QueryItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectQuery(final DataAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||
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);
|
||||
|
@ -10,7 +10,7 @@ import org.slf4j.LoggerFactory;
|
||||
import com.mongodb.client.model.Filters;
|
||||
|
||||
public class QueryCondition implements QueryItem {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(DataAccess.class);
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(DBAccess.class);
|
||||
private final String key;
|
||||
private final String comparator;
|
||||
private final Object value;
|
||||
@ -40,7 +40,7 @@ public class QueryCondition implements QueryItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectQuery(final DataAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||
public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||
throws Exception {
|
||||
ioDb.addElement(ps, this.value, iii);
|
||||
iii.inc();
|
||||
|
@ -48,7 +48,7 @@ public class QueryInList<T> implements QueryItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectQuery(final DataAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||
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);
|
||||
|
@ -10,7 +10,7 @@ public interface QueryItem {
|
||||
void generateQuery(StringBuilder query, String tableName);
|
||||
|
||||
// For SQL mode query injection
|
||||
void injectQuery(DataAccessSQL ioDb, PreparedStatement ps, CountInOut iii) throws Exception;
|
||||
void injectQuery(DBAccessSQL ioDb, PreparedStatement ps, CountInOut iii) throws Exception;
|
||||
|
||||
// For No-SQL mode filter creation
|
||||
void generateFilter(List<Bson> filters);
|
||||
|
@ -25,7 +25,7 @@ public class QueryNotNull implements QueryItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectQuery(final DataAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||
public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||
throws Exception {}
|
||||
|
||||
@Override
|
||||
|
@ -25,7 +25,7 @@ public class QueryNull implements QueryItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectQuery(final DataAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||
public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||
throws Exception {}
|
||||
|
||||
@Override
|
||||
|
@ -39,7 +39,7 @@ public class QueryOr implements QueryItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectQuery(final DataAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||
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);
|
||||
|
@ -11,8 +11,8 @@ import org.bson.Document;
|
||||
import org.kar.archidata.annotation.AnnotationTools;
|
||||
import org.kar.archidata.annotation.DataJson;
|
||||
import org.kar.archidata.dataAccess.CountInOut;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataAccessMorphia;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessMorphia;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.LazyGetter;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
@ -55,7 +55,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void insertData(
|
||||
final DataAccessMorphia ioDb,
|
||||
final DBAccessMorphia ioDb,
|
||||
final Field field,
|
||||
final Object rootObject,
|
||||
final Document docSet,
|
||||
@ -105,7 +105,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void fillFromDoc(
|
||||
final DataAccessMorphia ioDb,
|
||||
final DBAccessMorphia ioDb,
|
||||
final Document doc,
|
||||
final Field field,
|
||||
final Object data,
|
||||
@ -181,7 +181,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
public static void addLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final Long id,
|
||||
final String column,
|
||||
@ -212,12 +212,12 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
* @throws Exception If an error occurs during data retrieval or update.
|
||||
*/
|
||||
public static void addLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final Long id,
|
||||
final String column,
|
||||
final UUID remoteKey) throws Exception {
|
||||
if (ioDb instanceof final DataAccessMorphia daSQL) {
|
||||
if (ioDb instanceof final DBAccessMorphia daSQL) {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
// TODO: Get primary key name
|
||||
final TableCoversLongUUID data = ioDb.get(TableCoversLongUUID.class, id, new OverrideTableName(tableName));
|
||||
@ -231,7 +231,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
data.covers.add(remoteKey);
|
||||
ioDb.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));// TODO: ,new OverrideFieldName("covers", column));
|
||||
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||
} else if (ioDb instanceof final DBAccessMorphia dam) {
|
||||
|
||||
} else {
|
||||
throw new DataAccessException("DataAccess Not managed");
|
||||
@ -250,12 +250,12 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
* @throws Exception If an error occurs during data retrieval or update.
|
||||
*/
|
||||
public static void addLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final UUID uuid,
|
||||
final String column,
|
||||
final UUID remoteKey) throws Exception {
|
||||
if (ioDb instanceof final DataAccessMorphia daSQL) {
|
||||
if (ioDb instanceof final DBAccessMorphia daSQL) {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversUUIDUUID data = ioDb.get(TableCoversUUIDUUID.class, uuid,
|
||||
new OverrideTableName(tableName));
|
||||
@ -269,7 +269,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
data.covers.add(remoteKey);
|
||||
ioDb.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
||||
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||
} else if (ioDb instanceof final DBAccessMorphia dam) {
|
||||
|
||||
} else {
|
||||
throw new DataAccessException("DataAccess Not managed");
|
||||
@ -277,12 +277,12 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
public static void addLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final UUID uuid,
|
||||
final String column,
|
||||
final Long remoteKey) throws Exception {
|
||||
if (ioDb instanceof final DataAccessMorphia daSQL) {
|
||||
if (ioDb instanceof final DBAccessMorphia daSQL) {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversUUIDLong data = ioDb.get(TableCoversUUIDLong.class, uuid,
|
||||
new OverrideTableName(tableName));
|
||||
@ -296,7 +296,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
data.covers.add(remoteKey);
|
||||
ioDb.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
||||
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||
} else if (ioDb instanceof final DBAccessMorphia dam) {
|
||||
|
||||
} else {
|
||||
throw new DataAccessException("DataAccess Not managed");
|
||||
@ -304,12 +304,12 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
public static void removeLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final UUID uuid,
|
||||
final String column,
|
||||
final Long remoteKey) throws Exception {
|
||||
if (ioDb instanceof final DataAccessMorphia daSQL) {
|
||||
if (ioDb instanceof final DBAccessMorphia daSQL) {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversUUIDLong data = ioDb.get(TableCoversUUIDLong.class, uuid,
|
||||
new OverrideTableName(tableName));
|
||||
@ -325,7 +325,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
data.covers = newList;
|
||||
ioDb.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
||||
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||
} else if (ioDb instanceof final DBAccessMorphia dam) {
|
||||
|
||||
} else {
|
||||
throw new DataAccessException("DataAccess Not managed");
|
||||
@ -333,12 +333,12 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
public static void removeLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final UUID uuid,
|
||||
final String column,
|
||||
final UUID remoteKey) throws Exception {
|
||||
if (ioDb instanceof final DataAccessMorphia daSQL) {
|
||||
if (ioDb instanceof final DBAccessMorphia daSQL) {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversUUIDUUID data = ioDb.get(TableCoversUUIDUUID.class, uuid,
|
||||
new OverrideTableName(tableName));
|
||||
@ -354,7 +354,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
data.covers = newList;
|
||||
ioDb.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
||||
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||
} else if (ioDb instanceof final DBAccessMorphia dam) {
|
||||
|
||||
} else {
|
||||
throw new DataAccessException("DataAccess Not managed");
|
||||
@ -362,12 +362,12 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
public static void removeLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final Long id,
|
||||
final String column,
|
||||
final Long remoteKey) throws Exception {
|
||||
if (ioDb instanceof final DataAccessMorphia daSQL) {
|
||||
if (ioDb instanceof final DBAccessMorphia daSQL) {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversLongLong data = ioDb.get(TableCoversLongLong.class, id, new OverrideTableName(tableName));
|
||||
if (data.covers == null) {
|
||||
@ -382,7 +382,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
data.covers = newList;
|
||||
ioDb.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
|
||||
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||
} else if (ioDb instanceof final DBAccessMorphia dam) {
|
||||
|
||||
} else {
|
||||
throw new DataAccessException("DataAccess Not managed");
|
||||
@ -390,12 +390,12 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
public static void removeLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final Long id,
|
||||
final String column,
|
||||
final UUID remoteKey) throws Exception {
|
||||
if (ioDb instanceof final DataAccessMorphia daSQL) {
|
||||
if (ioDb instanceof final DBAccessMorphia daSQL) {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversLongUUID data = ioDb.get(TableCoversLongUUID.class, id, new OverrideTableName(tableName));
|
||||
if (data.covers == null) {
|
||||
@ -409,7 +409,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
newList.add(elem);
|
||||
}
|
||||
data.covers = newList;
|
||||
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||
} else if (ioDb instanceof final DBAccessMorphia dam) {
|
||||
final String collectionName = AnnotationTools.getCollectionName(clazz);
|
||||
final Field primaryfield = AnnotationTools.getPrimaryKeyField(clazz);
|
||||
final String primaryFieldName = AnnotationTools.getFieldName(primaryfield);
|
||||
|
@ -9,8 +9,8 @@ import java.util.UUID;
|
||||
import org.bson.Document;
|
||||
import org.kar.archidata.annotation.AnnotationTools;
|
||||
import org.kar.archidata.dataAccess.CountInOut;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataAccessMorphia;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessMorphia;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.LazyGetter;
|
||||
import org.kar.archidata.dataAccess.QueryAnd;
|
||||
@ -54,7 +54,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void insertData(
|
||||
final DataAccessMorphia ioDb,
|
||||
final DBAccessMorphia ioDb,
|
||||
final Field field,
|
||||
final Object rootObject,
|
||||
final Document docSet,
|
||||
@ -206,7 +206,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void fillFromDoc(
|
||||
final DataAccessMorphia ioDb,
|
||||
final DBAccessMorphia ioDb,
|
||||
final Document doc,
|
||||
final Field field,
|
||||
final Object data,
|
||||
@ -292,7 +292,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void asyncUpdate(
|
||||
final DataAccessMorphia ioDb,
|
||||
final DBAccessMorphia ioDb,
|
||||
final String tableName,
|
||||
final Object localKey,
|
||||
final Field field,
|
||||
@ -349,7 +349,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void asyncInsert(
|
||||
final DataAccessMorphia ioDb,
|
||||
final DBAccessMorphia ioDb,
|
||||
final String tableName,
|
||||
final Object localKey,
|
||||
final Field field,
|
||||
@ -474,7 +474,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drop(final DataAccessMorphia ioDb, final String tableName, final Field field) throws Exception {
|
||||
public void drop(final DBAccessMorphia ioDb, final String tableName, final Field field) throws Exception {
|
||||
final String columnName = AnnotationTools.getFieldName(field);
|
||||
final String linkTableName = generateLinkTableName(tableName, columnName);
|
||||
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
||||
@ -487,7 +487,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanAll(final DataAccessMorphia ioDb, final String tableName, final Field field) throws Exception {
|
||||
public void cleanAll(final DBAccessMorphia ioDb, final String tableName, final Field field) throws Exception {
|
||||
final String columnName = AnnotationTools.getFieldName(field);
|
||||
final String linkTableName = generateLinkTableName(tableName, columnName);
|
||||
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
||||
@ -500,19 +500,19 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
public static void addLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final long localKey,
|
||||
final String column,
|
||||
final long remoteKey) throws Exception {
|
||||
if (ioDb instanceof final DataAccessMorphia daSQL) {
|
||||
if (ioDb instanceof final DBAccessMorphia daSQL) {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final String linkTableName = generateLinkTableName(tableName, column);
|
||||
/* final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; if (objectClass != Long.class && objectClass != UUID.class) { throw new
|
||||
* DataAccessException("Can not ManyToMany with other than List<Long> or List<UUID> Model: List<" + objectClass.getCanonicalName() + ">"); } */
|
||||
final LinkTableLongLong insertElement = new LinkTableLongLong(localKey, remoteKey);
|
||||
daSQL.insert(insertElement, new OverrideTableName(linkTableName));
|
||||
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||
} else if (ioDb instanceof final DBAccessMorphia dam) {
|
||||
|
||||
} else {
|
||||
throw new DataAccessException("DataAccess Not managed");
|
||||
@ -521,18 +521,18 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
public static long removeLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final long localKey,
|
||||
final String column,
|
||||
final long remoteKey) throws Exception {
|
||||
if (ioDb instanceof final DataAccessMorphia daSQL) {
|
||||
if (ioDb instanceof final DBAccessMorphia daSQL) {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final String linkTableName = generateLinkTableName(tableName, column);
|
||||
return daSQL.deleteWhere(LinkTableLongLong.class, new OverrideTableName(linkTableName),
|
||||
new Condition(new QueryAnd(new QueryCondition("object1Id", "=", localKey),
|
||||
new QueryCondition("object2Id", "=", remoteKey))));
|
||||
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||
} else if (ioDb instanceof final DBAccessMorphia dam) {
|
||||
return 0L;
|
||||
} else {
|
||||
throw new DataAccessException("DataAccess Not managed");
|
||||
|
@ -7,7 +7,7 @@ import java.util.UUID;
|
||||
import org.bson.Document;
|
||||
import org.kar.archidata.annotation.AnnotationTools;
|
||||
import org.kar.archidata.dataAccess.CountInOut;
|
||||
import org.kar.archidata.dataAccess.DataAccessMorphia;
|
||||
import org.kar.archidata.dataAccess.DBAccessMorphia;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.LazyGetter;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
@ -43,7 +43,7 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void insertData(
|
||||
final DataAccessMorphia ioDb,
|
||||
final DBAccessMorphia ioDb,
|
||||
final Field field,
|
||||
final Object rootObject,
|
||||
final Document docSet,
|
||||
@ -143,7 +143,7 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void fillFromDoc(
|
||||
final DataAccessMorphia ioDb,
|
||||
final DBAccessMorphia ioDb,
|
||||
final Document doc,
|
||||
final Field field,
|
||||
final Object data,
|
||||
|
@ -12,7 +12,7 @@ import java.util.stream.Collectors;
|
||||
import org.bson.Document;
|
||||
import org.kar.archidata.annotation.AnnotationTools;
|
||||
import org.kar.archidata.dataAccess.CountInOut;
|
||||
import org.kar.archidata.dataAccess.DataAccessMorphia;
|
||||
import org.kar.archidata.dataAccess.DBAccessMorphia;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.LazyGetter;
|
||||
import org.kar.archidata.dataAccess.QueryCondition;
|
||||
@ -83,7 +83,7 @@ public class AddOnOneToMany implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void insertData(
|
||||
final DataAccessMorphia ioDb,
|
||||
final DBAccessMorphia ioDb,
|
||||
final Field field,
|
||||
final Object rootObject,
|
||||
final Document docSet,
|
||||
@ -222,7 +222,7 @@ public class AddOnOneToMany implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void fillFromDoc(
|
||||
final DataAccessMorphia ioDb,
|
||||
final DBAccessMorphia ioDb,
|
||||
final Document doc,
|
||||
final Field field,
|
||||
final Object data,
|
||||
|
@ -6,7 +6,7 @@ import java.util.List;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.kar.archidata.dataAccess.CountInOut;
|
||||
import org.kar.archidata.dataAccess.DataAccessMorphia;
|
||||
import org.kar.archidata.dataAccess.DBAccessMorphia;
|
||||
import org.kar.archidata.dataAccess.LazyGetter;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
|
||||
@ -34,7 +34,7 @@ public interface DataAccessAddOn {
|
||||
* @return the new index of injection in case of multiple value management
|
||||
* @throws SQLException */
|
||||
void insertData(
|
||||
final DataAccessMorphia ioDb,
|
||||
final DBAccessMorphia ioDb,
|
||||
final Field field,
|
||||
final Object rootObject,
|
||||
final Document docSet,
|
||||
@ -66,7 +66,7 @@ public interface DataAccessAddOn {
|
||||
|
||||
// Return the number of colomn read
|
||||
void fillFromDoc(
|
||||
final DataAccessMorphia ioDb,
|
||||
final DBAccessMorphia ioDb,
|
||||
Document doc,
|
||||
Field field,
|
||||
Object data,
|
||||
@ -108,7 +108,7 @@ public interface DataAccessAddOn {
|
||||
* @param data Data that might be inserted.
|
||||
* @param actions Asynchronous action to do after main request. */
|
||||
default void asyncInsert(
|
||||
final DataAccessMorphia ioDb,
|
||||
final DBAccessMorphia ioDb,
|
||||
final String tableName,
|
||||
final Object localId,
|
||||
final Field field,
|
||||
@ -131,7 +131,7 @@ public interface DataAccessAddOn {
|
||||
* @param data Data that might be inserted.
|
||||
* @param actions Asynchronous action to do after main request. */
|
||||
default void asyncUpdate(
|
||||
final DataAccessMorphia ioDb,
|
||||
final DBAccessMorphia ioDb,
|
||||
final String tableName,
|
||||
final Object localId,
|
||||
final Field field,
|
||||
@ -140,11 +140,11 @@ public interface DataAccessAddOn {
|
||||
|
||||
}
|
||||
|
||||
default void drop(final DataAccessMorphia ioDb, final String tableName, final Field field) throws Exception {
|
||||
default void drop(final DBAccessMorphia ioDb, final String tableName, final Field field) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
default void cleanAll(final DataAccessMorphia ioDb, final String tableName, final Field field) throws Exception {
|
||||
default void cleanAll(final DBAccessMorphia ioDb, final String tableName, final Field field) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
|
@ -14,9 +14,9 @@ import org.bson.Document;
|
||||
import org.kar.archidata.annotation.AnnotationTools;
|
||||
import org.kar.archidata.annotation.DataJson;
|
||||
import org.kar.archidata.dataAccess.CountInOut;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataAccessMorphia;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessMorphia;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.LazyGetter;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
@ -60,7 +60,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void insertData(
|
||||
final DataAccessSQL ioDb,
|
||||
final DBAccessSQL ioDb,
|
||||
final PreparedStatement ps,
|
||||
final Field field,
|
||||
final Object rootObject,
|
||||
@ -111,7 +111,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void fillFromQuery(
|
||||
final DataAccessSQL ioDb,
|
||||
final DBAccessSQL ioDb,
|
||||
final ResultSet rs,
|
||||
final Field field,
|
||||
final Object data,
|
||||
@ -183,7 +183,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
public static void addLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final Long id,
|
||||
final String column,
|
||||
@ -214,12 +214,12 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
* @throws Exception If an error occurs during data retrieval or update.
|
||||
*/
|
||||
public static void addLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final Long id,
|
||||
final String column,
|
||||
final UUID remoteKey) throws Exception {
|
||||
if (ioDb instanceof final DataAccessSQL daSQL) {
|
||||
if (ioDb instanceof final DBAccessSQL daSQL) {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
// TODO: Get primary key name
|
||||
final TableCoversLongUUID data = ioDb.get(TableCoversLongUUID.class, id, new OverrideTableName(tableName));
|
||||
@ -233,7 +233,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
data.covers.add(remoteKey);
|
||||
ioDb.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));// TODO: ,new OverrideFieldName("covers", column));
|
||||
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||
} else if (ioDb instanceof final DBAccessMorphia dam) {
|
||||
|
||||
} else {
|
||||
throw new DataAccessException("DataAccess Not managed");
|
||||
@ -252,12 +252,12 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
* @throws Exception If an error occurs during data retrieval or update.
|
||||
*/
|
||||
public static void addLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final UUID uuid,
|
||||
final String column,
|
||||
final UUID remoteKey) throws Exception {
|
||||
if (ioDb instanceof final DataAccessSQL daSQL) {
|
||||
if (ioDb instanceof final DBAccessSQL daSQL) {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversUUIDUUID data = ioDb.get(TableCoversUUIDUUID.class, uuid,
|
||||
new OverrideTableName(tableName));
|
||||
@ -271,7 +271,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
data.covers.add(remoteKey);
|
||||
ioDb.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
||||
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||
} else if (ioDb instanceof final DBAccessMorphia dam) {
|
||||
|
||||
} else {
|
||||
throw new DataAccessException("DataAccess Not managed");
|
||||
@ -279,12 +279,12 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
public static void addLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final UUID uuid,
|
||||
final String column,
|
||||
final Long remoteKey) throws Exception {
|
||||
if (ioDb instanceof final DataAccessSQL daSQL) {
|
||||
if (ioDb instanceof final DBAccessSQL daSQL) {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversUUIDLong data = ioDb.get(TableCoversUUIDLong.class, uuid,
|
||||
new OverrideTableName(tableName));
|
||||
@ -298,7 +298,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
data.covers.add(remoteKey);
|
||||
ioDb.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
||||
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||
} else if (ioDb instanceof final DBAccessMorphia dam) {
|
||||
|
||||
} else {
|
||||
throw new DataAccessException("DataAccess Not managed");
|
||||
@ -306,12 +306,12 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
public static void removeLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final UUID uuid,
|
||||
final String column,
|
||||
final Long remoteKey) throws Exception {
|
||||
if (ioDb instanceof final DataAccessSQL daSQL) {
|
||||
if (ioDb instanceof final DBAccessSQL daSQL) {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversUUIDLong data = ioDb.get(TableCoversUUIDLong.class, uuid,
|
||||
new OverrideTableName(tableName));
|
||||
@ -327,7 +327,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
data.covers = newList;
|
||||
ioDb.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
||||
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||
} else if (ioDb instanceof final DBAccessMorphia dam) {
|
||||
|
||||
} else {
|
||||
throw new DataAccessException("DataAccess Not managed");
|
||||
@ -335,12 +335,12 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
public static void removeLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final UUID uuid,
|
||||
final String column,
|
||||
final UUID remoteKey) throws Exception {
|
||||
if (ioDb instanceof final DataAccessSQL daSQL) {
|
||||
if (ioDb instanceof final DBAccessSQL daSQL) {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversUUIDUUID data = ioDb.get(TableCoversUUIDUUID.class, uuid,
|
||||
new OverrideTableName(tableName));
|
||||
@ -356,7 +356,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
data.covers = newList;
|
||||
ioDb.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
||||
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||
} else if (ioDb instanceof final DBAccessMorphia dam) {
|
||||
|
||||
} else {
|
||||
throw new DataAccessException("DataAccess Not managed");
|
||||
@ -364,12 +364,12 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
public static void removeLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final Long id,
|
||||
final String column,
|
||||
final Long remoteKey) throws Exception {
|
||||
if (ioDb instanceof final DataAccessSQL daSQL) {
|
||||
if (ioDb instanceof final DBAccessSQL daSQL) {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversLongLong data = ioDb.get(TableCoversLongLong.class, id, new OverrideTableName(tableName));
|
||||
if (data.covers == null) {
|
||||
@ -384,7 +384,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
data.covers = newList;
|
||||
ioDb.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
|
||||
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||
} else if (ioDb instanceof final DBAccessMorphia dam) {
|
||||
|
||||
} else {
|
||||
throw new DataAccessException("DataAccess Not managed");
|
||||
@ -392,12 +392,12 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
public static void removeLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final Long id,
|
||||
final String column,
|
||||
final UUID remoteKey) throws Exception {
|
||||
if (ioDb instanceof final DataAccessSQL daSQL) {
|
||||
if (ioDb instanceof final DBAccessSQL daSQL) {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversLongUUID data = ioDb.get(TableCoversLongUUID.class, id, new OverrideTableName(tableName));
|
||||
if (data.covers == null) {
|
||||
@ -411,7 +411,7 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
newList.add(elem);
|
||||
}
|
||||
data.covers = newList;
|
||||
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||
} else if (ioDb instanceof final DBAccessMorphia dam) {
|
||||
final String collectionName = AnnotationTools.getCollectionName(clazz);
|
||||
final Field primaryfield = AnnotationTools.getPrimaryKeyField(clazz);
|
||||
final String primaryFieldName = AnnotationTools.getFieldName(primaryfield);
|
||||
|
@ -11,9 +11,9 @@ import java.util.UUID;
|
||||
|
||||
import org.kar.archidata.annotation.AnnotationTools;
|
||||
import org.kar.archidata.dataAccess.CountInOut;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataAccessMorphia;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessMorphia;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.LazyGetter;
|
||||
import org.kar.archidata.dataAccess.QueryAnd;
|
||||
@ -58,7 +58,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void insertData(
|
||||
final DataAccessSQL ioDb,
|
||||
final DBAccessSQL ioDb,
|
||||
final PreparedStatement ps,
|
||||
final Field field,
|
||||
final Object rootObject,
|
||||
@ -214,7 +214,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void fillFromQuery(
|
||||
final DataAccessSQL ioDb,
|
||||
final DBAccessSQL ioDb,
|
||||
final ResultSet rs,
|
||||
final Field field,
|
||||
final Object data,
|
||||
@ -297,7 +297,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void asyncUpdate(
|
||||
final DataAccessSQL ioDb,
|
||||
final DBAccessSQL ioDb,
|
||||
final String tableName,
|
||||
final Object localKey,
|
||||
final Field field,
|
||||
@ -354,7 +354,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void asyncInsert(
|
||||
final DataAccessSQL ioDb,
|
||||
final DBAccessSQL ioDb,
|
||||
final String tableName,
|
||||
final Object localKey,
|
||||
final Field field,
|
||||
@ -479,7 +479,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drop(final DataAccessSQL ioDb, final String tableName, final Field field) throws Exception {
|
||||
public void drop(final DBAccessSQL ioDb, final String tableName, final Field field) throws Exception {
|
||||
final String columnName = AnnotationTools.getFieldName(field);
|
||||
final String linkTableName = generateLinkTableName(tableName, columnName);
|
||||
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
||||
@ -492,7 +492,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanAll(final DataAccessSQL ioDb, final String tableName, final Field field) throws Exception {
|
||||
public void cleanAll(final DBAccessSQL ioDb, final String tableName, final Field field) throws Exception {
|
||||
final String columnName = AnnotationTools.getFieldName(field);
|
||||
final String linkTableName = generateLinkTableName(tableName, columnName);
|
||||
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType())
|
||||
@ -505,19 +505,19 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
public static void addLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final long localKey,
|
||||
final String column,
|
||||
final long remoteKey) throws Exception {
|
||||
if (ioDb instanceof final DataAccessSQL daSQL) {
|
||||
if (ioDb instanceof final DBAccessSQL daSQL) {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final String linkTableName = generateLinkTableName(tableName, column);
|
||||
/* final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; if (objectClass != Long.class && objectClass != UUID.class) { throw new
|
||||
* DataAccessException("Can not ManyToMany with other than List<Long> or List<UUID> Model: List<" + objectClass.getCanonicalName() + ">"); } */
|
||||
final LinkTableLongLong insertElement = new LinkTableLongLong(localKey, remoteKey);
|
||||
daSQL.insert(insertElement, new OverrideTableName(linkTableName));
|
||||
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||
} else if (ioDb instanceof final DBAccessMorphia dam) {
|
||||
|
||||
} else {
|
||||
throw new DataAccessException("DataAccess Not managed");
|
||||
@ -526,18 +526,18 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
public static long removeLink(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<?> clazz,
|
||||
final long localKey,
|
||||
final String column,
|
||||
final long remoteKey) throws Exception {
|
||||
if (ioDb instanceof final DataAccessSQL daSQL) {
|
||||
if (ioDb instanceof final DBAccessSQL daSQL) {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final String linkTableName = generateLinkTableName(tableName, column);
|
||||
return daSQL.deleteWhere(LinkTableLongLong.class, new OverrideTableName(linkTableName),
|
||||
new Condition(new QueryAnd(new QueryCondition("object1Id", "=", localKey),
|
||||
new QueryCondition("object2Id", "=", remoteKey))));
|
||||
} else if (ioDb instanceof final DataAccessMorphia dam) {
|
||||
} else if (ioDb instanceof final DBAccessMorphia dam) {
|
||||
return 0L;
|
||||
} else {
|
||||
throw new DataAccessException("DataAccess Not managed");
|
||||
|
@ -9,7 +9,7 @@ import java.util.UUID;
|
||||
|
||||
import org.kar.archidata.annotation.AnnotationTools;
|
||||
import org.kar.archidata.dataAccess.CountInOut;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.LazyGetter;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
@ -48,7 +48,7 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void insertData(
|
||||
final DataAccessSQL ioDb,
|
||||
final DBAccessSQL ioDb,
|
||||
final PreparedStatement ps,
|
||||
final Field field,
|
||||
final Object rootObject,
|
||||
@ -152,7 +152,7 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
||||
if (field.getType() == decorators.targetEntity()) {
|
||||
if (decorators.fetch() == FetchType.EAGER) {
|
||||
// TODO: rework this to have a lazy mode ...
|
||||
DataAccessSQL.generateSelectField(querySelect, query, field.getType(), options, count);
|
||||
DBAccessSQL.generateSelectField(querySelect, query, field.getType(), options, count);
|
||||
final Class<?> subType = field.getType();
|
||||
final String subTableName = AnnotationTools.getTableName(subType);
|
||||
final Field idField = AnnotationTools.getFieldOfId(subType);
|
||||
@ -181,7 +181,7 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void fillFromQuery(
|
||||
final DataAccessSQL ioDb,
|
||||
final DBAccessSQL ioDb,
|
||||
final ResultSet rs,
|
||||
final Field field,
|
||||
final Object data,
|
||||
|
@ -12,7 +12,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.kar.archidata.annotation.AnnotationTools;
|
||||
import org.kar.archidata.dataAccess.CountInOut;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.LazyGetter;
|
||||
import org.kar.archidata.dataAccess.QueryCondition;
|
||||
@ -83,7 +83,7 @@ public class AddOnOneToMany implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void insertData(
|
||||
final DataAccessSQL ioDb,
|
||||
final DBAccessSQL ioDb,
|
||||
final PreparedStatement ps,
|
||||
final Field field,
|
||||
final Object rootObject,
|
||||
@ -222,7 +222,7 @@ public class AddOnOneToMany implements DataAccessAddOn {
|
||||
|
||||
@Override
|
||||
public void fillFromQuery(
|
||||
final DataAccessSQL ioDb,
|
||||
final DBAccessSQL ioDb,
|
||||
final ResultSet rs,
|
||||
final Field field,
|
||||
final Object data,
|
||||
|
@ -7,7 +7,7 @@ import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import org.kar.archidata.dataAccess.CountInOut;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.LazyGetter;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
|
||||
@ -34,7 +34,7 @@ public interface DataAccessAddOn {
|
||||
* @param iii The index of injection
|
||||
* @return the new index of injection in case of multiple value management
|
||||
* @throws SQLException */
|
||||
void insertData(final DataAccessSQL ioDb, PreparedStatement ps, final Field field, Object data, CountInOut iii)
|
||||
void insertData(final DBAccessSQL ioDb, PreparedStatement ps, final Field field, Object data, CountInOut iii)
|
||||
throws Exception, SQLException, IllegalArgumentException, IllegalAccessException;
|
||||
|
||||
/** Element can insert in the single request
|
||||
@ -63,7 +63,7 @@ public interface DataAccessAddOn {
|
||||
|
||||
// Return the number of colomn read
|
||||
void fillFromQuery(
|
||||
final DataAccessSQL ioDb,
|
||||
final DBAccessSQL ioDb,
|
||||
ResultSet rs,
|
||||
Field field,
|
||||
Object data,
|
||||
@ -106,7 +106,7 @@ public interface DataAccessAddOn {
|
||||
* @param data Data that might be inserted.
|
||||
* @param actions Asynchronous action to do after main request. */
|
||||
default void asyncInsert(
|
||||
final DataAccessSQL ioDb,
|
||||
final DBAccessSQL ioDb,
|
||||
final String tableName,
|
||||
final Object localId,
|
||||
final Field field,
|
||||
@ -129,7 +129,7 @@ public interface DataAccessAddOn {
|
||||
* @param data Data that might be inserted.
|
||||
* @param actions Asynchronous action to do after main request. */
|
||||
default void asyncUpdate(
|
||||
final DataAccessSQL ioDb,
|
||||
final DBAccessSQL ioDb,
|
||||
final String tableName,
|
||||
final Object localId,
|
||||
final Field field,
|
||||
@ -138,11 +138,11 @@ public interface DataAccessAddOn {
|
||||
|
||||
}
|
||||
|
||||
default void drop(final DataAccessSQL ioDb, final String tableName, final Field field) throws Exception {
|
||||
default void drop(final DBAccessSQL ioDb, final String tableName, final Field field) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
default void cleanAll(final DataAccessSQL ioDb, final String tableName, final Field field) throws Exception {
|
||||
default void cleanAll(final DBAccessSQL ioDb, final String tableName, final Field field) throws Exception {
|
||||
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@ package org.kar.archidata.dataAccess.options;
|
||||
import java.util.List;
|
||||
|
||||
import org.kar.archidata.annotation.AnnotationTools;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
|
||||
/** By default some element are not read like createAt and UpdatedAt. This option permit to read it. */
|
||||
@ -14,13 +14,13 @@ public interface CheckFunctionInterface {
|
||||
* @param filterValue List of fields that might be check. If null, then all column must be checked.
|
||||
* @throws Exception Exception is generate if the data are incorrect. */
|
||||
void check(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
Object data,
|
||||
List<String> filterValue,
|
||||
final QueryOptions options) throws Exception;
|
||||
|
||||
default void checkAll(final DataAccess ioDb, final String baseName, final Object data, final QueryOptions options)
|
||||
default void checkAll(final DBAccess ioDb, final String baseName, final Object data, final QueryOptions options)
|
||||
throws Exception {
|
||||
check(ioDb, baseName, data, AnnotationTools.getAllFieldsNames(data.getClass()), options);
|
||||
}
|
||||
|
@ -2,14 +2,14 @@ package org.kar.archidata.dataAccess.options;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
|
||||
/** By default some element are not read like createAt and UpdatedAt. This option permit to read it. */
|
||||
public class CheckFunctionVoid implements CheckFunctionInterface {
|
||||
@Override
|
||||
public void check(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final Object data,
|
||||
final List<String> filterValue,
|
||||
|
@ -14,7 +14,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
import org.kar.archidata.annotation.AnnotationTools;
|
||||
import org.kar.archidata.annotation.DataJson;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.QueryCondition;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
@ -38,7 +38,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
* @param data The object that might be injected.
|
||||
* @param filterValue List of fields that might be check. If null, then all column must be checked.
|
||||
* @throws Exception Exception is generate if the data are incorrect. */
|
||||
void check(DataAccess ioDb, final String baseName, final K data, final QueryOptions options) throws Exception;
|
||||
void check(DBAccess ioDb, final String baseName, final K data, final QueryOptions options) throws Exception;
|
||||
}
|
||||
|
||||
protected Map<String, List<CheckInterface<T>>> checking = null;
|
||||
@ -69,7 +69,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
if (AnnotationTools.isPrimaryKey(field)) {
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -80,7 +80,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
if (AnnotationTools.getConstraintsNotNull(field)) {
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -92,7 +92,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
if (AnnotationTools.isCreatedAtField(field) || AnnotationTools.isUpdateAtField(field)) {
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -106,7 +106,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
if (maxValue != null) {
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -125,7 +125,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
if (minValue != null) {
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -144,7 +144,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -170,7 +170,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
final int maxValue = maxValueRoot.intValue();
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -190,7 +190,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
final int minValue = minValueRoot.intValue();
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -209,7 +209,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -229,7 +229,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
if (annotationManyToOne != null && annotationManyToOne.targetEntity() != null) {
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -252,7 +252,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
final float maxValue = maxValueRoot.floatValue();
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -272,7 +272,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
final float minValue = minValueRoot.floatValue();
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -293,7 +293,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
final double maxValue = maxValueRoot.doubleValue();
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -313,7 +313,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
final double minValue = minValueRoot.doubleValue();
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -339,7 +339,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
if (maxSizeString > 0) {
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -358,7 +358,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
if (limitSize != null) {
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -382,7 +382,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
final Pattern pattern = Pattern.compile(patternString);
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -406,7 +406,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
.newInstance();
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -421,7 +421,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
// Create the request ...
|
||||
add(fieldName,
|
||||
(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final T data,
|
||||
final QueryOptions options) -> {
|
||||
@ -448,18 +448,18 @@ public class CheckJPA<T> implements CheckFunctionInterface {
|
||||
}
|
||||
}
|
||||
|
||||
public void check(final DataAccess ioDb, final String baseName, final Object data) throws Exception {
|
||||
public void check(final DBAccess ioDb, final String baseName, final Object data) throws Exception {
|
||||
check(ioDb, baseName, data, null, null);
|
||||
}
|
||||
|
||||
public void check(final DataAccess ioDb, final String baseName, final Object data, final List<String> filterValue)
|
||||
public void check(final DBAccess ioDb, final String baseName, final Object data, final List<String> filterValue)
|
||||
throws Exception {
|
||||
check(ioDb, baseName, data, filterValue, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void check(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final String baseName,
|
||||
final Object data,
|
||||
final List<String> filterValue,
|
||||
|
@ -6,7 +6,7 @@ import java.util.List;
|
||||
|
||||
import org.bson.conversions.Bson;
|
||||
import org.kar.archidata.dataAccess.CountInOut;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.QueryItem;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
|
||||
@ -30,7 +30,7 @@ public class Condition extends QueryOption {
|
||||
}
|
||||
}
|
||||
|
||||
public void injectQuery(final DataAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||
public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||
throws Exception {
|
||||
if (this.condition != null) {
|
||||
this.condition.injectQuery(ioDb, ps, iii);
|
||||
|
@ -3,7 +3,7 @@ package org.kar.archidata.dataAccess.options;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
import org.kar.archidata.dataAccess.CountInOut;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
|
||||
public class Limit extends QueryOption {
|
||||
protected final long limit;
|
||||
@ -16,7 +16,7 @@ public class Limit extends QueryOption {
|
||||
query.append(" LIMIT ? \n");
|
||||
}
|
||||
|
||||
public void injectQuery(final DataAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||
public void injectQuery(final DBAccessSQL ioDb, final PreparedStatement ps, final CountInOut iii)
|
||||
throws Exception {
|
||||
ioDb.addElement(ps, this.limit, iii);
|
||||
iii.inc();
|
||||
|
@ -1,12 +1,12 @@
|
||||
package org.kar.archidata.db;
|
||||
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class DBConfig {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(DataAccess.class);
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(DBAccess.class);
|
||||
private final String type;
|
||||
private final String hostname;
|
||||
private final int port;
|
||||
|
@ -8,31 +8,22 @@ import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class DBEntry implements Closeable {
|
||||
final static Logger LOGGER = LoggerFactory.getLogger(DBEntry.class);
|
||||
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<DBEntry> stored = new ArrayList<>();
|
||||
private static List<DBInterfaceFactory> stored = new ArrayList<>();
|
||||
|
||||
private DBEntry(final DBConfig config, final boolean root, final Class<?>... classes) throws IOException {
|
||||
private DBInterfaceFactory(final DBConfig config, final Class<?>... classes) throws IOException {
|
||||
this.config = config;
|
||||
this.classes = classes;
|
||||
if (root) {
|
||||
connectRoot();
|
||||
} else {
|
||||
connect();
|
||||
}
|
||||
connect();
|
||||
}
|
||||
|
||||
public static DBEntry createInterface(final DBConfig config, final Class<?>... classes) throws IOException {
|
||||
return createInterface(config, false, classes);
|
||||
}
|
||||
|
||||
public static DBEntry createInterface(final DBConfig config, final boolean root, final Class<?>... classes)
|
||||
throws IOException {
|
||||
public static DBInterfaceFactory create(final DBConfig config, final Class<?>... classes) throws IOException {
|
||||
if (config.getKeepConnected()) {
|
||||
for (final DBEntry elem : stored) {
|
||||
for (final DBInterfaceFactory elem : stored) {
|
||||
if (elem == null) {
|
||||
continue;
|
||||
}
|
||||
@ -40,24 +31,11 @@ public class DBEntry implements Closeable {
|
||||
return elem;
|
||||
}
|
||||
}
|
||||
final DBEntry tmp = new DBEntry(config, root);
|
||||
final DBInterfaceFactory tmp = new DBInterfaceFactory(config);
|
||||
stored.add(tmp);
|
||||
return tmp;
|
||||
} else {
|
||||
return new DBEntry(config, root, classes);
|
||||
}
|
||||
}
|
||||
|
||||
public void connectRoot() throws IOException {
|
||||
// TODO: maybe better check for root connection ...
|
||||
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");
|
||||
return new DBInterfaceFactory(config, classes);
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,7 +68,7 @@ public class DBEntry implements Closeable {
|
||||
}
|
||||
|
||||
public static void closeAllForceMode() throws IOException {
|
||||
for (final DBEntry entry : stored) {
|
||||
for (final DBInterfaceFactory entry : stored) {
|
||||
entry.closeForce();
|
||||
}
|
||||
stored = new ArrayList<>();
|
@ -1,7 +1,7 @@
|
||||
package org.kar.archidata.migration;
|
||||
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
|
||||
public interface AsyncCall {
|
||||
void doRequest(DataAccess da) throws Exception;
|
||||
void doRequest(DBAccess da) throws Exception;
|
||||
}
|
||||
|
@ -5,8 +5,8 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
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;
|
||||
@ -24,17 +24,17 @@ public class MigrationEngine {
|
||||
// initialization of the migration if the DB is not present...
|
||||
private MigrationInterface init;
|
||||
|
||||
protected final DataAccess da;
|
||||
protected final DBAccess da;
|
||||
|
||||
/** Migration engine constructor (empty). */
|
||||
public MigrationEngine(final DataAccess da) {
|
||||
public MigrationEngine(final DBAccess da) {
|
||||
this(da, new ArrayList<>(), null);
|
||||
}
|
||||
|
||||
/** Migration engine constructor (specific mode).
|
||||
* @param datas All the migration ordered.
|
||||
* @param init Initialization migration model. */
|
||||
public MigrationEngine(final DataAccess da, final List<MigrationInterface> datas, final MigrationInterface init) {
|
||||
public MigrationEngine(final DBAccess da, final List<MigrationInterface> datas, final MigrationInterface init) {
|
||||
this.datas = datas;
|
||||
this.init = init;
|
||||
this.da = da;
|
||||
@ -159,7 +159,7 @@ public class MigrationEngine {
|
||||
LOGGER.info("DB '{}' exist.", config.getDbName());
|
||||
// STEP 2: Check migration table exist:
|
||||
LOGGER.info("Verify existance of migration table '{}'", "KAR_migration");
|
||||
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
exist = this.da.isTableExist("KAR_migration");
|
||||
if (!exist) {
|
||||
LOGGER.info("'{}' Does not exist create a new one...", "KAR_migration");
|
||||
|
@ -1,6 +1,6 @@
|
||||
package org.kar.archidata.migration;
|
||||
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.migration.model.Migration;
|
||||
|
||||
public interface MigrationInterface {
|
||||
@ -13,13 +13,13 @@ public interface MigrationInterface {
|
||||
* @param log Stored data in the BDD for the migration progression.
|
||||
* @param migration Migration post data on each step...
|
||||
* @return true if migration is finished. */
|
||||
boolean applyMigration(DataAccess entry, StringBuilder log, Migration model) throws Exception;
|
||||
boolean applyMigration(DBAccess entry, StringBuilder log, Migration model) throws Exception;
|
||||
|
||||
/** Remove a migration the system to the previous version.
|
||||
* @param entry DB interface for the migration.
|
||||
* @param log Stored data in the BDD for the migration progression.
|
||||
* @return true if migration is finished. */
|
||||
boolean revertMigration(DataAccess entry, StringBuilder log) throws Exception;
|
||||
boolean revertMigration(DBAccess entry, StringBuilder log) throws Exception;
|
||||
|
||||
/** Get the number of step in the migration process.
|
||||
* @return count of SQL access. */
|
||||
|
@ -5,8 +5,8 @@ import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.migration.model.Migration;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
@ -70,7 +70,7 @@ public class MigrationSqlStep implements MigrationInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyMigration(final DataAccess da, final StringBuilder log, final Migration model)
|
||||
public boolean applyMigration(final DBAccess da, final StringBuilder log, final Migration model)
|
||||
throws Exception {
|
||||
if (!this.isGenerated) {
|
||||
this.isGenerated = true;
|
||||
@ -106,7 +106,7 @@ public class MigrationSqlStep implements MigrationInterface {
|
||||
}
|
||||
try {
|
||||
if (action.action() != null) {
|
||||
if (da instanceof final DataAccessSQL ioDBSQL) {
|
||||
if (da instanceof final DBAccessSQL ioDBSQL) {
|
||||
ioDBSQL.executeQuery(action.action());
|
||||
}
|
||||
} else {
|
||||
@ -145,7 +145,7 @@ public class MigrationSqlStep implements MigrationInterface {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean revertMigration(final DataAccess da, final StringBuilder log) throws Exception {
|
||||
public boolean revertMigration(final DBAccess da, final StringBuilder log) throws Exception {
|
||||
generateRevertStep();
|
||||
return false;
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import java.util.UUID;
|
||||
import org.apache.tika.Tika;
|
||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||
import org.kar.archidata.api.DataResource;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.QueryAnd;
|
||||
import org.kar.archidata.dataAccess.QueryCondition;
|
||||
import org.kar.archidata.dataAccess.addOnSQL.AddOnDataJson;
|
||||
@ -77,7 +77,7 @@ public class DataTools {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public static Data getWithSha512(final DataAccess ioDb, final String sha512) {
|
||||
public static Data getWithSha512(final DBAccess ioDb, final String sha512) {
|
||||
try {
|
||||
return ioDb.getWhere(Data.class, new Condition(new QueryCondition("sha512", "=", sha512)),
|
||||
new ReadAllColumn());
|
||||
@ -88,7 +88,7 @@ public class DataTools {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Data getWithId(final DataAccess ioDb, final long id) {
|
||||
public static Data getWithId(final DBAccess ioDb, final long id) {
|
||||
try {
|
||||
return ioDb.getWhere(Data.class, new Condition(new QueryAnd(
|
||||
List.of(new QueryCondition("deleted", "=", false), new QueryCondition("id", "=", id)))));
|
||||
@ -100,7 +100,7 @@ public class DataTools {
|
||||
}
|
||||
|
||||
public static Data createNewData(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final long tmpUID,
|
||||
final String originalFileName,
|
||||
final String sha512,
|
||||
@ -132,7 +132,7 @@ public class DataTools {
|
||||
}
|
||||
|
||||
public static Data createNewData(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final long tmpUID,
|
||||
final String originalFileName,
|
||||
final String sha512) throws IOException, SQLException {
|
||||
@ -151,7 +151,7 @@ public class DataTools {
|
||||
return createNewData(ioDb, tmpUID, originalFileName, sha512, mimeType);
|
||||
}
|
||||
|
||||
public static void undelete(final DataAccess ioDb, final UUID id) {
|
||||
public static void undelete(final DBAccess ioDb, final UUID id) {
|
||||
try {
|
||||
ioDb.unsetDelete(Data.class, id);
|
||||
} catch (final Exception e) {
|
||||
@ -276,7 +276,7 @@ public class DataTools {
|
||||
}
|
||||
|
||||
public static <CLASS_TYPE, ID_TYPE> void uploadCoverFromUri(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<CLASS_TYPE> clazz,
|
||||
final ID_TYPE id,
|
||||
final String url) throws Exception {
|
||||
@ -355,7 +355,7 @@ public class DataTools {
|
||||
}
|
||||
|
||||
public static <CLASS_TYPE, ID_TYPE> void uploadCover(
|
||||
final DataAccess ioDb,
|
||||
final DBAccess ioDb,
|
||||
final Class<CLASS_TYPE> clazz,
|
||||
final ID_TYPE id,
|
||||
final InputStream fileInputStream,
|
||||
|
@ -4,8 +4,8 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.db.DBInterfaceFactory;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -35,8 +35,8 @@ import test.kar.archidata.dataAccess.model.TypesTable;
|
||||
|
||||
public class ConfigureDb {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(ConfigureDb.class);
|
||||
final static private String modeTestForced = "MONGO";
|
||||
|
||||
final static private String modeTestForced = null;//"MONGO";
|
||||
|
||||
public static void configure() throws IOException {
|
||||
String modeTest = System.getenv("TEST_E2E_MODE");
|
||||
if (modeTest == null || modeTest.isEmpty() || "false".equalsIgnoreCase(modeTest)) {
|
||||
@ -97,17 +97,17 @@ public class ConfigureDb {
|
||||
ConfigBaseVariable.dbUser = "root";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.getDbconfig(),
|
||||
final DBInterfaceFactory entry = DBInterfaceFactory.create(GlobalConfiguration.getDbconfig(),
|
||||
listObject.toArray(new Class<?>[0]));
|
||||
entry.connect();
|
||||
|
||||
|
||||
removeDB();
|
||||
}
|
||||
|
||||
|
||||
public static void removeDB() {
|
||||
|
||||
final DataAccess da = DataAccess.createInterface();
|
||||
|
||||
|
||||
final DBAccess da = DBAccess.createInterface();
|
||||
|
||||
String modeTest = System.getenv("TEST_E2E_MODE");
|
||||
if (modeTest == null || modeTest.isEmpty() || "false".equalsIgnoreCase(modeTest)) {
|
||||
modeTest = "SQLITE-MEMORY";
|
||||
@ -128,12 +128,12 @@ public class ConfigureDb {
|
||||
da.deleteDB(ConfigBaseVariable.bdDatabase);
|
||||
} else {}
|
||||
}
|
||||
|
||||
|
||||
public static void clear() throws IOException {
|
||||
LOGGER.info("Remove the test db");
|
||||
removeDB();
|
||||
DBEntry.closeAllForceMode();
|
||||
DBInterfaceFactory.closeAllForceMode();
|
||||
ConfigBaseVariable.clearAllValue();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ 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.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.filter.CORSFilter;
|
||||
import org.kar.archidata.filter.OptionFilter;
|
||||
import org.kar.archidata.migration.MigrationEngine;
|
||||
@ -33,10 +33,10 @@ public class WebLauncher {
|
||||
protected UpdateJwtPublicKey keyUpdater = null;
|
||||
protected HttpServer server = null;
|
||||
|
||||
private final DataAccess da;
|
||||
private final DBAccess da;
|
||||
|
||||
public WebLauncher() {
|
||||
this.da = DataAccess.createInterface();
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
private static URI getBaseURI() {
|
||||
|
@ -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.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -27,7 +27,7 @@ import test.kar.archidata.dataAccess.model.SimpleTable;
|
||||
public class TestResourceSample {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(TestResource.class);
|
||||
private final DataAccess da = DataAccess.createInterface();
|
||||
private final DBAccess da = DBAccess.createInterface();
|
||||
|
||||
@GET
|
||||
@PermitAll
|
||||
|
@ -11,8 +11,8 @@ 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.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -27,7 +27,7 @@ import test.kar.archidata.dataAccess.model.SimpleTable;
|
||||
public class TestJson {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestJson.class);
|
||||
|
||||
private DataAccess da = null;
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
@ -40,14 +40,14 @@ public class TestJson {
|
||||
}
|
||||
|
||||
public TestJson() {
|
||||
this.da = DataAccess.createInterface();
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testTableFactory() throws Exception {
|
||||
final List<String> sqlCommand = DataFactory.createTable(SerializeAsJson.class);
|
||||
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
|
@ -12,8 +12,8 @@ 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.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -27,7 +27,7 @@ import test.kar.archidata.dataAccess.model.SerializeListAsJson;
|
||||
public class TestListJson {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestListJson.class);
|
||||
|
||||
private DataAccess da = null;
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
@ -40,14 +40,14 @@ public class TestListJson {
|
||||
}
|
||||
|
||||
public TestListJson() {
|
||||
this.da = DataAccess.createInterface();
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testTableInsertAndRetrieve() throws Exception {
|
||||
final List<String> sqlCommand = DataFactory.createTable(SerializeListAsJson.class);
|
||||
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
|
@ -11,8 +11,8 @@ 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.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
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.slf4j.Logger;
|
||||
@ -29,7 +29,7 @@ import test.kar.archidata.dataAccess.model.TypeManyToManyRootExpand;
|
||||
public class TestManyToMany {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestManyToMany.class);
|
||||
|
||||
private DataAccess da = null;
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
@ -42,7 +42,7 @@ public class TestManyToMany {
|
||||
}
|
||||
|
||||
public TestManyToMany() {
|
||||
this.da = DataAccess.createInterface();
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@ -51,7 +51,7 @@ public class TestManyToMany {
|
||||
final List<String> sqlCommand2 = DataFactory.createTable(TypeManyToManyRoot.class);
|
||||
final List<String> sqlCommand = DataFactory.createTable(TypeManyToManyRemote.class);
|
||||
sqlCommand.addAll(sqlCommand2);
|
||||
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
|
@ -11,8 +11,8 @@ 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.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -31,7 +31,7 @@ import test.kar.archidata.dataAccess.model.TypeManyToOneUUIDRootExpand;
|
||||
public class TestManyToOne {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestManyToOne.class);
|
||||
|
||||
private DataAccess da = null;
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
@ -44,7 +44,7 @@ public class TestManyToOne {
|
||||
}
|
||||
|
||||
public TestManyToOne() {
|
||||
this.da = DataAccess.createInterface();
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@ -54,7 +54,7 @@ public class TestManyToOne {
|
||||
sqlCommand.addAll(DataFactory.createTable(TypeManyToOneRoot.class));
|
||||
sqlCommand.addAll(DataFactory.createTable(TypeManyToOneUUIDRoot.class));
|
||||
sqlCommand.addAll(DataFactory.createTable(TypeManyToOneUUIDRemote.class));
|
||||
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
|
@ -11,8 +11,8 @@ 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.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -31,7 +31,7 @@ import test.kar.archidata.dataAccess.model.TypeOneToManyUUIDRootExpand;
|
||||
public class TestOneToMany {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestOneToMany.class);
|
||||
|
||||
private DataAccess da = null;
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
@ -44,7 +44,7 @@ public class TestOneToMany {
|
||||
}
|
||||
|
||||
public TestOneToMany() {
|
||||
this.da = DataAccess.createInterface();
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@ -54,7 +54,7 @@ public class TestOneToMany {
|
||||
sqlCommand.addAll(DataFactory.createTable(TypeOneToManyRoot.class));
|
||||
sqlCommand.addAll(DataFactory.createTable(TypeOneToManyUUIDRemote.class));
|
||||
sqlCommand.addAll(DataFactory.createTable(TypeOneToManyUUIDRoot.class));
|
||||
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
|
@ -11,8 +11,8 @@ 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.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -26,7 +26,7 @@ import test.kar.archidata.dataAccess.model.TypesTable;
|
||||
public class TestRawQuery {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypes.class);
|
||||
|
||||
private DataAccess da = null;
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
@ -39,8 +39,8 @@ public class TestRawQuery {
|
||||
}
|
||||
|
||||
public TestRawQuery() {
|
||||
this.da = DataAccess.createInterface();
|
||||
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||
this.da = DBAccess.createInterface();
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
LOGGER.error("lkjddlkj");
|
||||
}
|
||||
}
|
||||
@ -49,7 +49,7 @@ public class TestRawQuery {
|
||||
@Test
|
||||
public void testCreateTable() throws Exception {
|
||||
final List<String> sqlCommand = DataFactory.createTable(TypesTable.class);
|
||||
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
@ -60,7 +60,7 @@ public class TestRawQuery {
|
||||
@Order(2)
|
||||
@Test
|
||||
public void testGet() throws Exception {
|
||||
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
|
||||
final TypesTable test = new TypesTable();
|
||||
test.intData = 95;
|
||||
|
@ -14,8 +14,8 @@ 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.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
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.slf4j.Logger;
|
||||
@ -34,7 +34,7 @@ public class TestSimpleTable {
|
||||
private static Long idOfTheObject = null;
|
||||
private static Timestamp startAction = null;
|
||||
|
||||
private DataAccess da = null;
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
@ -50,7 +50,7 @@ public class TestSimpleTable {
|
||||
}
|
||||
|
||||
public TestSimpleTable() {
|
||||
this.da = DataAccess.createInterface();
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@ -58,7 +58,7 @@ public class TestSimpleTable {
|
||||
public void testTableInsertAndRetrieve() throws Exception {
|
||||
TestSimpleTable.startAction = Timestamp.from(Instant.now());
|
||||
final List<String> sqlCommand = DataFactory.createTable(SimpleTable.class);
|
||||
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
|
@ -14,8 +14,8 @@ 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.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
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.tools.ConfigBaseVariable;
|
||||
@ -35,7 +35,7 @@ public class TestSimpleTableSoftDelete {
|
||||
private static Long idOfTheObject = null;
|
||||
private static Timestamp startAction = null;
|
||||
|
||||
private DataAccess da = null;
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
@ -52,7 +52,7 @@ public class TestSimpleTableSoftDelete {
|
||||
}
|
||||
|
||||
public TestSimpleTableSoftDelete() {
|
||||
this.da = DataAccess.createInterface();
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@ -60,7 +60,7 @@ public class TestSimpleTableSoftDelete {
|
||||
public void testTableInsertAndRetrieve() throws Exception {
|
||||
TestSimpleTableSoftDelete.startAction = Timestamp.from(Instant.now());
|
||||
final List<String> sqlCommand = DataFactory.createTable(SimpleTableSoftDelete.class);
|
||||
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
|
@ -11,8 +11,8 @@ 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.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -27,7 +27,7 @@ import test.kar.archidata.dataAccess.model.TypesEnum1;
|
||||
public class TestTypeEnum1 {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypeEnum1.class);
|
||||
|
||||
private DataAccess da = null;
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
@ -40,14 +40,14 @@ public class TestTypeEnum1 {
|
||||
}
|
||||
|
||||
public TestTypeEnum1() {
|
||||
this.da = DataAccess.createInterface();
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testCreateTable() throws Exception {
|
||||
final List<String> sqlCommand = DataFactory.createTable(TypesEnum1.class);
|
||||
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
|
@ -11,8 +11,8 @@ 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.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -27,7 +27,7 @@ import test.kar.archidata.dataAccess.model.TypesEnum2;
|
||||
public class TestTypeEnum2 {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypeEnum2.class);
|
||||
|
||||
private DataAccess da = null;
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
@ -40,14 +40,14 @@ public class TestTypeEnum2 {
|
||||
}
|
||||
|
||||
public TestTypeEnum2() {
|
||||
this.da = DataAccess.createInterface();
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testCreateTable() throws Exception {
|
||||
final List<String> sqlCommand = DataFactory.createTable(TypesEnum2.class);
|
||||
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
|
@ -16,8 +16,8 @@ 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.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccessSQL;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -31,7 +31,7 @@ import test.kar.archidata.dataAccess.model.TypesTable;
|
||||
public class TestTypes {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestTypes.class);
|
||||
|
||||
private DataAccess da = null;
|
||||
private DBAccess da = null;
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
@ -44,14 +44,14 @@ public class TestTypes {
|
||||
}
|
||||
|
||||
public TestTypes() {
|
||||
this.da = DataAccess.createInterface();
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testCreateTable() throws Exception {
|
||||
final List<String> sqlCommand = DataFactory.createTable(TypesTable.class);
|
||||
if (this.da instanceof final DataAccessSQL daSQL) {
|
||||
if (this.da instanceof final DBAccessSQL daSQL) {
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
daSQL.executeSimpleQuery(elem);
|
||||
|
@ -2,7 +2,7 @@ package test.kar.archidata.migration;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.migration.MigrationSqlStep;
|
||||
|
||||
class MigrationFail extends MigrationSqlStep {
|
||||
@ -19,7 +19,7 @@ class MigrationFail extends MigrationSqlStep {
|
||||
@Override
|
||||
public void generateStep() throws Exception {
|
||||
|
||||
addAction((final DataAccess da) -> {
|
||||
addAction((final DBAccess da) -> {
|
||||
throw new IOException("FAIL migration");
|
||||
});
|
||||
display();
|
||||
|
@ -11,7 +11,7 @@ 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.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.migration.MigrationEngine;
|
||||
import org.kar.archidata.migration.MigrationException;
|
||||
import org.slf4j.Logger;
|
||||
@ -26,10 +26,10 @@ import test.kar.archidata.migration.model.TypesMigrationInitialisationFirst;
|
||||
public class TestMigrationFail {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestMigrationFirstInit.class);
|
||||
|
||||
private DataAccess da = null;
|
||||
private DBAccess da = null;
|
||||
|
||||
public TestMigrationFail() {
|
||||
this.da = DataAccess.createInterface();
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
|
@ -11,7 +11,7 @@ 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.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.migration.MigrationEngine;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -26,10 +26,10 @@ import test.kar.archidata.migration.model.TypesMigrationInitialisationFirst;
|
||||
public class TestMigrationFirstInit {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestMigrationFail.class);
|
||||
|
||||
private DataAccess da = null;
|
||||
private DBAccess da = null;
|
||||
|
||||
public TestMigrationFirstInit() {
|
||||
this.da = DataAccess.createInterface();
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
|
@ -12,7 +12,7 @@ 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.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DBAccess;
|
||||
import org.kar.archidata.migration.MigrationEngine;
|
||||
import org.kar.archidata.migration.model.Migration;
|
||||
import org.slf4j.Logger;
|
||||
@ -27,10 +27,10 @@ import test.kar.archidata.migration.model.TypesMigrationInitialisationCurrent;
|
||||
public class TestMigrationFirstInitWithMigration {
|
||||
final static private Logger LOGGER = LoggerFactory.getLogger(TestMigrationFirstInitWithMigration.class);
|
||||
|
||||
private DataAccess da = null;
|
||||
private DBAccess da = null;
|
||||
|
||||
public TestMigrationFirstInitWithMigration() {
|
||||
this.da = DataAccess.createInterface();
|
||||
this.da = DBAccess.createInterface();
|
||||
}
|
||||
|
||||
@BeforeAll
|
||||
|
Loading…
Reference in New Issue
Block a user