// Path: chapter07/src/main/java/com/packtpub/pf/blueprint/persistence/entity/Location.java
// @Data
// @Entity
// @Table
// public class Location implements Serializable {
// 
//     private static final long serialVersionUID = 1L;
// 
//     @Id
//     @GeneratedValue(strategy= GenerationType.AUTO)
//     private int id;
//     @NaturalId
//     @Basic(optional = false)
//     @Column(name = "franchisee_no")
//     Long franchiseeNo;
//     @Basic(optional = false)
//     double longitude;
//     @Basic(optional = false)
//     double latitude;
//     @Basic(optional = false)
//     String street1;
//     @Basic(optional = false)
//     String city;
//     String state;
//     @Basic(optional = false)
//     String zipcode;
//     String country;
// }
// 
// Path: chapter08/src/main/java/com/packtpub/pf/blueprint/service/DAOService.java
// @TransactionAttribute(TransactionAttributeType.REQUIRED)
// public class DAOService {
//     private static final Logger _log = Logger.getLogger(DAOService.class);
//     public final String OPEN_STATUS = "OPEN";
// 
//     public Customer validateUser(String username, String password) {
//         org.hibernate.Transaction tx = getSession().beginTransaction();
//         Criteria criteria = getSession().createCriteria(Customer.class);
//         criteria.add(Restrictions.eq("email", username));
//         criteria.add(Restrictions.eq("password", password));
//         criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
//         Customer user = (Customer) criteria.uniqueResult();
//         tx.commit();
//         getSession().close();
//         _log.info("Listed Successfully....");
//         return user;
//     }
// 
//     public List<Location> getAllLocations(){
//         org.hibernate.Transaction tx = getSession().beginTransaction();
//         List list = getSession().createCriteria(Location.class).list();
//         tx.commit();
//         getSession().close();
//         _log.info("Listed Successfully....");
//         return list;
//     }
// 
// 
//     public void addOrUpdateEntity(Object o) {
//         if (o != null) {
//             org.hibernate.Transaction tx = getSession().beginTransaction();
//             getSession().saveOrUpdate(o);
//             tx.commit();
//             getSession().close();
//             _log.info("Added Successfully....");
//         }
//     }
// 
//     public Object loadEntityById(Class<?> cl, Long id) {
//         Object o = null;
//         if (id != null) {
//             org.hibernate.Transaction tx = getSession().beginTransaction();
//             o = getSession().load(cl, id);
//             tx.commit();
//             getSession().close();
//             _log.info(" Successfully Loaded Object....");
//         }
//         return o;
//     }
// 
//     public List<PrintJobs> getJobsByCustomerId(Customer c) {
//         org.hibernate.Transaction tx = getSession().beginTransaction();
//         List list = getSession().createCriteria(PrintJobs.class)
//                 .add(Restrictions.eq("customer", c))
//                 .addOrder(Order.desc("createDate")).list();
//         tx.commit();
//         getSession().close();
//         _log.info("Listed Successfully....");
//         return list;
//     }
// 
//     public List<PrintJobs> getJobsBySubmittedStatus() {
//         org.hibernate.Transaction tx = getSession().beginTransaction();
//         List list = getSession().createCriteria(PrintJobs.class)
//                 .add(Restrictions.eq("status", JobStatus.SUBMITTED))
//                 .addOrder(Order.desc("createDate")).list();
//         tx.commit();
//         getSession().close();
//         _log.info("Listed Successfully....");
//         return list;
//     }
// 
// 
//     public Location getLocationByFranchiseeNo(Long franchiseeNo){
//         Location loc = null;
//         if (franchiseeNo != null) {
//             org.hibernate.Transaction tx = getSession().beginTransaction();
//             Criteria criteria = getSession().createCriteria(Location.class);
//             criteria.add(Restrictions.eq("franchiseeNo", franchiseeNo));
//             loc = (Location) criteria.uniqueResult();
//             tx.commit();
//             getSession().close();
//             _log.info("Added Successfully....");
//         }
//         return loc;
// 
//     }
// 
//     private Session getSession() {
//         SessionFactory sf = com.packtpub.pf.blueprint.persistence.HibernateUtil.getSessionFactory();
//         return sf.isClosed() ? sf.openSession() : sf.getCurrentSession();
//     }
// 
// 
// }


import com.packtpub.pf.blueprint.persistence.entity.Location;
import com.packtpub.pf.blueprint.service.DAOService;
import lombok.Getter;
import lombok.Setter;
import org.apache.log4j.Logger;
import org.primefaces.event.map.OverlaySelectEvent;
import org.primefaces.model.map.DefaultMapModel;
import org.primefaces.model.map.LatLng;
import org.primefaces.model.map.MapModel;
import org.primefaces.model.map.Marker;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ValueChangeEvent;
import java.io.Serializable;
import java.util.List;
package com.packtpub.pf.blueprint.controller;



/**
 * Created with IntelliJ IDEA.
 * User: Ramkumar Pillai
 * Date: 3/30/14
 * Time: 7:50 PM
 * To change this template use File | Settings | File Templates.
 */
@ManagedBean
@SessionScoped
public class LocationController  implements Serializable {

    private static final Logger log = Logger.getLogger(LocationController.class);

// Path: chapter07/src/main/java/com/packtpub/pf/blueprint/persistence/entity/Location.java
// @Data
// @Entity
// @Table
// public class Location implements Serializable {
// 
//     private static final long serialVersionUID = 1L;
// 
//     @Id
//     @GeneratedValue(strategy= GenerationType.AUTO)
//     private int id;
//     @NaturalId
//     @Basic(optional = false)
//     @Column(name = "franchisee_no")
//     Long franchiseeNo;
//     @Basic(optional = false)
//     double longitude;
//     @Basic(optional = false)
//     double latitude;
//     @Basic(optional = false)
//     String street1;
//     @Basic(optional = false)
//     String city;
//     String state;
//     @Basic(optional = false)
//     String zipcode;
//     String country;
// }
// 
// Path: chapter08/src/main/java/com/packtpub/pf/blueprint/service/DAOService.java
// @TransactionAttribute(TransactionAttributeType.REQUIRED)
// public class DAOService {
//     private static final Logger _log = Logger.getLogger(DAOService.class);
//     public final String OPEN_STATUS = "OPEN";
// 
//     public Customer validateUser(String username, String password) {
//         org.hibernate.Transaction tx = getSession().beginTransaction();
//         Criteria criteria = getSession().createCriteria(Customer.class);
//         criteria.add(Restrictions.eq("email", username));
//         criteria.add(Restrictions.eq("password", password));
//         criteria.setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY);
//         Customer user = (Customer) criteria.uniqueResult();
//         tx.commit();
//         getSession().close();
//         _log.info("Listed Successfully....");
//         return user;
//     }
// 
//     public List<Location> getAllLocations(){
//         org.hibernate.Transaction tx = getSession().beginTransaction();
//         List list = getSession().createCriteria(Location.class).list();
//         tx.commit();
//         getSession().close();
//         _log.info("Listed Successfully....");
//         return list;
//     }
// 
// 
//     public void addOrUpdateEntity(Object o) {
//         if (o != null) {
//             org.hibernate.Transaction tx = getSession().beginTransaction();
//             getSession().saveOrUpdate(o);
//             tx.commit();
//             getSession().close();
//             _log.info("Added Successfully....");
//         }
//     }
// 
//     public Object loadEntityById(Class<?> cl, Long id) {
//         Object o = null;
//         if (id != null) {
//             org.hibernate.Transaction tx = getSession().beginTransaction();
//             o = getSession().load(cl, id);
//             tx.commit();
//             getSession().close();
//             _log.info(" Successfully Loaded Object....");
//         }
//         return o;
//     }
// 
//     public List<PrintJobs> getJobsByCustomerId(Customer c) {
//         org.hibernate.Transaction tx = getSession().beginTransaction();
//         List list = getSession().createCriteria(PrintJobs.class)
//                 .add(Restrictions.eq("customer", c))
//                 .addOrder(Order.desc("createDate")).list();
//         tx.commit();
//         getSession().close();
//         _log.info("Listed Successfully....");
//         return list;
//     }
// 
//     public List<PrintJobs> getJobsBySubmittedStatus() {
//         org.hibernate.Transaction tx = getSession().beginTransaction();
//         List list = getSession().createCriteria(PrintJobs.class)
//                 .add(Restrictions.eq("status", JobStatus.SUBMITTED))
//                 .addOrder(Order.desc("createDate")).list();
//         tx.commit();
//         getSession().close();
//         _log.info("Listed Successfully....");
//         return list;
//     }
// 
// 
//     public Location getLocationByFranchiseeNo(Long franchiseeNo){
//         Location loc = null;
//         if (franchiseeNo != null) {
//             org.hibernate.Transaction tx = getSession().beginTransaction();
//             Criteria criteria = getSession().createCriteria(Location.class);
//             criteria.add(Restrictions.eq("franchiseeNo", franchiseeNo));
//             loc = (Location) criteria.uniqueResult();
//             tx.commit();
//             getSession().close();
//             _log.info("Added Successfully....");
//         }
//         return loc;
// 
//     }
// 
//     private Session getSession() {
//         SessionFactory sf = com.packtpub.pf.blueprint.persistence.HibernateUtil.getSessionFactory();
//         return sf.isClosed() ? sf.openSession() : sf.getCurrentSession();
//     }
// 
// 
// }


// Path: chapter07/src/main/java/com/packtpub/pf/blueprint/controller/LocationController.java
import com.packtpub.pf.blueprint.persistence.entity.Location;
import com.packtpub.pf.blueprint.service.DAOService;
import lombok.Getter;
import lombok.Setter;
import org.apache.log4j.Logger;
import org.primefaces.event.map.OverlaySelectEvent;
import org.primefaces.model.map.DefaultMapModel;
import org.primefaces.model.map.LatLng;
import org.primefaces.model.map.MapModel;
import org.primefaces.model.map.Marker;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ValueChangeEvent;
import java.io.Serializable;
import java.util.List;

package com.packtpub.pf.blueprint.controller;



/**
 * Created with IntelliJ IDEA.
 * User: Ramkumar Pillai
 * Date: 3/30/14
 * Time: 7:50 PM
 * To change this template use File | Settings | File Templates.
 */
@ManagedBean
@SessionScoped
public class LocationController  implements Serializable {

    private static final Logger log = Logger.getLogger(LocationController.class);

    DAOService ds = new DAOService();