Package org.springframework.samples.petclinic

Examples of org.springframework.samples.petclinic.Owner


    assertEquals(EntityUtils.getById(types, PetType.class, 4).getId(), p6.getType().getId());
    assertEquals("Peter", p6.getOwner().getFirstName());
  }

  public void testInsertPet() {
    Owner o6 = this.clinic.loadOwner(6);
    int found = o6.getPets().size();
    Pet pet = new Pet();
    pet.setName("bowser");
    Collection<PetType> types = this.clinic.getPetTypes();
    pet.setType(EntityUtils.getById(types, PetType.class, 2));
    pet.setBirthDate(new Date());
    o6.addPet(pet);
    assertEquals(found + 1, o6.getPets().size());
    this.clinic.storeOwner(o6);
    // assertTrue(!pet.isNew()); -- NOT TRUE FOR TOPLINK (before commit)
    o6 = this.clinic.loadOwner(6);
    assertEquals(found + 1, o6.getPets().size());
  }
View Full Code Here


    dataBinder.setDisallowedFields("id");
  }

  @RequestMapping(value = "/owners/search", method = RequestMethod.GET)
  public String setupForm(Model model) {
    model.addAttribute("owner", new Owner());
    return "owners/search";
  }
View Full Code Here

    dataBinder.setDisallowedFields("id");
  }

  @RequestMapping(method = RequestMethod.GET)
  public String setupForm(@PathVariable("ownerId") int ownerId, Model model) {
    Owner owner = this.clinic.loadOwner(ownerId);
    Pet pet = new Pet();
    owner.addPet(pet);
    model.addAttribute("pet", pet);
    return "pets/form";
  }
View Full Code Here

  }

  public void storeOwner(Owner owner) {
    // Consider returning the persistent object here, for exposing
    // a newly assigned id using any persistence provider...
    Owner merged = this.em.merge(owner);
    this.em.flush();
    owner.setId(merged.getId());
  }
View Full Code Here

    dataBinder.setDisallowedFields("id");
  }

  @RequestMapping(method = RequestMethod.GET)
  public String setupForm(@PathVariable("ownerId") int ownerId, Model model) {
    Owner owner = this.clinic.loadOwner(ownerId);
    model.addAttribute(owner);
    return "owners/form";
  }
View Full Code Here

   * the {@link Pet Pets} and {@link Visit Visits} for the corresponding
   * owner, if not already loaded.
   */
  @Transactional(readOnly = true)
  public Owner loadOwner(int id) throws DataAccessException {
    Owner owner;
    try {
      owner = this.simpleJdbcTemplate.queryForObject(
          "SELECT id, first_name, last_name, address, city, telephone FROM owners WHERE id=?",
          ParameterizedBeanPropertyRowMapper.newInstance(Owner.class),
          id);
View Full Code Here

          id);
    }
    catch (EmptyResultDataAccessException ex) {
      throw new ObjectRetrievalFailureException(Pet.class, new Integer(id));
    }
    Owner owner = loadOwner(pet.getOwnerId());
    owner.addPet(pet);
    pet.setType(EntityUtils.getById(getPetTypes(), PetType.class, pet.getTypeId()));
    loadVisits(pet);
    return pet;
  }
View Full Code Here

    dataBinder.setDisallowedFields("id");
  }

  @RequestMapping(method = RequestMethod.GET)
  public String setupForm(Model model) {
    Owner owner = new Owner();
    model.addAttribute(owner);
    return "owners/form";
  }
View Full Code Here

    owners = this.clinic.findOwners("Daviss");
    assertEquals(0, owners.size());
  }

  public void testLoadOwner() {
    Owner o1 = this.clinic.loadOwner(1);
    assertTrue(o1.getLastName().startsWith("Franklin"));
    Owner o10 = this.clinic.loadOwner(10);
    assertEquals("Carlos", o10.getFirstName());

    // Check lazy loading, by ending the transaction
    endTransaction();

    // Now Owners are "disconnected" from the data store.
View Full Code Here

  }

  public void testInsertOwner() {
    Collection<Owner> owners = this.clinic.findOwners("Schultz");
    int found = owners.size();
    Owner owner = new Owner();
    owner.setLastName("Schultz");
    this.clinic.storeOwner(owner);
    // assertTrue(!owner.isNew()); -- NOT TRUE FOR TOPLINK (before commit)
    owners = this.clinic.findOwners("Schultz");
    assertEquals(found + 1, owners.size());
  }
View Full Code Here

TOP

Related Classes of org.springframework.samples.petclinic.Owner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.