Compare commits

..

8 Commits

40 changed files with 297 additions and 213 deletions

View File

@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>kangaroo-and-rabbit</groupId> <groupId>kangaroo-and-rabbit</groupId>
<artifactId>archidata</artifactId> <artifactId>archidata</artifactId>
<version>0.8.0</version> <version>0.8.2</version>
<properties> <properties>
<maven.compiler.version>3.1</maven.compiler.version> <maven.compiler.version>3.1</maven.compiler.version>
<maven.compiler.source>21</maven.compiler.source> <maven.compiler.source>21</maven.compiler.source>

View File

@@ -161,7 +161,7 @@ public class DataResource {
e.printStackTrace(); e.printStackTrace();
return null; return null;
} }
final String mediaPath = getFileData(injectedData.id); final String mediaPath = getFileData(injectedData.uuid);
LOGGER.info("src = {}", tmpPath); LOGGER.info("src = {}", tmpPath);
LOGGER.info("dst = {}", mediaPath); LOGGER.info("dst = {}", mediaPath);
Files.move(Paths.get(tmpPath), Paths.get(mediaPath), StandardCopyOption.ATOMIC_MOVE); Files.move(Paths.get(tmpPath), Paths.get(mediaPath), StandardCopyOption.ATOMIC_MOVE);
@@ -278,45 +278,45 @@ public class DataResource {
} }
@GET @GET
@Path("{id}") @Path("{uuid}")
@PermitTokenInURI @PermitTokenInURI
@RolesAllowed("USER") @RolesAllowed("USER")
@Produces(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM)
@Operation(description = "Get back some data from the data environment", tags = "SYSTEM") @Operation(description = "Get back some data from the data environment", tags = "SYSTEM")
public Response retrieveDataId(@Context final SecurityContext sc, @QueryParam(HttpHeaders.AUTHORIZATION) final String token, @HeaderParam("Range") final String range, public Response retrieveDataId(@Context final SecurityContext sc, @QueryParam(HttpHeaders.AUTHORIZATION) final String token, @HeaderParam("Range") final String range,
@PathParam("id") final UUID id) throws Exception { @PathParam("uuid") final UUID uuid) throws Exception {
final GenericContext gc = (GenericContext) sc.getUserPrincipal(); final GenericContext gc = (GenericContext) sc.getUserPrincipal();
// logger.info("==================================================="); // logger.info("===================================================");
LOGGER.info("== DATA retrieveDataId ? id={} user={}", id, (gc == null ? "null" : gc.userByToken)); LOGGER.info("== DATA retrieveDataId ? id={} user={}", uuid, (gc == null ? "null" : gc.userByToken));
// logger.info("==================================================="); // logger.info("===================================================");
final Data value = getSmall(id); final Data value = getSmall(uuid);
if (value == null) { if (value == null) {
Response.status(404).entity("media NOT FOUND: " + id).type("text/plain").build(); Response.status(404).entity("media NOT FOUND: " + uuid).type("text/plain").build();
} }
return buildStream(getFileData(id), range, value.mimeType); return buildStream(getFileData(uuid), range, value.mimeType);
} }
@GET @GET
@Path("thumbnail/{id}") @Path("thumbnail/{uuid}")
@RolesAllowed("USER") @RolesAllowed("USER")
@PermitTokenInURI @PermitTokenInURI
@Produces(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM)
@Operation(description = "Get a thumbnail of from the data environment (if resize is possible)", tags = "SYSTEM") @Operation(description = "Get a thumbnail of from the data environment (if resize is possible)", tags = "SYSTEM")
// @CacheMaxAge(time = 10, unit = TimeUnit.DAYS) // @CacheMaxAge(time = 10, unit = TimeUnit.DAYS)
public Response retrieveDataThumbnailId(@Context final SecurityContext sc, @QueryParam(HttpHeaders.AUTHORIZATION) final String token, @HeaderParam("Range") final String range, public Response retrieveDataThumbnailId(@Context final SecurityContext sc, @QueryParam(HttpHeaders.AUTHORIZATION) final String token, @HeaderParam("Range") final String range,
@PathParam("id") final UUID id) throws Exception { @PathParam("uuid") final UUID uuid) throws Exception {
// GenericContext gc = (GenericContext) sc.getUserPrincipal(); // GenericContext gc = (GenericContext) sc.getUserPrincipal();
// logger.info("==================================================="); // logger.info("===================================================");
// logger.info("== DATA retrieveDataThumbnailId ? {}", (gc==null?"null":gc.user)); // logger.info("== DATA retrieveDataThumbnailId ? {}", (gc==null?"null":gc.user));
// logger.info("==================================================="); // logger.info("===================================================");
final Data value = getSmall(id); final Data value = getSmall(uuid);
if (value == null) { if (value == null) {
return Response.status(404).entity("media NOT FOUND: " + id).type("text/plain").build(); return Response.status(404).entity("media NOT FOUND: " + uuid).type("text/plain").build();
} }
final String filePathName = getFileData(id); final String filePathName = getFileData(uuid);
final File inputFile = new File(filePathName); final File inputFile = new File(filePathName);
if (!inputFile.exists()) { if (!inputFile.exists()) {
return Response.status(404).entity("{\"error\":\"media Does not exist: " + id + "\"}").type("application/json").build(); return Response.status(404).entity("{\"error\":\"media Does not exist: " + uuid + "\"}").type("application/json").build();
} }
if (value.mimeType.contentEquals("image/jpeg") || value.mimeType.contentEquals("image/png") if (value.mimeType.contentEquals("image/jpeg") || value.mimeType.contentEquals("image/png")
// || value.mimeType.contentEquals("image/webp") // || value.mimeType.contentEquals("image/webp")
@@ -356,22 +356,22 @@ public class DataResource {
} }
@GET @GET
@Path("{id}/{name}") @Path("{uuid}/{name}")
@PermitTokenInURI @PermitTokenInURI
@RolesAllowed("USER") @RolesAllowed("USER")
@Produces(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM)
@Operation(description = "Get back some data from the data environment (with a beautiful name (permit download with basic name)", tags = "SYSTEM") @Operation(description = "Get back some data from the data environment (with a beautiful name (permit download with basic name)", tags = "SYSTEM")
public Response retrieveDataFull(@Context final SecurityContext sc, @QueryParam(HttpHeaders.AUTHORIZATION) final String token, @HeaderParam("Range") final String range, public Response retrieveDataFull(@Context final SecurityContext sc, @QueryParam(HttpHeaders.AUTHORIZATION) final String token, @HeaderParam("Range") final String range,
@PathParam("id") final UUID id, @PathParam("name") final String name) throws Exception { @PathParam("uuid") final UUID uuid, @PathParam("name") final String name) throws Exception {
final GenericContext gc = (GenericContext) sc.getUserPrincipal(); final GenericContext gc = (GenericContext) sc.getUserPrincipal();
// logger.info("==================================================="); // logger.info("===================================================");
LOGGER.info("== DATA retrieveDataFull ? id={} user={}", id, (gc == null ? "null" : gc.userByToken)); LOGGER.info("== DATA retrieveDataFull ? id={} user={}", uuid, (gc == null ? "null" : gc.userByToken));
// logger.info("==================================================="); // logger.info("===================================================");
final Data value = getSmall(id); final Data value = getSmall(uuid);
if (value == null) { if (value == null) {
Response.status(404).entity("media NOT FOUND: " + id).type("text/plain").build(); Response.status(404).entity("media NOT FOUND: " + uuid).type("text/plain").build();
} }
return buildStream(getFileData(id), range, value.mimeType); return buildStream(getFileData(uuid), range, value.mimeType);
} }
/** Adapted from http://stackoverflow.com/questions/12768812/video-streaming-to-ipad-does-not-work-with-tapestry5/12829541#12829541 /** Adapted from http://stackoverflow.com/questions/12768812/video-streaming-to-ipad-does-not-work-with-tapestry5/12829541#12829541

View File

@@ -14,6 +14,7 @@ import java.time.Instant;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalTime; import java.time.LocalTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
@@ -125,7 +126,7 @@ public class DataAccess {
return true; return true;
} }
try { try {
return 1 == DataAccess.executeSimpleQuerry("CREATE DATABASE `" + name + "`;", new DBInterfaceRoot(true)); return 1 == DataAccess.executeSimpleQuery("CREATE DATABASE `" + name + "`;", new DBInterfaceRoot(true));
} catch (final SQLException | IOException ex) { } catch (final SQLException | IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
LOGGER.error("Can not check if the DB exist!!! {}", ex.getMessage()); LOGGER.error("Can not check if the DB exist!!! {}", ex.getMessage());
@@ -212,6 +213,34 @@ public class DataAccess {
return out; return out;
} }
public static byte[][] splitIntoGroupsOf16Bytes(final byte[] input) {
final int inputLength = input.length;
final int numOfGroups = (inputLength + 15) / 16; // Calculate the number of groups needed
final byte[][] groups = new byte[numOfGroups][16];
for (int i = 0; i < numOfGroups; i++) {
final int startIndex = i * 16;
final int endIndex = Math.min(startIndex + 16, inputLength);
groups[i] = Arrays.copyOfRange(input, startIndex, endIndex);
}
return groups;
}
public static List<UUID> getListOfRawUUIDs(final ResultSet rs, final int iii) throws SQLException, DataAccessException {
final byte[] trackString = rs.getBytes(iii);
if (rs.wasNull()) {
return null;
}
final byte[][] elements = splitIntoGroupsOf16Bytes(trackString);
final List<UUID> out = new ArrayList<>();
for (final byte[] elem : elements) {
final UUID tmp = UuidUtils.asUuid(elem);
out.add(tmp);
}
return out;
}
protected static <T> void setValuedb(final Class<?> type, final T data, final CountInOut iii, final Field field, final PreparedStatement ps) throws Exception { protected static <T> void setValuedb(final Class<?> type, final T data, final CountInOut iii, final Field field, final PreparedStatement ps) throws Exception {
if (type == UUID.class) { if (type == UUID.class) {
final Object tmp = field.get(data); final Object tmp = field.get(data);
@@ -844,7 +873,7 @@ public class DataAccess {
query.append(")"); query.append(")");
final OrderBy orders = options.get(OrderBy.class); final OrderBy orders = options.get(OrderBy.class);
if (orders != null) { if (orders != null) {
orders.generateQuerry(query, tableName); orders.generateQuery(query, tableName);
} }
LOGGER.warn("generate the query: '{}'", query.toString()); LOGGER.warn("generate the query: '{}'", query.toString());
// prepare the request: // prepare the request:
@@ -1119,7 +1148,7 @@ public class DataAccess {
query.append(" "); query.append(" ");
final OrderBy orders = options.get(OrderBy.class); final OrderBy orders = options.get(OrderBy.class);
if (orders != null) { if (orders != null) {
orders.generateQuerry(query, tableName); orders.generateQuery(query, tableName);
} }
query.append(" "); query.append(" ");
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz); final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
@@ -1159,7 +1188,7 @@ public class DataAccess {
addOn.insertData(ps, field, data, iii); addOn.insertData(ps, field, data, iii);
} }
} }
condition.injectQuerry(ps, iii); condition.injectQuery(ps, iii);
return ps.executeUpdate(); return ps.executeUpdate();
} }
} catch (final SQLException ex) { } catch (final SQLException ex) {
@@ -1219,14 +1248,14 @@ public class DataAccess {
} }
} }
public static int executeSimpleQuerry(final String query, final QueryOption... option) throws SQLException, IOException { public static int executeSimpleQuery(final String query, final QueryOption... option) throws SQLException, IOException {
final QueryOptions options = new QueryOptions(option); final QueryOptions options = new QueryOptions(option);
final DBEntry entry = DBInterfaceOption.getAutoEntry(options); final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
final Statement stmt = entry.connection.createStatement(); final Statement stmt = entry.connection.createStatement();
return stmt.executeUpdate(query); return stmt.executeUpdate(query);
} }
public static boolean executeQuerry(final String query, final QueryOption... option) throws SQLException, IOException { public static boolean executeQuery(final String query, final QueryOption... option) throws SQLException, IOException {
final QueryOptions options = new QueryOptions(option); final QueryOptions options = new QueryOptions(option);
final DBEntry entry = DBInterfaceOption.getAutoEntry(options); final DBEntry entry = DBInterfaceOption.getAutoEntry(options);
final Statement stmt = entry.connection.createStatement(); final Statement stmt = entry.connection.createStatement();
@@ -1243,9 +1272,16 @@ public class DataAccess {
return values.get(0); return values.get(0);
} }
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 {
final boolean readAllfields = QueryOptions.readAllColomn(options); final boolean readAllfields = QueryOptions.readAllColomn(options);
final String tableName = AnnotationTools.getTableName(clazz, options); final String tableName = AnnotationTools.getTableName(clazz, options);
final String primaryKey = AnnotationTools.getPrimaryKeyField(clazz).getName();
boolean firstField = true; boolean firstField = true;
for (final Field elem : clazz.getFields()) { for (final Field elem : clazz.getFields()) {
@@ -1269,7 +1305,7 @@ public class DataAccess {
} }
querySelect.append(" "); querySelect.append(" ");
if (addOn != null) { if (addOn != null) {
addOn.generateQuerry(tableName, elem, querySelect, query, name, count, options); addOn.generateQuery(tableName, primaryKey, elem, querySelect, query, name, count, options);
} else { } else {
querySelect.append(tableName); querySelect.append(tableName);
querySelect.append("."); querySelect.append(".");
@@ -1311,23 +1347,23 @@ public class DataAccess {
condition.whereAppendQuery(query, tableName, options, deletedFieldName); condition.whereAppendQuery(query, tableName, options, deletedFieldName);
final GroupBy groups = options.get(GroupBy.class); final GroupBy groups = options.get(GroupBy.class);
if (groups != null) { if (groups != null) {
groups.generateQuerry(query, null); groups.generateQuery(query, null);
} }
final OrderBy orders = options.get(OrderBy.class); final OrderBy orders = options.get(OrderBy.class);
if (orders != null) { if (orders != null) {
orders.generateQuerry(query, tableName); orders.generateQuery(query, tableName);
} }
final Limit limit = options.get(Limit.class); final Limit limit = options.get(Limit.class);
if (limit != null) { if (limit != null) {
limit.generateQuerry(query, tableName); limit.generateQuery(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);
final CountInOut iii = new CountInOut(1); final CountInOut iii = new CountInOut(1);
condition.injectQuerry(ps, iii); condition.injectQuery(ps, iii);
if (limit != null) { if (limit != null) {
limit.injectQuerry(ps, iii); limit.injectQuery(ps, iii);
} }
// execute the request // execute the request
final ResultSet rs = ps.executeQuery(); final ResultSet rs = ps.executeQuery();
@@ -1380,7 +1416,7 @@ public class DataAccess {
continue; continue;
} }
if (addOn != null) { if (addOn != null) {
addOn.fillFromQuerry(rs, elem, data, count, options, lazyCall); addOn.fillFromQuery(rs, elem, data, count, options, lazyCall);
} else { } else {
setValueFromDb(elem.getType(), data, count, elem, rs, countNotNull); setValueFromDb(elem.getType(), data, count, elem, rs, countNotNull);
} }
@@ -1411,15 +1447,15 @@ public class DataAccess {
condition.whereAppendQuery(query, tableName, options, deletedFieldName); condition.whereAppendQuery(query, tableName, options, deletedFieldName);
final Limit limit = options.get(Limit.class); final Limit limit = options.get(Limit.class);
if (limit != null) { if (limit != null) {
limit.generateQuerry(query, tableName); limit.generateQuery(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);
final CountInOut iii = new CountInOut(1); final CountInOut iii = new CountInOut(1);
condition.injectQuerry(ps, iii); condition.injectQuery(ps, iii);
if (limit != null) { if (limit != null) {
limit.injectQuerry(ps, iii); limit.injectQuery(ps, iii);
} }
// execute the request // execute the request
final ResultSet rs = ps.executeQuery(); final ResultSet rs = ps.executeQuery();
@@ -1511,7 +1547,7 @@ public class DataAccess {
LOGGER.debug("APPLY: {}", query.toString()); LOGGER.debug("APPLY: {}", query.toString());
final PreparedStatement ps = entry.connection.prepareStatement(query.toString()); final PreparedStatement ps = entry.connection.prepareStatement(query.toString());
final CountInOut iii = new CountInOut(1); final CountInOut iii = new CountInOut(1);
condition.injectQuerry(ps, iii); condition.injectQuery(ps, iii);
return ps.executeUpdate(); return ps.executeUpdate();
} finally { } finally {
entry.close(); entry.close();
@@ -1548,7 +1584,7 @@ public class DataAccess {
LOGGER.debug("APPLY UPDATE: {}", query.toString()); LOGGER.debug("APPLY UPDATE: {}", query.toString());
final PreparedStatement ps = entry.connection.prepareStatement(query.toString()); final PreparedStatement ps = entry.connection.prepareStatement(query.toString());
final CountInOut iii = new CountInOut(1); final CountInOut iii = new CountInOut(1);
condition.injectQuerry(ps, iii); condition.injectQuery(ps, iii);
return ps.executeUpdate(); return ps.executeUpdate();
} finally { } finally {
entry.close(); entry.close();
@@ -1589,7 +1625,7 @@ public class DataAccess {
try { try {
final PreparedStatement ps = entry.connection.prepareStatement(query.toString()); final PreparedStatement ps = entry.connection.prepareStatement(query.toString());
final CountInOut iii = new CountInOut(1); final CountInOut iii = new CountInOut(1);
condition.injectQuerry(ps, iii); condition.injectQuery(ps, iii);
return ps.executeUpdate(); return ps.executeUpdate();
} finally { } finally {
entry.close(); entry.close();
@@ -1605,7 +1641,7 @@ public class DataAccess {
query.append(tableName); query.append(tableName);
query.append("`"); query.append("`");
try { try {
LOGGER.trace("Execute Querry: {}", query.toString()); LOGGER.trace("Execute Query: {}", query.toString());
// Remove main table // Remove main table
final PreparedStatement ps = entry.connection.prepareStatement(query.toString()); final PreparedStatement ps = entry.connection.prepareStatement(query.toString());
ps.executeUpdate(); ps.executeUpdate();
@@ -1637,7 +1673,7 @@ public class DataAccess {
query.append(tableName); query.append(tableName);
query.append("`"); query.append("`");
try { try {
LOGGER.trace("Execute Querry: {}", query.toString()); LOGGER.trace("Execute Query: {}", query.toString());
// Remove main table // Remove main table
final PreparedStatement ps = entry.connection.prepareStatement(query.toString()); final PreparedStatement ps = entry.connection.prepareStatement(query.toString());
ps.executeUpdate(); ps.executeUpdate();
@@ -1692,15 +1728,15 @@ public class DataAccess {
final GroupBy groups = options.get(GroupBy.class); final GroupBy groups = options.get(GroupBy.class);
if (groups != null) { if (groups != null) {
groups.generateQuerry(query, null); groups.generateQuery(query, null);
} }
final OrderBy orders = options.get(OrderBy.class); final OrderBy orders = options.get(OrderBy.class);
if (orders != null) { if (orders != null) {
orders.generateQuerry(query, null); orders.generateQuery(query, null);
} }
final Limit limit = options.get(Limit.class); final Limit limit = options.get(Limit.class);
if (limit != null) { if (limit != null) {
limit.generateQuerry(query, null); limit.generateQuery(query, null);
} }
LOGGER.warn("generate the query: '{}'", query.toString()); LOGGER.warn("generate the query: '{}'", query.toString());
// prepare the request: // prepare the request:
@@ -1712,9 +1748,9 @@ public class DataAccess {
} }
iii.inc(); iii.inc();
} }
condition.injectQuerry(ps, iii); condition.injectQuery(ps, iii);
if (limit != null) { if (limit != null) {
limit.injectQuerry(ps, iii); limit.injectQuery(ps, iii);
} }
// execute the request // execute the request
final ResultSet rs = ps.executeQuery(); final ResultSet rs = ps.executeQuery();
@@ -1727,7 +1763,7 @@ public class DataAccess {
// find field name ... // find field name ...
final Field field = AnnotationTools.getFieldNamed(clazz, label); final Field field = AnnotationTools.getFieldNamed(clazz, label);
if (field == null) { if (field == null) {
throw new DataAccessException("Querry with unknown field: '" + label + "'"); throw new DataAccessException("Query with unknown field: '" + label + "'");
} }
// create the callback... // create the callback...
final RetreiveFromDB element = createSetValueFromDbCallback(jjj + 1, field); final RetreiveFromDB element = createSetValueFromDbCallback(jjj + 1, field);

View File

@@ -45,11 +45,19 @@ public interface DataAccessAddOn {
return false; return false;
} }
void generateQuerry(@NotNull String tableName, @NotNull Field field, @NotNull final StringBuilder querySelect, @NotNull final StringBuilder query, @NotNull String name, @NotNull CountInOut count, void generateQuery(//
QueryOptions options) throws Exception; @NotNull String tableName, //
@NotNull final String primaryKey, //
@NotNull Field field, //
@NotNull final StringBuilder querySelect, //
@NotNull final StringBuilder query, //
@NotNull String name, //
@NotNull CountInOut count, //
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 fillFromQuery(ResultSet rs, Field field, Object data, CountInOut count, QueryOptions options, final List<LazyGetter> lazyCall)
throws Exception, SQLException, IllegalArgumentException, IllegalAccessException; throws Exception, SQLException, IllegalArgumentException, IllegalAccessException;
/** Create associated table of the specific element. /** Create associated table of the specific element.

View File

@@ -234,7 +234,7 @@ public class DataExport {
return iii; return iii;
} }
} }
throw new DataAccessException("Querry with unknown field: '" + name + "'"); throw new DataAccessException("Query with unknown field: '" + name + "'");
} }
public static TableQuery queryTable(final List<TableQueryTypes> headers, final String query, final List<Object> parameters, final QueryOption... option) throws Exception { public static TableQuery queryTable(final List<TableQueryTypes> headers, final String query, final List<Object> parameters, final QueryOption... option) throws Exception {
@@ -260,15 +260,15 @@ public class DataExport {
final GroupBy groups = options.get(GroupBy.class); final GroupBy groups = options.get(GroupBy.class);
if (groups != null) { if (groups != null) {
groups.generateQuerry(query, null); groups.generateQuery(query, null);
} }
final OrderBy orders = options.get(OrderBy.class); final OrderBy orders = options.get(OrderBy.class);
if (orders != null) { if (orders != null) {
orders.generateQuerry(query, null); orders.generateQuery(query, null);
} }
final Limit limit = options.get(Limit.class); final Limit limit = options.get(Limit.class);
if (limit != null) { if (limit != null) {
limit.generateQuerry(query, null); limit.generateQuery(query, null);
} }
LOGGER.warn("generate the query: '{}'", query.toString()); LOGGER.warn("generate the query: '{}'", query.toString());
// prepare the request: // prepare the request:
@@ -280,9 +280,9 @@ public class DataExport {
} }
iii.inc(); iii.inc();
} }
condition.injectQuerry(ps, iii); condition.injectQuery(ps, iii);
if (limit != null) { if (limit != null) {
limit.injectQuerry(ps, iii); limit.injectQuery(ps, iii);
} }
// execute the request // execute the request
final ResultSet rs = ps.executeQuery(); final ResultSet rs = ps.executeQuery();

View File

@@ -269,6 +269,7 @@ public class DataFactoryTsApi {
} }
return out; return out;
} }
public static String convertInTypeScriptCheckType(final List<ClassElement> tmp) { public static String convertInTypeScriptCheckType(final List<ClassElement> tmp) {
String out = ""; String out = "";
for (final ClassElement elem : tmp) { for (final ClassElement elem : tmp) {

View File

@@ -14,7 +14,7 @@ public class GroupBy extends QueryOption {
this.childs = List.of(childs); this.childs = List.of(childs);
} }
public void generateQuerry(final StringBuilder query, final String tableName) { public void generateQuery(final StringBuilder query, final String tableName) {
if (this.childs.size() == 0) { if (this.childs.size() == 0) {
return; return;
} }
@@ -33,7 +33,7 @@ public class GroupBy extends QueryOption {
query.append("\n"); query.append("\n");
} }
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception { public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {
// nothing to add. // nothing to add.
} }
} }

View File

@@ -9,11 +9,11 @@ public class Limit extends QueryOption {
this.limit = limit; this.limit = limit;
} }
public void generateQuerry(final StringBuilder query, final String tableName) { public void generateQuery(final StringBuilder query, final String tableName) {
query.append(" LIMIT ? \n"); query.append(" LIMIT ? \n");
} }
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception { public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {
DataAccess.addElement(ps, this.limit, iii); DataAccess.addElement(ps, this.limit, iii);
iii.inc(); iii.inc();
} }

View File

@@ -14,7 +14,7 @@ public class OrderBy extends QueryOption {
this.childs = List.of(childs); this.childs = List.of(childs);
} }
public void generateQuerry(final StringBuilder query, final String tableName) { public void generateQuery(final StringBuilder query, final String tableName) {
if (this.childs.size() == 0) { if (this.childs.size() == 0) {
return; return;
} }
@@ -35,7 +35,7 @@ public class OrderBy extends QueryOption {
query.append("\n"); query.append("\n");
} }
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception { public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {
// nothing to add. // nothing to add.
} }
} }

View File

@@ -22,7 +22,7 @@ public class QueryAnd implements QueryItem {
} }
@Override @Override
public void generateQuerry(final StringBuilder query, final String tableName) { public void generateQuery(final StringBuilder query, final String tableName) {
if (this.childs.size() >= 1) { if (this.childs.size() >= 1) {
query.append(" ("); query.append(" (");
} }
@@ -33,7 +33,7 @@ public class QueryAnd implements QueryItem {
} else { } else {
query.append(" AND "); query.append(" AND ");
} }
elem.generateQuerry(query, tableName); elem.generateQuery(query, tableName);
} }
if (this.childs.size() >= 1) { if (this.childs.size() >= 1) {
query.append(")"); query.append(")");
@@ -41,10 +41,10 @@ public class QueryAnd implements QueryItem {
} }
@Override @Override
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception { public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {
for (final QueryItem elem : this.childs) { for (final QueryItem elem : this.childs) {
elem.injectQuerry(ps, iii); elem.injectQuery(ps, iii);
} }
} }

View File

@@ -14,7 +14,7 @@ public class QueryCondition implements QueryItem {
} }
@Override @Override
public void generateQuerry(final StringBuilder query, final String tableName) { public void generateQuery(final StringBuilder query, final String tableName) {
if (tableName != null) { if (tableName != null) {
query.append(tableName); query.append(tableName);
query.append("."); query.append(".");
@@ -26,7 +26,7 @@ public class QueryCondition implements QueryItem {
} }
@Override @Override
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception { public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {
DataAccess.addElement(ps, this.value, iii); DataAccess.addElement(ps, this.value, iii);
iii.inc(); iii.inc();
} }

View File

@@ -23,7 +23,7 @@ public class QueryInList<T> implements QueryItem {
} }
@Override @Override
public void generateQuerry(final StringBuilder query, final String tableName) { public void generateQuery(final StringBuilder query, final String tableName) {
if (tableName != null) { if (tableName != null) {
query.append(tableName); query.append(tableName);
query.append("."); query.append(".");
@@ -44,7 +44,7 @@ public class QueryInList<T> implements QueryItem {
} }
@Override @Override
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception { public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {
for (final Object elem : this.value) { for (final Object elem : this.value) {
DataAccess.addElement(ps, elem, iii); DataAccess.addElement(ps, elem, iii);
iii.inc(); iii.inc();

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 query, String tableName); void generateQuery(StringBuilder query, String tableName);
void injectQuerry(PreparedStatement ps, CountInOut iii) throws Exception; void injectQuery(PreparedStatement ps, CountInOut iii) throws Exception;
} }

View File

@@ -10,7 +10,7 @@ public class QueryNotNull implements QueryItem {
} }
@Override @Override
public void generateQuerry(final StringBuilder query, final String tableName) { public void generateQuery(final StringBuilder query, final String tableName) {
if (tableName != null) { if (tableName != null) {
query.append(tableName); query.append(tableName);
query.append("."); query.append(".");
@@ -20,5 +20,5 @@ public class QueryNotNull implements QueryItem {
} }
@Override @Override
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception {} public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {}
} }

View File

@@ -10,7 +10,7 @@ public class QueryNull implements QueryItem {
} }
@Override @Override
public void generateQuerry(final StringBuilder query, final String tableName) { public void generateQuery(final StringBuilder query, final String tableName) {
if (tableName != null) { if (tableName != null) {
query.append(tableName); query.append(tableName);
query.append("."); query.append(".");
@@ -20,5 +20,5 @@ public class QueryNull implements QueryItem {
} }
@Override @Override
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception {} public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {}
} }

View File

@@ -15,7 +15,7 @@ public class QueryOr implements QueryItem {
} }
@Override @Override
public void generateQuerry(final StringBuilder query, final String tableName) { public void generateQuery(final StringBuilder query, final String tableName) {
if (this.childs.size() >= 1) { if (this.childs.size() >= 1) {
query.append(" ("); query.append(" (");
} }
@@ -26,7 +26,7 @@ public class QueryOr implements QueryItem {
} else { } else {
query.append(" OR "); query.append(" OR ");
} }
elem.generateQuerry(query, tableName); elem.generateQuery(query, tableName);
} }
if (this.childs.size() >= 1) { if (this.childs.size() >= 1) {
query.append(")"); query.append(")");
@@ -34,9 +34,9 @@ public class QueryOr implements QueryItem {
} }
@Override @Override
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception { public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {
for (final QueryItem elem : this.childs) { for (final QueryItem elem : this.childs) {
elem.injectQuerry(ps, iii); elem.injectQuery(ps, iii);
} }
} }
} }

View File

@@ -79,18 +79,26 @@ public class AddOnDataJson implements DataAccessAddOn {
} }
@Override @Override
public void generateQuerry(@NotNull final String tableName, @NotNull final Field field, @NotNull final StringBuilder querrySelect, @NotNull final StringBuilder querry, @NotNull final String name, public void generateQuery(//
@NotNull final CountInOut elemCount, final QueryOptions options) throws Exception { @NotNull final String tableName, //
querrySelect.append(" "); @NotNull final String primaryKey, //
querrySelect.append(tableName); @NotNull final Field field, //
querrySelect.append("."); @NotNull final StringBuilder querySelect, //
querrySelect.append(name); @NotNull final StringBuilder query, //
elemCount.inc(); @NotNull final String name, //
@NotNull final CountInOut count, //
final QueryOptions options//
) throws Exception {
querySelect.append(" ");
querySelect.append(tableName);
querySelect.append(".");
querySelect.append(name);
count.inc();
return; return;
} }
@Override @Override
public void fillFromQuerry(final ResultSet rs, final Field field, final Object data, final CountInOut count, final QueryOptions options, final List<LazyGetter> lazyCall) throws Exception { public void fillFromQuery(final ResultSet rs, final Field field, final Object data, final CountInOut count, final QueryOptions options, final List<LazyGetter> lazyCall) throws Exception {
final String jsonData = rs.getString(count.value); final String jsonData = rs.getString(count.value);
count.inc(); count.inc();
if (!rs.wasNull()) { if (!rs.wasNull()) {

View File

@@ -73,9 +73,15 @@ public class AddOnManyToMany implements DataAccessAddOn {
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
if (objectClass == Long.class || objectClass == UUID.class) { if (objectClass == Long.class || objectClass == UUID.class) {
return true; return true;
} else { }
final ManyToMany decorators = field.getDeclaredAnnotation(ManyToMany.class);
if (decorators == null) {
return false; return false;
} }
if (decorators.targetEntity() == objectClass) {
return true;
}
return false;
} }
public static String generateLinkTableNameField(final String tableName, final Field field) throws Exception { public static String generateLinkTableNameField(final String tableName, final Field field) throws Exception {
@@ -91,79 +97,79 @@ public class AddOnManyToMany implements DataAccessAddOn {
return tableName + "_link_" + localName; return tableName + "_link_" + localName;
} }
public void generateConcatQuerry( // public void generateConcatQuery(//
@NotNull final String tableName, // @NotNull final String tableName, //
@NotNull final String primaryKey, //
@NotNull final Field field, // @NotNull final Field field, //
@NotNull final StringBuilder querrySelect, // @NotNull final StringBuilder querySelect, //
@NotNull final StringBuilder querry, // @NotNull final StringBuilder query, //
@NotNull final String name, // @NotNull final String name, //
@NotNull final CountInOut elemCount, // @NotNull final CountInOut count, //
final QueryOptions options// final QueryOptions options//
) { ) throws Exception {
final String linkTableName = generateLinkTableName(tableName, name); final String linkTableName = generateLinkTableName(tableName, name);
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
final String tmpVariable = "tmp_" + Integer.toString(elemCount.value); final String tmpVariable = "tmp_" + Integer.toString(count.value);
querrySelect.append(" (SELECT GROUP_CONCAT("); querySelect.append(" (SELECT GROUP_CONCAT(");
if (objectClass == Long.class) { querySelect.append(tmpVariable);
querrySelect.append(tmpVariable); querySelect.append(".object2Id ");
querrySelect.append(".object2Id ");
} else {
querrySelect.append("BIN_TO_UUID(");
querrySelect.append(tmpVariable);
querrySelect.append(".object2Id) ");
}
if ("sqlite".equals(ConfigBaseVariable.getDBType())) { if ("sqlite".equals(ConfigBaseVariable.getDBType())) {
querrySelect.append(", "); querySelect.append(", ");
} else { } else {
querrySelect.append("SEPARATOR "); querySelect.append("SEPARATOR ");
} }
querrySelect.append("'"); querySelect.append("'");
if (objectClass == Long.class) { if (objectClass == Long.class) {
querrySelect.append(SEPARATOR_LONG); querySelect.append(SEPARATOR_LONG);
} else { } else if (objectClass == UUID.class) {} else {
querrySelect.append(SEPARATOR_UUID); final Class<?> foreignKeyType = AnnotationTools.getPrimaryKeyField(objectClass).getType();
if (foreignKeyType == Long.class) {
querySelect.append(SEPARATOR_LONG);
}
} }
querrySelect.append("') FROM "); querySelect.append("') FROM ");
querrySelect.append(linkTableName); querySelect.append(linkTableName);
querrySelect.append(" "); querySelect.append(" ");
querrySelect.append(tmpVariable); querySelect.append(tmpVariable);
querrySelect.append(" WHERE "); querySelect.append(" WHERE ");
/* querrySelect.append(tmpVariable); querrySelect.append(".deleted = false AND "); */ /* querySelect.append(tmpVariable); querySelect.append(".deleted = false AND "); */
querrySelect.append(tableName); querySelect.append(tableName);
querrySelect.append(".id = "); querySelect.append(".");
querrySelect.append(tmpVariable); querySelect.append(primaryKey);
querrySelect.append("."); querySelect.append(" = ");
querrySelect.append("object1Id "); querySelect.append(tmpVariable);
querySelect.append(".");
querySelect.append("object1Id ");
if (!"sqlite".equals(ConfigBaseVariable.getDBType())) { if (!"sqlite".equals(ConfigBaseVariable.getDBType())) {
querrySelect.append(" GROUP BY "); querySelect.append(" GROUP BY ");
querrySelect.append(tmpVariable); querySelect.append(tmpVariable);
querrySelect.append(".object1Id"); querySelect.append(".object1Id");
} }
querrySelect.append(") AS "); querySelect.append(") AS ");
querrySelect.append(name); querySelect.append(name);
querrySelect.append(" "); querySelect.append(" ");
/* " (SELECT GROUP_CONCAT(tmp.data_id SEPARATOR '-')" + " FROM cover_link_node tmp" + " WHERE tmp.deleted = false" + /* " (SELECT GROUP_CONCAT(tmp.data_id SEPARATOR '-')" + " FROM cover_link_node tmp" + " WHERE tmp.deleted = false" +
* " AND node.id = tmp.node_id" + " GROUP BY tmp.node_id) AS covers" + */ * " AND node.id = tmp.node_id" + " GROUP BY tmp.node_id) AS covers" + */
elemCount.inc(); count.inc();
} }
@Override @Override
public void generateQuerry( // public void generateQuery(//
@NotNull final String tableName, // @NotNull final String tableName, //
@NotNull final String primaryKey, //
@NotNull final Field field, // @NotNull final Field field, //
@NotNull final StringBuilder querrySelect, // @NotNull final StringBuilder querySelect, //
@NotNull final StringBuilder querry, // @NotNull final StringBuilder query, //
@NotNull final String name, // @NotNull final String name, //
@NotNull final CountInOut elemCount, // @NotNull final CountInOut count, //
final QueryOptions options // final QueryOptions options//
) throws Exception { ) throws Exception {
if (field.getType() != List.class) { if (field.getType() != List.class) {
return; return;
} }
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
if (objectClass == Long.class || objectClass == UUID.class) { if (objectClass == Long.class || objectClass == UUID.class) {
generateConcatQuerry(tableName, field, querrySelect, querry, name, elemCount, options); generateConcatQuery(tableName, primaryKey, field, querySelect, query, name, count, options);
} }
final ManyToMany decorators = field.getDeclaredAnnotation(ManyToMany.class); final ManyToMany decorators = field.getDeclaredAnnotation(ManyToMany.class);
if (decorators == null) { if (decorators == null) {
@@ -173,13 +179,13 @@ public class AddOnManyToMany implements DataAccessAddOn {
if (decorators.fetch() == FetchType.EAGER) { if (decorators.fetch() == FetchType.EAGER) {
throw new DataAccessException("EAGER is not supported for list of element..."); throw new DataAccessException("EAGER is not supported for list of element...");
} else { } else {
generateConcatQuerry(tableName, field, querrySelect, querry, name, elemCount, options); generateConcatQuery(tableName, primaryKey, field, querySelect, query, name, count, options);
} }
} }
} }
@Override @Override
public void fillFromQuerry( // public void fillFromQuery( //
final ResultSet rs, // final ResultSet rs, //
final Field field, // final Field field, //
final Object data, // final Object data, //
@@ -198,7 +204,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
count.inc(); count.inc();
return; return;
} else if (objectClass == UUID.class) { } else if (objectClass == UUID.class) {
final List<UUID> idList = DataAccess.getListOfUUIDs(rs, count.value, SEPARATOR_UUID); final List<UUID> idList = DataAccess.getListOfRawUUIDs(rs, count.value);
field.set(data, idList); field.set(data, idList);
count.inc(); count.inc();
return; return;
@@ -208,9 +214,10 @@ public class AddOnManyToMany implements DataAccessAddOn {
return; return;
} }
if (objectClass == decorators.targetEntity()) { if (objectClass == decorators.targetEntity()) {
final Class<?> foreignKeyType = AnnotationTools.getPrimaryKeyField(objectClass).getType();
if (decorators.fetch() == FetchType.EAGER) { if (decorators.fetch() == FetchType.EAGER) {
throw new DataAccessException("EAGER is not supported for list of element..."); throw new DataAccessException("EAGER is not supported for list of element...");
} else if (objectClass == Long.class) { } else if (foreignKeyType == Long.class) {
final List<Long> idList = DataAccess.getListOfIds(rs, count.value, SEPARATOR_LONG); final List<Long> idList = DataAccess.getListOfIds(rs, count.value, SEPARATOR_LONG);
// field.set(data, idList); // field.set(data, idList);
count.inc(); count.inc();
@@ -229,8 +236,8 @@ public class AddOnManyToMany implements DataAccessAddOn {
}; };
lazyCall.add(lambda); lazyCall.add(lambda);
} }
} else if (objectClass == UUID.class) { } else if (foreignKeyType == UUID.class) {
final List<UUID> idList = DataAccess.getListOfUUIDs(rs, count.value, SEPARATOR_UUID); final List<UUID> idList = DataAccess.getListOfRawUUIDs(rs, count.value);
// field.set(data, idList); // field.set(data, idList);
count.inc(); count.inc();
if (idList != null && idList.size() > 0) { if (idList != null && idList.size() > 0) {

View File

@@ -132,13 +132,14 @@ public class AddOnManyToOne implements DataAccessAddOn {
} }
@Override @Override
public void generateQuerry( // public void generateQuery(//
@NotNull final String tableName, // @NotNull final String tableName, //
@NotNull final String primaryKey, //
@NotNull final Field field, // @NotNull final Field field, //
@NotNull final StringBuilder querrySelect, // @NotNull final StringBuilder querySelect, //
@NotNull final StringBuilder querry, // @NotNull final StringBuilder query, //
@NotNull final String name, // @NotNull final String name, //
@NotNull final CountInOut elemCount, // @NotNull final CountInOut count, //
final QueryOptions options// final QueryOptions options//
) throws Exception { ) throws Exception {
if (field.getType() == Long.class // if (field.getType() == Long.class //
@@ -146,37 +147,37 @@ public class AddOnManyToOne implements DataAccessAddOn {
|| field.getType() == Short.class // || field.getType() == Short.class //
|| field.getType() == String.class // || field.getType() == String.class //
|| field.getType() == UUID.class) { || field.getType() == UUID.class) {
querrySelect.append(" "); querySelect.append(" ");
querrySelect.append(tableName); querySelect.append(tableName);
querrySelect.append("."); querySelect.append(".");
querrySelect.append(name); querySelect.append(name);
elemCount.inc(); count.inc();
return; return;
} }
final ManyToOne decorators = field.getDeclaredAnnotation(ManyToOne.class); final ManyToOne decorators = field.getDeclaredAnnotation(ManyToOne.class);
if (field.getType() == decorators.targetEntity()) { if (field.getType() == decorators.targetEntity()) {
if (decorators.fetch() == FetchType.EAGER) { if (decorators.fetch() == FetchType.EAGER) {
// TODO: rework this to have a lazy mode ... // TODO: rework this to have a lazy mode ...
DataAccess.generateSelectField(querrySelect, querry, field.getType(), options, elemCount); DataAccess.generateSelectField(querySelect, query, field.getType(), options, count);
final Class<?> subType = field.getType(); final Class<?> subType = field.getType();
final String subTableName = AnnotationTools.getTableName(subType); final String subTableName = AnnotationTools.getTableName(subType);
final Field idField = AnnotationTools.getFieldOfId(subType); final Field idField = AnnotationTools.getFieldOfId(subType);
querry.append("LEFT OUTER JOIN `"); query.append("LEFT OUTER JOIN `");
querry.append(subTableName); query.append(subTableName);
querry.append("` ON "); query.append("` ON ");
querry.append(subTableName); query.append(subTableName);
querry.append("."); query.append(".");
querry.append(AnnotationTools.getFieldName(idField)); query.append(AnnotationTools.getFieldName(idField));
querry.append(" = "); query.append(" = ");
querry.append(tableName); query.append(tableName);
querry.append("."); query.append(".");
querry.append(AnnotationTools.getFieldName(field)); query.append(AnnotationTools.getFieldName(field));
} else { } else {
querrySelect.append(" "); querySelect.append(" ");
querrySelect.append(tableName); querySelect.append(tableName);
querrySelect.append("."); querySelect.append(".");
querrySelect.append(name); querySelect.append(name);
elemCount.inc(); count.inc();
return; return;
} }
} }
@@ -185,7 +186,7 @@ public class AddOnManyToOne implements DataAccessAddOn {
} }
@Override @Override
public void fillFromQuerry(final ResultSet rs, final Field field, final Object data, final CountInOut count, final QueryOptions options, final List<LazyGetter> lazyCall) throws Exception { public void fillFromQuery(final ResultSet rs, final Field field, final Object data, final CountInOut count, final QueryOptions options, final List<LazyGetter> lazyCall) throws Exception {
if (field.getType() == Long.class) { if (field.getType() == Long.class) {
final Long foreignKey = rs.getLong(count.value); final Long foreignKey = rs.getLong(count.value);
count.inc(); count.inc();

View File

@@ -103,17 +103,25 @@ public class AddOnOneToMany implements DataAccessAddOn {
} }
@Override @Override
public void generateQuerry(@NotNull final String tableName, @NotNull final Field field, @NotNull final StringBuilder querrySelect, @NotNull final StringBuilder querry, @NotNull final String name, public void generateQuery(//
@NotNull final CountInOut elemCount, final QueryOptions options) { @NotNull final String tableName, //
querrySelect.append(" "); @NotNull final String primaryKey, //
querrySelect.append(tableName); @NotNull final Field field, //
querrySelect.append("."); @NotNull final StringBuilder querySelect, //
querrySelect.append(name); @NotNull final StringBuilder query, //
elemCount.inc(); @NotNull final String name, //
@NotNull final CountInOut count, //
final QueryOptions options//
) {
querySelect.append(" ");
querySelect.append(tableName);
querySelect.append(".");
querySelect.append(name);
count.inc();
} }
@Override @Override
public void fillFromQuerry(final ResultSet rs, final Field field, final Object data, final CountInOut count, final QueryOptions options, final List<LazyGetter> lazyCall) public void fillFromQuery(final ResultSet rs, final Field field, final Object data, final CountInOut count, final QueryOptions options, final List<LazyGetter> lazyCall)
throws SQLException, IllegalArgumentException, IllegalAccessException { throws SQLException, IllegalArgumentException, IllegalAccessException {
final Long foreignKey = rs.getLong(count.value); final Long foreignKey = rs.getLong(count.value);
count.inc(); count.inc();

View File

@@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory;
import jakarta.validation.constraints.NotNull; import jakarta.validation.constraints.NotNull;
// TODO: maybe deprecated ==> use DataJson instead... // TODO: maybe deprecated ==> use DataJson instead...
@Deprecated
public class AddOnSQLTableExternalForeinKeyAsList implements DataAccessAddOn { public class AddOnSQLTableExternalForeinKeyAsList implements DataAccessAddOn {
static final Logger LOGGER = LoggerFactory.getLogger(AddOnManyToMany.class); static final Logger LOGGER = LoggerFactory.getLogger(AddOnManyToMany.class);
static final String SEPARATOR = "-"; static final String SEPARATOR = "-";
@@ -87,17 +88,25 @@ public class AddOnSQLTableExternalForeinKeyAsList implements DataAccessAddOn {
} }
@Override @Override
public void generateQuerry(@NotNull final String tableName, @NotNull final Field field, @NotNull final StringBuilder querrySelect, @NotNull final StringBuilder querry, @NotNull final String name, public void generateQuery(//
@NotNull final CountInOut elemCount, final QueryOptions options) { @NotNull final String tableName, //
elemCount.inc(); @NotNull final String primaryKey, //
querrySelect.append(" "); @NotNull final Field field, //
querrySelect.append(tableName); @NotNull final StringBuilder querySelect, //
querrySelect.append("."); @NotNull final StringBuilder query, //
querrySelect.append(name); @NotNull final String name, //
@NotNull final CountInOut count, //
final QueryOptions options//
) {
count.inc();
querySelect.append(" ");
querySelect.append(tableName);
querySelect.append(".");
querySelect.append(name);
} }
@Override @Override
public void fillFromQuerry(final ResultSet rs, final Field field, final Object data, final CountInOut count, final QueryOptions options, final List<LazyGetter> lazyCall) public void fillFromQuery(final ResultSet rs, final Field field, final Object data, final CountInOut count, final QueryOptions options, final List<LazyGetter> lazyCall)
throws SQLException, IllegalArgumentException, IllegalAccessException { throws SQLException, IllegalArgumentException, IllegalAccessException {
final List<Long> idList = DataAccess.getListOfIds(rs, count.value, SEPARATOR); final List<Long> idList = DataAccess.getListOfIds(rs, count.value, SEPARATOR);
field.set(data, idList); field.set(data, idList);

View File

@@ -19,15 +19,15 @@ public class Condition extends QueryOption {
this.condition = null; this.condition = null;
} }
public void generateQuerry(final StringBuilder query, final String tableName) { public void generateQuery(final StringBuilder query, final String tableName) {
if (this.condition != null) { if (this.condition != null) {
this.condition.generateQuerry(query, tableName); this.condition.generateQuery(query, tableName);
} }
} }
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception { public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {
if (this.condition != null) { if (this.condition != null) {
this.condition.injectQuerry(ps, iii); this.condition.injectQuery(ps, iii);
} }
} }
@@ -48,7 +48,7 @@ public class Condition extends QueryOption {
return; return;
} }
query.append(" WHERE ("); query.append(" WHERE (");
this.condition.generateQuerry(query, tableName); this.condition.generateQuery(query, tableName);
query.append(") "); query.append(") ");
if (exclude_deleted && deletedFieldName != null) { if (exclude_deleted && deletedFieldName != null) {
query.append("AND "); query.append("AND ");

View File

@@ -166,7 +166,7 @@ public class MigrationEngine {
} }
LOGGER.info("Create Table with : {}", sqlQuery.get(0)); LOGGER.info("Create Table with : {}", sqlQuery.get(0));
try { try {
DataAccess.executeQuerry(sqlQuery.get(0)); DataAccess.executeQuery(sqlQuery.get(0));
} catch (SQLException | IOException ex) { } catch (SQLException | IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
throw new MigrationException("Fail to create the local DB model for migaration ==> wait administrator interventions"); throw new MigrationException("Fail to create the local DB model for migaration ==> wait administrator interventions");

View File

@@ -98,7 +98,7 @@ public class MigrationSqlStep implements MigrationInterface {
} }
try { try {
if (action.action() != null) { if (action.action() != null) {
DataAccess.executeQuerry(action.action()); DataAccess.executeQuery(action.action());
} else { } else {
action.async().doRequest(); action.async().doRequest();
} }

View File

@@ -12,5 +12,5 @@ public class UUIDGenericData extends GenericTiming {
@DefaultValue("(UUID_TO_BIN(UUID(), TRUE))") @DefaultValue("(UUID_TO_BIN(UUID(), TRUE))")
@Column(nullable = false, unique = true) @Column(nullable = false, unique = true)
@Schema(description = "Unique UUID of the object", required = false, readOnly = true, example = "e6b33c1c-d24d-11ee-b616-02420a030102") @Schema(description = "Unique UUID of the object", required = false, readOnly = true, example = "e6b33c1c-d24d-11ee-b616-02420a030102")
public UUID id = null; public UUID uuid = null;
} }

View File

@@ -115,7 +115,7 @@ public class DataTools {
return null; return null;
} }
final String mediaPath = DataResource.getFileData(out.id); final String mediaPath = DataResource.getFileData(out.uuid);
LOGGER.info("src = {}", tmpPath); LOGGER.info("src = {}", tmpPath);
LOGGER.info("dst = {}", mediaPath); LOGGER.info("dst = {}", mediaPath);
Files.move(Paths.get(tmpPath), Paths.get(mediaPath), StandardCopyOption.ATOMIC_MOVE); Files.move(Paths.get(tmpPath), Paths.get(mediaPath), StandardCopyOption.ATOMIC_MOVE);
@@ -246,7 +246,7 @@ public class DataTools {
} }
} else if (data.deleted) { } else if (data.deleted) {
LOGGER.error("Data already exist but deleted"); LOGGER.error("Data already exist but deleted");
undelete(data.id); undelete(data.uuid);
data.deleted = false; data.deleted = false;
} else { } else {
LOGGER.error("Data already exist ... all good"); LOGGER.error("Data already exist ... all good");
@@ -254,9 +254,9 @@ public class DataTools {
// Fist step: retrieve all the Id of each parents:... // Fist step: retrieve all the Id of each parents:...
LOGGER.info("Find typeNode"); LOGGER.info("Find typeNode");
if (id instanceof final Long idLong) { if (id instanceof final Long idLong) {
AddOnDataJson.addLink(clazz, idLong, "covers", data.id); AddOnDataJson.addLink(clazz, idLong, "covers", data.uuid);
} else if (id instanceof final UUID idUUID) { } else if (id instanceof final UUID idUUID) {
AddOnDataJson.addLink(clazz, idUUID, "covers", data.id); AddOnDataJson.addLink(clazz, idUUID, "covers", data.uuid);
} else { } else {
throw new IOException("Fail to add Cover can not detect type..."); throw new IOException("Fail to add Cover can not detect type...");
} }

View File

@@ -135,6 +135,7 @@ public class RESTApi {
if (clazz.equals(String.class)) { if (clazz.equals(String.class)) {
return (T) httpResponse.body(); return (T) httpResponse.body();
} }
LOGGER.trace("Receive model: {} with data: '{}'", clazz.getCanonicalName(), httpResponse.body());
return this.mapper.readValue(httpResponse.body(), clazz); return this.mapper.readValue(httpResponse.body(), clazz);
} }

View File

@@ -8,6 +8,8 @@ import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.UUID; import java.util.UUID;
import org.kar.archidata.exception.DataAccessException;
public class UuidUtils { public class UuidUtils {
public static UUID asUuid(final BigInteger bigInteger) { public static UUID asUuid(final BigInteger bigInteger) {
@@ -16,7 +18,10 @@ public class UuidUtils {
return new UUID(mostSignificantBits, leastSignificantBits); return new UUID(mostSignificantBits, leastSignificantBits);
} }
public static UUID asUuid(final byte[] bytes) { public static UUID asUuid(final byte[] bytes) throws DataAccessException {
if (bytes.length != 16) {
throw new DataAccessException("Try to convert wrong size of UUID: " + bytes.length + " expected 16.");
}
final ByteBuffer bb = ByteBuffer.wrap(bytes); final ByteBuffer bb = ByteBuffer.wrap(bytes);
final long firstLong = bb.getLong(); final long firstLong = bb.getLong();
final long secondLong = bb.getLong(); final long secondLong = bb.getLong();

View File

@@ -53,7 +53,7 @@ public class TestJson {
final List<String> sqlCommand = DataFactory.createTable(SerializeAsJson.class); final List<String> sqlCommand = DataFactory.createTable(SerializeAsJson.class);
for (final String elem : sqlCommand) { for (final String elem : sqlCommand) {
LOGGER.debug("request: '{}'", elem); LOGGER.debug("request: '{}'", elem);
DataAccess.executeSimpleQuerry(elem); DataAccess.executeSimpleQuery(elem);
} }
} }

View File

@@ -53,7 +53,7 @@ public class TestListJson {
final List<String> sqlCommand = DataFactory.createTable(SerializeListAsJson.class); final List<String> sqlCommand = DataFactory.createTable(SerializeListAsJson.class);
for (final String elem : sqlCommand) { for (final String elem : sqlCommand) {
LOGGER.debug("request: '{}'", elem); LOGGER.debug("request: '{}'", elem);
DataAccess.executeSimpleQuerry(elem); DataAccess.executeSimpleQuery(elem);
} }
} }

View File

@@ -57,7 +57,7 @@ public class TestManyToMany {
sqlCommand.addAll(sqlCommand2); sqlCommand.addAll(sqlCommand2);
for (final String elem : sqlCommand) { for (final String elem : sqlCommand) {
LOGGER.debug("request: '{}'", elem); LOGGER.debug("request: '{}'", elem);
DataAccess.executeSimpleQuerry(elem); DataAccess.executeSimpleQuery(elem);
} }
} }

View File

@@ -56,7 +56,7 @@ public class TestManyToOne {
sqlCommand.addAll(sqlCommand2); sqlCommand.addAll(sqlCommand2);
for (final String elem : sqlCommand) { for (final String elem : sqlCommand) {
LOGGER.debug("request: '{}'", elem); LOGGER.debug("request: '{}'", elem);
DataAccess.executeSimpleQuerry(elem); DataAccess.executeSimpleQuery(elem);
} }
} }

View File

@@ -51,7 +51,7 @@ public class TestOneToMany {
final List<String> sqlCommand = DataFactory.createTable(TypesTable.class); final List<String> sqlCommand = DataFactory.createTable(TypesTable.class);
for (final String elem : sqlCommand) { for (final String elem : sqlCommand) {
LOGGER.debug("request: '{}'", elem); LOGGER.debug("request: '{}'", elem);
DataAccess.executeSimpleQuerry(elem); DataAccess.executeSimpleQuery(elem);
} }
} }

View File

@@ -52,7 +52,7 @@ public class TestRawQuery {
final List<String> sqlCommand = DataFactory.createTable(TypesTable.class); final List<String> sqlCommand = DataFactory.createTable(TypesTable.class);
for (final String elem : sqlCommand) { for (final String elem : sqlCommand) {
LOGGER.debug("request: '{}'", elem); LOGGER.debug("request: '{}'", elem);
DataAccess.executeSimpleQuerry(elem); DataAccess.executeSimpleQuery(elem);
} }
} }
@@ -83,7 +83,7 @@ public class TestRawQuery {
test.floatData = 7.0F; test.floatData = 7.0F;
DataAccess.insert(test); DataAccess.insert(test);
{ {
String querry = """ String query = """
SELECT * SELECT *
FROM TypesTable FROM TypesTable
WHERE `intData` = ? WHERE `intData` = ?
@@ -91,7 +91,7 @@ public class TestRawQuery {
"""; """;
List<Object> parameters = List.of(Integer.valueOf(99)); List<Object> parameters = List.of(Integer.valueOf(99));
// Try to retrieve all the data: // Try to retrieve all the data:
final List<TypesTable> retrieve = DataAccess.query(TypesTable.class, querry, parameters); final List<TypesTable> retrieve = DataAccess.query(TypesTable.class, query, parameters);
Assertions.assertNotNull(retrieve); Assertions.assertNotNull(retrieve);
Assertions.assertEquals(3, retrieve.size()); Assertions.assertEquals(3, retrieve.size());
@@ -102,7 +102,7 @@ public class TestRawQuery {
} }
{ {
String querry = """ String query = """
SELECT DISTINCT intData SELECT DISTINCT intData
FROM TypesTable FROM TypesTable
WHERE `intData` = ? WHERE `intData` = ?
@@ -110,7 +110,7 @@ public class TestRawQuery {
"""; """;
List<Object> parameters = List.of(Integer.valueOf(99)); List<Object> parameters = List.of(Integer.valueOf(99));
// Try to retrieve all the data: // Try to retrieve all the data:
final List<TypesTable> retrieve = DataAccess.query(TypesTable.class, querry, parameters); final List<TypesTable> retrieve = DataAccess.query(TypesTable.class, query, parameters);
Assertions.assertNotNull(retrieve); Assertions.assertNotNull(retrieve);
Assertions.assertEquals(1, retrieve.size()); Assertions.assertEquals(1, retrieve.size());

View File

@@ -65,7 +65,7 @@ public class TestSimpleTable {
final List<String> sqlCommand = DataFactory.createTable(SimpleTable.class); final List<String> sqlCommand = DataFactory.createTable(SimpleTable.class);
for (final String elem : sqlCommand) { for (final String elem : sqlCommand) {
LOGGER.debug("request: '{}'", elem); LOGGER.debug("request: '{}'", elem);
DataAccess.executeSimpleQuerry(elem); DataAccess.executeSimpleQuery(elem);
} }
final SimpleTable test = new SimpleTable(); final SimpleTable test = new SimpleTable();
test.data = TestSimpleTable.DATA_INJECTED; test.data = TestSimpleTable.DATA_INJECTED;

View File

@@ -65,7 +65,7 @@ public class TestSimpleTableSoftDelete {
final List<String> sqlCommand = DataFactory.createTable(SimpleTableSoftDelete.class); final List<String> sqlCommand = DataFactory.createTable(SimpleTableSoftDelete.class);
for (final String elem : sqlCommand) { for (final String elem : sqlCommand) {
LOGGER.debug("request: '{}'", elem); LOGGER.debug("request: '{}'", elem);
DataAccess.executeSimpleQuerry(elem); DataAccess.executeSimpleQuery(elem);
} }
final SimpleTableSoftDelete test = new SimpleTableSoftDelete(); final SimpleTableSoftDelete test = new SimpleTableSoftDelete();
test.data = TestSimpleTableSoftDelete.DATA_INJECTED; test.data = TestSimpleTableSoftDelete.DATA_INJECTED;

View File

@@ -53,7 +53,7 @@ public class TestTypeEnum1 {
final List<String> sqlCommand = DataFactory.createTable(TypesEnum1.class); final List<String> sqlCommand = DataFactory.createTable(TypesEnum1.class);
for (final String elem : sqlCommand) { for (final String elem : sqlCommand) {
LOGGER.debug("request: '{}'", elem); LOGGER.debug("request: '{}'", elem);
DataAccess.executeSimpleQuerry(elem); DataAccess.executeSimpleQuery(elem);
} }
} }

View File

@@ -53,7 +53,7 @@ public class TestTypeEnum2 {
final List<String> sqlCommand = DataFactory.createTable(TypesEnum2.class); final List<String> sqlCommand = DataFactory.createTable(TypesEnum2.class);
for (final String elem : sqlCommand) { for (final String elem : sqlCommand) {
LOGGER.debug("request: '{}'", elem); LOGGER.debug("request: '{}'", elem);
DataAccess.executeSimpleQuerry(elem); DataAccess.executeSimpleQuery(elem);
} }
} }

View File

@@ -57,7 +57,7 @@ public class TestTypes {
final List<String> sqlCommand = DataFactory.createTable(TypesTable.class); final List<String> sqlCommand = DataFactory.createTable(TypesTable.class);
for (final String elem : sqlCommand) { for (final String elem : sqlCommand) {
LOGGER.debug("request: '{}'", elem); LOGGER.debug("request: '{}'", elem);
DataAccess.executeSimpleQuerry(elem); DataAccess.executeSimpleQuery(elem);
} }
} }

View File

@@ -1 +1 @@
0.8.0 0.8.2