org.springframework.samples.petclinic.model.Visit Java Examples

The following examples show how to use org.springframework.samples.petclinic.model.Visit. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JdbcVisitRepositoryImpl.java    From audit4j-demo with Apache License 2.0 7 votes vote down vote up
@Override
public List<Visit> findByPetId(Integer petId) {
    final List<Visit> visits = this.jdbcTemplate.query(
            "SELECT id, visit_date, description FROM visits WHERE pet_id=?",
            new BeanPropertyRowMapper<Visit>() {
                @Override
                public Visit mapRow(ResultSet rs, int row) throws SQLException {
                    Visit visit = new Visit();
                    visit.setId(rs.getInt("id"));
                    Date visitDate = rs.getDate("visit_date");
                    visit.setDate(new DateTime(visitDate));
                    visit.setDescription(rs.getString("description"));
                    return visit;
                }
            },
            petId);
    return visits;
}
 
Example #2
Source File: JdbcOwnerRepositoryImpl.java    From docker-workflow-plugin with MIT License 6 votes vote down vote up
public void loadPetsAndVisits(final Owner owner) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("id", owner.getId().intValue());
    final List<JdbcPet> pets = this.namedParameterJdbcTemplate.query(
            "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE owner_id=:id",
            params,
            new JdbcPetRowMapper()
    );
    for (JdbcPet pet : pets) {
        owner.addPet(pet);
        pet.setType(EntityUtils.getById(getPetTypes(), PetType.class, pet.getTypeId()));
        List<Visit> visits = this.visitRepository.findByPetId(pet.getId());
        for (Visit visit : visits) {
            pet.addVisit(visit);
        }
    }
}
 
Example #3
Source File: JdbcPetRepositoryImpl.java    From DevOps-for-Web-Development with MIT License 6 votes vote down vote up
@Override
public Pet findById(int id) throws DataAccessException {
    JdbcPet pet;
    try {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        pet = this.namedParameterJdbcTemplate.queryForObject(
            "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id",
            params,
            new JdbcPetRowMapper());
    } catch (EmptyResultDataAccessException ex) {
        throw new ObjectRetrievalFailureException(Pet.class, id);
    }
    Owner owner = this.ownerRepository.findById(pet.getOwnerId());
    owner.addPet(pet);
    pet.setType(EntityUtils.getById(findPetTypes(), PetType.class, pet.getTypeId()));

    List<Visit> visits = this.visitRepository.findByPetId(pet.getId());
    for (Visit visit : visits) {
        pet.addVisit(visit);
    }
    return pet;
}
 
Example #4
Source File: JdbcOwnerRepositoryImpl.java    From audit4j-demo with Apache License 2.0 6 votes vote down vote up
public void loadPetsAndVisits(final Owner owner) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("id", owner.getId().intValue());
    final List<JdbcPet> pets = this.namedParameterJdbcTemplate.query(
            "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE owner_id=:id",
            params,
            new JdbcPetRowMapper()
    );
    for (JdbcPet pet : pets) {
        owner.addPet(pet);
        pet.setType(EntityUtils.getById(getPetTypes(), PetType.class, pet.getTypeId()));
        List<Visit> visits = this.visitRepository.findByPetId(pet.getId());
        for (Visit visit : visits) {
            pet.addVisit(visit);
        }
    }
}
 
Example #5
Source File: JdbcPetRepositoryImpl.java    From audit4j-demo with Apache License 2.0 6 votes vote down vote up
@Override
public Pet findById(int id) throws DataAccessException {
    JdbcPet pet;
    try {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", id);
        pet = this.namedParameterJdbcTemplate.queryForObject(
                "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id",
                params,
                new JdbcPetRowMapper());
    } catch (EmptyResultDataAccessException ex) {
        throw new ObjectRetrievalFailureException(Pet.class, new Integer(id));
    }
    Owner owner = this.ownerRepository.findById(pet.getOwnerId());
    owner.addPet(pet);
    pet.setType(EntityUtils.getById(findPetTypes(), PetType.class, pet.getTypeId()));

    List<Visit> visits = this.visitRepository.findByPetId(pet.getId());
    for (Visit visit : visits) {
        pet.addVisit(visit);
    }
    return pet;
}
 
Example #6
Source File: JdbcVisitRepositoryImpl.java    From DevOps-for-Web-Development with MIT License 6 votes vote down vote up
@Override
public List<Visit> findByPetId(Integer petId) {
    Map<String, Object> params = new HashMap<>();
    params.put("id", petId);
    JdbcPet pet = this.jdbcTemplate.queryForObject(
            "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id",
            params,
            new JdbcPetRowMapper());

    List<Visit> visits = this.jdbcTemplate.query(
        "SELECT id as visit_id, visit_date, description FROM visits WHERE pet_id=:id",
        params, new JdbcVisitRowMapper());

    for (Visit visit: visits) {
        visit.setPet(pet);
    }

    return visits;
}
 
Example #7
Source File: JdbcVisitRepositoryImpl.java    From docker-workflow-plugin with MIT License 6 votes vote down vote up
@Override
public List<Visit> findByPetId(Integer petId) {
    final List<Visit> visits = this.jdbcTemplate.query(
            "SELECT id, visit_date, description FROM visits WHERE pet_id=?",
            new BeanPropertyRowMapper<Visit>() {
                @Override
                public Visit mapRow(ResultSet rs, int row) throws SQLException {
                    Visit visit = new Visit();
                    visit.setId(rs.getInt("id"));
                    Date visitDate = rs.getDate("visit_date");
                    visit.setDate(new DateTime(visitDate));
                    visit.setDescription(rs.getString("description"));
                    return visit;
                }
            },
            petId);
    return visits;
}
 
Example #8
Source File: JdbcPetRepositoryImpl.java    From docker-workflow-plugin with MIT License 6 votes vote down vote up
@Override
public Pet findById(int id) throws DataAccessException {
    JdbcPet pet;
    try {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("id", id);
        pet = this.namedParameterJdbcTemplate.queryForObject(
                "SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=:id",
                params,
                new JdbcPetRowMapper());
    } catch (EmptyResultDataAccessException ex) {
        throw new ObjectRetrievalFailureException(Pet.class, new Integer(id));
    }
    Owner owner = this.ownerRepository.findById(pet.getOwnerId());
    owner.addPet(pet);
    pet.setType(EntityUtils.getById(findPetTypes(), PetType.class, pet.getTypeId()));

    List<Visit> visits = this.visitRepository.findByPetId(pet.getId());
    for (Visit visit : visits) {
        pet.addVisit(visit);
    }
    return pet;
}
 
Example #9
Source File: JdbcVisitRowMapper.java    From DevOps-for-Web-Development with MIT License 5 votes vote down vote up
@Override
public Visit mapRow(ResultSet rs, int row) throws SQLException {
    Visit visit = new Visit();
    visit.setId(rs.getInt("visit_id"));
    Date visitDate = rs.getDate("visit_date");
    visit.setDate(new Date(visitDate.getTime()));
    visit.setDescription(rs.getString("description"));
    return visit;
}
 
Example #10
Source File: VisitController.java    From docker-workflow-plugin with MIT License 5 votes vote down vote up
@RequestMapping(value = "/owners/{ownerId}/pets/{petId}/visits/new", method = RequestMethod.POST)
public String processNewVisitForm(@Valid Visit visit, BindingResult result) {
    if (result.hasErrors()) {
        return "pets/createOrUpdateVisitForm";
    } else {
        this.clinicService.saveVisit(visit);
        return "redirect:/owners/{ownerId}";
    }
}
 
Example #11
Source File: JpaVisitRepositoryImpl.java    From DevOps-for-Web-Development with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public List<Visit> findByPetId(Integer petId) {
    Query query = this.em.createQuery("SELECT v FROM Visit v where v.pet.id= :id");
    query.setParameter("id", petId);
    return query.getResultList();
}
 
Example #12
Source File: JdbcVisitRepositoryImpl.java    From DevOps-for-Web-Development with MIT License 5 votes vote down vote up
@Override
public void save(Visit visit) throws DataAccessException {
    if (visit.isNew()) {
        Number newKey = this.insertVisit.executeAndReturnKey(
            createVisitParameterSource(visit));
        visit.setId(newKey.intValue());
    } else {
        throw new UnsupportedOperationException("Visit update not supported");
    }
}
 
Example #13
Source File: JdbcVisitRowMapper.java    From DevOps-for-Web-Development with MIT License 5 votes vote down vote up
@Override
public Visit mapRow(ResultSet rs, int row) throws SQLException {
    Visit visit = new Visit();
    visit.setId(rs.getInt("visit_id"));
    Date visitDate = rs.getDate("visit_date");
    visit.setDate(new LocalDate(visitDate));
    visit.setDescription(rs.getString("description"));
    return visit;
}
 
Example #14
Source File: JpaVisitRepositoryImpl.java    From DevOps-for-Web-Development with MIT License 5 votes vote down vote up
@Override
public void save(Visit visit) {
    if (visit.getId() == null) {
        this.em.persist(visit);
    } else {
        this.em.merge(visit);
    }
}
 
Example #15
Source File: OwnerController.java    From amazon-ecs-java-microservices with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/owner/{ownerId}/getVisits", method = RequestMethod.GET)
public ResponseEntity<List<Visit>> getOwnerVisits(@PathVariable int ownerId){
    List<Pet> petList = this.owners.findById(ownerId).getPets();
    List<Visit> visitList = new ArrayList<Visit>();
    petList.forEach(pet -> visitList.addAll(pet.getVisits()));
    return new ResponseEntity<List<Visit>>(visitList, HttpStatus.OK);
}
 
Example #16
Source File: JpaVisitRepositoryImpl.java    From DevOps-for-Web-Development with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public List<Visit> findByPetId(Integer petId) {
    Query query = this.em.createQuery("SELECT visit FROM Visit v where v.pets.id= :id");
    query.setParameter("id", petId);
    return query.getResultList();
}
 
Example #17
Source File: AbstractClinicServiceTests.java    From DevOps-for-Web-Development with MIT License 5 votes vote down vote up
@Test
@Transactional
public void shouldAddNewVisitForPet() {
    Pet pet7 = this.clinicService.findPetById(7);
    int found = pet7.getVisits().size();
    Visit visit = new Visit();
    pet7.addVisit(visit);
    visit.setDescription("test");
    this.clinicService.saveVisit(visit);
    this.clinicService.savePet(pet7);

    pet7 = this.clinicService.findPetById(7);
    assertThat(pet7.getVisits().size()).isEqualTo(found + 1);
    assertThat(visit.getId()).isNotNull();
}
 
Example #18
Source File: VisitController.java    From DevOps-for-Web-Development with MIT License 5 votes vote down vote up
@RequestMapping(value = "/owners/{ownerId}/pets/{petId}/visits/new", method = RequestMethod.POST)
public String processNewVisitForm(@Valid Visit visit, BindingResult result) {
    if (result.hasErrors()) {
        return "pets/createOrUpdateVisitForm";
    } else {
        this.clinicService.saveVisit(visit);
        return "redirect:/owners/{ownerId}";
    }
}
 
Example #19
Source File: AbstractClinicServiceTests.java    From DevOps-for-Web-Development with MIT License 5 votes vote down vote up
@Test
   public void shouldFindVisitsByPetId() throws Exception {
    Collection<Visit> visits = this.clinicService.findVisitsByPetId(7);
    assertThat(visits.size()).isEqualTo(2);
    Visit[] visitArr = visits.toArray(new Visit[visits.size()]);
    assertThat(visitArr[0].getPet()).isNotNull();
    assertThat(visitArr[0].getDate()).isNotNull();
    assertThat(visitArr[0].getPet().getId()).isEqualTo(7);
}
 
Example #20
Source File: JdbcVisitRepositoryImpl.java    From DevOps-for-Web-Development with MIT License 5 votes vote down vote up
/**
 * Creates a {@link MapSqlParameterSource} based on data values from the supplied {@link Visit} instance.
 */
private MapSqlParameterSource createVisitParameterSource(Visit visit) {
    return new MapSqlParameterSource()
        .addValue("id", visit.getId())
        .addValue("visit_date", visit.getDate())
        .addValue("description", visit.getDescription())
        .addValue("pet_id", visit.getPet().getId());
}
 
Example #21
Source File: JpaVisitRepositoryImpl.java    From docker-workflow-plugin with MIT License 5 votes vote down vote up
@Override
public void save(Visit visit) {
	if (visit.getId() == null) {
		this.em.persist(visit);     		
	}
	else {
		this.em.merge(visit);    
	}
}
 
Example #22
Source File: JpaVisitRepositoryImpl.java    From docker-workflow-plugin with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public List<Visit> findByPetId(Integer petId) {
    Query query = this.em.createQuery("SELECT visit FROM Visit v where v.pets.id= :id");
    query.setParameter("id", petId);
    return query.getResultList();
}
 
Example #23
Source File: JdbcVisitRepositoryImpl.java    From docker-workflow-plugin with MIT License 5 votes vote down vote up
@Override
public void save(Visit visit) throws DataAccessException {
    if (visit.isNew()) {
        Number newKey = this.insertVisit.executeAndReturnKey(
                createVisitParameterSource(visit));
        visit.setId(newKey.intValue());
    } else {
        throw new UnsupportedOperationException("Visit update not supported");
    }
}
 
Example #24
Source File: JdbcVisitRepositoryImpl.java    From docker-workflow-plugin with MIT License 5 votes vote down vote up
/**
 * Creates a {@link MapSqlParameterSource} based on data values from the supplied {@link Visit} instance.
 */
private MapSqlParameterSource createVisitParameterSource(Visit visit) {
    return new MapSqlParameterSource()
            .addValue("id", visit.getId())
            .addValue("visit_date", visit.getDate().toDate())
            .addValue("description", visit.getDescription())
            .addValue("pet_id", visit.getPet().getId());
}
 
Example #25
Source File: JdbcVisitRepositoryImpl.java    From audit4j-demo with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link MapSqlParameterSource} based on data values from the supplied {@link Visit} instance.
 */
private MapSqlParameterSource createVisitParameterSource(Visit visit) {
    return new MapSqlParameterSource()
            .addValue("id", visit.getId())
            .addValue("visit_date", visit.getDate().toDate())
            .addValue("description", visit.getDescription())
            .addValue("pet_id", visit.getPet().getId());
}
 
Example #26
Source File: AbstractClinicServiceTests.java    From docker-workflow-plugin with MIT License 5 votes vote down vote up
@Test
@Transactional
public void shouldAddNewVisitForPet() {
    Pet pet7 = this.clinicService.findPetById(7);
    int found = pet7.getVisits().size();
    Visit visit = new Visit();
    pet7.addVisit(visit);
    visit.setDescription("test");	    
    this.clinicService.saveVisit(visit);
    this.clinicService.savePet(pet7);

    pet7 = this.clinicService.findPetById(7);
    assertThat(pet7.getVisits().size()).isEqualTo(found + 1);
    assertThat(visit.getId()).isNotNull();
}
 
Example #27
Source File: VisitController.java    From audit4j-demo with Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/owners/{ownerId}/pets/{petId}/visits/new", method = RequestMethod.POST)
public String processNewVisitForm(@Valid Visit visit, BindingResult result) {
    if (result.hasErrors()) {
        return "pets/createOrUpdateVisitForm";
    } else {
        this.clinicService.saveVisit(visit);
        return "redirect:/owners/{ownerId}";
    }
}
 
Example #28
Source File: JpaVisitRepositoryImpl.java    From audit4j-demo with Apache License 2.0 5 votes vote down vote up
@Override
public void save(Visit visit) {
	if (visit.getId() == null) {
		this.em.persist(visit);     		
	}
	else {
		this.em.merge(visit);    
	}
}
 
Example #29
Source File: JpaVisitRepositoryImpl.java    From audit4j-demo with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public List<Visit> findByPetId(Integer petId) {
    Query query = this.em.createQuery("SELECT visit FROM Visit v where v.pets.id= :id");
    query.setParameter("id", petId);
    return query.getResultList();
}
 
Example #30
Source File: JdbcVisitRepositoryImpl.java    From audit4j-demo with Apache License 2.0 5 votes vote down vote up
@Override
public void save(Visit visit) throws DataAccessException {
    if (visit.isNew()) {
        Number newKey = this.insertVisit.executeAndReturnKey(
                createVisitParameterSource(visit));
        visit.setId(newKey.intValue());
    } else {
        throw new UnsupportedOperationException("Visit update not supported");
    }
}