[DEV] rework to finalize API

This commit is contained in:
Edouard DUPIN 2023-12-16 11:09:41 +01:00
parent 5fc45a23d3
commit d9fcacc812
17 changed files with 300 additions and 138 deletions

View File

@ -15,6 +15,9 @@ import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType; import jakarta.persistence.GenerationType;
import jakarta.persistence.Id; import jakarta.persistence.Id;
import jakarta.persistence.Table; import jakarta.persistence.Table;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
public class AnnotationTools { public class AnnotationTools {
static final Logger LOGGER = LoggerFactory.getLogger(AnnotationTools.class); static final Logger LOGGER = LoggerFactory.getLogger(AnnotationTools.class);
@ -79,6 +82,28 @@ public class AnnotationTools {
return length <= 0 ? null : length; return length <= 0 ? null : length;
} }
public static Size getConstraintsSize(final Field element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Size.class);
if (annotation.length == 0) {
return null;
}
if (annotation.length > 1) {
throw new Exception("Must not have more than 1 element @Size on " + element.getClass().getCanonicalName());
}
return (Size) annotation[0];
}
public static String getConstraintsPattern(final Field element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Pattern.class);
if (annotation.length == 0) {
return null;
}
if (annotation.length > 1) {
throw new Exception("Must not have more than 1 element @Pattern on " + element.getClass().getCanonicalName());
}
return ((Pattern) annotation[0]).regexp();
}
public static boolean isAnnotationGroup(final Field field, final Class<?> annotationType) { public static boolean isAnnotationGroup(final Field field, final Class<?> annotationType) {
try { try {
final Annotation[] anns = field.getAnnotations(); final Annotation[] anns = field.getAnnotations();
@ -117,7 +142,7 @@ public class AnnotationTools {
return name; return name;
} }
public static boolean getNotNull(final Field element) throws Exception { public static boolean getColumnNotNull(final Field element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Column.class); final Annotation[] annotation = element.getDeclaredAnnotationsByType(Column.class);
if (annotation.length == 0) { if (annotation.length == 0) {
return false; return false;
@ -128,6 +153,17 @@ public class AnnotationTools {
return !((Column) annotation[0]).nullable(); return !((Column) annotation[0]).nullable();
} }
public static boolean getConstraintsNotNull(final Field element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(NotNull.class);
if (annotation.length == 0) {
return false;
}
if (annotation.length > 1) {
throw new Exception("Must not have more than 1 element @NotNull on " + element.getClass().getCanonicalName());
}
return true;
}
public static boolean isPrimaryKey(final Field element) throws Exception { public static boolean isPrimaryKey(final Field element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Id.class); final Annotation[] annotation = element.getDeclaredAnnotationsByType(Id.class);
if (annotation.length == 0) { if (annotation.length == 0) {
@ -135,6 +171,7 @@ public class AnnotationTools {
} }
return true; return true;
} }
public static boolean isUnique(final Field element) throws Exception { public static boolean isUnique(final Field element) throws Exception {
final Annotation[] annotation = element.getDeclaredAnnotationsByType(Column.class); final Annotation[] annotation = element.getDeclaredAnnotationsByType(Column.class);
if (annotation.length == 0) { if (annotation.length == 0) {

View File

@ -27,7 +27,7 @@ import org.kar.archidata.dataAccess.addOn.AddOnManyToOne;
import org.kar.archidata.dataAccess.addOn.AddOnSQLTableExternalForeinKeyAsList; import org.kar.archidata.dataAccess.addOn.AddOnSQLTableExternalForeinKeyAsList;
import org.kar.archidata.dataAccess.options.AccessDeletedItems; import org.kar.archidata.dataAccess.options.AccessDeletedItems;
import org.kar.archidata.dataAccess.options.CheckFunction; import org.kar.archidata.dataAccess.options.CheckFunction;
import org.kar.archidata.dataAccess.options.Limit; import org.kar.archidata.dataAccess.options.Condition;
import org.kar.archidata.db.DBEntry; import org.kar.archidata.db.DBEntry;
import org.kar.archidata.exception.DataAccessException; import org.kar.archidata.exception.DataAccessException;
import org.kar.archidata.tools.ConfigBaseVariable; import org.kar.archidata.tools.ConfigBaseVariable;
@ -544,6 +544,10 @@ public class DataAccess {
query.append("?"); query.append("?");
} }
query.append(")"); query.append(")");
final OrderBy orders = options.get(OrderBy.class);
if (orders != null) {
orders.generateQuerry(query, tableName);
}
LOGGER.warn("generate the query: '{}'", query.toString()); LOGGER.warn("generate the query: '{}'", query.toString());
// prepare the request: // prepare the request:
final PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS); final PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
@ -628,7 +632,6 @@ public class DataAccess {
final ObjectMapper mapper = new ObjectMapper(); final ObjectMapper mapper = new ObjectMapper();
// parse the object to be sure the data are valid: // parse the object to be sure the data are valid:
final T data = mapper.readValue(jsonData, clazz); final T data = mapper.readValue(jsonData, clazz);
return insert(data); return insert(data);
} }
@ -746,6 +749,11 @@ public class DataAccess {
query.append("` = ? "); query.append("` = ? ");
} }
query.append(" "); query.append(" ");
final OrderBy orders = options.get(OrderBy.class);
if (orders != null) {
orders.generateQuerry(query, tableName);
}
query.append(" ");
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz); final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
whereAppendQuery(query, tableName, condition, null, deletedFieldName); whereAppendQuery(query, tableName, condition, null, deletedFieldName);
firstField = true; firstField = true;
@ -855,12 +863,15 @@ public class DataAccess {
} }
} }
public static void whereInjectValue(final PreparedStatement ps, final QueryItem condition, final CountInOut iii) throws Exception { public static void whereInjectValue(final PreparedStatement ps, final QueryOptions options, final CountInOut iii) throws Exception {
// Check if we have a condition to generate // Check if we have a condition to generate
if (options != null) {
final Condition condition = options.get(Condition.class);
if (condition != null) { if (condition != null) {
condition.injectQuerry(ps, iii); condition.injectQuerry(ps, iii);
} }
} }
}
public static int executeSimpleQuerry(final String query, final boolean root) throws SQLException, IOException { public static int executeSimpleQuerry(final String query, final boolean root) throws SQLException, IOException {
final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig, root); final DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig, root);
@ -882,16 +893,16 @@ public class DataAccess {
return executeQuerry(query, false); return executeQuerry(query, false);
} }
public static <T> T getWhere(final Class<T> clazz, final QueryItem condition) throws Exception { public static <T> T getWhere(final Class<T> clazz, QueryOptions options) throws Exception {
return getWhere(clazz, condition, null); return getWhere(clazz, options);
}
public static <T> T getWhere(final Class<T> clazz, final QueryItem condition, QueryOptions options) throws Exception {
if (options == null) { if (options == null) {
options = new QueryOptions(); options = new QueryOptions();
} }
final Limit limit = options.get(Limit.class);
if (limit != null) {
options.add(new Limit(1)); options.add(new Limit(1));
final List<T> values = getsWhere(clazz, condition, options); }
final List<T> values = getsWhere(clazz, options);
if (values.size() == 0) { if (values.size() == 0) {
return null; return null;
} }
@ -899,11 +910,7 @@ public class DataAccess {
} }
public static <T> List<T> getsWhere(final Class<T> clazz, final QueryItem condition) throws Exception { public static <T> List<T> getsWhere(final Class<T> clazz, final QueryItem condition) throws Exception {
return getsWhere(clazz, condition, null, null); return getsWhere(clazz, condition, 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);
} }
public static void generateSelectField(final StringBuilder querySelect, final StringBuilder query, final Class<?> clazz, final QueryOptions options, final CountInOut count) throws Exception { public static void generateSelectField(final StringBuilder querySelect, final StringBuilder query, final Class<?> clazz, final QueryOptions options, final CountInOut count) throws Exception {
@ -943,7 +950,7 @@ public class DataAccess {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T> List<T> getsWhere(final Class<T> clazz, final QueryItem condition, final String orderBy, final QueryOptions options) throws Exception { public static <T> List<T> getsWhere(final Class<T> clazz, final QueryItem condition, final QueryOptions options) throws Exception {
final List<LazyGetter> lazyCall = new ArrayList<>(); final List<LazyGetter> lazyCall = new ArrayList<>();
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz); final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig); DBEntry entry = DBEntry.createInterface(GlobalConfiguration.dbConfig);
@ -963,22 +970,13 @@ public class DataAccess {
querySelect.append(query.toString()); querySelect.append(query.toString());
query = querySelect; query = querySelect;
whereAppendQuery(query, tableName, condition, options, deletedFieldName); whereAppendQuery(query, tableName, condition, options, deletedFieldName);
if (orderBy != null && orderBy.length() >= 1) { final OrderBy orders = options.get(OrderBy.class);
query.append(" ORDER BY "); if (orders != null) {
query.append(orderBy); orders.generateQuerry(query, tableName);
} }
if (options != null) {
final Limit limit = options.get(Limit.class); final Limit limit = options.get(Limit.class);
if (limit != null) { if (limit != null) {
if (limit.getLimit() >= 1) { limit.generateQuerry(query, tableName);
query.append(" LIMIT " + limit.getLimit());
} else {
LOGGER.warn("Limit is equal @ {}", limit.getLimit());
entry.close();
entry = null;
return outs;
}
}
} }
LOGGER.warn("generate the query: '{}'", query.toString()); LOGGER.warn("generate the query: '{}'", query.toString());
// prepare the request: // prepare the request:

View File

@ -37,8 +37,8 @@ public interface DataAccessAddOn {
// Element can be retrieve with the specific mode // Element can be retrieve with the specific mode
boolean canRetrieve(final Field field); boolean canRetrieve(final Field field);
void generateQuerry(@NotNull String tableName, @NotNull Field field, @NotNull final StringBuilder querrySelect, @NotNull final StringBuilder querry, @NotNull String name, void generateQuerry(@NotNull String tableName, @NotNull Field field, @NotNull final StringBuilder querySelect, @NotNull final StringBuilder query, @NotNull String name, @NotNull CountInOut count,
@NotNull CountInOut count, QueryOptions options) throws Exception; QueryOptions options) throws Exception;
// Return the number of colomn read // Return the number of colomn read
void fillFromQuerry(ResultSet rs, Field field, Object data, CountInOut count, QueryOptions options, final List<LazyGetter> lazyCall) void fillFromQuerry(ResultSet rs, Field field, Object data, CountInOut count, QueryOptions options, final List<LazyGetter> lazyCall)

View File

@ -132,7 +132,7 @@ public class DataFactory {
final boolean createIfNotExist, final boolean createDrop, final int fieldId, final Class<?> classModel) throws Exception { final boolean createIfNotExist, final boolean createDrop, final int fieldId, final Class<?> classModel) throws Exception {
final String name = AnnotationTools.getFieldName(elem); final String name = AnnotationTools.getFieldName(elem);
final Integer limitSize = AnnotationTools.getLimitSize(elem); final Integer limitSize = AnnotationTools.getLimitSize(elem);
final boolean notNull = AnnotationTools.getNotNull(elem); final boolean notNull = AnnotationTools.getColumnNotNull(elem);
final boolean primaryKey = AnnotationTools.isPrimaryKey(elem); final boolean primaryKey = AnnotationTools.isPrimaryKey(elem);
final GenerationType strategy = AnnotationTools.getStrategy(elem); final GenerationType strategy = AnnotationTools.getStrategy(elem);

View File

@ -0,0 +1,20 @@
package org.kar.archidata.dataAccess;
import java.sql.PreparedStatement;
public class Limit extends QueryOption {
protected final long limit;
public Limit(final long limit) {
this.limit = limit;
}
public void generateQuerry(final StringBuilder query, final String tableName) {
query.append(" LIMIT ? ");
}
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception {
DataAccess.addElement(ps, this.limit, iii);
iii.inc();
}
}

View File

@ -0,0 +1,41 @@
package org.kar.archidata.dataAccess;
import java.sql.PreparedStatement;
import java.util.List;
public class OrderBy extends QueryOption {
protected final List<OrderItem> childs;
public OrderBy(final List<OrderItem> childs) {
this.childs = childs;
}
public OrderBy(final OrderItem... childs) {
this.childs = List.of(childs);
}
public void generateQuerry(final StringBuilder query, final String tableName) {
if (this.childs.size() >= 1) {
query.append(" ORDER BY ");
}
boolean first = true;
for (final OrderItem elem : this.childs) {
if (first) {
first = false;
} else {
query.append(", ");
}
query.append("`");
query.append(elem.value);
query.append("` ");
query.append(elem.order.toString());
}
if (this.childs.size() >= 1) {
query.append(")");
}
}
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception {
// nothing to add.
}
}

View File

@ -0,0 +1,16 @@
package org.kar.archidata.dataAccess;
public class OrderItem {
public enum Order {
ASC, DESC
};
public final String value;
public final Order order;
public OrderItem(final String value, final Order order) {
this.value = value;
this.order = order;
}
}

View File

@ -18,21 +18,21 @@ public class QueryAnd implements QueryItem {
} }
@Override @Override
public void generateQuerry(final StringBuilder querry, final String tableName) { public void generateQuerry(final StringBuilder query, final String tableName) {
if (this.childs.size() >= 1) { if (this.childs.size() >= 1) {
querry.append(" ("); query.append(" (");
} }
boolean first = true; boolean first = true;
for (final QueryItem elem : this.childs) { for (final QueryItem elem : this.childs) {
if (first) { if (first) {
first = false; first = false;
} else { } else {
querry.append(" AND "); query.append(" AND ");
} }
elem.generateQuerry(querry, tableName); elem.generateQuerry(query, tableName);
} }
if (this.childs.size() >= 1) { if (this.childs.size() >= 1) {
querry.append(")"); query.append(")");
} }
} }

View File

@ -14,14 +14,13 @@ public class QueryCondition implements QueryItem {
} }
@Override @Override
public void generateQuerry(final StringBuilder querry, final String tableName) { public void generateQuerry(final StringBuilder query, final String tableName) {
querry.append(tableName); query.append(tableName);
querry.append("."); query.append(".");
querry.append(this.key); query.append(this.key);
querry.append(" "); query.append(" ");
querry.append(this.comparator); query.append(this.comparator);
querry.append(" ?"); query.append(" ?");
} }
@Override @Override

View File

@ -18,22 +18,26 @@ public class QueryInList<T> implements QueryItem {
this(key, "IN", value); this(key, "IN", value);
} }
public QueryInList(final String key, final T... value) {
this(key, "IN", List.of(value));
}
@Override @Override
public void generateQuerry(final StringBuilder querry, final String tableName) { public void generateQuerry(final StringBuilder query, final String tableName) {
querry.append(tableName); query.append(tableName);
querry.append("."); query.append(".");
querry.append(this.key); query.append(this.key);
querry.append(" "); query.append(" ");
querry.append(this.comparator); query.append(this.comparator);
querry.append(" ("); query.append(" (");
for (int iii = 0; iii < this.value.size(); iii++) { for (int iii = 0; iii < this.value.size(); iii++) {
if (iii != 0) { if (iii != 0) {
querry.append(",?"); query.append(",?");
} else { } else {
querry.append("?"); query.append("?");
} }
} }
querry.append(")"); query.append(")");
} }

View File

@ -3,7 +3,7 @@ package org.kar.archidata.dataAccess;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
public interface QueryItem { public interface QueryItem {
void generateQuerry(StringBuilder querry, String tableName); void generateQuerry(StringBuilder query, String tableName);
void injectQuerry(PreparedStatement ps, CountInOut iii) throws Exception; void injectQuerry(PreparedStatement ps, CountInOut iii) throws Exception;
} }

View File

@ -10,22 +10,26 @@ public class QueryOr implements QueryItem {
this.childs = childs; this.childs = childs;
} }
public QueryOr(final QueryItem... childs) {
this.childs = List.of(childs);
}
@Override @Override
public void generateQuerry(final StringBuilder querry, final String tableName) { public void generateQuerry(final StringBuilder query, final String tableName) {
if (this.childs.size() >= 1) { if (this.childs.size() >= 1) {
querry.append(" ("); query.append(" (");
} }
boolean first = true; boolean first = true;
for (final QueryItem elem : this.childs) { for (final QueryItem elem : this.childs) {
if (first) { if (first) {
first = false; first = false;
} else { } else {
querry.append(" OR "); query.append(" OR ");
} }
elem.generateQuerry(querry, tableName); elem.generateQuerry(query, tableName);
} }
if (this.childs.size() >= 1) { if (this.childs.size() >= 1) {
querry.append(")"); query.append(")");
} }
} }

View File

@ -9,6 +9,7 @@ import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern;
import org.kar.archidata.annotation.AnnotationTools; import org.kar.archidata.annotation.AnnotationTools;
import org.kar.archidata.dataAccess.DataAccess; import org.kar.archidata.dataAccess.DataAccess;
@ -20,6 +21,8 @@ import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.annotation.JsonValue; import com.fasterxml.jackson.annotation.JsonValue;
import jakarta.validation.constraints.Size;
public class CheckJPA<T> implements CheckFunctionInterface { public class CheckJPA<T> implements CheckFunctionInterface {
private static final Logger LOGGER = LoggerFactory.getLogger(CheckJPA.class); private static final Logger LOGGER = LoggerFactory.getLogger(CheckJPA.class);
@ -36,7 +39,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
private Map<String, List<CheckInterface<T>>> checking = null; private Map<String, List<CheckInterface<T>>> checking = null;
protected void add(String field, CheckInterface<T> checkFunction) { protected void add(final String field, final CheckInterface<T> checkFunction) {
List<CheckInterface<T>> actions = this.checking.get(field); List<CheckInterface<T>> actions = this.checking.get(field);
if (actions == null) { if (actions == null) {
actions = new ArrayList<>(); actions = new ArrayList<>();
@ -45,7 +48,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
actions.add(checkFunction); actions.add(checkFunction);
} }
public CheckJPA(Class<T> clazz) { public CheckJPA(final Class<T> clazz) {
this.clazz = clazz; this.clazz = clazz;
} }
@ -58,26 +61,26 @@ public class CheckJPA<T> implements CheckFunctionInterface {
// create Table: // create Table:
final List<String> primaryKeys = new ArrayList<>(); final List<String> primaryKeys = new ArrayList<>();
for (final Field field : this.clazz.getFields()) { for (final Field field : this.clazz.getFields()) {
String fieldName = AnnotationTools.getFieldName(field); final String fieldName = AnnotationTools.getFieldName(field);
if (AnnotationTools.isPrimaryKey(field)) { if (AnnotationTools.isPrimaryKey(field)) {
add(fieldName, (T data) -> { add(fieldName, (final T data) -> {
throw new InputException(fieldName, "This is a '@Id' (primaryKey) ==> can not be change"); throw new InputException(fieldName, "This is a '@Id' (primaryKey) ==> can not be change");
}); });
} }
if (AnnotationTools.getNotNull(field)) { if (AnnotationTools.getConstraintsNotNull(field)) {
add(fieldName, (T data) -> { add(fieldName, (final T data) -> {
if (field.get(data) == null) { if (field.get(data) == null) {
throw new InputException(fieldName, "Can not be null"); throw new InputException(fieldName, "Can not be null");
} }
}); });
} }
if (AnnotationTools.isCreatedAtField(field) || AnnotationTools.isUpdateAtField(field)) { if (AnnotationTools.isCreatedAtField(field) || AnnotationTools.isUpdateAtField(field)) {
add(fieldName, (T data) -> { add(fieldName, (final T data) -> {
throw new InputException(fieldName, "It is forbidden to change this field"); throw new InputException(fieldName, "It is forbidden to change this field");
}); });
} }
Class<?> type = field.getType(); final Class<?> type = field.getType();
if (type == Long.class || type == long.class) { if (type == Long.class || type == long.class) {
} else if (type == Integer.class || type == int.class) { } else if (type == Integer.class || type == int.class) {
@ -95,17 +98,46 @@ public class CheckJPA<T> implements CheckFunctionInterface {
} else if (type == LocalTime.class) { } else if (type == LocalTime.class) {
} else if (type == String.class) { } else if (type == String.class) {
int maxSizeString = AnnotationTools.getLimitSize(field); final int maxSizeString = AnnotationTools.getLimitSize(field);
if (maxSizeString > 0) { if (maxSizeString > 0) {
add(fieldName, (T data) -> { add(fieldName, (final T data) -> {
Object elem = field.get(data); final Object elem = field.get(data);
if (elem == null) { if (elem == null) {
return; return;
} }
String elemTyped = (String) elem; final String elemTyped = (String) elem;
if (elemTyped.length() > maxSizeString) { if (elemTyped.length() > maxSizeString) {
throw new InputException("name", "Too long size must be <= " + maxSizeString); throw new InputException(fieldName, "Too long size must be <= " + maxSizeString);
}
});
}
final Size limitSize = AnnotationTools.getConstraintsSize(field);
if (limitSize != null) {
add(fieldName, (final T data) -> {
final Object elem = field.get(data);
if (elem == null) {
return;
}
final String elemTyped = (String) elem;
if (elemTyped.length() > limitSize.max()) {
throw new InputException(fieldName, "Too long size (constraints) must be <= " + limitSize.max());
}
if (elemTyped.length() < limitSize.min()) {
throw new InputException(fieldName, "Too small size (constraints) must be >= " + limitSize.max());
}
});
}
final String patternString = AnnotationTools.getConstraintsPattern(field);
if (patternString != null) {
final Pattern pattern = Pattern.compile(patternString);
add(fieldName, (final T data) -> {
final Object elem = field.get(data);
if (elem == null) {
return;
}
final String elemTyped = (String) elem;
if (!pattern.matcher(elemTyped).find()) {
throw new InputException(fieldName, "does not match the required pattern (constraints) must be '" + patternString + "'");
} }
}); });
} }
@ -117,7 +149,7 @@ public class CheckJPA<T> implements CheckFunctionInterface {
// keep this is last ==> take more time... // keep this is last ==> take more time...
if (AnnotationTools.isUnique(field)) { if (AnnotationTools.isUnique(field)) {
// Create the request ... // Create the request ...
add(fieldName, (T data) -> { add(fieldName, (final T data) -> {
final Object other = DataAccess.getWhere(this.clazz, new QueryCondition(fieldName, "==", field.get(data))); final Object other = DataAccess.getWhere(this.clazz, new QueryCondition(fieldName, "==", field.get(data)));
if (other != null) { if (other != null) {
throw new InputException(fieldName, "Name already exist in the DB"); throw new InputException(fieldName, "Name already exist in the DB");
@ -126,33 +158,33 @@ public class CheckJPA<T> implements CheckFunctionInterface {
} }
} }
} catch (Exception ex) { } catch (final Exception ex) {
this.checking = null; this.checking = null;
throw ex; throw ex;
} }
} }
@Override @Override
public void check(Object data, List<String> filterValue) throws Exception { public void check(final Object data, final List<String> filterValue) throws Exception {
initialize(); initialize();
if (!(this.clazz.isAssignableFrom(data.getClass()))) { if (!(this.clazz.isAssignableFrom(data.getClass()))) {
throw new DataAccessException("Incompatatyble type of Object" + data.getClass().getCanonicalName()); throw new DataAccessException("Incompatatyble type of Object" + data.getClass().getCanonicalName());
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
T dataCasted = (T) data; final T dataCasted = (T) data;
for (String filter : filterValue) { for (final String filter : filterValue) {
List<CheckInterface<T>> actions = this.checking.get(filter); final List<CheckInterface<T>> actions = this.checking.get(filter);
if (actions == null) { if (actions == null) {
continue; continue;
} }
for (CheckInterface<T> action : actions) { for (final CheckInterface<T> action : actions) {
action.check(dataCasted); action.check(dataCasted);
} }
} }
checkTyped(dataCasted, filterValue); checkTyped(dataCasted, filterValue);
} }
public void checkTyped(T data, List<String> filterValue) throws Exception { public void checkTyped(final T data, final List<String> filterValue) throws Exception {
// nothing to do ... // nothing to do ...
} }
} }

View File

@ -0,0 +1,28 @@
package org.kar.archidata.dataAccess.options;
import java.sql.PreparedStatement;
import org.kar.archidata.dataAccess.CountInOut;
import org.kar.archidata.dataAccess.QueryItem;
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 Condition extends QueryOption {
public final QueryItem condition;
public Condition(final QueryItem items) {
this.condition = items;
}
public void generateQuerry(final StringBuilder query, final String tableName) {
if (this.condition != null) {
this.condition.generateQuerry(query, tableName);
}
}
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception {
if (this.condition != null) {
this.condition.injectQuerry(ps, iii);
}
}
}

View File

@ -1,17 +0,0 @@
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;
}
}