|
|
|
@ -6132,17 +6132,11 @@ that uses the `@PersistenceUnit` annotation: |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Collection loadProductsByCategory(String category) { |
|
|
|
public Collection loadProductsByCategory(String category) { |
|
|
|
EntityManager em = this.emf.createEntityManager(); |
|
|
|
try (EntityManager em = this.emf.createEntityManager()) { |
|
|
|
try { |
|
|
|
|
|
|
|
Query query = em.createQuery("from Product as p where p.category = ?1"); |
|
|
|
Query query = em.createQuery("from Product as p where p.category = ?1"); |
|
|
|
query.setParameter(1, category); |
|
|
|
query.setParameter(1, category); |
|
|
|
return query.getResultList(); |
|
|
|
return query.getResultList(); |
|
|
|
} |
|
|
|
} |
|
|
|
finally { |
|
|
|
|
|
|
|
if (em != null) { |
|
|
|
|
|
|
|
em.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
---- |
|
|
|
---- |
|
|
|
@ -6610,26 +6604,14 @@ constructs a Spring application context and calls these two methods: |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void saveSettings() throws IOException { |
|
|
|
public void saveSettings() throws IOException { |
|
|
|
FileOutputStream os = null; |
|
|
|
try (FileOutputStream os = new FileOutputStream(FILE_NAME)) { |
|
|
|
try { |
|
|
|
|
|
|
|
os = new FileOutputStream(FILE_NAME); |
|
|
|
|
|
|
|
this.marshaller.marshal(settings, new StreamResult(os)); |
|
|
|
this.marshaller.marshal(settings, new StreamResult(os)); |
|
|
|
} finally { |
|
|
|
|
|
|
|
if (os != null) { |
|
|
|
|
|
|
|
os.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void loadSettings() throws IOException { |
|
|
|
public void loadSettings() throws IOException { |
|
|
|
FileInputStream is = null; |
|
|
|
try (FileInputStream is = new FileInputStream(FILE_NAME)) { |
|
|
|
try { |
|
|
|
|
|
|
|
is = new FileInputStream(FILE_NAME); |
|
|
|
|
|
|
|
this.settings = (Settings) this.unmarshaller.unmarshal(new StreamSource(is)); |
|
|
|
this.settings = (Settings) this.unmarshaller.unmarshal(new StreamSource(is)); |
|
|
|
} finally { |
|
|
|
|
|
|
|
if (is != null) { |
|
|
|
|
|
|
|
is.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|