2024-09-18 13:37:11 +03:00
|
|
|
|
package Visual_DVM_2021.Passes.Server;
|
2023-12-06 01:50:11 +03:00
|
|
|
|
import Common.Current;
|
|
|
|
|
|
import Common.Database.DBObject;
|
|
|
|
|
|
import Common.Database.DBTable;
|
|
|
|
|
|
import Common.Database.Database;
|
|
|
|
|
|
import Common.UI.UI;
|
2024-09-18 13:37:11 +03:00
|
|
|
|
import Common.UI.VisualCache.VisualCaches;
|
2023-12-06 01:50:11 +03:00
|
|
|
|
import Repository.RepositoryServer;
|
|
|
|
|
|
import Repository.Server.ServerCode;
|
|
|
|
|
|
import Repository.Server.ServerExchangeUnit_2021;
|
|
|
|
|
|
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();
|
|
|
|
|
|
return UI.Warning(table.getCheckedCount()+" объектов будет удален(о).");
|
|
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
if (Current.Check(Log, table.CurrentName())){
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
}
|