2024-09-18 13:37:11 +03:00
|
|
|
|
package Visual_DVM_2021.Passes.Server;
|
2024-10-09 23:37:58 +03:00
|
|
|
|
import Common.Current_;
|
2024-10-07 00:58:29 +03:00
|
|
|
|
import Common.Database.Objects.DBObject;
|
|
|
|
|
|
import Common.Database.Tables.DBTable;
|
2023-12-06 01:50:11 +03:00
|
|
|
|
import Common.Database.Database;
|
2024-10-08 22:33:49 +03:00
|
|
|
|
import Common.Visual.CommonUI;
|
2024-10-08 23:45:06 +03:00
|
|
|
|
import _VisualDVM.ServerObjectsCache.VisualCaches;
|
2024-10-09 22:21:57 +03:00
|
|
|
|
import _VisualDVM.Repository.RepositoryServer;
|
|
|
|
|
|
import _VisualDVM.Repository.Server.ServerCode;
|
|
|
|
|
|
import _VisualDVM.Repository.Server.ServerExchangeUnit_2021;
|
2023-12-06 01:50:11 +03:00
|
|
|
|
import javafx.util.Pair;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Vector;
|
|
|
|
|
|
public class DeleteServerObjects <S extends RepositoryServer, D extends DBObject> extends RepositoryPass<S, Vector<Object>> {
|
|
|
|
|
|
protected Class<D> d; //класс объектов.
|
|
|
|
|
|
//---
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public String getIconPath() {
|
|
|
|
|
|
return "/icons/Delete.png";
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
public String getButtonText() {
|
|
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
//---
|
|
|
|
|
|
protected Database getDb() {
|
|
|
|
|
|
return server.db;
|
|
|
|
|
|
}
|
|
|
|
|
|
protected String getEmail(){return null;}
|
|
|
|
|
|
//---
|
|
|
|
|
|
public DeleteServerObjects(S server_in, Class<D> d_in) {
|
|
|
|
|
|
super(server_in);
|
|
|
|
|
|
d = d_in;
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected boolean canStart(Object... args) throws Exception {
|
|
|
|
|
|
DBTable table =getDb().tables.get(d);
|
|
|
|
|
|
if (table.getCheckedCount()>0) {
|
|
|
|
|
|
target = table.getCheckedKeys();
|
2024-10-08 22:33:49 +03:00
|
|
|
|
return CommonUI.Warning(table.getCheckedCount()+" объектов будет удален(о).");
|
2023-12-06 01:50:11 +03:00
|
|
|
|
}
|
|
|
|
|
|
else {
|
2024-10-09 23:37:58 +03:00
|
|
|
|
if (Current_.Check(Log, table.CurrentName())){
|
2023-12-06 01:50:11 +03:00
|
|
|
|
target = new Vector<>();
|
|
|
|
|
|
target.add(table.getCurrent().getPK());
|
|
|
|
|
|
return getDb().tables.get(d).CheckCurrent(Log) && getDb().tables.get(d).ShowDeleteObjectDialog(table.getCurrent());
|
|
|
|
|
|
}
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2024-09-18 13:37:11 +03:00
|
|
|
|
}
|
2023-12-06 01:50:11 +03:00
|
|
|
|
//Очищаем все связанные таблицы, чтобы не допустить перерисовки во время удаления объекта.
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void showPreparation() throws Exception {
|
|
|
|
|
|
getDb().tables.get(d).ClearUI();
|
|
|
|
|
|
for (Class dep : getDb().tables.get(d).getFKDependencies().keySet()) {
|
|
|
|
|
|
switch (getDb().tables.get(d).getFKDependencies().get(dep).data) {
|
|
|
|
|
|
case NONE:
|
|
|
|
|
|
case DROP:
|
|
|
|
|
|
break;
|
|
|
|
|
|
case DELETE:
|
|
|
|
|
|
getDb().tables.get(dep).ClearUI();
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void ServerAction() throws Exception {
|
|
|
|
|
|
Command(new ServerExchangeUnit_2021(ServerCode.DeleteObjectsByPK, getEmail(),new Pair<>(d, target)));
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
|
|
|
protected void performFinish() throws Exception {
|
|
|
|
|
|
super.performFinish();
|
|
|
|
|
|
passes.get(getDb().getSynchronizePassCode()).Do();
|
2024-09-19 00:24:36 +03:00
|
|
|
|
for (Object key: target){
|
|
|
|
|
|
VisualCaches.DeleteCache(d, key);
|
|
|
|
|
|
}
|
2023-12-06 01:50:11 +03:00
|
|
|
|
}
|
|
|
|
|
|
}
|