Metodo Update Listo
This commit is contained in:
@@ -240,6 +240,32 @@ public class DepartamentoEXistDao extends AbstractGenericDao<Departamento> imple
|
|||||||
// throw new UnsupportedOperationException("Este método update debe ser
|
// throw new UnsupportedOperationException("Este método update debe ser
|
||||||
// implementado");
|
// implementado");
|
||||||
boolean exito = false;
|
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");
|
||||||
|
|
||||||
|
String xmlFormatoString = toXMLString(entity);
|
||||||
|
|
||||||
|
String consulta = "update replace //DEP_ROW[DEPT_NO=" + numeroDep + "] with " + xmlFormatoString;
|
||||||
|
|
||||||
|
// 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;
|
return exito;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user