Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d94e526bd4 | |||
| b9b008b103 | |||
| c43dfa097a | |||
| 4fd13ceb1d | |||
| 6c8ea9e46e | |||
| e183ea7ff6 | |||
| 69006ca067 | |||
| cfe488f2be |
2
pom.xml
2
pom.xml
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>kangaroo-and-rabbit</groupId>
|
||||
<artifactId>archidata</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<version>0.8.2</version>
|
||||
<properties>
|
||||
<maven.compiler.version>3.1</maven.compiler.version>
|
||||
<maven.compiler.source>21</maven.compiler.source>
|
||||
|
||||
@@ -161,7 +161,7 @@ public class DataResource {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
final String mediaPath = getFileData(injectedData.id);
|
||||
final String mediaPath = getFileData(injectedData.uuid);
|
||||
LOGGER.info("src = {}", tmpPath);
|
||||
LOGGER.info("dst = {}", mediaPath);
|
||||
Files.move(Paths.get(tmpPath), Paths.get(mediaPath), StandardCopyOption.ATOMIC_MOVE);
|
||||
@@ -278,45 +278,45 @@ public class DataResource {
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}")
|
||||
@Path("{uuid}")
|
||||
@PermitTokenInURI
|
||||
@RolesAllowed("USER")
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
@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,
|
||||
@PathParam("id") final UUID id) throws Exception {
|
||||
@PathParam("uuid") final UUID uuid) throws Exception {
|
||||
final GenericContext gc = (GenericContext) sc.getUserPrincipal();
|
||||
// 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("===================================================");
|
||||
final Data value = getSmall(id);
|
||||
final Data value = getSmall(uuid);
|
||||
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
|
||||
@Path("thumbnail/{id}")
|
||||
@Path("thumbnail/{uuid}")
|
||||
@RolesAllowed("USER")
|
||||
@PermitTokenInURI
|
||||
@Produces(MediaType.APPLICATION_OCTET_STREAM)
|
||||
@Operation(description = "Get a thumbnail of from the data environment (if resize is possible)", tags = "SYSTEM")
|
||||
// @CacheMaxAge(time = 10, unit = TimeUnit.DAYS)
|
||||
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();
|
||||
// logger.info("===================================================");
|
||||
// logger.info("== DATA retrieveDataThumbnailId ? {}", (gc==null?"null":gc.user));
|
||||
// logger.info("===================================================");
|
||||
final Data value = getSmall(id);
|
||||
final Data value = getSmall(uuid);
|
||||
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);
|
||||
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")
|
||||
// || value.mimeType.contentEquals("image/webp")
|
||||
@@ -356,22 +356,22 @@ public class DataResource {
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("{id}/{name}")
|
||||
@Path("{uuid}/{name}")
|
||||
@PermitTokenInURI
|
||||
@RolesAllowed("USER")
|
||||
@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")
|
||||
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();
|
||||
// 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("===================================================");
|
||||
final Data value = getSmall(id);
|
||||
final Data value = getSmall(uuid);
|
||||
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
|
||||
|
||||
@@ -14,6 +14,7 @@ import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
@@ -125,7 +126,7 @@ public class DataAccess {
|
||||
return true;
|
||||
}
|
||||
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) {
|
||||
ex.printStackTrace();
|
||||
LOGGER.error("Can not check if the DB exist!!! {}", ex.getMessage());
|
||||
@@ -212,6 +213,34 @@ public class DataAccess {
|
||||
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 {
|
||||
if (type == UUID.class) {
|
||||
final Object tmp = field.get(data);
|
||||
@@ -844,7 +873,7 @@ public class DataAccess {
|
||||
query.append(")");
|
||||
final OrderBy orders = options.get(OrderBy.class);
|
||||
if (orders != null) {
|
||||
orders.generateQuerry(query, tableName);
|
||||
orders.generateQuery(query, tableName);
|
||||
}
|
||||
LOGGER.warn("generate the query: '{}'", query.toString());
|
||||
// prepare the request:
|
||||
@@ -1119,7 +1148,7 @@ public class DataAccess {
|
||||
query.append(" ");
|
||||
final OrderBy orders = options.get(OrderBy.class);
|
||||
if (orders != null) {
|
||||
orders.generateQuerry(query, tableName);
|
||||
orders.generateQuery(query, tableName);
|
||||
}
|
||||
query.append(" ");
|
||||
final String deletedFieldName = AnnotationTools.getDeletedFieldName(clazz);
|
||||
@@ -1159,7 +1188,7 @@ public class DataAccess {
|
||||
addOn.insertData(ps, field, data, iii);
|
||||
}
|
||||
}
|
||||
condition.injectQuerry(ps, iii);
|
||||
condition.injectQuery(ps, iii);
|
||||
return ps.executeUpdate();
|
||||
}
|
||||
} 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 DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||
final Statement stmt = entry.connection.createStatement();
|
||||
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 DBEntry entry = DBInterfaceOption.getAutoEntry(options);
|
||||
final Statement stmt = entry.connection.createStatement();
|
||||
@@ -1243,9 +1272,16 @@ public class DataAccess {
|
||||
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 String tableName = AnnotationTools.getTableName(clazz, options);
|
||||
final String primaryKey = AnnotationTools.getPrimaryKeyField(clazz).getName();
|
||||
boolean firstField = true;
|
||||
|
||||
for (final Field elem : clazz.getFields()) {
|
||||
@@ -1269,7 +1305,7 @@ public class DataAccess {
|
||||
}
|
||||
querySelect.append(" ");
|
||||
if (addOn != null) {
|
||||
addOn.generateQuerry(tableName, elem, querySelect, query, name, count, options);
|
||||
addOn.generateQuery(tableName, primaryKey, elem, querySelect, query, name, count, options);
|
||||
} else {
|
||||
querySelect.append(tableName);
|
||||
querySelect.append(".");
|
||||
@@ -1311,23 +1347,23 @@ public class DataAccess {
|
||||
condition.whereAppendQuery(query, tableName, options, deletedFieldName);
|
||||
final GroupBy groups = options.get(GroupBy.class);
|
||||
if (groups != null) {
|
||||
groups.generateQuerry(query, null);
|
||||
groups.generateQuery(query, null);
|
||||
}
|
||||
final OrderBy orders = options.get(OrderBy.class);
|
||||
if (orders != null) {
|
||||
orders.generateQuerry(query, tableName);
|
||||
orders.generateQuery(query, tableName);
|
||||
}
|
||||
final Limit limit = options.get(Limit.class);
|
||||
if (limit != null) {
|
||||
limit.generateQuerry(query, tableName);
|
||||
limit.generateQuery(query, tableName);
|
||||
}
|
||||
LOGGER.warn("generate the query: '{}'", query.toString());
|
||||
// prepare the request:
|
||||
final PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
|
||||
final CountInOut iii = new CountInOut(1);
|
||||
condition.injectQuerry(ps, iii);
|
||||
condition.injectQuery(ps, iii);
|
||||
if (limit != null) {
|
||||
limit.injectQuerry(ps, iii);
|
||||
limit.injectQuery(ps, iii);
|
||||
}
|
||||
// execute the request
|
||||
final ResultSet rs = ps.executeQuery();
|
||||
@@ -1380,7 +1416,7 @@ public class DataAccess {
|
||||
continue;
|
||||
}
|
||||
if (addOn != null) {
|
||||
addOn.fillFromQuerry(rs, elem, data, count, options, lazyCall);
|
||||
addOn.fillFromQuery(rs, elem, data, count, options, lazyCall);
|
||||
} else {
|
||||
setValueFromDb(elem.getType(), data, count, elem, rs, countNotNull);
|
||||
}
|
||||
@@ -1411,15 +1447,15 @@ public class DataAccess {
|
||||
condition.whereAppendQuery(query, tableName, options, deletedFieldName);
|
||||
final Limit limit = options.get(Limit.class);
|
||||
if (limit != null) {
|
||||
limit.generateQuerry(query, tableName);
|
||||
limit.generateQuery(query, tableName);
|
||||
}
|
||||
LOGGER.warn("generate the query: '{}'", query.toString());
|
||||
// prepare the request:
|
||||
final PreparedStatement ps = entry.connection.prepareStatement(query.toString(), Statement.RETURN_GENERATED_KEYS);
|
||||
final CountInOut iii = new CountInOut(1);
|
||||
condition.injectQuerry(ps, iii);
|
||||
condition.injectQuery(ps, iii);
|
||||
if (limit != null) {
|
||||
limit.injectQuerry(ps, iii);
|
||||
limit.injectQuery(ps, iii);
|
||||
}
|
||||
// execute the request
|
||||
final ResultSet rs = ps.executeQuery();
|
||||
@@ -1511,7 +1547,7 @@ public class DataAccess {
|
||||
LOGGER.debug("APPLY: {}", query.toString());
|
||||
final PreparedStatement ps = entry.connection.prepareStatement(query.toString());
|
||||
final CountInOut iii = new CountInOut(1);
|
||||
condition.injectQuerry(ps, iii);
|
||||
condition.injectQuery(ps, iii);
|
||||
return ps.executeUpdate();
|
||||
} finally {
|
||||
entry.close();
|
||||
@@ -1548,7 +1584,7 @@ public class DataAccess {
|
||||
LOGGER.debug("APPLY UPDATE: {}", query.toString());
|
||||
final PreparedStatement ps = entry.connection.prepareStatement(query.toString());
|
||||
final CountInOut iii = new CountInOut(1);
|
||||
condition.injectQuerry(ps, iii);
|
||||
condition.injectQuery(ps, iii);
|
||||
return ps.executeUpdate();
|
||||
} finally {
|
||||
entry.close();
|
||||
@@ -1589,7 +1625,7 @@ public class DataAccess {
|
||||
try {
|
||||
final PreparedStatement ps = entry.connection.prepareStatement(query.toString());
|
||||
final CountInOut iii = new CountInOut(1);
|
||||
condition.injectQuerry(ps, iii);
|
||||
condition.injectQuery(ps, iii);
|
||||
return ps.executeUpdate();
|
||||
} finally {
|
||||
entry.close();
|
||||
@@ -1605,7 +1641,7 @@ public class DataAccess {
|
||||
query.append(tableName);
|
||||
query.append("`");
|
||||
try {
|
||||
LOGGER.trace("Execute Querry: {}", query.toString());
|
||||
LOGGER.trace("Execute Query: {}", query.toString());
|
||||
// Remove main table
|
||||
final PreparedStatement ps = entry.connection.prepareStatement(query.toString());
|
||||
ps.executeUpdate();
|
||||
@@ -1637,7 +1673,7 @@ public class DataAccess {
|
||||
query.append(tableName);
|
||||
query.append("`");
|
||||
try {
|
||||
LOGGER.trace("Execute Querry: {}", query.toString());
|
||||
LOGGER.trace("Execute Query: {}", query.toString());
|
||||
// Remove main table
|
||||
final PreparedStatement ps = entry.connection.prepareStatement(query.toString());
|
||||
ps.executeUpdate();
|
||||
@@ -1692,15 +1728,15 @@ public class DataAccess {
|
||||
|
||||
final GroupBy groups = options.get(GroupBy.class);
|
||||
if (groups != null) {
|
||||
groups.generateQuerry(query, null);
|
||||
groups.generateQuery(query, null);
|
||||
}
|
||||
final OrderBy orders = options.get(OrderBy.class);
|
||||
if (orders != null) {
|
||||
orders.generateQuerry(query, null);
|
||||
orders.generateQuery(query, null);
|
||||
}
|
||||
final Limit limit = options.get(Limit.class);
|
||||
if (limit != null) {
|
||||
limit.generateQuerry(query, null);
|
||||
limit.generateQuery(query, null);
|
||||
}
|
||||
LOGGER.warn("generate the query: '{}'", query.toString());
|
||||
// prepare the request:
|
||||
@@ -1712,9 +1748,9 @@ public class DataAccess {
|
||||
}
|
||||
iii.inc();
|
||||
}
|
||||
condition.injectQuerry(ps, iii);
|
||||
condition.injectQuery(ps, iii);
|
||||
if (limit != null) {
|
||||
limit.injectQuerry(ps, iii);
|
||||
limit.injectQuery(ps, iii);
|
||||
}
|
||||
// execute the request
|
||||
final ResultSet rs = ps.executeQuery();
|
||||
@@ -1727,7 +1763,7 @@ public class DataAccess {
|
||||
// find field name ...
|
||||
final Field field = AnnotationTools.getFieldNamed(clazz, label);
|
||||
if (field == null) {
|
||||
throw new DataAccessException("Querry with unknown field: '" + label + "'");
|
||||
throw new DataAccessException("Query with unknown field: '" + label + "'");
|
||||
}
|
||||
// create the callback...
|
||||
final RetreiveFromDB element = createSetValueFromDbCallback(jjj + 1, field);
|
||||
|
||||
@@ -45,11 +45,19 @@ public interface DataAccessAddOn {
|
||||
return false;
|
||||
}
|
||||
|
||||
void generateQuerry(@NotNull String tableName, @NotNull Field field, @NotNull final StringBuilder querySelect, @NotNull final StringBuilder query, @NotNull String name, @NotNull CountInOut count,
|
||||
QueryOptions options) throws Exception;
|
||||
void generateQuery(//
|
||||
@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
|
||||
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;
|
||||
|
||||
/** Create associated table of the specific element.
|
||||
|
||||
@@ -234,7 +234,7 @@ public class DataExport {
|
||||
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 {
|
||||
@@ -260,15 +260,15 @@ public class DataExport {
|
||||
|
||||
final GroupBy groups = options.get(GroupBy.class);
|
||||
if (groups != null) {
|
||||
groups.generateQuerry(query, null);
|
||||
groups.generateQuery(query, null);
|
||||
}
|
||||
final OrderBy orders = options.get(OrderBy.class);
|
||||
if (orders != null) {
|
||||
orders.generateQuerry(query, null);
|
||||
orders.generateQuery(query, null);
|
||||
}
|
||||
final Limit limit = options.get(Limit.class);
|
||||
if (limit != null) {
|
||||
limit.generateQuerry(query, null);
|
||||
limit.generateQuery(query, null);
|
||||
}
|
||||
LOGGER.warn("generate the query: '{}'", query.toString());
|
||||
// prepare the request:
|
||||
@@ -280,9 +280,9 @@ public class DataExport {
|
||||
}
|
||||
iii.inc();
|
||||
}
|
||||
condition.injectQuerry(ps, iii);
|
||||
condition.injectQuery(ps, iii);
|
||||
if (limit != null) {
|
||||
limit.injectQuerry(ps, iii);
|
||||
limit.injectQuery(ps, iii);
|
||||
}
|
||||
// execute the request
|
||||
final ResultSet rs = ps.executeQuery();
|
||||
|
||||
@@ -269,6 +269,7 @@ public class DataFactoryTsApi {
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static String convertInTypeScriptCheckType(final List<ClassElement> tmp) {
|
||||
String out = "";
|
||||
for (final ClassElement elem : tmp) {
|
||||
|
||||
@@ -14,7 +14,7 @@ public class GroupBy extends QueryOption {
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class GroupBy extends QueryOption {
|
||||
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.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ public class Limit extends QueryOption {
|
||||
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");
|
||||
}
|
||||
|
||||
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);
|
||||
iii.inc();
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class OrderBy extends QueryOption {
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
@@ -35,7 +35,7 @@ public class OrderBy extends QueryOption {
|
||||
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.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ public class QueryAnd implements QueryItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateQuerry(final StringBuilder query, final String tableName) {
|
||||
public void generateQuery(final StringBuilder query, final String tableName) {
|
||||
if (this.childs.size() >= 1) {
|
||||
query.append(" (");
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class QueryAnd implements QueryItem {
|
||||
} else {
|
||||
query.append(" AND ");
|
||||
}
|
||||
elem.generateQuerry(query, tableName);
|
||||
elem.generateQuery(query, tableName);
|
||||
}
|
||||
if (this.childs.size() >= 1) {
|
||||
query.append(")");
|
||||
@@ -41,10 +41,10 @@ public class QueryAnd implements QueryItem {
|
||||
}
|
||||
|
||||
@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) {
|
||||
elem.injectQuerry(ps, iii);
|
||||
elem.injectQuery(ps, iii);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ public class QueryCondition implements QueryItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateQuerry(final StringBuilder query, final String tableName) {
|
||||
public void generateQuery(final StringBuilder query, final String tableName) {
|
||||
if (tableName != null) {
|
||||
query.append(tableName);
|
||||
query.append(".");
|
||||
@@ -26,7 +26,7 @@ public class QueryCondition implements QueryItem {
|
||||
}
|
||||
|
||||
@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);
|
||||
iii.inc();
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class QueryInList<T> implements QueryItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateQuerry(final StringBuilder query, final String tableName) {
|
||||
public void generateQuery(final StringBuilder query, final String tableName) {
|
||||
if (tableName != null) {
|
||||
query.append(tableName);
|
||||
query.append(".");
|
||||
@@ -44,7 +44,7 @@ public class QueryInList<T> implements QueryItem {
|
||||
}
|
||||
|
||||
@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) {
|
||||
DataAccess.addElement(ps, elem, iii);
|
||||
iii.inc();
|
||||
|
||||
@@ -3,7 +3,7 @@ package org.kar.archidata.dataAccess;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ public class QueryNotNull implements QueryItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateQuerry(final StringBuilder query, final String tableName) {
|
||||
public void generateQuery(final StringBuilder query, final String tableName) {
|
||||
if (tableName != null) {
|
||||
query.append(tableName);
|
||||
query.append(".");
|
||||
@@ -20,5 +20,5 @@ public class QueryNotNull implements QueryItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception {}
|
||||
public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ public class QueryNull implements QueryItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateQuerry(final StringBuilder query, final String tableName) {
|
||||
public void generateQuery(final StringBuilder query, final String tableName) {
|
||||
if (tableName != null) {
|
||||
query.append(tableName);
|
||||
query.append(".");
|
||||
@@ -20,5 +20,5 @@ public class QueryNull implements QueryItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectQuerry(final PreparedStatement ps, final CountInOut iii) throws Exception {}
|
||||
public void injectQuery(final PreparedStatement ps, final CountInOut iii) throws Exception {}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ public class QueryOr implements QueryItem {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateQuerry(final StringBuilder query, final String tableName) {
|
||||
public void generateQuery(final StringBuilder query, final String tableName) {
|
||||
if (this.childs.size() >= 1) {
|
||||
query.append(" (");
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public class QueryOr implements QueryItem {
|
||||
} else {
|
||||
query.append(" OR ");
|
||||
}
|
||||
elem.generateQuerry(query, tableName);
|
||||
elem.generateQuery(query, tableName);
|
||||
}
|
||||
if (this.childs.size() >= 1) {
|
||||
query.append(")");
|
||||
@@ -34,9 +34,9 @@ public class QueryOr implements QueryItem {
|
||||
}
|
||||
|
||||
@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) {
|
||||
elem.injectQuerry(ps, iii);
|
||||
elem.injectQuery(ps, iii);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,18 +79,26 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateQuerry(@NotNull final String tableName, @NotNull final Field field, @NotNull final StringBuilder querrySelect, @NotNull final StringBuilder querry, @NotNull final String name,
|
||||
@NotNull final CountInOut elemCount, final QueryOptions options) throws Exception {
|
||||
querrySelect.append(" ");
|
||||
querrySelect.append(tableName);
|
||||
querrySelect.append(".");
|
||||
querrySelect.append(name);
|
||||
elemCount.inc();
|
||||
public void generateQuery(//
|
||||
@NotNull final String tableName, //
|
||||
@NotNull final String primaryKey, //
|
||||
@NotNull final Field field, //
|
||||
@NotNull final StringBuilder querySelect, //
|
||||
@NotNull final StringBuilder query, //
|
||||
@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;
|
||||
}
|
||||
|
||||
@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);
|
||||
count.inc();
|
||||
if (!rs.wasNull()) {
|
||||
|
||||
@@ -73,9 +73,15 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
|
||||
if (objectClass == Long.class || objectClass == UUID.class) {
|
||||
return true;
|
||||
} else {
|
||||
}
|
||||
final ManyToMany decorators = field.getDeclaredAnnotation(ManyToMany.class);
|
||||
if (decorators == null) {
|
||||
return false;
|
||||
}
|
||||
if (decorators.targetEntity() == objectClass) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public void generateConcatQuerry( //
|
||||
public void generateConcatQuery(//
|
||||
@NotNull final String tableName, //
|
||||
@NotNull final String primaryKey, //
|
||||
@NotNull final Field field, //
|
||||
@NotNull final StringBuilder querrySelect, //
|
||||
@NotNull final StringBuilder querry, //
|
||||
@NotNull final StringBuilder querySelect, //
|
||||
@NotNull final StringBuilder query, //
|
||||
@NotNull final String name, //
|
||||
@NotNull final CountInOut elemCount, //
|
||||
@NotNull final CountInOut count, //
|
||||
final QueryOptions options//
|
||||
) {
|
||||
) throws Exception {
|
||||
final String linkTableName = generateLinkTableName(tableName, name);
|
||||
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
|
||||
final String tmpVariable = "tmp_" + Integer.toString(elemCount.value);
|
||||
querrySelect.append(" (SELECT GROUP_CONCAT(");
|
||||
if (objectClass == Long.class) {
|
||||
querrySelect.append(tmpVariable);
|
||||
querrySelect.append(".object2Id ");
|
||||
} else {
|
||||
querrySelect.append("BIN_TO_UUID(");
|
||||
querrySelect.append(tmpVariable);
|
||||
querrySelect.append(".object2Id) ");
|
||||
}
|
||||
final String tmpVariable = "tmp_" + Integer.toString(count.value);
|
||||
querySelect.append(" (SELECT GROUP_CONCAT(");
|
||||
querySelect.append(tmpVariable);
|
||||
querySelect.append(".object2Id ");
|
||||
if ("sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||
querrySelect.append(", ");
|
||||
querySelect.append(", ");
|
||||
} else {
|
||||
querrySelect.append("SEPARATOR ");
|
||||
querySelect.append("SEPARATOR ");
|
||||
}
|
||||
querrySelect.append("'");
|
||||
querySelect.append("'");
|
||||
if (objectClass == Long.class) {
|
||||
querrySelect.append(SEPARATOR_LONG);
|
||||
} else {
|
||||
querrySelect.append(SEPARATOR_UUID);
|
||||
|
||||
querySelect.append(SEPARATOR_LONG);
|
||||
} else if (objectClass == UUID.class) {} else {
|
||||
final Class<?> foreignKeyType = AnnotationTools.getPrimaryKeyField(objectClass).getType();
|
||||
if (foreignKeyType == Long.class) {
|
||||
querySelect.append(SEPARATOR_LONG);
|
||||
}
|
||||
}
|
||||
querrySelect.append("') FROM ");
|
||||
querrySelect.append(linkTableName);
|
||||
querrySelect.append(" ");
|
||||
querrySelect.append(tmpVariable);
|
||||
querrySelect.append(" WHERE ");
|
||||
/* querrySelect.append(tmpVariable); querrySelect.append(".deleted = false AND "); */
|
||||
querrySelect.append(tableName);
|
||||
querrySelect.append(".id = ");
|
||||
querrySelect.append(tmpVariable);
|
||||
querrySelect.append(".");
|
||||
querrySelect.append("object1Id ");
|
||||
querySelect.append("') FROM ");
|
||||
querySelect.append(linkTableName);
|
||||
querySelect.append(" ");
|
||||
querySelect.append(tmpVariable);
|
||||
querySelect.append(" WHERE ");
|
||||
/* querySelect.append(tmpVariable); querySelect.append(".deleted = false AND "); */
|
||||
querySelect.append(tableName);
|
||||
querySelect.append(".");
|
||||
querySelect.append(primaryKey);
|
||||
querySelect.append(" = ");
|
||||
querySelect.append(tmpVariable);
|
||||
querySelect.append(".");
|
||||
querySelect.append("object1Id ");
|
||||
if (!"sqlite".equals(ConfigBaseVariable.getDBType())) {
|
||||
querrySelect.append(" GROUP BY ");
|
||||
querrySelect.append(tmpVariable);
|
||||
querrySelect.append(".object1Id");
|
||||
querySelect.append(" GROUP BY ");
|
||||
querySelect.append(tmpVariable);
|
||||
querySelect.append(".object1Id");
|
||||
}
|
||||
querrySelect.append(") AS ");
|
||||
querrySelect.append(name);
|
||||
querrySelect.append(" ");
|
||||
querySelect.append(") AS ");
|
||||
querySelect.append(name);
|
||||
querySelect.append(" ");
|
||||
/* " (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" + */
|
||||
elemCount.inc();
|
||||
count.inc();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateQuerry( //
|
||||
public void generateQuery(//
|
||||
@NotNull final String tableName, //
|
||||
@NotNull final String primaryKey, //
|
||||
@NotNull final Field field, //
|
||||
@NotNull final StringBuilder querrySelect, //
|
||||
@NotNull final StringBuilder querry, //
|
||||
@NotNull final StringBuilder querySelect, //
|
||||
@NotNull final StringBuilder query, //
|
||||
@NotNull final String name, //
|
||||
@NotNull final CountInOut elemCount, //
|
||||
final QueryOptions options //
|
||||
@NotNull final CountInOut count, //
|
||||
final QueryOptions options//
|
||||
) throws Exception {
|
||||
if (field.getType() != List.class) {
|
||||
return;
|
||||
}
|
||||
final Class<?> objectClass = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
|
||||
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);
|
||||
if (decorators == null) {
|
||||
@@ -173,13 +179,13 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
if (decorators.fetch() == FetchType.EAGER) {
|
||||
throw new DataAccessException("EAGER is not supported for list of element...");
|
||||
} else {
|
||||
generateConcatQuerry(tableName, field, querrySelect, querry, name, elemCount, options);
|
||||
generateConcatQuery(tableName, primaryKey, field, querySelect, query, name, count, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillFromQuerry( //
|
||||
public void fillFromQuery( //
|
||||
final ResultSet rs, //
|
||||
final Field field, //
|
||||
final Object data, //
|
||||
@@ -198,7 +204,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
count.inc();
|
||||
return;
|
||||
} 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);
|
||||
count.inc();
|
||||
return;
|
||||
@@ -208,9 +214,10 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
return;
|
||||
}
|
||||
if (objectClass == decorators.targetEntity()) {
|
||||
final Class<?> foreignKeyType = AnnotationTools.getPrimaryKeyField(objectClass).getType();
|
||||
if (decorators.fetch() == FetchType.EAGER) {
|
||||
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);
|
||||
// field.set(data, idList);
|
||||
count.inc();
|
||||
@@ -229,8 +236,8 @@ public class AddOnManyToMany implements DataAccessAddOn {
|
||||
};
|
||||
lazyCall.add(lambda);
|
||||
}
|
||||
} else if (objectClass == UUID.class) {
|
||||
final List<UUID> idList = DataAccess.getListOfUUIDs(rs, count.value, SEPARATOR_UUID);
|
||||
} else if (foreignKeyType == UUID.class) {
|
||||
final List<UUID> idList = DataAccess.getListOfRawUUIDs(rs, count.value);
|
||||
// field.set(data, idList);
|
||||
count.inc();
|
||||
if (idList != null && idList.size() > 0) {
|
||||
|
||||
@@ -132,13 +132,14 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateQuerry( //
|
||||
public void generateQuery(//
|
||||
@NotNull final String tableName, //
|
||||
@NotNull final String primaryKey, //
|
||||
@NotNull final Field field, //
|
||||
@NotNull final StringBuilder querrySelect, //
|
||||
@NotNull final StringBuilder querry, //
|
||||
@NotNull final StringBuilder querySelect, //
|
||||
@NotNull final StringBuilder query, //
|
||||
@NotNull final String name, //
|
||||
@NotNull final CountInOut elemCount, //
|
||||
@NotNull final CountInOut count, //
|
||||
final QueryOptions options//
|
||||
) throws Exception {
|
||||
if (field.getType() == Long.class //
|
||||
@@ -146,37 +147,37 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
||||
|| field.getType() == Short.class //
|
||||
|| field.getType() == String.class //
|
||||
|| field.getType() == UUID.class) {
|
||||
querrySelect.append(" ");
|
||||
querrySelect.append(tableName);
|
||||
querrySelect.append(".");
|
||||
querrySelect.append(name);
|
||||
elemCount.inc();
|
||||
querySelect.append(" ");
|
||||
querySelect.append(tableName);
|
||||
querySelect.append(".");
|
||||
querySelect.append(name);
|
||||
count.inc();
|
||||
return;
|
||||
}
|
||||
final ManyToOne decorators = field.getDeclaredAnnotation(ManyToOne.class);
|
||||
if (field.getType() == decorators.targetEntity()) {
|
||||
if (decorators.fetch() == FetchType.EAGER) {
|
||||
// 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 String subTableName = AnnotationTools.getTableName(subType);
|
||||
final Field idField = AnnotationTools.getFieldOfId(subType);
|
||||
querry.append("LEFT OUTER JOIN `");
|
||||
querry.append(subTableName);
|
||||
querry.append("` ON ");
|
||||
querry.append(subTableName);
|
||||
querry.append(".");
|
||||
querry.append(AnnotationTools.getFieldName(idField));
|
||||
querry.append(" = ");
|
||||
querry.append(tableName);
|
||||
querry.append(".");
|
||||
querry.append(AnnotationTools.getFieldName(field));
|
||||
query.append("LEFT OUTER JOIN `");
|
||||
query.append(subTableName);
|
||||
query.append("` ON ");
|
||||
query.append(subTableName);
|
||||
query.append(".");
|
||||
query.append(AnnotationTools.getFieldName(idField));
|
||||
query.append(" = ");
|
||||
query.append(tableName);
|
||||
query.append(".");
|
||||
query.append(AnnotationTools.getFieldName(field));
|
||||
} else {
|
||||
querrySelect.append(" ");
|
||||
querrySelect.append(tableName);
|
||||
querrySelect.append(".");
|
||||
querrySelect.append(name);
|
||||
elemCount.inc();
|
||||
querySelect.append(" ");
|
||||
querySelect.append(tableName);
|
||||
querySelect.append(".");
|
||||
querySelect.append(name);
|
||||
count.inc();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -185,7 +186,7 @@ public class AddOnManyToOne implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
@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) {
|
||||
final Long foreignKey = rs.getLong(count.value);
|
||||
count.inc();
|
||||
|
||||
@@ -103,17 +103,25 @@ public class AddOnOneToMany implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateQuerry(@NotNull final String tableName, @NotNull final Field field, @NotNull final StringBuilder querrySelect, @NotNull final StringBuilder querry, @NotNull final String name,
|
||||
@NotNull final CountInOut elemCount, final QueryOptions options) {
|
||||
querrySelect.append(" ");
|
||||
querrySelect.append(tableName);
|
||||
querrySelect.append(".");
|
||||
querrySelect.append(name);
|
||||
elemCount.inc();
|
||||
public void generateQuery(//
|
||||
@NotNull final String tableName, //
|
||||
@NotNull final String primaryKey, //
|
||||
@NotNull final Field field, //
|
||||
@NotNull final StringBuilder querySelect, //
|
||||
@NotNull final StringBuilder query, //
|
||||
@NotNull final String name, //
|
||||
@NotNull final CountInOut count, //
|
||||
final QueryOptions options//
|
||||
) {
|
||||
querySelect.append(" ");
|
||||
querySelect.append(tableName);
|
||||
querySelect.append(".");
|
||||
querySelect.append(name);
|
||||
count.inc();
|
||||
}
|
||||
|
||||
@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 {
|
||||
final Long foreignKey = rs.getLong(count.value);
|
||||
count.inc();
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.slf4j.LoggerFactory;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
|
||||
// TODO: maybe deprecated ==> use DataJson instead...
|
||||
@Deprecated
|
||||
public class AddOnSQLTableExternalForeinKeyAsList implements DataAccessAddOn {
|
||||
static final Logger LOGGER = LoggerFactory.getLogger(AddOnManyToMany.class);
|
||||
static final String SEPARATOR = "-";
|
||||
@@ -87,17 +88,25 @@ public class AddOnSQLTableExternalForeinKeyAsList implements DataAccessAddOn {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generateQuerry(@NotNull final String tableName, @NotNull final Field field, @NotNull final StringBuilder querrySelect, @NotNull final StringBuilder querry, @NotNull final String name,
|
||||
@NotNull final CountInOut elemCount, final QueryOptions options) {
|
||||
elemCount.inc();
|
||||
querrySelect.append(" ");
|
||||
querrySelect.append(tableName);
|
||||
querrySelect.append(".");
|
||||
querrySelect.append(name);
|
||||
public void generateQuery(//
|
||||
@NotNull final String tableName, //
|
||||
@NotNull final String primaryKey, //
|
||||
@NotNull final Field field, //
|
||||
@NotNull final StringBuilder querySelect, //
|
||||
@NotNull final StringBuilder query, //
|
||||
@NotNull final String name, //
|
||||
@NotNull final CountInOut count, //
|
||||
final QueryOptions options//
|
||||
) {
|
||||
count.inc();
|
||||
querySelect.append(" ");
|
||||
querySelect.append(tableName);
|
||||
querySelect.append(".");
|
||||
querySelect.append(name);
|
||||
}
|
||||
|
||||
@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 {
|
||||
final List<Long> idList = DataAccess.getListOfIds(rs, count.value, SEPARATOR);
|
||||
field.set(data, idList);
|
||||
|
||||
@@ -19,15 +19,15 @@ public class Condition extends QueryOption {
|
||||
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) {
|
||||
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) {
|
||||
this.condition.injectQuerry(ps, iii);
|
||||
this.condition.injectQuery(ps, iii);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class Condition extends QueryOption {
|
||||
return;
|
||||
}
|
||||
query.append(" WHERE (");
|
||||
this.condition.generateQuerry(query, tableName);
|
||||
this.condition.generateQuery(query, tableName);
|
||||
query.append(") ");
|
||||
if (exclude_deleted && deletedFieldName != null) {
|
||||
query.append("AND ");
|
||||
|
||||
@@ -166,7 +166,7 @@ public class MigrationEngine {
|
||||
}
|
||||
LOGGER.info("Create Table with : {}", sqlQuery.get(0));
|
||||
try {
|
||||
DataAccess.executeQuerry(sqlQuery.get(0));
|
||||
DataAccess.executeQuery(sqlQuery.get(0));
|
||||
} catch (SQLException | IOException ex) {
|
||||
ex.printStackTrace();
|
||||
throw new MigrationException("Fail to create the local DB model for migaration ==> wait administrator interventions");
|
||||
|
||||
@@ -98,7 +98,7 @@ public class MigrationSqlStep implements MigrationInterface {
|
||||
}
|
||||
try {
|
||||
if (action.action() != null) {
|
||||
DataAccess.executeQuerry(action.action());
|
||||
DataAccess.executeQuery(action.action());
|
||||
} else {
|
||||
action.async().doRequest();
|
||||
}
|
||||
|
||||
@@ -12,5 +12,5 @@ public class UUIDGenericData extends GenericTiming {
|
||||
@DefaultValue("(UUID_TO_BIN(UUID(), TRUE))")
|
||||
@Column(nullable = false, unique = true)
|
||||
@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;
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class DataTools {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String mediaPath = DataResource.getFileData(out.id);
|
||||
final String mediaPath = DataResource.getFileData(out.uuid);
|
||||
LOGGER.info("src = {}", tmpPath);
|
||||
LOGGER.info("dst = {}", mediaPath);
|
||||
Files.move(Paths.get(tmpPath), Paths.get(mediaPath), StandardCopyOption.ATOMIC_MOVE);
|
||||
@@ -246,7 +246,7 @@ public class DataTools {
|
||||
}
|
||||
} else if (data.deleted) {
|
||||
LOGGER.error("Data already exist but deleted");
|
||||
undelete(data.id);
|
||||
undelete(data.uuid);
|
||||
data.deleted = false;
|
||||
} else {
|
||||
LOGGER.error("Data already exist ... all good");
|
||||
@@ -254,9 +254,9 @@ public class DataTools {
|
||||
// Fist step: retrieve all the Id of each parents:...
|
||||
LOGGER.info("Find typeNode");
|
||||
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) {
|
||||
AddOnDataJson.addLink(clazz, idUUID, "covers", data.id);
|
||||
AddOnDataJson.addLink(clazz, idUUID, "covers", data.uuid);
|
||||
} else {
|
||||
throw new IOException("Fail to add Cover can not detect type...");
|
||||
}
|
||||
|
||||
@@ -135,6 +135,7 @@ public class RESTApi {
|
||||
if (clazz.equals(String.class)) {
|
||||
return (T) httpResponse.body();
|
||||
}
|
||||
LOGGER.trace("Receive model: {} with data: '{}'", clazz.getCanonicalName(), httpResponse.body());
|
||||
return this.mapper.readValue(httpResponse.body(), clazz);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import java.time.ZoneOffset;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.kar.archidata.exception.DataAccessException;
|
||||
|
||||
public class UuidUtils {
|
||||
|
||||
public static UUID asUuid(final BigInteger bigInteger) {
|
||||
@@ -16,7 +18,10 @@ public class UuidUtils {
|
||||
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 long firstLong = bb.getLong();
|
||||
final long secondLong = bb.getLong();
|
||||
|
||||
@@ -53,7 +53,7 @@ public class TestJson {
|
||||
final List<String> sqlCommand = DataFactory.createTable(SerializeAsJson.class);
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
DataAccess.executeSimpleQuerry(elem);
|
||||
DataAccess.executeSimpleQuery(elem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class TestListJson {
|
||||
final List<String> sqlCommand = DataFactory.createTable(SerializeListAsJson.class);
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
DataAccess.executeSimpleQuerry(elem);
|
||||
DataAccess.executeSimpleQuery(elem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class TestManyToMany {
|
||||
sqlCommand.addAll(sqlCommand2);
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
DataAccess.executeSimpleQuerry(elem);
|
||||
DataAccess.executeSimpleQuery(elem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public class TestManyToOne {
|
||||
sqlCommand.addAll(sqlCommand2);
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
DataAccess.executeSimpleQuerry(elem);
|
||||
DataAccess.executeSimpleQuery(elem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class TestOneToMany {
|
||||
final List<String> sqlCommand = DataFactory.createTable(TypesTable.class);
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
DataAccess.executeSimpleQuerry(elem);
|
||||
DataAccess.executeSimpleQuery(elem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public class TestRawQuery {
|
||||
final List<String> sqlCommand = DataFactory.createTable(TypesTable.class);
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
DataAccess.executeSimpleQuerry(elem);
|
||||
DataAccess.executeSimpleQuery(elem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ public class TestRawQuery {
|
||||
test.floatData = 7.0F;
|
||||
DataAccess.insert(test);
|
||||
{
|
||||
String querry = """
|
||||
String query = """
|
||||
SELECT *
|
||||
FROM TypesTable
|
||||
WHERE `intData` = ?
|
||||
@@ -91,7 +91,7 @@ public class TestRawQuery {
|
||||
""";
|
||||
List<Object> parameters = List.of(Integer.valueOf(99));
|
||||
// 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.assertEquals(3, retrieve.size());
|
||||
@@ -102,7 +102,7 @@ public class TestRawQuery {
|
||||
}
|
||||
{
|
||||
|
||||
String querry = """
|
||||
String query = """
|
||||
SELECT DISTINCT intData
|
||||
FROM TypesTable
|
||||
WHERE `intData` = ?
|
||||
@@ -110,7 +110,7 @@ public class TestRawQuery {
|
||||
""";
|
||||
List<Object> parameters = List.of(Integer.valueOf(99));
|
||||
// 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.assertEquals(1, retrieve.size());
|
||||
|
||||
@@ -65,7 +65,7 @@ public class TestSimpleTable {
|
||||
final List<String> sqlCommand = DataFactory.createTable(SimpleTable.class);
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
DataAccess.executeSimpleQuerry(elem);
|
||||
DataAccess.executeSimpleQuery(elem);
|
||||
}
|
||||
final SimpleTable test = new SimpleTable();
|
||||
test.data = TestSimpleTable.DATA_INJECTED;
|
||||
|
||||
@@ -65,7 +65,7 @@ public class TestSimpleTableSoftDelete {
|
||||
final List<String> sqlCommand = DataFactory.createTable(SimpleTableSoftDelete.class);
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
DataAccess.executeSimpleQuerry(elem);
|
||||
DataAccess.executeSimpleQuery(elem);
|
||||
}
|
||||
final SimpleTableSoftDelete test = new SimpleTableSoftDelete();
|
||||
test.data = TestSimpleTableSoftDelete.DATA_INJECTED;
|
||||
|
||||
@@ -53,7 +53,7 @@ public class TestTypeEnum1 {
|
||||
final List<String> sqlCommand = DataFactory.createTable(TypesEnum1.class);
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
DataAccess.executeSimpleQuerry(elem);
|
||||
DataAccess.executeSimpleQuery(elem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class TestTypeEnum2 {
|
||||
final List<String> sqlCommand = DataFactory.createTable(TypesEnum2.class);
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
DataAccess.executeSimpleQuerry(elem);
|
||||
DataAccess.executeSimpleQuery(elem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ public class TestTypes {
|
||||
final List<String> sqlCommand = DataFactory.createTable(TypesTable.class);
|
||||
for (final String elem : sqlCommand) {
|
||||
LOGGER.debug("request: '{}'", elem);
|
||||
DataAccess.executeSimpleQuerry(elem);
|
||||
DataAccess.executeSimpleQuery(elem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
0.8.0
|
||||
0.8.2
|
||||
|
||||
Reference in New Issue
Block a user