// Path: examples/microservice/dao-api/src/main/java/org/osgi/enroute/examples/microservice/dao/AddressDao.java
// @ProviderType
// public interface AddressDao {
//     
//     public List<AddressDTO> select(Long personId);
// 
//     public AddressDTO findByPK(String emailAddress);
// 
//     public void save(Long personId,AddressDTO data);
// 
//     public void update(Long personId,AddressDTO data);
// 
//     public void delete(Long personId) ;
// 
// }
// 
// Path: examples/microservice/dao-api/src/main/java/org/osgi/enroute/examples/microservice/dao/dto/AddressDTO.java
// public class AddressDTO {
// 
// 	public long personId;
// 	public String emailAddress;
// 	public String city;
// 	public String country;
// }
// 
// Path: examples/microservice/dao-impl-jpa/src/main/java/org/osgi/enroute/examples/microservice/dao/impl/jpa/entities/AddressEntity.java
// @Entity
// @Table(name="addresses")
// public class AddressEntity {
// 
//     @ManyToOne
//     @JoinColumn(name="person_id", foreignKey=@ForeignKey(name="person"))
//     private PersonEntity person;
//     
//     @Id
//     @Column(name="email_address")
//     private String emailAddress;
//     private String city;
//     private String country;
//     
//     public static AddressEntity fromDTO(PersonEntity person, AddressDTO dto) {
//         AddressEntity entity = new AddressEntity();
//         entity.person = person;
//         entity.emailAddress = dto.emailAddress;
//         entity.city = dto.city;
//         entity.country = dto.country;
//         
//         return entity;
//     }
//     
//     public AddressDTO toDTO() {
//         AddressDTO dto = new AddressDTO();
//         dto.personId = person.getPersonId();
//         dto.emailAddress = emailAddress;
//         dto.city = city;
//         dto.country = country;
//         
//         return dto;
//     }
// 
//     public void setCity(String city) {
//         this.city = city;
//     }
// 
//     public void setCountry(String country) {
//         this.country = country;
//     }
// }
// 
// Path: examples/microservice/dao-impl-jpa/src/main/java/org/osgi/enroute/examples/microservice/dao/impl/jpa/entities/PersonEntity.java
// @Entity
// @Table(name="persons")
// public class PersonEntity {
//     
//     @GeneratedValue(strategy = IDENTITY)
//     @Id
//     @Column(name="person_id")
//     private Long personId;
//     
//     @Column(name="first_name")
//     private String firstName;
//     
//     @Column(name="last_name")
//     private String lastName;
// 
//     @OneToMany(mappedBy="person", cascade=ALL)
//     private List<AddressEntity> addresses = new ArrayList<>();
// 
//     public Long getPersonId() {
//         return personId;
//     }
// 
//     public PersonDTO toDTO() {
//         PersonDTO dto = new PersonDTO();
//         dto.personId = personId;
//         dto.firstName = firstName;
//         dto.lastName = lastName;
//         dto.addresses = addresses.stream()
//                 .map(AddressEntity::toDTO)
//                 .collect(toList());
//         return dto;
//     }
//     
//     public static PersonEntity fromDTO(PersonDTO dto) {
//         PersonEntity entity = new PersonEntity();
//         if(dto.personId != 0) {
//             entity.personId = Long.valueOf(dto.personId);
//         }
//         entity.firstName = dto.firstName;
//         entity.lastName = dto.lastName;
//         entity.addresses = dto.addresses.stream()
//                 .map(a -> AddressEntity.fromDTO(entity, a))
//                 .collect(toList());
//         
//         return entity;
//     }
// }


import static java.util.stream.Collectors.toList;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaDelete;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.osgi.enroute.examples.microservice.dao.AddressDao;
import org.osgi.enroute.examples.microservice.dao.dto.AddressDTO;
import org.osgi.enroute.examples.microservice.dao.impl.jpa.entities.AddressEntity;
import org.osgi.enroute.examples.microservice.dao.impl.jpa.entities.PersonEntity;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.transaction.control.TransactionControl;
import org.osgi.service.transaction.control.jpa.JPAEntityManagerProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package org.osgi.enroute.examples.microservice.dao.impl.jpa;





@Component
public class AddressDaoImpl implements AddressDao {

    private static final Logger logger = LoggerFactory.getLogger(AddressDaoImpl.class);

	@Reference
	TransactionControl transactionControl;

	@Reference(name="provider")
	JPAEntityManagerProvider jpaEntityManagerProvider;

	EntityManager em;

	@Activate
	void activate(Map<String, Object> props) throws SQLException {
		em = jpaEntityManagerProvider.getResource(transactionControl);
	}

	@Override
// Path: examples/microservice/dao-api/src/main/java/org/osgi/enroute/examples/microservice/dao/AddressDao.java
// @ProviderType
// public interface AddressDao {
//     
//     public List<AddressDTO> select(Long personId);
// 
//     public AddressDTO findByPK(String emailAddress);
// 
//     public void save(Long personId,AddressDTO data);
// 
//     public void update(Long personId,AddressDTO data);
// 
//     public void delete(Long personId) ;
// 
// }
// 
// Path: examples/microservice/dao-api/src/main/java/org/osgi/enroute/examples/microservice/dao/dto/AddressDTO.java
// public class AddressDTO {
// 
// 	public long personId;
// 	public String emailAddress;
// 	public String city;
// 	public String country;
// }
// 
// Path: examples/microservice/dao-impl-jpa/src/main/java/org/osgi/enroute/examples/microservice/dao/impl/jpa/entities/AddressEntity.java
// @Entity
// @Table(name="addresses")
// public class AddressEntity {
// 
//     @ManyToOne
//     @JoinColumn(name="person_id", foreignKey=@ForeignKey(name="person"))
//     private PersonEntity person;
//     
//     @Id
//     @Column(name="email_address")
//     private String emailAddress;
//     private String city;
//     private String country;
//     
//     public static AddressEntity fromDTO(PersonEntity person, AddressDTO dto) {
//         AddressEntity entity = new AddressEntity();
//         entity.person = person;
//         entity.emailAddress = dto.emailAddress;
//         entity.city = dto.city;
//         entity.country = dto.country;
//         
//         return entity;
//     }
//     
//     public AddressDTO toDTO() {
//         AddressDTO dto = new AddressDTO();
//         dto.personId = person.getPersonId();
//         dto.emailAddress = emailAddress;
//         dto.city = city;
//         dto.country = country;
//         
//         return dto;
//     }
// 
//     public void setCity(String city) {
//         this.city = city;
//     }
// 
//     public void setCountry(String country) {
//         this.country = country;
//     }
// }
// 
// Path: examples/microservice/dao-impl-jpa/src/main/java/org/osgi/enroute/examples/microservice/dao/impl/jpa/entities/PersonEntity.java
// @Entity
// @Table(name="persons")
// public class PersonEntity {
//     
//     @GeneratedValue(strategy = IDENTITY)
//     @Id
//     @Column(name="person_id")
//     private Long personId;
//     
//     @Column(name="first_name")
//     private String firstName;
//     
//     @Column(name="last_name")
//     private String lastName;
// 
//     @OneToMany(mappedBy="person", cascade=ALL)
//     private List<AddressEntity> addresses = new ArrayList<>();
// 
//     public Long getPersonId() {
//         return personId;
//     }
// 
//     public PersonDTO toDTO() {
//         PersonDTO dto = new PersonDTO();
//         dto.personId = personId;
//         dto.firstName = firstName;
//         dto.lastName = lastName;
//         dto.addresses = addresses.stream()
//                 .map(AddressEntity::toDTO)
//                 .collect(toList());
//         return dto;
//     }
//     
//     public static PersonEntity fromDTO(PersonDTO dto) {
//         PersonEntity entity = new PersonEntity();
//         if(dto.personId != 0) {
//             entity.personId = Long.valueOf(dto.personId);
//         }
//         entity.firstName = dto.firstName;
//         entity.lastName = dto.lastName;
//         entity.addresses = dto.addresses.stream()
//                 .map(a -> AddressEntity.fromDTO(entity, a))
//                 .collect(toList());
//         
//         return entity;
//     }
// }


// Path: examples/microservice/dao-impl-jpa/src/main/java/org/osgi/enroute/examples/microservice/dao/impl/jpa/AddressDaoImpl.java
import static java.util.stream.Collectors.toList;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaDelete;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.osgi.enroute.examples.microservice.dao.AddressDao;
import org.osgi.enroute.examples.microservice.dao.dto.AddressDTO;
import org.osgi.enroute.examples.microservice.dao.impl.jpa.entities.AddressEntity;
import org.osgi.enroute.examples.microservice.dao.impl.jpa.entities.PersonEntity;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.transaction.control.TransactionControl;
import org.osgi.service.transaction.control.jpa.JPAEntityManagerProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

package org.osgi.enroute.examples.microservice.dao.impl.jpa;





@Component
public class AddressDaoImpl implements AddressDao {

    private static final Logger logger = LoggerFactory.getLogger(AddressDaoImpl.class);

	@Reference
	TransactionControl transactionControl;

	@Reference(name="provider")
	JPAEntityManagerProvider jpaEntityManagerProvider;

	EntityManager em;

	@Activate
	void activate(Map<String, Object> props) throws SQLException {
		em = jpaEntityManagerProvider.getResource(transactionControl);
	}

	@Override
	public List<AddressDTO> select(Long personId) {