Metodo Borrado Listo
This commit is contained in:
@@ -237,14 +237,47 @@ public class DepartamentoEXistDao extends AbstractGenericDao<Departamento> imple
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean update(Departamento entity) {
|
public boolean update(Departamento entity) {
|
||||||
throw new UnsupportedOperationException("Este método update debe ser implementado");
|
// throw new UnsupportedOperationException("Este método update debe ser
|
||||||
|
// implementado");
|
||||||
|
boolean exito = false;
|
||||||
|
|
||||||
|
return exito;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean delete(Departamento entity) {
|
public boolean delete(Departamento entity) {
|
||||||
throw new UnsupportedOperationException("Este método delete debe ser implementado");
|
// throw new UnsupportedOperationException("Este método delete debe ser
|
||||||
|
// implementado");
|
||||||
|
boolean exito = false;
|
||||||
|
int numeroDep = entity.getDeptno();
|
||||||
|
|
||||||
|
try (Collection col = DatabaseManager.getCollection(dataSource.getUrl() + dataSource.getColeccion(),
|
||||||
|
dataSource.getUser(), dataSource.getPwd())) {
|
||||||
|
|
||||||
|
XQueryService xqs = (XQueryService) col.getService("XQueryService", "1.0");
|
||||||
|
xqs.setProperty("indent", "yes");
|
||||||
|
|
||||||
|
// Consulta de borrado para o eXide
|
||||||
|
String consulta = "update delete //DEP_ROW[DEPT_NO=" + numeroDep + "]";
|
||||||
|
|
||||||
|
// Ver se esta o departamento que temos que eliminar.
|
||||||
|
ResourceSet check = xqs.query("//DEP_ROW[DEPT_NO=" + numeroDep + "]");
|
||||||
|
if (check.getSize() == 0) {
|
||||||
|
System.out.println("Non se atopa o departamento con ID " + numeroDep);
|
||||||
|
throw new InstanceNotFoundException(numeroDep, Departamento.class.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Executamos a consulta
|
||||||
|
xqs.query(consulta);
|
||||||
|
|
||||||
|
System.out.println("Departamento co ID " + numeroDep + " eliminado con éxito.");
|
||||||
|
exito = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (InstanceNotFoundException | XMLDBException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return exito;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -274,12 +307,23 @@ public class DepartamentoEXistDao extends AbstractGenericDao<Departamento> imple
|
|||||||
Resource res = null;
|
Resource res = null;
|
||||||
|
|
||||||
while (i.hasMoreResources()) {
|
while (i.hasMoreResources()) {
|
||||||
|
try {
|
||||||
res = i.nextResource();
|
res = i.nextResource();
|
||||||
departamento = stringNodeToDepartamento(res.getContent().toString());
|
departamento = stringNodeToDepartamento(res.getContent().toString());
|
||||||
System.out.println(departamento.toString());
|
System.out.println(departamento.toString());
|
||||||
listaDepartamentos.add(departamento);
|
listaDepartamentos.add(departamento);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Non esquecer liberar os recursos
|
||||||
|
finally {
|
||||||
|
try {
|
||||||
|
((EXistResource) res).freeResources();
|
||||||
|
} catch (XMLDBException xe) {
|
||||||
|
departamento = null;
|
||||||
|
xe.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (XMLDBException e) {
|
catch (XMLDBException e) {
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ public class DeptWindow extends JFrame {
|
|||||||
departamentoServicio = new ServicioDepartamento();
|
departamentoServicio = new ServicioDepartamento();
|
||||||
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
setBounds(100, 100, 847, 772);
|
setBounds(100, 100, 847, 550);
|
||||||
contentPane = new JPanel();
|
contentPane = new JPanel();
|
||||||
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user