// Path: examples/microservice/dao-api/src/main/java/org/osgi/enroute/examples/microservice/dao/PersonDao.java
// @ProviderType
// public interface PersonDao {
//     
//     public List<PersonDTO> select();
// 
//     public PersonDTO findByPK(Long pk) ;
// 
//     public Long save(PersonDTO data);
// 
//     public void update(PersonDTO data);
// 
//     public void delete(Long pk) ;
// }
// 
// Path: examples/microservice/dao-api/src/main/java/org/osgi/enroute/examples/microservice/dao/dto/PersonDTO.java
// public class PersonDTO {
// 
// 	public long personId;
// 	public String firstName;
// 	public String lastName;
// 
// 	public List<AddressDTO> addresses = new ArrayList<>();
// }
// 
// 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.PersonDao;
import org.osgi.enroute.examples.microservice.dao.dto.PersonDTO;
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 PersonDaoImpl implements PersonDao {
    
    private static final Logger logger = LoggerFactory.getLogger(PersonDaoImpl.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/PersonDao.java
// @ProviderType
// public interface PersonDao {
//     
//     public List<PersonDTO> select();
// 
//     public PersonDTO findByPK(Long pk) ;
// 
//     public Long save(PersonDTO data);
// 
//     public void update(PersonDTO data);
// 
//     public void delete(Long pk) ;
// }
// 
// Path: examples/microservice/dao-api/src/main/java/org/osgi/enroute/examples/microservice/dao/dto/PersonDTO.java
// public class PersonDTO {
// 
// 	public long personId;
// 	public String firstName;
// 	public String lastName;
// 
// 	public List<AddressDTO> addresses = new ArrayList<>();
// }
// 
// 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/PersonDaoImpl.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.PersonDao;
import org.osgi.enroute.examples.microservice.dao.dto.PersonDTO;
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 PersonDaoImpl implements PersonDao {
    
    private static final Logger logger = LoggerFactory.getLogger(PersonDaoImpl.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<PersonDTO> select() {