[DEV] update options and where condition, some normalisation
This commit is contained in:
parent
ed3bfa0604
commit
c3d2eff5be
@ -1,7 +1,7 @@
|
||||
package org.kar.archidata;
|
||||
|
||||
import org.kar.archidata.db.DBConfig;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
|
||||
public class GlobalConfiguration {
|
||||
public static DBConfig dbConfig = null;
|
||||
|
@ -1,7 +1,7 @@
|
||||
package org.kar.archidata;
|
||||
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.util.JWTWrapper;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.JWTWrapper;
|
||||
|
||||
public class UpdateJwtPublicKey extends Thread {
|
||||
boolean kill = false;
|
||||
|
@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
import org.kar.archidata.dataAccess.options.OverrideTableName;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -20,11 +21,9 @@ public class AnnotationTools {
|
||||
|
||||
public static String getTableName(final Class<?> clazz, final QueryOptions options) throws Exception {
|
||||
if (options != null) {
|
||||
final Object data = options.get(QueryOptions.OVERRIDE_TABLE_NAME);
|
||||
if (data instanceof final String optionString) {
|
||||
return optionString;
|
||||
} else if (data != null) {
|
||||
LOGGER.error("'{}' ==> has not a String value: {}", QueryOptions.SQL_DELETED_DISABLE, data);
|
||||
final OverrideTableName data = options.get(OverrideTableName.class);
|
||||
if (data != null) {
|
||||
return data.getName();
|
||||
}
|
||||
}
|
||||
return AnnotationTools.getTableName(clazz);
|
||||
|
@ -26,7 +26,7 @@ import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.QueryCondition;
|
||||
import org.kar.archidata.filter.GenericContext;
|
||||
import org.kar.archidata.model.Data;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -1,16 +1,20 @@
|
||||
package org.kar.archidata.dataAccess;
|
||||
|
||||
/** Java does not permit to set return data (eg: integer) in the function parameter. This class permit to update a value as in/out function parameters. */
|
||||
public class CountInOut {
|
||||
// internal value of the stream
|
||||
public int value = 0;
|
||||
|
||||
public CountInOut() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
/** Default constructor */
|
||||
public CountInOut() {}
|
||||
|
||||
/** Constructor with the initial value.
|
||||
* @param i Initial Value */
|
||||
public CountInOut(final int i) {
|
||||
this.value = i;
|
||||
}
|
||||
|
||||
/** Increment by one the value. */
|
||||
public void inc() {
|
||||
this.value++;
|
||||
}
|
||||
|
@ -25,9 +25,13 @@ import org.kar.archidata.dataAccess.addOn.AddOnDataJson;
|
||||
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
|
||||
import org.kar.archidata.dataAccess.addOn.AddOnManyToOne;
|
||||
import org.kar.archidata.dataAccess.addOn.AddOnSQLTableExternalForeinKeyAsList;
|
||||
import org.kar.archidata.dataAccess.options.AccessDeletedItems;
|
||||
import org.kar.archidata.dataAccess.options.CheckFunction;
|
||||
import org.kar.archidata.dataAccess.options.Limit;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.DateTools;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -166,7 +170,7 @@ public class DataAccess {
|
||||
* @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. */
|
||||
* @throws SQLException if an error is generated in the SQL request. */
|
||||
public static List<Long> getListOfIds(final ResultSet rs, final int iii, final String separator) throws SQLException {
|
||||
final String trackString = rs.getString(iii);
|
||||
if (rs.wasNull()) {
|
||||
@ -278,14 +282,12 @@ public class DataAccess {
|
||||
iii.inc();
|
||||
}
|
||||
|
||||
// TODO: maybe wrap this if the use of sqlite ==> maybe some problems came with sqlite ...
|
||||
protected static <T> void setValueFromDb(final Class<?> type, final Object data, final CountInOut count, final Field field, final ResultSet rs, final CountInOut countNotNull) throws Exception {
|
||||
if (type == Long.class) {
|
||||
final Long tmp = rs.getLong(count.value);
|
||||
if (rs.wasNull()) {
|
||||
field.set(data, null);
|
||||
} else {
|
||||
// logger.debug(" ==> {}", tmp);
|
||||
field.set(data, tmp);
|
||||
countNotNull.inc();
|
||||
}
|
||||
@ -381,11 +383,12 @@ public class DataAccess {
|
||||
} catch (final SQLException ex) {
|
||||
final String tmp = rs.getString(count.value);
|
||||
LOGGER.error("Fail to parse the SQL time !!! {}", tmp);
|
||||
LOGGER.error("Fail to parse the SQL time !!! {}", Date.parse(tmp));
|
||||
if (rs.wasNull()) {
|
||||
field.set(data, null);
|
||||
} else {
|
||||
field.set(data, Date.parse(tmp));
|
||||
final Date date = DateTools.parseDate(tmp);
|
||||
LOGGER.error("Fail to parse the SQL time !!! {}", date);
|
||||
field.set(data, date);
|
||||
countNotNull.inc();
|
||||
}
|
||||
}
|
||||
@ -418,15 +421,19 @@ public class DataAccess {
|
||||
if (rs.wasNull()) {
|
||||
field.set(data, null);
|
||||
} else {
|
||||
boolean find = false;
|
||||
final Object[] arr = type.getEnumConstants();
|
||||
for (final Object elem : arr) {
|
||||
if (elem.toString().equals(tmp)) {
|
||||
field.set(data, elem);
|
||||
countNotNull.inc();
|
||||
find = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// TODO: maybe do something stupid if not exist ???
|
||||
if (!find) {
|
||||
throw new DataAccessException("Enum value does not exist in the Model: '" + tmp + "'");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw new DataAccessException("Unknown Field Type");
|
||||
@ -463,6 +470,14 @@ public class DataAccess {
|
||||
public static <T> T insert(final T data, final QueryOptions options) throws Exception {
|
||||
final Class<?> clazz = data.getClass();
|
||||
|
||||
// External checker of data:
|
||||
if (options != null) {
|
||||
final CheckFunction check = options.get(CheckFunction.class);
|
||||
if (check != null) {
|
||||
check.getChecker().check(data, null);
|
||||
}
|
||||
}
|
||||
|
||||
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
// real add in the BDD:
|
||||
try {
|
||||
@ -672,6 +687,14 @@ public class DataAccess {
|
||||
final Class<?> clazz = data.getClass();
|
||||
// public static NodeSmall createNode(String typeInNode, String name, String description, Long parentId) {
|
||||
|
||||
// External checker of data:
|
||||
if (options != null) {
|
||||
final CheckFunction check = options.get(CheckFunction.class);
|
||||
if (check != null) {
|
||||
check.getChecker().check(data, filterValue);
|
||||
}
|
||||
}
|
||||
|
||||
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
// real add in the BDD:
|
||||
try {
|
||||
@ -803,12 +826,7 @@ public class DataAccess {
|
||||
throws ExceptionDBInterface {
|
||||
boolean exclude_deleted = true;
|
||||
if (options != null) {
|
||||
final Object data = options.get(QueryOptions.SQL_DELETED_DISABLE);
|
||||
if (data instanceof final Boolean elem) {
|
||||
exclude_deleted = !elem;
|
||||
} else if (data != null) {
|
||||
LOGGER.error("'{}' ==> has not a boolean value: {}", QueryOptions.SQL_DELETED_DISABLE, data);
|
||||
}
|
||||
exclude_deleted = !options.exist(AccessDeletedItems.class);
|
||||
}
|
||||
// Check if we have a condition to generate
|
||||
if (condition == null) {
|
||||
@ -823,7 +841,7 @@ public class DataAccess {
|
||||
}
|
||||
query.append(" WHERE (");
|
||||
condition.generateQuerry(query, tableName);
|
||||
|
||||
|
||||
query.append(") ");
|
||||
if (exclude_deleted && deletedFieldName != null) {
|
||||
query.append("AND ");
|
||||
@ -865,8 +883,12 @@ public class DataAccess {
|
||||
return getWhere(clazz, condition, null);
|
||||
}
|
||||
|
||||
public static <T> T getWhere(final Class<T> clazz, final QueryItem condition, final QueryOptions options) throws Exception {
|
||||
final List<T> values = getsWhere(clazz, condition, options, 1);
|
||||
public static <T> T getWhere(final Class<T> clazz, final QueryItem condition, QueryOptions options) throws Exception {
|
||||
if (options == null) {
|
||||
options = new QueryOptions();
|
||||
}
|
||||
options.add(new Limit(1));
|
||||
final List<T> values = getsWhere(clazz, condition, options);
|
||||
if (values.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
@ -874,19 +896,15 @@ public class DataAccess {
|
||||
}
|
||||
|
||||
public static <T> List<T> getsWhere(final Class<T> clazz, final QueryItem condition) throws Exception {
|
||||
return getsWhere(clazz, condition, null, null, null);
|
||||
return getsWhere(clazz, condition, null, null);
|
||||
}
|
||||
|
||||
public static <T> List<T> getsWhere(final Class<T> clazz, final QueryItem condition, final QueryOptions options) throws Exception {
|
||||
return getsWhere(clazz, condition, null, options, null);
|
||||
}
|
||||
|
||||
public static <T> List<T> getsWhere(final Class<T> clazz, final QueryItem condition, final QueryOptions options, final Integer linit) throws Exception {
|
||||
return getsWhere(clazz, condition, null, options, linit);
|
||||
return getsWhere(clazz, condition, null, options);
|
||||
}
|
||||
|
||||
public static void generateSelectField(final StringBuilder querySelect, final StringBuilder query, final Class<?> clazz, final QueryOptions options, final CountInOut count) throws Exception {
|
||||
final boolean readAllfields = QueryOptions.readAllFields(options);
|
||||
final boolean readAllfields = QueryOptions.readAllColomn(options);
|
||||
final String tableName = AnnotationTools.getTableName(clazz, options);
|
||||
boolean firstField = true;
|
||||
|
||||
@ -899,7 +917,6 @@ public class DataAccess {
|
||||
if (addOn != null && !addOn.canRetrieve(elem)) {
|
||||
continue;
|
||||
}
|
||||
// TODO: Manage it with AddOn
|
||||
final boolean notRead = AnnotationTools.isdefaultNotRead(elem);
|
||||
if (!readAllfields && notRead) {
|
||||
continue;
|
||||
@ -922,9 +939,8 @@ public class DataAccess {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: set limit as an query Option...
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> List<T> getsWhere(final Class<T> clazz, final QueryItem condition, final String orderBy, final QueryOptions options, final Integer linit) throws Exception {
|
||||
public static <T> List<T> getsWhere(final Class<T> clazz, final QueryItem condition, final String orderBy, final QueryOptions options) throws Exception {
|
||||
final List<LazyGetter> lazyCall = new ArrayList<>();
|
||||
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
@ -948,10 +964,20 @@ public class DataAccess {
|
||||
query.append(" ORDER BY ");
|
||||
query.append(orderBy);
|
||||
}
|
||||
if (linit != null && linit >= 1) {
|
||||
query.append(" LIMIT " + linit);
|
||||
if (options != null) {
|
||||
final Limit limit = options.get(Limit.class);
|
||||
if (limit != null) {
|
||||
if (limit.getLimit() >= 1) {
|
||||
query.append(" LIMIT " + limit.getLimit());
|
||||
} else {
|
||||
LOGGER.warn("Limit is equal @ {}", limit.getLimit());
|
||||
entry.close();
|
||||
entry = null;
|
||||
return outs;
|
||||
}
|
||||
}
|
||||
}
|
||||
LOGGER.debug("generate the query: '{}'", query.toString());
|
||||
LOGGER.warn("generate the query: '{}'", query.toString());
|
||||
// prepare the request:
|
||||
final PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
|
||||
final CountInOut iii = new CountInOut(1);
|
||||
@ -983,7 +1009,7 @@ public class DataAccess {
|
||||
|
||||
public static Object createObjectFromSQLRequest(final ResultSet rs, final Class<?> clazz, final CountInOut count, final CountInOut countNotNull, final QueryOptions options,
|
||||
final List<LazyGetter> lazyCall) throws Exception {
|
||||
final boolean readAllfields = QueryOptions.readAllFields(options);
|
||||
final boolean readAllfields = QueryOptions.readAllColomn(options);
|
||||
// TODO: manage class that is defined inside a class ==> Not manage for now...
|
||||
final Object data = clazz.getConstructors()[0].newInstance();
|
||||
for (final Field elem : clazz.getFields()) {
|
||||
@ -995,7 +1021,6 @@ public class DataAccess {
|
||||
if (addOn != null && !addOn.canRetrieve(elem)) {
|
||||
continue;
|
||||
}
|
||||
// TODO: Manage it with AddOn
|
||||
final boolean notRead = AnnotationTools.isdefaultNotRead(elem);
|
||||
if (!readAllfields && notRead) {
|
||||
continue;
|
||||
@ -1009,7 +1034,6 @@ public class DataAccess {
|
||||
return data;
|
||||
}
|
||||
|
||||
// TODO : detect the @Id
|
||||
public static <T, ID_TYPE> T get(final Class<T> clazz, final ID_TYPE id) throws Exception {
|
||||
return get(clazz, id, null);
|
||||
}
|
||||
@ -1030,7 +1054,6 @@ public class DataAccess {
|
||||
return getsWhere(clazz, null, options);
|
||||
}
|
||||
|
||||
// TODO : detect the @Id
|
||||
public static <ID_TYPE> int delete(final Class<?> clazz, final ID_TYPE id) throws Exception {
|
||||
return delete(clazz, id, null);
|
||||
}
|
||||
@ -1142,7 +1165,7 @@ public class DataAccess {
|
||||
query.append("`=false ");
|
||||
/* is is needed only for SQLite ??? query.append("`modify_date`="); query.append(getDBNow()); query.append(", "); */
|
||||
// need to disable the deleted false because the model must be unselected to be updated.
|
||||
options.put(QueryOptions.SQL_DELETED_DISABLE, true);
|
||||
options.add(QueryOptions.ACCESS_DELETED_ITEMS);
|
||||
whereAppendQuery(query, tableName, condition, options, deletedFieldName);
|
||||
try {
|
||||
final PreparedStatement ps = entry.connection.prepareStatement(query.toString());
|
||||
|
@ -12,8 +12,9 @@ import org.kar.archidata.annotation.AnnotationTools;
|
||||
import org.kar.archidata.annotation.CreationTimestamp;
|
||||
import org.kar.archidata.annotation.DataIfNotExists;
|
||||
import org.kar.archidata.annotation.UpdateTimestamp;
|
||||
import org.kar.archidata.dataAccess.options.CreateDropTable;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -23,7 +24,7 @@ import jakarta.persistence.GenerationType;
|
||||
|
||||
public class DataFactory {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(DataFactory.class);
|
||||
|
||||
|
||||
public static String convertTypeInSQL(final Class<?> type, final String fieldName) throws Exception {
|
||||
if (!"sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||
if (type == Long.class || type == long.class) {
|
||||
@ -126,21 +127,21 @@ public class DataFactory {
|
||||
}
|
||||
throw new DataAccessException("Imcompatible type of element in object for: " + type.getCanonicalName());
|
||||
}
|
||||
|
||||
|
||||
public static void createTablesSpecificType(final String tableName, final Field elem, final StringBuilder mainTableBuilder, final List<String> preOtherTables, final List<String> postOtherTables,
|
||||
final boolean createIfNotExist, final boolean createDrop, final int fieldId, final Class<?> classModel) throws Exception {
|
||||
final String name = AnnotationTools.getFieldName(elem);
|
||||
final Integer limitSize = AnnotationTools.getLimitSize(elem);
|
||||
final boolean notNull = AnnotationTools.getNotNull(elem);
|
||||
|
||||
|
||||
final boolean primaryKey = AnnotationTools.isPrimaryKey(elem);
|
||||
final GenerationType strategy = AnnotationTools.getStrategy(elem);
|
||||
|
||||
|
||||
final boolean createTime = elem.getDeclaredAnnotationsByType(CreationTimestamp.class).length != 0;
|
||||
final boolean updateTime = elem.getDeclaredAnnotationsByType(UpdateTimestamp.class).length != 0;
|
||||
final String comment = AnnotationTools.getComment(elem);
|
||||
final String defaultValue = AnnotationTools.getDefault(elem);
|
||||
|
||||
|
||||
if (fieldId == 0) {
|
||||
mainTableBuilder.append("\n\t\t`");
|
||||
} else {
|
||||
@ -193,13 +194,13 @@ public class DataFactory {
|
||||
triggerBuilder.append(tableName);
|
||||
triggerBuilder.append(" SET ");
|
||||
triggerBuilder.append(name);
|
||||
//triggerBuilder.append(" = datetime('now') WHERE id = NEW.id; \n");
|
||||
// triggerBuilder.append(" = datetime('now') WHERE id = NEW.id; \n");
|
||||
triggerBuilder.append(" = strftime('%Y-%m-%d %H:%M:%f', 'now') WHERE id = NEW.id; \n");
|
||||
triggerBuilder.append("END;");
|
||||
|
||||
|
||||
postOtherTables.add(triggerBuilder.toString());
|
||||
}
|
||||
|
||||
|
||||
mainTableBuilder.append(" ");
|
||||
}
|
||||
} else {
|
||||
@ -234,11 +235,11 @@ public class DataFactory {
|
||||
mainTableBuilder.append("DEFAULT ");
|
||||
mainTableBuilder.append(defaultValue);
|
||||
mainTableBuilder.append(" ");
|
||||
|
||||
|
||||
}
|
||||
if (primaryKey && "sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||
mainTableBuilder.append("PRIMARY KEY ");
|
||||
|
||||
|
||||
}
|
||||
if (strategy == GenerationType.IDENTITY) {
|
||||
if (!"sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||
@ -249,14 +250,14 @@ public class DataFactory {
|
||||
} else if (strategy != null) {
|
||||
throw new DataAccessException("Can not generate a stategy different of IDENTITY");
|
||||
}
|
||||
|
||||
|
||||
if (comment != null && !"sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||
mainTableBuilder.append("COMMENT '");
|
||||
mainTableBuilder.append(comment.replace('\'', '\''));
|
||||
mainTableBuilder.append("' ");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static boolean isFieldFromSuperClass(final Class<?> model, final String filedName) {
|
||||
final Class<?> superClass = model.getSuperclass();
|
||||
if (superClass == null) {
|
||||
@ -276,24 +277,19 @@ public class DataFactory {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static List<String> createTable(final Class<?> clazz) throws Exception {
|
||||
return createTable(clazz, null);
|
||||
}
|
||||
|
||||
|
||||
public static List<String> createTable(final Class<?> clazz, final QueryOptions options) throws Exception {
|
||||
final String tableName = AnnotationTools.getTableName(clazz, options);
|
||||
|
||||
|
||||
boolean createDrop = false;
|
||||
if (options != null) {
|
||||
final Object data = options.get(QueryOptions.CREATE_DROP_TABLE);
|
||||
if (data instanceof final Boolean optionBoolean) {
|
||||
createDrop = optionBoolean;
|
||||
} else if (data != null) {
|
||||
LOGGER.error("'{}' ==> has not a Boolean value: {}", QueryOptions.CREATE_DROP_TABLE, data);
|
||||
}
|
||||
createDrop = options.exist(CreateDropTable.class);
|
||||
}
|
||||
|
||||
|
||||
final boolean createIfNotExist = clazz.getDeclaredAnnotationsByType(DataIfNotExists.class).length != 0;
|
||||
final List<String> preActionList = new ArrayList<>();
|
||||
final List<String> postActionList = new ArrayList<>();
|
||||
@ -313,7 +309,7 @@ public class DataFactory {
|
||||
int fieldId = 0;
|
||||
LOGGER.debug("===> TABLE `{}`", tableName);
|
||||
final List<String> primaryKeys = new ArrayList<>();
|
||||
|
||||
|
||||
for (final Field elem : clazz.getFields()) {
|
||||
// DEtect the primary key (support only one primary key right now...
|
||||
if (AnnotationTools.isPrimaryKey(elem)) {
|
||||
@ -394,5 +390,5 @@ public class DataFactory {
|
||||
preActionList.addAll(postActionList);
|
||||
return preActionList;
|
||||
}
|
||||
|
||||
|
||||
}
|
47
src/org/kar/archidata/dataAccess/QueryInList.java
Normal file
47
src/org/kar/archidata/dataAccess/QueryInList.java
Normal file
@ -0,0 +1,47 @@
|
||||
package org.kar.archidata.dataAccess;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.List;
|
||||
|
||||
public class QueryInList<T> implements QueryItem {
|
||||
protected final String key;
|
||||
protected final String comparator;
|
||||
protected final List<T> value;
|
||||
|
||||
protected QueryInList(final String key, final String comparator, final List<T> value) {
|
||||
this.key = key;
|
||||
this.comparator = comparator;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public QueryInList(final String key, final List<T> value) {
|
||||
this(key, "IN", value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateQuerry(final StringBuilder querry, final String tableName) {
|
||||
querry.append(tableName);
|
||||
querry.append(".");
|
||||
querry.append(this.key);
|
||||
querry.append(" ");
|
||||
querry.append(this.comparator);
|
||||
querry.append(" (");
|
||||
for (int iii = 0; iii < this.value.size(); iii++) {
|
||||
if (iii != 0) {
|
||||
querry.append(",?");
|
||||
} else {
|
||||
querry.append("?");
|
||||
}
|
||||
}
|
||||
querry.append(")");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception {
|
||||
for (final Object elem : this.value) {
|
||||
DataAccess.addElement(ps, elem, iii);
|
||||
iii.inc();
|
||||
}
|
||||
}
|
||||
}
|
9
src/org/kar/archidata/dataAccess/QueryNoInList.java
Normal file
9
src/org/kar/archidata/dataAccess/QueryNoInList.java
Normal file
@ -0,0 +1,9 @@
|
||||
package org.kar.archidata.dataAccess;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class QueryNoInList<T> extends QueryInList<T> {
|
||||
public QueryNoInList(final String key, final List<T> value) {
|
||||
super(key, "NOT IN", value);
|
||||
}
|
||||
}
|
3
src/org/kar/archidata/dataAccess/QueryOption.java
Normal file
3
src/org/kar/archidata/dataAccess/QueryOption.java
Normal file
@ -0,0 +1,3 @@
|
||||
package org.kar.archidata.dataAccess;
|
||||
|
||||
public class QueryOption {}
|
@ -1,57 +1,61 @@
|
||||
package org.kar.archidata.dataAccess;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.kar.archidata.dataAccess.options.AccessDeletedItems;
|
||||
import org.kar.archidata.dataAccess.options.CreateDropTable;
|
||||
import org.kar.archidata.dataAccess.options.ReadAllColumn;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class QueryOptions {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(QueryOptions.class);
|
||||
public static final String SQL_NOT_READ_DISABLE = "SQLNotRead_disable";
|
||||
public static final String SQL_DELETED_DISABLE = "SQLDeleted_disable";
|
||||
public static final String OVERRIDE_TABLE_NAME = "SQL_OVERRIDE_TABLE_NAME";
|
||||
public static final String CREATE_DROP_TABLE = "CREATE_DROP_TABLE";
|
||||
public static final ReadAllColumn READ_ALL_COLOMN = new ReadAllColumn();
|
||||
public static final AccessDeletedItems ACCESS_DELETED_ITEMS = new AccessDeletedItems();
|
||||
public static final CreateDropTable CREATE_DROP_TABLE = new CreateDropTable();
|
||||
|
||||
private final Map<String, Object> options = new HashMap<>();
|
||||
|
||||
public QueryOptions() {
|
||||
private final List<QueryOption> options = new ArrayList<>();
|
||||
|
||||
public QueryOptions(final QueryOption... elems) {
|
||||
Collections.addAll(this.options, elems);
|
||||
}
|
||||
|
||||
public QueryOptions(final String key, final Object value) {
|
||||
this.options.put(key, value);
|
||||
public QueryOptions() {}
|
||||
|
||||
public void add(final QueryOption option) {
|
||||
this.options.add(option);
|
||||
}
|
||||
|
||||
public QueryOptions(final String key, final Object value, final String key2, final Object value2) {
|
||||
this.options.put(key, value);
|
||||
this.options.put(key2, value2);
|
||||
public List<QueryOption> getAll() {
|
||||
return this.options;
|
||||
}
|
||||
|
||||
public QueryOptions(final String key, final Object value, final String key2, final Object value2, final String key3, final Object value3) {
|
||||
this.options.put(key, value);
|
||||
this.options.put(key2, value2);
|
||||
this.options.put(key3, value3);
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T get(final Class<T> type) {
|
||||
for (final QueryOption elem : this.options) {
|
||||
if (elem.getClass() == type) {
|
||||
return (T) elem;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void put(final String key, final Object value) {
|
||||
this.options.put(key, value);
|
||||
}
|
||||
|
||||
public Object get(final String value) {
|
||||
return this.options.get(value);
|
||||
}
|
||||
|
||||
public static boolean readAllFields(final QueryOptions options) {
|
||||
if (options != null) {
|
||||
final Object data = options.get(QueryOptions.SQL_NOT_READ_DISABLE);
|
||||
if (data instanceof final Boolean elem) {
|
||||
return elem;
|
||||
} else if (data != null) {
|
||||
LOGGER.error("'{}' ==> has not a boolean value: {}", QueryOptions.SQL_NOT_READ_DISABLE, data);
|
||||
public boolean exist(final Class<?> type) {
|
||||
for (final QueryOption elem : this.options) {
|
||||
if (elem.getClass() == type) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean readAllColomn(final QueryOptions options) {
|
||||
if (options != null) {
|
||||
return options.exist(ReadAllColumn.class);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,12 +16,12 @@ import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.LazyGetter;
|
||||
import org.kar.archidata.dataAccess.QueryAnd;
|
||||
import org.kar.archidata.dataAccess.QueryCondition;
|
||||
import org.kar.archidata.dataAccess.QueryItem;
|
||||
import org.kar.archidata.dataAccess.QueryInList;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
import org.kar.archidata.dataAccess.QueryOr;
|
||||
import org.kar.archidata.dataAccess.addOn.model.LinkTable;
|
||||
import org.kar.archidata.dataAccess.options.OverrideTableName;
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -166,12 +166,10 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
final String idField = AnnotationTools.getFieldName(AnnotationTools.getIdField(objectClass));
|
||||
// In the lazy mode, the request is done in asynchronous mode, they will be done after...
|
||||
final LazyGetter lambda = () -> {
|
||||
final List<QueryItem> childs = new ArrayList<>();
|
||||
for (final Long elem : idList) {
|
||||
childs.add(new QueryCondition(idField, "=", elem));
|
||||
}
|
||||
final List<Long> childs = new ArrayList<>(idList);
|
||||
// TODO: update to have get with abstract types ....
|
||||
final Object foreignData = DataAccess.getsWhere(decorators.targetEntity(), new QueryOr(childs), options);
|
||||
@SuppressWarnings("unchecked")
|
||||
final Object foreignData = DataAccess.getsWhere(decorators.targetEntity(), new QueryInList<>(idField, childs), null);
|
||||
if (foreignData == null) {
|
||||
return;
|
||||
}
|
||||
@ -187,7 +185,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final String linkTableName = generateLinkTableName(tableName, column);
|
||||
final LinkTable insertElement = new LinkTable(localKey, remoteKey);
|
||||
final QueryOptions options = new QueryOptions(QueryOptions.OVERRIDE_TABLE_NAME, linkTableName);
|
||||
final QueryOptions options = new QueryOptions(new OverrideTableName(linkTableName));
|
||||
DataAccess.insert(insertElement, options);
|
||||
|
||||
}
|
||||
@ -195,7 +193,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
public static int removeLink(final Class<?> clazz, final long localKey, final String column, final long remoteKey) throws Exception {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final String linkTableName = generateLinkTableName(tableName, column);
|
||||
final QueryOptions options = new QueryOptions(QueryOptions.OVERRIDE_TABLE_NAME, linkTableName);
|
||||
final QueryOptions options = new QueryOptions(new OverrideTableName(linkTableName));
|
||||
final QueryAnd condition = new QueryAnd(new QueryCondition("object1Id", "=", localKey), new QueryCondition("object2Id", "=", remoteKey));
|
||||
return DataAccess.deleteWhere(LinkTable.class, condition, options);
|
||||
}
|
||||
@ -204,7 +202,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
public void createTables(final String tableName, final Field field, final StringBuilder mainTableBuilder, final List<String> preActionList, final List<String> postActionList,
|
||||
final boolean createIfNotExist, final boolean createDrop, final int fieldId) throws Exception {
|
||||
final String linkTableName = generateLinkTableNameField(tableName, field);
|
||||
final QueryOptions options = new QueryOptions(QueryOptions.OVERRIDE_TABLE_NAME, linkTableName);
|
||||
final QueryOptions options = new QueryOptions(new OverrideTableName(linkTableName));
|
||||
final List<String> sqlCommand = DataFactory.createTable(LinkTable.class, options);
|
||||
postActionList.addAll(sqlCommand);
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
package org.kar.archidata.dataAccess.options;
|
||||
|
||||
import org.kar.archidata.dataAccess.QueryOption;
|
||||
|
||||
/** This option permit to access on deleted items of a table */
|
||||
public class AccessDeletedItems extends QueryOption {
|
||||
public AccessDeletedItems() {}
|
||||
}
|
16
src/org/kar/archidata/dataAccess/options/CheckFunction.java
Normal file
16
src/org/kar/archidata/dataAccess/options/CheckFunction.java
Normal file
@ -0,0 +1,16 @@
|
||||
package org.kar.archidata.dataAccess.options;
|
||||
|
||||
import org.kar.archidata.dataAccess.QueryOption;
|
||||
|
||||
/** By default some element are not read like createAt and UpdatedAt. This option permit to read it. */
|
||||
public class CheckFunction extends QueryOption {
|
||||
private final CheckFunctionInterface checker;
|
||||
|
||||
public CheckFunction(final CheckFunctionInterface checker) {
|
||||
this.checker = checker;
|
||||
}
|
||||
|
||||
public CheckFunctionInterface getChecker() {
|
||||
return this.checker;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package org.kar.archidata.dataAccess.options;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** By default some element are not read like createAt and UpdatedAt. This option permit to read it. */
|
||||
public interface CheckFunctionInterface {
|
||||
/** This function implementation is design to check if the updated class is valid of not for insertion
|
||||
* @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(Object data, List<String> filterValue) throws Exception;
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package org.kar.archidata.dataAccess.options;
|
||||
|
||||
import org.kar.archidata.dataAccess.QueryOption;
|
||||
|
||||
/** This option permit to create the DROP `Table` IF EXIST in the generation of structure. */
|
||||
public class CreateDropTable extends QueryOption {
|
||||
public CreateDropTable() {}
|
||||
}
|
17
src/org/kar/archidata/dataAccess/options/Limit.java
Normal file
17
src/org/kar/archidata/dataAccess/options/Limit.java
Normal file
@ -0,0 +1,17 @@
|
||||
package org.kar.archidata.dataAccess.options;
|
||||
|
||||
import org.kar.archidata.dataAccess.QueryOption;
|
||||
|
||||
/** Option that permit to access to a table structure with an other name that is define in the structure. Note: Internal use for link tables (see:
|
||||
* org.kar.archidata.dataAccess.addOn.model.LinkTable). */
|
||||
public class Limit extends QueryOption {
|
||||
private final int limit;
|
||||
|
||||
public Limit(final int limit) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public int getLimit() {
|
||||
return this.limit;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package org.kar.archidata.dataAccess.options;
|
||||
|
||||
import org.kar.archidata.dataAccess.QueryOption;
|
||||
|
||||
/** Option that permit to access to a table structure with an other name that is define in the structure. Note: Internal use for link tables (see:
|
||||
* org.kar.archidata.dataAccess.addOn.model.LinkTable). */
|
||||
public class OverrideTableName extends QueryOption {
|
||||
private final String name;
|
||||
|
||||
public OverrideTableName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package org.kar.archidata.dataAccess.options;
|
||||
|
||||
import org.kar.archidata.dataAccess.QueryOption;
|
||||
|
||||
/** By default some element are not read like createAt and UpdatedAt. This option permit to read it. */
|
||||
public class ReadAllColumn extends QueryOption {
|
||||
public ReadAllColumn() {}
|
||||
}
|
@ -13,7 +13,7 @@ import java.util.Map.Entry;
|
||||
import org.kar.archidata.annotation.security.PermitTokenInURI;
|
||||
import org.kar.archidata.catcher.RestErrorResponse;
|
||||
import org.kar.archidata.model.UserByToken;
|
||||
import org.kar.archidata.util.JWTWrapper;
|
||||
import org.kar.archidata.tools.JWTWrapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -16,17 +16,17 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
public class MigrationEngine {
|
||||
final static Logger LOGGER = LoggerFactory.getLogger(MigrationEngine.class);
|
||||
|
||||
|
||||
// List of order migrations
|
||||
private final List<MigrationInterface> datas;
|
||||
// initialization of the migration if the DB is not present...
|
||||
private MigrationInterface init;
|
||||
|
||||
|
||||
/** Migration engine constructor (empty). */
|
||||
public MigrationEngine() {
|
||||
this(new ArrayList<>(), null);
|
||||
}
|
||||
|
||||
|
||||
/** Migration engine constructor (specific mode).
|
||||
* @param datas All the migration ordered.
|
||||
* @param init Initialization migration model. */
|
||||
@ -34,19 +34,19 @@ public class MigrationEngine {
|
||||
this.datas = datas;
|
||||
this.init = init;
|
||||
}
|
||||
|
||||
|
||||
/** Add a Migration in the list
|
||||
* @param migration Migration to add. */
|
||||
public void add(final MigrationInterface migration) {
|
||||
this.datas.add(migration);
|
||||
}
|
||||
|
||||
|
||||
/** Set first initialization class
|
||||
* @param migration migration class for first init. */
|
||||
public void setInit(final MigrationInterface migration) {
|
||||
this.init = migration;
|
||||
}
|
||||
|
||||
|
||||
/** Get the current version/migration name
|
||||
* @return Model represent the last migration. If null then no migration has been done. */
|
||||
public Migration getCurrentVersion() {
|
||||
@ -54,7 +54,7 @@ public class MigrationEngine {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
final List<Migration> data = DataAccess.gets(Migration.class, new QueryOptions("SQLNotRead_disable", true));
|
||||
final List<Migration> data = DataAccess.gets(Migration.class, new QueryOptions(QueryOptions.READ_ALL_COLOMN));
|
||||
if (data == null) {
|
||||
LOGGER.error("Can not collect the migration table in the DB:{}");
|
||||
return null;
|
||||
@ -74,7 +74,7 @@ public class MigrationEngine {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/** Process the automatic migration of the system The function wait the Administrator intervention to correct the bug.
|
||||
* @param config SQL connection for the migration.
|
||||
* @throws InterruptedException user interrupt the migration */
|
||||
@ -92,7 +92,7 @@ public class MigrationEngine {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Process the automatic migration of the system
|
||||
* @param config SQL connection for the migration
|
||||
* @throws IOException Error if access on the DB */
|
||||
@ -118,7 +118,7 @@ public class MigrationEngine {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// STEP 1: Check the DB exist:
|
||||
LOGGER.info("Verify existance of '{}'", config.getDbName());
|
||||
boolean exist = DataAccess.isDBExist(config.getDbName());
|
||||
@ -230,7 +230,7 @@ public class MigrationEngine {
|
||||
}
|
||||
LOGGER.info("Execute migration ... [ END ]");
|
||||
}
|
||||
|
||||
|
||||
public void migrateSingle(final DBEntry entry, final MigrationInterface elem, final int id, final int count) throws MigrationException {
|
||||
LOGGER.info("---------------------------------------------------------");
|
||||
LOGGER.info("-- Migrate: [{}/{}] {} [BEGIN]", id, count, elem.getName());
|
||||
@ -277,7 +277,7 @@ public class MigrationEngine {
|
||||
}
|
||||
LOGGER.info("Migrate: [{}/{}] {} [ END ]", id, count, elem.getName());
|
||||
}
|
||||
|
||||
|
||||
public void revertTo(final DBEntry entry, final String migrationName) {
|
||||
final Migration currentVersion = getCurrentVersion();
|
||||
final List<MigrationInterface> toApply = new ArrayList<>();
|
||||
@ -300,10 +300,10 @@ public class MigrationEngine {
|
||||
revertSingle(entry, elem, id, count);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void revertSingle(final DBEntry entry, final MigrationInterface elem, final int id, final int count) {
|
||||
LOGGER.info("Revert migration: {} [BEGIN]", elem.getName());
|
||||
|
||||
|
||||
LOGGER.info("Revert migration: {} [ END ]", elem.getName());
|
||||
}
|
||||
}
|
||||
|
@ -7,20 +7,20 @@ public interface MigrationInterface {
|
||||
/** Get Name of the migration
|
||||
* @return Migration name */
|
||||
String getName();
|
||||
|
||||
|
||||
/** Migrate the system to a new version.
|
||||
* @param entry DB interface for the migration.
|
||||
* @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(DBEntry 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(DBEntry entry, StringBuilder log) throws Exception;
|
||||
|
||||
|
||||
/** Get the number of step in the migration process.
|
||||
* @return count of SQL access. */
|
||||
int getNumberOfStep();
|
||||
|
@ -9,17 +9,15 @@ import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.migration.model.Migration;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
record Action(
|
||||
String action,
|
||||
List<String> filterDB) {
|
||||
record Action(String action, List<String> filterDB) {
|
||||
public Action(final String action) {
|
||||
this(action, List.of());
|
||||
}
|
||||
|
||||
|
||||
public Action(final String action, final String filterDB) {
|
||||
this(action, List.of(filterDB));
|
||||
}
|
||||
@ -28,27 +26,27 @@ record Action(
|
||||
public class MigrationSqlStep implements MigrationInterface {
|
||||
final static Logger LOGGER = LoggerFactory.getLogger(MigrationSqlStep.class);
|
||||
private final List<Action> actions = new ArrayList<>();
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return getClass().getCanonicalName();
|
||||
}
|
||||
|
||||
|
||||
public void display() {
|
||||
for (int iii = 0; iii < this.actions.size(); iii++) {
|
||||
final Action action = this.actions.get(iii);
|
||||
LOGGER.info(" >>>> SQL ACTION : {}/{} ==> filter='{}'\n{}", iii, this.actions.size(), action.filterDB(), action.action());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void generateStep() throws Exception {
|
||||
throw new Exception("Forward is not implemented");
|
||||
}
|
||||
|
||||
|
||||
public void generateRevertStep() throws Exception {
|
||||
throw new Exception("Backward is not implemented");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean applyMigration(final DBEntry entry, final StringBuilder log, final Migration model) throws Exception {
|
||||
generateStep();
|
||||
@ -56,7 +54,7 @@ public class MigrationSqlStep implements MigrationInterface {
|
||||
log.append("action [" + (iii + 1) + "/" + this.actions.size() + "]\n");
|
||||
LOGGER.info(" >>>> SQL ACTION : {}/{}", iii + 1, this.actions.size());
|
||||
final Action action = this.actions.get(iii);
|
||||
|
||||
|
||||
LOGGER.info("SQL request: ```{}``` on '{}' current={}", action.action(), action.filterDB(), ConfigBaseVariable.getDBType());
|
||||
log.append("SQL: " + action.action() + " on " + action.filterDB() + "\n");
|
||||
boolean isValid = true;
|
||||
@ -107,31 +105,31 @@ public class MigrationSqlStep implements MigrationInterface {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean revertMigration(final DBEntry entry, final StringBuilder log) throws Exception {
|
||||
generateRevertStep();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void addAction(final String action) {
|
||||
this.actions.add(new Action(action));
|
||||
}
|
||||
|
||||
|
||||
public void addAction(final String action, final String filterdBType) {
|
||||
this.actions.add(new Action(action, filterdBType));
|
||||
}
|
||||
|
||||
|
||||
public void addClass(final Class<?> clazz) throws Exception {
|
||||
final List<String> tmp = DataFactory.createTable(clazz);
|
||||
for (final String elem : tmp) {
|
||||
this.actions.add(new Action(elem));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getNumberOfStep() {
|
||||
return this.actions.size();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.kar.archidata.util;
|
||||
package org.kar.archidata.tools;
|
||||
|
||||
public class ConfigBaseVariable {
|
||||
static public String tmpDataFolder;
|
@ -1,4 +1,4 @@
|
||||
package org.kar.archidata.util;
|
||||
package org.kar.archidata.tools;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
53
src/org/kar/archidata/tools/DateTools.java
Normal file
53
src/org/kar/archidata/tools/DateTools.java
Normal file
@ -0,0 +1,53 @@
|
||||
package org.kar.archidata.tools;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class DateTools {
|
||||
static private List<SimpleDateFormat> knownPatterns = new ArrayList<>();
|
||||
{
|
||||
// SYSTEM mode
|
||||
DateTools.knownPatterns.add(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"));
|
||||
DateTools.knownPatterns.add(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm.ss.SSS'Z'"));
|
||||
DateTools.knownPatterns.add(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"));
|
||||
DateTools.knownPatterns.add(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"));
|
||||
// Human mode
|
||||
DateTools.knownPatterns.add(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss"));
|
||||
DateTools.knownPatterns.add(new SimpleDateFormat("yyyy-MM-dd' 'HH:mm:ss.SSS"));
|
||||
// date mode
|
||||
DateTools.knownPatterns.add(new SimpleDateFormat("yyyy-MM-dd"));
|
||||
// time mode
|
||||
DateTools.knownPatterns.add(new SimpleDateFormat("HH:mm:ss"));
|
||||
DateTools.knownPatterns.add(new SimpleDateFormat("HH:mm:ss.SSS"));
|
||||
}
|
||||
|
||||
public static Date parseDate(final String inputDate, final String pattern) throws ParseException {
|
||||
final SimpleDateFormat format = new SimpleDateFormat(pattern);
|
||||
return format.parse(inputDate);
|
||||
}
|
||||
|
||||
public static Date parseDate(final String inputDate) throws ParseException {
|
||||
for (final SimpleDateFormat pattern : DateTools.knownPatterns) {
|
||||
try {
|
||||
return pattern.parse(inputDate);
|
||||
} catch (final ParseException e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
throw new ParseException("Can not parse the date-time format: '" + inputDate + "'", 0);
|
||||
|
||||
}
|
||||
|
||||
public static String formatDate(final Date date, final String requiredDateFormat) {
|
||||
final SimpleDateFormat df = new SimpleDateFormat(requiredDateFormat);
|
||||
final String outputDateFormatted = df.format(date);
|
||||
return outputDateFormatted;
|
||||
}
|
||||
|
||||
public static String formatDate(final Date date) {
|
||||
return formatDate(date, "yyyy-MM-dd'T'HH:mm.ss.SSS'Z'");
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package org.kar.archidata.util;
|
||||
package org.kar.archidata.tools;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
@ -1,4 +1,4 @@
|
||||
package org.kar.archidata.util;
|
||||
package org.kar.archidata.tools;
|
||||
|
||||
public class PublicKey {
|
||||
public String key;
|
@ -1,4 +1,4 @@
|
||||
package org.kar.archidata.util;
|
||||
package org.kar.archidata.tools;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
@ -15,7 +15,7 @@ import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -29,11 +29,12 @@ public class TestJson {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
|
@ -16,7 +16,7 @@ import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.addOn.AddOnManyToMany;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -31,11 +31,12 @@ public class TestManyToMany {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
|
@ -15,7 +15,7 @@ import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -30,11 +30,12 @@ public class TestManyToOne {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
|
@ -14,7 +14,7 @@ import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -27,11 +27,12 @@ public class TestOneToMany {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
|
@ -19,7 +19,7 @@ import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -33,30 +33,31 @@ public class TestSimpleTable {
|
||||
private static final String DATA_INJECTED_2 = "dsqfsdfqsdfsqdf";
|
||||
private static Long idOfTheObject = null;
|
||||
private static Timestamp startAction = null;
|
||||
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Clear the static test:
|
||||
idOfTheObject = null;
|
||||
startAction = null;
|
||||
|
||||
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
}
|
||||
|
||||
|
||||
@AfterAll
|
||||
public static void removeDataBase() throws IOException {
|
||||
LOGGER.info("Remove the test db");
|
||||
DBEntry.closeAllForceMode();
|
||||
ConfigBaseVariable.clearAllValue();
|
||||
}
|
||||
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testTableInsertAndRetrieve() throws Exception {
|
||||
@ -69,14 +70,14 @@ public class TestSimpleTable {
|
||||
final SimpleTable test = new SimpleTable();
|
||||
test.data = TestSimpleTable.DATA_INJECTED;
|
||||
final SimpleTable insertedData = DataAccess.insert(test);
|
||||
|
||||
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, insertedData.id);
|
||||
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||
@ -85,13 +86,13 @@ public class TestSimpleTable {
|
||||
Assertions.assertNull(retrieve.updatedAt);
|
||||
TestSimpleTable.idOfTheObject = retrieve.id;
|
||||
}
|
||||
|
||||
|
||||
@Order(2)
|
||||
@Test
|
||||
public void testReadAllValuesUnreadable() throws Exception {
|
||||
// check the full values
|
||||
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject, new QueryOptions(QueryOptions.SQL_NOT_READ_DISABLE, true));
|
||||
|
||||
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject, new QueryOptions(QueryOptions.READ_ALL_COLOMN));
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
Assertions.assertEquals(TestSimpleTable.idOfTheObject, retrieve.id);
|
||||
@ -104,7 +105,7 @@ public class TestSimpleTable {
|
||||
// Assertions.assertTrue(retrieve.updatedAt.after(this.startAction));
|
||||
Assertions.assertEquals(retrieve.createdAt, retrieve.updatedAt);
|
||||
}
|
||||
|
||||
|
||||
@Order(3)
|
||||
@Test
|
||||
public void testUpdateData() throws Exception {
|
||||
@ -113,7 +114,7 @@ public class TestSimpleTable {
|
||||
final SimpleTable test = new SimpleTable();
|
||||
test.data = TestSimpleTable.DATA_INJECTED_2;
|
||||
DataAccess.update(test, TestSimpleTable.idOfTheObject, List.of("data"));
|
||||
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject, new QueryOptions(QueryOptions.SQL_NOT_READ_DISABLE, true));
|
||||
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject, new QueryOptions(QueryOptions.READ_ALL_COLOMN));
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
Assertions.assertEquals(TestSimpleTable.idOfTheObject, retrieve.id);
|
||||
@ -123,7 +124,7 @@ public class TestSimpleTable {
|
||||
LOGGER.info("created @ {} updated @ {}", retrieve.createdAt, retrieve.updatedAt);
|
||||
Assertions.assertTrue(retrieve.updatedAt.after(retrieve.createdAt));
|
||||
}
|
||||
|
||||
|
||||
@Order(4)
|
||||
@Test
|
||||
public void testDeleteTheObject() throws Exception {
|
||||
@ -132,24 +133,23 @@ public class TestSimpleTable {
|
||||
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject);
|
||||
Assertions.assertNull(retrieve);
|
||||
}
|
||||
|
||||
|
||||
@Order(5)
|
||||
@Test
|
||||
public void testReadDeletedObject() throws Exception {
|
||||
|
||||
|
||||
// check if we set get deleted element
|
||||
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject, new QueryOptions(QueryOptions.SQL_DELETED_DISABLE, true));
|
||||
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject, new QueryOptions(QueryOptions.ACCESS_DELETED_ITEMS));
|
||||
Assertions.assertNull(retrieve);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Order(6)
|
||||
@Test
|
||||
public void testReadAllValuesUnreadableOfDeletedObject() throws Exception {
|
||||
// check if we set get deleted element with all data
|
||||
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject,
|
||||
new QueryOptions(QueryOptions.SQL_DELETED_DISABLE, true, QueryOptions.SQL_NOT_READ_DISABLE, true));
|
||||
final SimpleTable retrieve = DataAccess.get(SimpleTable.class, TestSimpleTable.idOfTheObject, new QueryOptions(QueryOptions.ACCESS_DELETED_ITEMS, QueryOptions.READ_ALL_COLOMN));
|
||||
Assertions.assertNull(retrieve);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.dataAccess.QueryOptions;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -33,30 +33,31 @@ public class TestSimpleTableSoftDelete {
|
||||
private static final String DATA_INJECTED_2 = "qsdfqsdfqsdfsqdf";
|
||||
private static Long idOfTheObject = null;
|
||||
private static Timestamp startAction = null;
|
||||
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Clear the static test:
|
||||
idOfTheObject = null;
|
||||
startAction = null;
|
||||
|
||||
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
}
|
||||
|
||||
|
||||
@AfterAll
|
||||
public static void removeDataBase() throws IOException {
|
||||
LOGGER.info("Remove the test db");
|
||||
DBEntry.closeAllForceMode();
|
||||
ConfigBaseVariable.clearAllValue();
|
||||
}
|
||||
|
||||
|
||||
@Order(1)
|
||||
@Test
|
||||
public void testTableInsertAndRetrieve() throws Exception {
|
||||
@ -69,14 +70,14 @@ public class TestSimpleTableSoftDelete {
|
||||
final SimpleTableSoftDelete test = new SimpleTableSoftDelete();
|
||||
test.data = TestSimpleTableSoftDelete.DATA_INJECTED;
|
||||
final SimpleTableSoftDelete insertedData = DataAccess.insert(test);
|
||||
|
||||
|
||||
Assertions.assertNotNull(insertedData);
|
||||
Assertions.assertNotNull(insertedData.id);
|
||||
Assertions.assertTrue(insertedData.id >= 0);
|
||||
|
||||
|
||||
// Try to retrieve all the data:
|
||||
final SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class, insertedData.id);
|
||||
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
Assertions.assertEquals(insertedData.id, retrieve.id);
|
||||
@ -86,13 +87,13 @@ public class TestSimpleTableSoftDelete {
|
||||
Assertions.assertNull(retrieve.deleted);
|
||||
TestSimpleTableSoftDelete.idOfTheObject = retrieve.id;
|
||||
}
|
||||
|
||||
|
||||
@Order(2)
|
||||
@Test
|
||||
public void testReadAllValuesUnreadable() throws Exception {
|
||||
// check the full values
|
||||
final SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class, TestSimpleTableSoftDelete.idOfTheObject, new QueryOptions(QueryOptions.SQL_NOT_READ_DISABLE, true));
|
||||
|
||||
final SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class, TestSimpleTableSoftDelete.idOfTheObject, new QueryOptions(QueryOptions.READ_ALL_COLOMN));
|
||||
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
Assertions.assertEquals(TestSimpleTableSoftDelete.idOfTheObject, retrieve.id);
|
||||
@ -107,18 +108,18 @@ public class TestSimpleTableSoftDelete {
|
||||
Assertions.assertNotNull(retrieve.deleted);
|
||||
Assertions.assertEquals(false, retrieve.deleted);
|
||||
}
|
||||
|
||||
|
||||
@Order(3)
|
||||
@Test
|
||||
public void testUpdateData() throws Exception {
|
||||
Thread.sleep(Duration.ofMillis(15));
|
||||
|
||||
|
||||
// Delete the entry:
|
||||
final SimpleTableSoftDelete test = new SimpleTableSoftDelete();
|
||||
test.data = TestSimpleTableSoftDelete.DATA_INJECTED_2;
|
||||
DataAccess.update(test, TestSimpleTableSoftDelete.idOfTheObject, List.of("data"));
|
||||
final SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class, TestSimpleTableSoftDelete.idOfTheObject,
|
||||
new QueryOptions(QueryOptions.SQL_DELETED_DISABLE, true, QueryOptions.SQL_NOT_READ_DISABLE, true));
|
||||
new QueryOptions(QueryOptions.ACCESS_DELETED_ITEMS, QueryOptions.READ_ALL_COLOMN));
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
Assertions.assertEquals(TestSimpleTableSoftDelete.idOfTheObject, retrieve.id);
|
||||
@ -130,7 +131,7 @@ public class TestSimpleTableSoftDelete {
|
||||
Assertions.assertNotNull(retrieve.deleted);
|
||||
Assertions.assertEquals(false, retrieve.deleted);
|
||||
}
|
||||
|
||||
|
||||
@Order(4)
|
||||
@Test
|
||||
public void testSoftDeleteTheObject() throws Exception {
|
||||
@ -144,13 +145,13 @@ public class TestSimpleTableSoftDelete {
|
||||
final SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class, TestSimpleTableSoftDelete.idOfTheObject);
|
||||
Assertions.assertNull(retrieve);
|
||||
}
|
||||
|
||||
|
||||
@Order(5)
|
||||
@Test
|
||||
public void testReadDeletedObject() throws Exception {
|
||||
|
||||
|
||||
// check if we set get deleted element
|
||||
final SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class, TestSimpleTableSoftDelete.idOfTheObject, new QueryOptions(QueryOptions.SQL_DELETED_DISABLE, true));
|
||||
final SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class, TestSimpleTableSoftDelete.idOfTheObject, new QueryOptions(QueryOptions.ACCESS_DELETED_ITEMS));
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
Assertions.assertEquals(TestSimpleTableSoftDelete.idOfTheObject, retrieve.id);
|
||||
@ -158,15 +159,15 @@ public class TestSimpleTableSoftDelete {
|
||||
Assertions.assertNull(retrieve.createdAt);
|
||||
Assertions.assertNull(retrieve.updatedAt);
|
||||
Assertions.assertNull(retrieve.deleted);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Order(6)
|
||||
@Test
|
||||
public void testReadAllValuesUnreadableOfDeletedObject() throws Exception {
|
||||
// check if we set get deleted element with all data
|
||||
final SimpleTableSoftDelete retrieve = DataAccess.get(SimpleTableSoftDelete.class, TestSimpleTableSoftDelete.idOfTheObject,
|
||||
new QueryOptions(QueryOptions.SQL_DELETED_DISABLE, true, QueryOptions.SQL_NOT_READ_DISABLE, true));
|
||||
new QueryOptions(QueryOptions.ACCESS_DELETED_ITEMS, QueryOptions.READ_ALL_COLOMN));
|
||||
Assertions.assertNotNull(retrieve);
|
||||
Assertions.assertNotNull(retrieve.id);
|
||||
Assertions.assertEquals(TestSimpleTableSoftDelete.idOfTheObject, retrieve.id);
|
||||
@ -177,6 +178,6 @@ public class TestSimpleTableSoftDelete {
|
||||
Assertions.assertTrue(retrieve.updatedAt.after(retrieve.createdAt));
|
||||
Assertions.assertNotNull(retrieve.deleted);
|
||||
Assertions.assertEquals(true, retrieve.deleted);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -29,11 +29,12 @@ public class TestTypeEnum1 {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
|
@ -15,7 +15,7 @@ import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -29,11 +29,12 @@ public class TestTypeEnum2 {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
|
@ -20,7 +20,7 @@ import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.dataAccess.DataFactory;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -33,11 +33,12 @@ public class TestTypes {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
|
@ -5,16 +5,16 @@ import org.kar.archidata.migration.MigrationSqlStep;
|
||||
import test.kar.archidata.migration.model.TypesMigrationInitialisationCurrent;
|
||||
|
||||
class InitializationCurrent extends MigrationSqlStep {
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Initialization";
|
||||
}
|
||||
|
||||
|
||||
public InitializationCurrent() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void generateStep() throws Exception {
|
||||
addClass(TypesMigrationInitialisationCurrent.class);
|
||||
|
@ -5,16 +5,16 @@ import org.kar.archidata.migration.MigrationSqlStep;
|
||||
import test.kar.archidata.migration.model.TypesMigrationInitialisationFirst;
|
||||
|
||||
class InitializationFirst extends MigrationSqlStep {
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Initialization";
|
||||
}
|
||||
|
||||
|
||||
public InitializationFirst() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void generateStep() throws Exception {
|
||||
addClass(TypesMigrationInitialisationFirst.class);
|
||||
|
@ -3,24 +3,24 @@ package test.kar.archidata.migration;
|
||||
import org.kar.archidata.migration.MigrationSqlStep;
|
||||
|
||||
class Migration1 extends MigrationSqlStep {
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "first migratiion";
|
||||
}
|
||||
|
||||
|
||||
public Migration1() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void generateStep() throws Exception {
|
||||
|
||||
|
||||
addAction("""
|
||||
ALTER TABLE `TestTableMigration`
|
||||
RENAME COLUMN `testData` TO `testDataMigration1`
|
||||
""");
|
||||
display();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -3,24 +3,24 @@ package test.kar.archidata.migration;
|
||||
import org.kar.archidata.migration.MigrationSqlStep;
|
||||
|
||||
class Migration2 extends MigrationSqlStep {
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Second migration";
|
||||
}
|
||||
|
||||
|
||||
public Migration2() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void generateStep() throws Exception {
|
||||
|
||||
|
||||
addAction("""
|
||||
ALTER TABLE `TestTableMigration`
|
||||
RENAME COLUMN `testDataMigration1` TO `testDataMigration2`
|
||||
""");
|
||||
display();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -3,24 +3,24 @@ package test.kar.archidata.migration;
|
||||
import org.kar.archidata.migration.MigrationSqlStep;
|
||||
|
||||
class MigrationFail extends MigrationSqlStep {
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Fail migration Test";
|
||||
}
|
||||
|
||||
|
||||
public MigrationFail() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void generateStep() throws Exception {
|
||||
|
||||
|
||||
addAction("""
|
||||
ALTER TABLE `TestTableMigrationqs`
|
||||
RENAME COLUMN `testDataMisqdgration1` TO `testDataMiqsdgration2`
|
||||
""");
|
||||
display();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -15,7 +15,7 @@ import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.migration.MigrationEngine;
|
||||
import org.kar.archidata.migration.MigrationException;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -29,10 +29,12 @@ public class TestMigrationFail {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
|
@ -14,7 +14,7 @@ import org.kar.archidata.GlobalConfiguration;
|
||||
import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.migration.MigrationEngine;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -29,10 +29,12 @@ public class TestMigrationFirstInit {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
|
@ -16,7 +16,7 @@ import org.kar.archidata.dataAccess.DataAccess;
|
||||
import org.kar.archidata.db.DBEntry;
|
||||
import org.kar.archidata.migration.MigrationEngine;
|
||||
import org.kar.archidata.migration.model.Migration;
|
||||
import org.kar.archidata.util.ConfigBaseVariable;
|
||||
import org.kar.archidata.tools.ConfigBaseVariable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -30,10 +30,12 @@ public class TestMigrationFirstInitWithMigration {
|
||||
|
||||
@BeforeAll
|
||||
public static void configureWebServer() throws Exception {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
if (!"true".equalsIgnoreCase(System.getenv("TEST_E2E_MODE"))) {
|
||||
ConfigBaseVariable.dbType = "sqlite";
|
||||
ConfigBaseVariable.dbHost = "memory";
|
||||
// for test we need to connect all time the DB
|
||||
ConfigBaseVariable.dbKeepConnected = "true";
|
||||
}
|
||||
// Connect the dataBase...
|
||||
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
|
||||
entry.connect();
|
||||
|
Loading…
x
Reference in New Issue
Block a user