En DepartamentoExistDao se completa el metodo findAll, falta la excepccion.
This commit is contained in:
@@ -249,8 +249,47 @@ public class DepartamentoEXistDao extends AbstractGenericDao<Departamento> imple
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Departamento> findAll() {
|
public List<Departamento> findAll() {
|
||||||
throw new UnsupportedOperationException("Este método findAll debe ser implementado");
|
List<Departamento> listaDepartamentos = new ArrayList<>();
|
||||||
|
Departamento departamento = null;
|
||||||
|
|
||||||
|
try (Collection col = DatabaseManager.getCollection(dataSource.getUrl() + dataSource.getColeccion(),
|
||||||
|
dataSource.getUser(), dataSource.getPwd())) {
|
||||||
|
System.out.println("A conexion coa base de datos foi establecida correctamente");
|
||||||
|
|
||||||
|
XQueryService xqs = (XQueryService) col.getService("XQueryService", "1.0");
|
||||||
|
xqs.setProperty("indent", "yes");
|
||||||
|
|
||||||
|
CompiledExpression compiled = xqs.compile("//DEP_ROW");
|
||||||
|
ResourceSet result = xqs.execute(compiled);
|
||||||
|
|
||||||
|
// Para enviar unha excepcion se non se atopa nada
|
||||||
|
/*
|
||||||
|
* if (result.getSize() == 0)
|
||||||
|
* throw new InstanceNotFoundException(id, Departamento.class.getName());
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Iteramos sobre os resultados e convertimos cada nodo a un obxecto
|
||||||
|
// Departamento
|
||||||
|
ResourceIterator i = result.getIterator();
|
||||||
|
Resource res = null;
|
||||||
|
|
||||||
|
while (i.hasMoreResources()) {
|
||||||
|
res = i.nextResource();
|
||||||
|
departamento = stringNodeToDepartamento(res.getContent().toString());
|
||||||
|
System.out.println(departamento.toString());
|
||||||
|
listaDepartamentos.add(departamento);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
catch (XMLDBException e) {
|
||||||
|
listaDepartamentos = null;
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// throw new UnsupportedOperationException("Este método findAll debe ser
|
||||||
|
// implementado");
|
||||||
|
return listaDepartamentos;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user