[FEAT] update naming of the TableCoversGeneric to be generic
This commit is contained in:
parent
70a9be86b2
commit
7f5987338a
@ -219,62 +219,63 @@ public class AddOnDataJson implements DataAccessAddOn {
|
|||||||
public static void addLink(
|
public static void addLink(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
final Class<?> clazz,
|
final Class<?> clazz,
|
||||||
final String clazzPrimaryKeyName,
|
String clazzPrimaryKeyName,
|
||||||
final Object clazzPrimaryKeyValue,
|
final Object clazzPrimaryKeyValue,
|
||||||
final String fieldNameToUpdate,
|
final String fieldNameToUpdate,
|
||||||
final Object valueToAdd) throws Exception {
|
final Object valueToAdd) throws Exception {
|
||||||
final String tableName = AnnotationTools.getTableName(clazz);
|
final String tableName = AnnotationTools.getTableName(clazz);
|
||||||
final QueryOptions options = new QueryOptions(new OverrideTableName(tableName),
|
final QueryOptions options = new QueryOptions(new OverrideTableName(tableName),
|
||||||
new OptionSpecifyType("id", clazzPrimaryKeyValue.getClass()),
|
new OptionSpecifyType("idOfTheObject", clazzPrimaryKeyValue.getClass()),
|
||||||
new OptionSpecifyType("covers", valueToAdd.getClass(), true));
|
new OptionSpecifyType("filedNameOfTheObject", valueToAdd.getClass(), true));
|
||||||
if (clazzPrimaryKeyName != null && !clazzPrimaryKeyName.equals("id")) {
|
if (clazzPrimaryKeyName == null) {
|
||||||
options.add(new OptionRenameColumn("id", clazzPrimaryKeyName));
|
clazzPrimaryKeyName = "id";
|
||||||
}
|
|
||||||
if (fieldNameToUpdate != null && !fieldNameToUpdate.equals("covers")) {
|
|
||||||
options.add(new OptionRenameColumn("covers", fieldNameToUpdate));
|
|
||||||
}
|
}
|
||||||
|
options.add(new OptionRenameColumn("idOfTheObject", clazzPrimaryKeyName));
|
||||||
|
options.add(new OptionRenameColumn("filedNameOfTheObject", fieldNameToUpdate));
|
||||||
final TableCoversGeneric data = ioDb.get(TableCoversGeneric.class, clazzPrimaryKeyValue, options.getAllArray());
|
final TableCoversGeneric data = ioDb.get(TableCoversGeneric.class, clazzPrimaryKeyValue, options.getAllArray());
|
||||||
if (data.covers == null) {
|
if (data.filedNameOfTheObject == null) {
|
||||||
data.covers = new ArrayList<>();
|
data.filedNameOfTheObject = new ArrayList<>();
|
||||||
}
|
}
|
||||||
for (final Object elem : data.covers) {
|
for (final Object elem : data.filedNameOfTheObject) {
|
||||||
if (elem.equals(valueToAdd)) {
|
if (elem.equals(valueToAdd)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.covers.add(valueToAdd);
|
data.filedNameOfTheObject.add(valueToAdd);
|
||||||
ioDb.update(data, data.id, List.of("covers"), options.getAllArray());
|
ioDb.update(data, data.idOfTheObject, List.of("filedNameOfTheObject"), options.getAllArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeLink(
|
public static void removeLink(
|
||||||
final DBAccess ioDb,
|
final DBAccess ioDb,
|
||||||
final Class<?> clazz,
|
final Class<?> clazz,
|
||||||
final String clazzPrimaryKeyName,
|
String clazzPrimaryKeyName,
|
||||||
final Object clazzPrimaryKeyValue,
|
final Object clazzPrimaryKeyValue,
|
||||||
final String fieldNameToUpdate,
|
final String fieldNameToUpdate,
|
||||||
final Object valueToRemove) throws Exception {
|
final Object valueToRemove) throws Exception {
|
||||||
final String tableName = AnnotationTools.getTableName(clazz);
|
final String tableName = AnnotationTools.getTableName(clazz);
|
||||||
final QueryOptions options = new QueryOptions(new OverrideTableName(tableName),
|
final QueryOptions options = new QueryOptions(new OverrideTableName(tableName),
|
||||||
new OptionSpecifyType("id", clazzPrimaryKeyValue.getClass()),
|
new OptionSpecifyType("idOfTheObject", clazzPrimaryKeyValue.getClass()),
|
||||||
new OptionSpecifyType("covers", valueToRemove.getClass(), true));
|
new OptionSpecifyType("filedNameOfTheObject", valueToRemove.getClass(), true));
|
||||||
if (clazzPrimaryKeyName != null && !clazzPrimaryKeyName.equals("id")) {
|
if (clazzPrimaryKeyName == null) {
|
||||||
options.add(new OptionRenameColumn("id", clazzPrimaryKeyName));
|
clazzPrimaryKeyName = "id";
|
||||||
}
|
|
||||||
if (fieldNameToUpdate != null && !fieldNameToUpdate.equals("covers")) {
|
|
||||||
options.add(new OptionRenameColumn("covers", fieldNameToUpdate));
|
|
||||||
}
|
}
|
||||||
|
options.add(new OptionRenameColumn("idOfTheObject", clazzPrimaryKeyName));
|
||||||
|
options.add(new OptionRenameColumn("filedNameOfTheObject", fieldNameToUpdate));
|
||||||
final TableCoversGeneric data = ioDb.get(TableCoversGeneric.class, clazzPrimaryKeyValue, options.getAllArray());
|
final TableCoversGeneric data = ioDb.get(TableCoversGeneric.class, clazzPrimaryKeyValue, options.getAllArray());
|
||||||
if (data.covers == null) {
|
if (data.filedNameOfTheObject == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final List<Object> newList = new ArrayList<>();
|
final List<Object> newList = new ArrayList<>();
|
||||||
for (final Object elem : data.covers) {
|
for (final Object elem : data.filedNameOfTheObject) {
|
||||||
if (elem.equals(valueToRemove)) {
|
if (elem.equals(valueToRemove)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
newList.add(elem);
|
newList.add(elem);
|
||||||
}
|
}
|
||||||
data.covers = newList;
|
data.filedNameOfTheObject = newList;
|
||||||
ioDb.update(data, data.id, List.of("covers"), options.getAllArray());
|
if (data.filedNameOfTheObject.isEmpty()) {
|
||||||
|
data.filedNameOfTheObject = null;
|
||||||
|
}
|
||||||
|
ioDb.update(data, data.idOfTheObject, List.of("filedNameOfTheObject"), options.getAllArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,15 +11,15 @@ public class TableCoversGeneric {
|
|||||||
// nothing to do...
|
// nothing to do...
|
||||||
}
|
}
|
||||||
|
|
||||||
public TableCoversGeneric(final Object id, final List<Object> covers) {
|
public TableCoversGeneric(final Object idOfTheObject, final List<Object> filedNameOfTheObject) {
|
||||||
this.id = id;
|
this.idOfTheObject = idOfTheObject;
|
||||||
this.covers = covers;
|
this.filedNameOfTheObject = filedNameOfTheObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
public Object id;
|
public Object idOfTheObject;
|
||||||
|
|
||||||
@DataJson()
|
@DataJson()
|
||||||
public List<Object> covers;
|
public List<Object> filedNameOfTheObject;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user