Skip to content
This repository has been archived by the owner on Jul 17, 2019. It is now read-only.

Commit

Permalink
Refactoring. Creating superclasses.
Browse files Browse the repository at this point in the history
  • Loading branch information
freein committed Oct 23, 2012
1 parent a468de1 commit 79a5f06
Show file tree
Hide file tree
Showing 23 changed files with 171 additions and 174 deletions.
3 changes: 0 additions & 3 deletions nbactions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
<goals>
<goal>install</goal>
</goals>
<properties>
<skipTests>true</skipTests>
</properties>
</action>
<action>
<actionName>run</actionName>
Expand Down
14 changes: 8 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<eclipselink.version>2.4.0</eclipselink.version>
<netbeans.hint.deploy.server>gfv3ee6</netbeans.hint.deploy.server>
<glassfish.embedded-static-shell.jar>C:\Program Files\glassfish-3.1.2.2\glassfish\lib\embedded\glassfish-embedded-static-shell.jar</glassfish.embedded-static-shell.jar>
</properties>
<repositories>
<repository>
Expand Down Expand Up @@ -47,12 +48,6 @@
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.icefaces</groupId>
Expand All @@ -69,6 +64,13 @@
<artifactId>derbyclient</artifactId>
<version>10.9.1.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-static-shell</artifactId>
<version>3.1.1</version>
<scope>system</scope>
<systemPath>${glassfish.embedded-static-shell.jar}</systemPath>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dat076/frukostklubben/bb/CartBB.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* and open the template in the editor.
*/
package dat076.frukostklubben.bb;
import dat076.frukostklubben.ejb.FlightEJB;
import dat076.frukostklubben.persistenceEJB.FlightEJB;
import dat076.frukostklubben.ejb.ShoppingCartEJB;
import dat076.frukostklubben.model.Flight;
import java.io.Serializable;
Expand Down Expand Up @@ -39,7 +39,7 @@ public List<Flight> getFlights(){
}

public String removeFlight(Long id){
cartEJB.removeItem(flightEJB.findFlightById(id));
cartEJB.removeItem(flightEJB.find(id));
return "cart?faces-redirect=true";
}
}
6 changes: 3 additions & 3 deletions src/main/java/dat076/frukostklubben/bb/ChangeInfoBB.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
package dat076.frukostklubben.bb;

import dat076.frukostklubben.ejb.UserEJB;
import dat076.frukostklubben.persistenceEJB.UserEJB;
import dat076.frukostklubben.model.User;
import java.io.Serializable;
import javax.annotation.ManagedBean;
Expand Down Expand Up @@ -43,14 +43,14 @@ public class ChangeInfoBB implements Serializable {
// = Public Methods =
// ======================================
public String fetchUser() {
user = userRegistry.findByMail(currentMail);
user = userRegistry.find(currentMail);
return "/users/changeInfo?faces-redirect=true";
}

public void change() {
if (checkPasswd.equals(user.getPasswd())) {
user.setPasswd(newPasswd);
userRegistry.updateUser(user);
userRegistry.update(user);
} else {
checkPasswd = "";
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/dat076/frukostklubben/bb/FlightController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
package dat076.frukostklubben.bb;

import dat076.frukostklubben.ejb.FlightEJB;
import dat076.frukostklubben.persistenceEJB.FlightEJB;
import dat076.frukostklubben.ejb.ShoppingCartEJB;
import dat076.frukostklubben.model.Flight;
import java.util.ArrayList;
Expand Down Expand Up @@ -38,7 +38,7 @@ public class FlightController {
// ======================================

public String doCreateFlight() {
flight = flightEJB.createFlight(flight);
flightEJB.create(flight);
return "browse?faces-redirect=true"; // bug fix, need parameter to redirect correctly
}

Expand All @@ -54,7 +54,7 @@ public void setFlight(Flight flight) {
}

public List<Flight> getFlightList() {
return flightEJB.findFlights();
return flightEJB.findAll();
}

public void buy(){
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dat076/frukostklubben/bb/OrderBB.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
package dat076.frukostklubben.bb;

import dat076.frukostklubben.ejb.ShoppingCartEJB;
import dat076.frukostklubben.ejb.UserEJB;
import dat076.frukostklubben.model.User;
import dat076.frukostklubben.persistenceEJB.UserEJB;
import javax.ejb.EJB;
import javax.faces.bean.RequestScoped;
import javax.inject.Named;
Expand Down Expand Up @@ -34,7 +34,7 @@ public void setMail(String mail) {
}

public String checkout(){
User user = userEJB.findByMail(mail);
User user = userEJB.find(mail);
shoppingCartEJB.checkout(user);
return null; //när en order är skickad. var ska jag då?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/
package dat076.frukostklubben.bb;

import dat076.frukostklubben.ejb.FlightEJB;
import dat076.frukostklubben.model.Flight;
import dat076.frukostklubben.persistenceEJB.FlightEJB;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/dat076/frukostklubben/bb/SignupBB.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package dat076.frukostklubben.bb;

import dat076.frukostklubben.ejb.UserEJB;

import dat076.frukostklubben.model.User;
import dat076.frukostklubben.persistenceEJB.UserEJB;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.ManagedBean;
Expand Down Expand Up @@ -87,7 +88,7 @@ else if((!input1.equals(input2)) || input1 == null)

public String doCreateUser() {
try {
user = userRegistry.createUser(user);
userRegistry.create(user);
return "login?faces-redirect=true"; // bug fix, need parameter to redirect correctly
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Bad Login name"));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/dat076/frukostklubben/bb/UserController.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dat076.frukostklubben.bb;

import dat076.frukostklubben.ejb.UserEJB;
import dat076.frukostklubben.model.User;
import dat076.frukostklubben.persistenceEJB.UserEJB;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
Expand Down Expand Up @@ -48,7 +48,7 @@ public void setPassword(String password) {
}

public String signin() {
user = userEJB.findByMail(mail);
user = userEJB.find(mail);
if (user != null) {
if (user.getPasswd().equals(password)) {
return "chat?faces-redirect=true";
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/dat076/frukostklubben/ejb/ShoppingCartEJB.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package dat076.frukostklubben.ejb;

import dat076.frukostklubben.model.Flight;
import dat076.frukostklubben.model.Order;
import dat076.frukostklubben.model.FinnishedOrder;
import dat076.frukostklubben.model.User;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -99,10 +99,10 @@ public void empty() {

@Remove //Detta betyder att denna böna försvinner när checkout() anropas.
public void checkout(User user) {
Order order = new Order();
FinnishedOrder order = new FinnishedOrder();
order.setFlights(cartItems);
order.setUser(user); ///Hur vet jag vem???
user.getOrderhistory().add(order);
user.getFinnishedOrders().add(order);
em.persist(order);
cartItems.clear();
}
Expand Down
56 changes: 0 additions & 56 deletions src/main/java/dat076/frukostklubben/ejb/UserEJB.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

/**
*
* @author Fredrik
*/
@Entity
public class Order implements Serializable {
public class FinnishedOrder implements Serializable {
@Id @GeneratedValue
private Long id;
@ElementCollection(fetch = FetchType.LAZY)
@OneToMany
List<Flight> flights = new ArrayList<>();
@OneToOne //Lägg till casce. //bidirectional

@ManyToOne
User user;

public Order(){
public FinnishedOrder(){
}

public List<Flight> getFlights() {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/dat076/frukostklubben/model/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public class User extends Subject implements Serializable {
@Embedded
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private Address address = new Address();
@OneToMany
private List<Order> orderhistory = new ArrayList<>();
@OneToMany(mappedBy = "user")
private List<FinnishedOrder> finnishedOrders;

public User(String firstName, String lastName, String mail, Address address) {
this.firstName = firstName;
Expand Down Expand Up @@ -76,12 +76,12 @@ public void setAddress(Address address) {
this.address = address;
}

public List<Order> getOrderhistory() {
return orderhistory;
public List<FinnishedOrder> getFinnishedOrders() {
return finnishedOrders;
}

public void setOrderhistory(List<Order> orderhistory) {
this.orderhistory = orderhistory;
public void setFinnishedOrders(List<FinnishedOrder> finnishedOrders) {
this.finnishedOrders = finnishedOrders;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dat076.frukostklubben.persistenceEJB;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
/**
*
* @author Fredrik
*/

public abstract class AbstractPersistenceEJB<T,K>{
@PersistenceContext(unitName = "projectPU")
private EntityManager em;

public void create(T t) {
em.persist(t);
}


public void delete(T t) {
em.remove(em.merge(t));
}


public T update(T t) {
return em.merge(t);
}

public T find(Class clazz,K k) {
return (T) em.find(clazz, k);
}
}
Loading

0 comments on commit 79a5f06

Please sign in to comment.