[FIX] correct the uuid list getted

This commit is contained in:
Edouard DUPIN 2024-04-27 08:52:55 +02:00
parent e183ea7ff6
commit 6c8ea9e46e
3 changed files with 17 additions and 10 deletions

View File

@ -213,29 +213,29 @@ public class DataAccess {
return out;
}
public static byte[][] splitIntoGroupsOf32Bytes(final byte[] input) {
public static byte[][] splitIntoGroupsOf16Bytes(final byte[] input) {
final int inputLength = input.length;
final int numOfGroups = (inputLength + 31) / 32; // Calculate the number of groups needed
final byte[][] groups = new byte[numOfGroups][32];
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 * 32;
final int endIndex = Math.min(startIndex + 32, inputLength);
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 {
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 = splitIntoGroupsOf32Bytes(trackString);
final byte[][] elements = splitIntoGroupsOf16Bytes(trackString);
final List<UUID> out = new ArrayList<>();
for (final byte[] elem : elements) {
final UUID tmp = UUID.nameUUIDFromBytes(elem);
final UUID tmp = UuidUtils.asUuid(elem);
out.add(tmp);
}
return out;

View File

@ -9,6 +9,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.apache.velocity.tools.generic.ResourceTool.Key;
import org.kar.archidata.annotation.AnnotationTools;
import org.kar.archidata.dataAccess.CountInOut;
import org.kar.archidata.dataAccess.DataAccess;
@ -133,6 +134,7 @@ public class AddOnManyToMany implements DataAccessAddOn {
querrySelect.append(" WHERE ");
/* querrySelect.append(tmpVariable); querrySelect.append(".deleted = false AND "); */
querrySelect.append(tableName);
final la il faut final retouvrt la primary final Key de la final table courante ...
querrySelect.append(".id = ");
querrySelect.append(tmpVariable);
querrySelect.append(".");
@ -200,7 +202,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;

View File

@ -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();