Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- BillOrderDao.getBillOrderById returns Optional<BillOrder>

  • Loading branch information...
commit 4ab32705658fd83e69e3d25f521d431c1dce6c3e 1 parent ffa6604
@alexbiehl alexbiehl authored
View
8 src/main/java/org/fhw/asta/kasse/client/activity/PrintCustomsActivity.java
@@ -109,12 +109,12 @@ private void printLetterHead(LetterHead letterHead) {
private void printBILLORDER(int id) {
- billOrderService.getBillOrder(id, new AsyncCallback<BillOrder>() {
+ billOrderService.getBillOrder(id, new AsyncCallback<Optional<BillOrder>>() {
@Override
- public void onSuccess(BillOrder result) {
- billOrder = result;
- billOrderService.getBillOrderArticles(result.getId(),
+ public void onSuccess(Optional<BillOrder> result) {
+ billOrder = result.get();
+ billOrderService.getBillOrderArticles(billOrder.getId(),
new AsyncCallback<List<BasketItem>>() {
@Override
View
80 src/main/java/org/fhw/asta/kasse/server/dao/BillOrderDao.java
@@ -10,46 +10,54 @@
import org.fhw.asta.kasse.shared.model.OrderState;
import org.springframework.jdbc.core.RowMapper;
+import com.google.common.base.Optional;
import com.google.inject.Singleton;
@Singleton
public class BillOrderDao extends GenericDao {
- private BillOrderRowMapper billOrderMapper = new BillOrderRowMapper();
- private BasketItemMapper basketItemMapper = new BasketItemMapper();
-
- private class BillOrderRowMapper implements RowMapper<BillOrder> {
- @Override
- public BillOrder mapRow(final ResultSet arg0, final int arg1) throws SQLException {
- return new BillOrder(arg0.getInt(1), arg0.getInt(2), arg0.getString(3), arg0.getInt(4), arg0.getString(5),
- arg0.getDate(6), arg0.getBoolean(7), OrderState.valueOf(arg0.getString(8)), arg0.getBoolean(9),
- arg0.getInt(10));
- }
- }
-
- private class BasketItemMapper implements RowMapper<BasketItem> {
- @Override
- public BasketItem mapRow(ResultSet arg0, int arg1) throws SQLException {
- // TODO Auto-generated method stub
- return new BasketItem(arg0.getString(1), new EuroAmount(arg0.getInt(2)), arg0.getInt(3), arg0.getInt(4),
- arg0.getInt(5));
- }
- }
-
- public List<BillOrder> getAllBillOrders() {
- return this.template.query("SELECT * FROM bill_order", this.billOrderMapper);
- }
-
- public BillOrder getBillOrder(int id) {
- // TODO: loggen, falls wider erwarten mehr als ein ergebnis zurückkommt
- return this.template.queryForObject("SELECT * FROM bill_order WHERE bill_id = ?", new Object[]{id},
- this.billOrderMapper);
- }
-
- public List<BasketItem> getBillOrderArticles(int id) {
- return this.template.query("SELECT a.name, a.price, a.article_id, bca.count,"
- + " bca.discount FROM bill_order bo INNER JOIN bill_contains_article "
- + "bca INNER JOIN article a WHERE bo.bill_id = ?", this.basketItemMapper);
- }
+ private static final BillOrderRowMapper billOrderMapper = new BillOrderRowMapper();
+ private static final BasketItemMapper basketItemMapper = new BasketItemMapper();
+
+ private static class BillOrderRowMapper implements RowMapper<BillOrder> {
+ @Override
+ public BillOrder mapRow(final ResultSet arg0, final int arg1)
+ throws SQLException {
+ return new BillOrder(arg0.getInt(1), arg0.getInt(2),
+ arg0.getString(3), arg0.getInt(4), arg0.getString(5),
+ arg0.getDate(6), arg0.getBoolean(7),
+ OrderState.valueOf(arg0.getString(8)), arg0.getBoolean(9),
+ arg0.getInt(10));
+ }
+ }
+
+ private static class BasketItemMapper implements RowMapper<BasketItem> {
+ @Override
+ public BasketItem mapRow(ResultSet arg0, int arg1) throws SQLException {
+ // TODO Auto-generated method stub
+ return new BasketItem(arg0.getString(1), new EuroAmount(
+ arg0.getInt(2)), arg0.getInt(3), arg0.getInt(4),
+ arg0.getInt(5));
+ }
+ }
+
+ public List<BillOrder> getAllBillOrders() {
+ return this.template.query("SELECT * FROM bill_order",
+ this.billOrderMapper);
+ }
+
+ public Optional<BillOrder> getBillOrder(int id) {
+ // TODO: loggen, falls wider erwarten mehr als ein ergebnis zurückkommt
+
+ return queryForObject("SELECT * FROM bill_order WHERE bill_id = ?", new Object[] { id }, billOrderMapper);
+ }
+
+ public List<BasketItem> getBillOrderArticles(int id) {
+ return this.template
+ .query("SELECT a.name, a.price, a.article_id, bca.count,"
+ + " bca.discount FROM bill_order bo INNER JOIN bill_contains_article "
+ + "bca INNER JOIN article a WHERE bo.bill_id = ?",
+ this.basketItemMapper);
+ }
}
View
15 src/main/java/org/fhw/asta/kasse/server/dao/GenericDao.java
@@ -1,11 +1,26 @@
package org.fhw.asta.kasse.server.dao;
+import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.core.RowMapper;
+import com.google.common.base.Optional;
import com.google.inject.Inject;
public abstract class GenericDao
{
@Inject
protected JdbcTemplate template;
+
+ protected <T> Optional<T> queryForObject(String sql, Object[] objects, RowMapper<T> rowMapper) {
+
+ try {
+ T result = template.queryForObject(sql, objects, rowMapper);
+ return Optional.of(result);
+ } catch (EmptyResultDataAccessException e) {
+ return Optional.absent();
+ }
+ }
+
+
}
View
3  src/main/java/org/fhw/asta/kasse/server/service/BillOrderServiceEndpoint.java
@@ -8,6 +8,7 @@
import org.fhw.asta.kasse.shared.model.BillOrder;
import org.fhw.asta.kasse.shared.service.billorder.BillOrderService;
+import com.google.common.base.Optional;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -27,7 +28,7 @@
private BillOrderDao billOrderDao;
@Override
- public BillOrder getBillOrder(int id) {
+ public Optional<BillOrder> getBillOrder(int id) {
return this.billOrderDao.getBillOrder(id);
}
View
3  src/main/java/org/fhw/asta/kasse/shared/service/billorder/BillOrderService.java
@@ -5,12 +5,13 @@
import org.fhw.asta.kasse.shared.basket.BasketItem;
import org.fhw.asta.kasse.shared.model.BillOrder;
+import com.google.common.base.Optional;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("billorder")
public interface BillOrderService extends RemoteService {
- BillOrder getBillOrder(int id);
+ Optional<BillOrder> getBillOrder(int id);
List<BasketItem> getBillOrderArticles(int id);
}
View
3  src/main/java/org/fhw/asta/kasse/shared/service/billorder/BillOrderServiceAsync.java
@@ -5,11 +5,12 @@
import org.fhw.asta.kasse.shared.basket.BasketItem;
import org.fhw.asta.kasse.shared.model.BillOrder;
+import com.google.common.base.Optional;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface BillOrderServiceAsync {
- void getBillOrder(int id, AsyncCallback<BillOrder> callback);
+ void getBillOrder(int id, AsyncCallback<Optional<BillOrder>> callback);
void getBillOrderArticles(int id, AsyncCallback<List<BasketItem>> callback);
Please sign in to comment.
Something went wrong with that request. Please try again.