Skip to content
Snippets Groups Projects
Commit 8367ae0f authored by Benjamin Lang's avatar Benjamin Lang
Browse files

Test auf Zweig bevor zum Master

parent b3b2f300
No related branches found
No related tags found
No related merge requests found
...@@ -5,10 +5,62 @@ ...@@ -5,10 +5,62 @@
*/ */
package org.s4s.dao; package org.s4s.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.s4s.modell.dto.User;
import org.s4s.services.db.JDBCConnection;
/** /**
* *
* @author Holger * @author Benjamin
*/ */
public interface ShopDAO { public class ShopDAO {
public static ShopDAO dao = null;
private final Statement statement = JDBCConnection.getInstance().getStatement();
private ShopDAO() {
}
public static ShopDAO getInstance() {
if (dao == null) {
dao = new ShopDAO();
}
return dao;
}
//Shop anhand von User/Besitzer auslesen
public boolean viewShop (User user) {
boolean result = true;
try {
ResultSet set = statement.executeQuery("SELECT *"
+ "FROM ERR.shop"
+ "WHERE besitzer = \'" + user.getBenutzername() + "\'");
if (set != null) {
result = false;
}
} catch (SQLException ex) {
Logger.getLogger(ShopDAO.class.getName()).log(Level.SEVERE, null, ex);
}
return result;
}
public boolean addShop (User user, String shopName, String shopDescription) {
//Shop via Benutzername anlegen da dieser idR eindeutig ist
try {
// vorausgesetzt ID wird automatisch gesetzt von der DB
statement.execute("INSERT INTO ERR.shop (name, besitzer, beschreibung) VALUES ("
+ shopName + ","
+ user.getBenutzername() + ","
+ shopDescription + ");");
return true;
} catch (SQLException ex) {
Logger.getLogger(ShopDAO.class.getName()).log(Level.SEVERE, null, ex);
return false;
}
}
} }
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.s4s.dao.impl;
import com.vaadin.server.VaadinSession;
import com.vaadin.ui.UI;
import java.sql.SQLException;
import org.s4s.dao.ShopDAO;
import org.s4s.services.util.Roles;
import org.s4s.exceptions.OwnsAlreadyShop;
import org.s4s.modell.dto.User;
import org.s4s.services.util.Views;
/**
*
* @author Benjamin
*/
public class ShopControl {
private static final User user = (User) VaadinSession.getCurrent().getAttribute(Roles.CURRENTUSER);
//bekommt User aus der View übergeben und prüft ob dieser schon in der Shopdb vorhanden ist (= hat schon einen Shop).
public static void checkUserShop( String shopName, String shopBeschreibung) throws OwnsAlreadyShop, SQLException {
boolean test = ShopDAO.getInstance().viewShop(user);
//Shop mit dem Nutzer schon vorhanden
if (test == false) {
throw new OwnsAlreadyShop("Sie besitzen bereits einen Shop!");
} //noch kein Shop vorhanden
else {
addUserShop(shopName, shopBeschreibung);
}
}
private static void addUserShop(String shopName, String shopBeschreibung) throws SQLException {
boolean erstellung = ShopDAO.getInstance().addShop(user, shopName, shopBeschreibung);
if (erstellung == true){
//Weiterleitung zur Shopseite, wenn Shop erfolgreich erstellt
UI.getCurrent().getNavigator().navigateTo(Views.SHOP);
} else {
//Fehlerhandling
throw new SQLException("Fehler beim Anlegen des Shops bitte noch einmal versuchen oder Programmierer kontaktieren!");
}
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.s4s.exceptions;
/**
*
* @author Benjamin
*/
public class OwnsAlreadyShop extends Exception {
private String reason = null;
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
public OwnsAlreadyShop (String reason) {
this.reason = reason;
}
}
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