Skip to content
Snippets Groups Projects
Commit 6ac94a45 authored by sknobl2s's avatar sknobl2s
Browse files

Transaction.java : Verkaeufer von String zu Int

TransactionControl.java: Logik erstellt
parent 4b906f34
No related branches found
No related tags found
No related merge requests found
...@@ -11,21 +11,21 @@ package org.s4s.modell.dto; ...@@ -11,21 +11,21 @@ package org.s4s.modell.dto;
*/ */
public class Transaction { public class Transaction {
private String verkaeufer; private Integer verkaeufer;
private User kaeufer; private User kaeufer;
private Product produkt; private Product produkt;
public Transaction(String verkaeufer, User kaeufer, Product produkt) { public Transaction(Integer verkaeufer, User kaeufer, Product produkt) {
this.verkaeufer = verkaeufer; this.verkaeufer = verkaeufer;
this.kaeufer = kaeufer; this.kaeufer = kaeufer;
this.produkt = produkt; this.produkt = produkt;
} }
public String getVerkaeufer() { public Integer getVerkaeufer() {
return verkaeufer; return verkaeufer;
} }
public void setVerkaeufer(String verkaeufer) { public void setVerkaeufer(Integer verkaeufer) {
this.verkaeufer = verkaeufer; this.verkaeufer = verkaeufer;
} }
......
...@@ -3,10 +3,14 @@ package org.s4s.process.control; ...@@ -3,10 +3,14 @@ package org.s4s.process.control;
import com.vaadin.ui.UI; import com.vaadin.ui.UI;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement;
import org.s4s.dao.impl.AbstractDatabaseClass; import org.s4s.dao.impl.AbstractDatabaseClass;
import org.s4s.exceptions.DAOException; import org.s4s.exceptions.DAOException;
import org.s4s.modell.dto.Product; import org.s4s.modell.dto.Product;
import org.s4s.modell.dto.Transaction;
import org.s4s.modell.dto.User; import org.s4s.modell.dto.User;
import org.s4s.modell.dto.Warenkorb;
import org.s4s.services.db.JDBCConnection;
import org.s4s.services.util.Roles; import org.s4s.services.util.Roles;
/** /**
...@@ -15,23 +19,53 @@ import org.s4s.services.util.Roles; ...@@ -15,23 +19,53 @@ import org.s4s.services.util.Roles;
*/ */
public class TransactionControl extends AbstractDatabaseClass { public class TransactionControl extends AbstractDatabaseClass {
String verkaeufer; Transaction transaktion;
User kaeufer; private final Statement statement = JDBCConnection.getInstance().getStatement();
Product produkt;
//Warenkorb warenkorb = Warenkorb.getInstance();
String kaufer = (String) UI.getCurrent().getSession().getAttribute(Roles.CURRENTUSER); //String kaeuferString = (String) UI.getCurrent().getSession().getAttribute(Roles.CURRENTUSER);
public void createTransactions() throws DAOException, SQLException {
for (Product p : Warenkorb.getInstance().inhalt()) {
transaktion.setKaeufer((User) UI.getCurrent().getSession().getAttribute(Roles.CURRENTUSER));
transaktion.setVerkaeufer(kaeuferinDB(p.getId()));
transaktion.setProdukt(p);
createTransactionInDB(transaktion);
updateGekauftStatusInArtikel(transaktion);
}
}
public void createTransaction() throws DAOException, SQLException { public Integer kaeuferinDB(int produktid) throws DAOException, SQLException {
Integer verkaeufer;
try (ResultSet rs = executeQuery("SELECT u.\"besitzer\"" + " FROM \"ERR\".\"shop\" u , \"ERR\".\"artikel\" s" try (ResultSet rs = executeQuery("SELECT u.\"besitzer\"" + " FROM \"ERR\".\"shop\" u , \"ERR\".\"artikel\" s"
+ " WHERE u.shopid = s.shopid AND " + " WHERE u.shopid = s.shopid AND "
+ "s.artikelid'" + produkt.getId() + "';");) { + "s.artikelid'" + transaktion.getProdukt().getId() + "';");) {
verkaeufer = rs.getString("besitzer"); verkaeufer = rs.getInt("besitzer");
} catch (SQLException ex) { } catch (SQLException ex) {
throw new DAOException(ex); throw new DAOException(ex);
} }
return verkaeufer;
}
public void createTransactionInDB(Transaction transaktion) throws DAOException, SQLException {
try {
statement.execute("INSERT INTO \"ERR\".\"transaktion\" (verkaeufer, kaeufer, artikelid) VALUES("
+ transaktion.getVerkaeufer() + ","
+ transaktion.getKaeufer().getUserId() + ","
+ transaktion.getProdukt().getId());
} catch (SQLException ex) {
throw new DAOException(ex);
}
}
public void updateGekauftStatusInArtikel(Transaction transaktion) throws DAOException, SQLException {
try {
statement.execute("UPDATE INTO \"ERR\".\"artikel\""
+ "SET gekauft = true"
+ "WHERE artikelid = "
+ transaktion.getProdukt().getId());
} catch (SQLException ex) {
throw new DAOException(ex);
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment