[FIX] correct the ID in uuid for uuid primary-key
This commit is contained in:
parent
15688f93e5
commit
d4eb9c2a5f
@ -188,9 +188,21 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a remoteKey to the covers list of a data entry identified by the given class type and ID.
|
||||
* If the covers list is null, it initializes it. If the remoteKey already exists in the list,
|
||||
* the method returns without making any changes.
|
||||
*
|
||||
* @param clazz The class type to retrieve the table name from.
|
||||
* @param id The ID of the data object to fetch.
|
||||
* @param column The name of the column (currently not used, but may be used for specifying a field name).
|
||||
* @param remoteKey The UUID to add to the covers list.
|
||||
* @throws Exception If an error occurs during data retrieval or update.
|
||||
*/
|
||||
public static void addLink(final Class<?> clazz, final Long id, final String column, final UUID remoteKey)
|
||||
throws Exception {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
// TODO: Get primary key name
|
||||
final TableCoversLongUUID data = DataAccess.get(TableCoversLongUUID.class, id,
|
||||
new OverrideTableName(tableName));
|
||||
if (data.covers == null) {
|
||||
@ -205,10 +217,21 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));// TODO: ,new OverrideFieldName("covers", column));
|
||||
}
|
||||
|
||||
public static void addLink(final Class<?> clazz, final UUID id, final String column, final UUID remoteKey)
|
||||
/**
|
||||
* Adds a remoteKey to the covers list of a data entry identified by the given class type and ID.
|
||||
* If the covers list is null, it initializes it. If the remoteKey already exists in the list,
|
||||
* the method returns without making any changes.
|
||||
*
|
||||
* @param clazz The class type to retrieve the table name from.
|
||||
* @param id The ID of the data object to fetch.
|
||||
* @param column The name of the column (currently not used, but may be used for specifying a field name).
|
||||
* @param remoteKey The UUID to add to the covers list.
|
||||
* @throws Exception If an error occurs during data retrieval or update.
|
||||
*/
|
||||
public static void addLink(final Class<?> clazz, final UUID uuid, final String column, final UUID remoteKey)
|
||||
throws Exception {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversUUIDUUID data = DataAccess.get(TableCoversUUIDUUID.class, id,
|
||||
final TableCoversUUIDUUID data = DataAccess.get(TableCoversUUIDUUID.class, uuid,
|
||||
new OverrideTableName(tableName));
|
||||
if (data.covers == null) {
|
||||
data.covers = new ArrayList<>();
|
||||
@ -222,10 +245,10 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
|
||||
}
|
||||
|
||||
public static void addLink(final Class<?> clazz, final UUID id, final String column, final Long remoteKey)
|
||||
public static void addLink(final Class<?> clazz, final UUID uuid, final String column, final Long remoteKey)
|
||||
throws Exception {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversUUIDLong data = DataAccess.get(TableCoversUUIDLong.class, id,
|
||||
final TableCoversUUIDLong data = DataAccess.get(TableCoversUUIDLong.class, uuid,
|
||||
new OverrideTableName(tableName));
|
||||
if (data.covers == null) {
|
||||
data.covers = new ArrayList<>();
|
||||
@ -236,13 +259,13 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
}
|
||||
}
|
||||
data.covers.add(remoteKey);
|
||||
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
|
||||
DataAccess.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
||||
}
|
||||
|
||||
public static void removeLink(final Class<?> clazz, final UUID id, final String column, final Long remoteKey)
|
||||
public static void removeLink(final Class<?> clazz, final UUID uuid, final String column, final Long remoteKey)
|
||||
throws Exception {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversUUIDLong data = DataAccess.get(TableCoversUUIDLong.class, id,
|
||||
final TableCoversUUIDLong data = DataAccess.get(TableCoversUUIDLong.class, uuid,
|
||||
new OverrideTableName(tableName));
|
||||
if (data.covers == null) {
|
||||
return;
|
||||
@ -255,13 +278,13 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
newList.add(elem);
|
||||
}
|
||||
data.covers = newList;
|
||||
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
|
||||
DataAccess.update(data, data.uuid, List.of("covers"), new OverrideTableName(tableName));
|
||||
}
|
||||
|
||||
public static void removeLink(final Class<?> clazz, final UUID id, final String column, final UUID remoteKey)
|
||||
public static void removeLink(final Class<?> clazz, final UUID uuid, final String column, final UUID remoteKey)
|
||||
throws Exception {
|
||||
final String tableName = AnnotationTools.getTableName(clazz);
|
||||
final TableCoversUUIDUUID data = DataAccess.get(TableCoversUUIDUUID.class, id,
|
||||
final TableCoversUUIDUUID data = DataAccess.get(TableCoversUUIDUUID.class, uuid,
|
||||
new OverrideTableName(tableName));
|
||||
if (data.covers == null) {
|
||||
return;
|
||||
@ -314,9 +337,4 @@ public class AddOnDataJson implements DataAccessAddOn {
|
||||
data.covers = newList;
|
||||
DataAccess.update(data, data.id, List.of("covers"), new OverrideTableName(tableName));
|
||||
}
|
||||
/* public static <TYPE> void addLink(final Class<TYPE> clazz, final Object localKey, final String column, final Object remoteKey) throws Exception { final String tableName =
|
||||
* AnnotationTools.getTableName(clazz); final TYPE data = DataAccess.get(clazz, localKey); // TODO: add filter of the "column" // find the field column: // add the remoteKey in the list: // post
|
||||
* new data in the DB final String linkTableName = generateLinkTableName(this.tableName, this.column); final LinkTable insertElement = new LinkTable(this.localKey, this.remoteKey);
|
||||
* DataAccess.insert(insertElement, new OverrideTableName(linkTableName)); } */
|
||||
|
||||
}
|
||||
|
@ -4,11 +4,10 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.kar.archidata.annotation.DataJson;
|
||||
import org.kar.archidata.model.GenericDataSoftDelete;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
public class TableCoversLongUUID extends GenericDataSoftDelete {
|
||||
public class TableCoversLongUUID {
|
||||
public TableCoversLongUUID() {
|
||||
// nothing to do...
|
||||
}
|
||||
@ -18,8 +17,10 @@ public class TableCoversLongUUID extends GenericDataSoftDelete {
|
||||
this.covers = covers;
|
||||
}
|
||||
|
||||
@Id
|
||||
public Long id;
|
||||
|
||||
@DataJson()
|
||||
@Column(nullable = false)
|
||||
public List<UUID> covers;
|
||||
|
||||
}
|
||||
|
@ -4,26 +4,22 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.kar.archidata.annotation.DataJson;
|
||||
import org.kar.archidata.model.GenericDataSoftDelete;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
public class TableCoversUUIDLong extends GenericDataSoftDelete {
|
||||
public class TableCoversUUIDLong {
|
||||
public TableCoversUUIDLong() {
|
||||
// nothing to do...
|
||||
}
|
||||
|
||||
public TableCoversUUIDLong(final UUID id, final List<Long> covers) {
|
||||
this.id = id;
|
||||
public TableCoversUUIDLong(final UUID uuid, final List<Long> covers) {
|
||||
this.uuid = uuid;
|
||||
this.covers = covers;
|
||||
}
|
||||
|
||||
@Column(nullable = false)
|
||||
@Id
|
||||
public UUID id;
|
||||
public UUID uuid;
|
||||
@DataJson()
|
||||
@Column(nullable = false)
|
||||
public List<Long> covers;
|
||||
|
||||
}
|
||||
|
@ -14,14 +14,14 @@ public class TableCoversUUIDUUID extends GenericDataSoftDelete {
|
||||
// nothing to do...
|
||||
}
|
||||
|
||||
public TableCoversUUIDUUID(final UUID id, final List<UUID> covers) {
|
||||
this.id = id;
|
||||
public TableCoversUUIDUUID(final UUID uuid, final List<UUID> covers) {
|
||||
this.uuid = uuid;
|
||||
this.covers = covers;
|
||||
}
|
||||
|
||||
@Column(nullable = false)
|
||||
@Id
|
||||
public UUID id;
|
||||
public UUID uuid;
|
||||
@DataJson()
|
||||
@Column(nullable = false)
|
||||
public List<UUID> covers;
|
||||
|
Loading…
x
Reference in New Issue
Block a user