package proxy;
import java.io.Serializable;
import java.util.Date;
public class Order implements Serializable {
private int orderId;
private String sku;
private Date createdOn;
private Date updatedOn;
private int status;
public int getOrderId() {
return orderId;
}
public void setOrderId(int orderId) {
this.orderId = orderId;
}
public String getSku() {
return sku;
}
public void setSku(String sku) {
this.sku = sku;
}
public Date getCreatedOn() {
return createdOn;
}
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
public Date getUpdatedOn() {
return updatedOn;
}
public void setUpdatedOn(Date updatedOn) {
this.updatedOn = updatedOn;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((sku == null) ? 0 : sku.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Order other = (Order) obj;
if (sku == null) {
if (other.sku != null)
return false;
} else if (!sku.equals(other.sku))
return false;
return true;
}
}
OrderDAO.java
package proxy;
import java.util.List;
public interface OrderDAO {
public List<Order> getAllOrders();
}
OrderDAOImpl.java
package proxy;
import java.util.ArrayList;
import java.util.List;
public class OrderDAOImpl implements OrderDAO{
public List<Order> getAllOrders(){
List<Order> list = new ArrayList<Order>();
for(int i =0; i<10; i++){
Order order = new Order();
order.setSku("sku"+i);
list.add(order);
}
return list;
}
}
OrderDAOProxy.java
package proxy;
import java.util.List;
public class OrderDAOProxy implements OrderDAO{
public List<Order> getAllOrders(){
long stTime = System.currentTimeMillis();
OrderDAO orderDAOImpl = new OrderDAOImpl();
List<Order> list = orderDAOImpl.getAllOrders();
long endTime = System.currentTimeMillis();
System.out.println("took " + (endTime - stTime) + " milliseconds.");
return list;
}
}
ProxyTest.java
package proxy;
public class ProxyTest {
public static void main(String[] args) {
OrderDAO orderDAOProxy = new OrderDAOProxy();
orderDAOProxy.getAllOrders();
}
}
you may download the source code.
No comments:
Post a Comment