Commit 387c46e0 by Patryk Czarnik

try-with-res

parent 4ad7d1be
......@@ -11,7 +11,6 @@ import hr.model.Employee;
public class Odczyt04_WszystkieRekordy_Stream {
public static void main(String[] args) {
EntityManagerFactory emf = null;
EntityManager em = null;
try {
......@@ -20,11 +19,11 @@ public class Odczyt04_WszystkieRekordy_Stream {
TypedQuery<Employee> query = em.createNamedQuery("Employee.findAll", Employee.class);
// Używając Stream zamiast List pobieramy dane "strumieniowo", czyli pojedynczo i przetwarzamy na bieżąco.
Stream<Employee> stream = query.getResultStream();
try(Stream<Employee> stream = query.getResultStream()) {
stream.forEach(emp -> {
System.out.println(emp.getFirstName() + " " + emp.getLastName());
});
}
} finally {
if (em != null)
em.close();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment