Package org.springframework.samples.petclinic

Examples of org.springframework.samples.petclinic.Pet


        pt1.setName("Cat");
        pt2.setName("Dog");
        pt1 = (PetType) system.save(pt1);
        pt2 = (PetType) system.save(pt2);
       
        Pet p1 = new Pet();
        Pet p2 = new Pet();
        p1.setName("Jack");
        p1.setBirthDate(new Date());
        p1.setType(pt1);
        p2.setName("Camilla");
        p2.setBirthDate(new Date());
        p2.setType(pt2);
        p1 = (Pet) system.save(p1);
        p2 = (Pet) system.save(p2);
       
        Owner owner = new Owner();
        owner.setFirstName("Tom");
View Full Code Here


    setSessionForm(true);
  }

  /** Method creates a new <code>Visit</code> with the correct <code>Pet</code> info */
  protected Object formBackingObject(HttpServletRequest request) throws ServletException {
    Pet pet = getClinic().loadPet(RequestUtils.getRequiredIntParameter(request, "petId"));
    Visit visit = new Visit();
    pet.addVisit(visit);
    return visit;
  }
View Full Code Here

    // get the Pet referred to by id in the request
    return getClinic().loadPet(RequestUtils.getRequiredIntParameter(request, "petId"));
  }

  protected void onBind(HttpServletRequest request, Object command) throws ServletException {
    Pet pet = (Pet) command;
    int typeId = RequestUtils.getRequiredIntParameter(request, "typeId");
    pet.setType((PetType) EntityUtils.getById(getClinic().getPetTypes(), PetType.class, typeId));
  }
View Full Code Here

    pet.setType((PetType) EntityUtils.getById(getClinic().getPetTypes(), PetType.class, typeId));
  }

  /** Method updates an existing Pet */
  protected ModelAndView onSubmit(Object command) throws ServletException {
    Pet pet = (Pet) command;
    // delegate the update to the business layer
    getClinic().storePet(pet);
    return new ModelAndView(getSuccessView(), "ownerId", pet.getOwner().getId());
  }
View Full Code Here

    return refData;
  }

  protected Object formBackingObject(HttpServletRequest request) throws ServletException {
    Owner owner = getClinic().loadOwner(RequestUtils.getRequiredIntParameter(request, "ownerId"));
    Pet pet = new Pet();
    owner.addPet(pet);
    return pet;
  }
View Full Code Here

    owner.addPet(pet);
    return pet;
  }

  protected void onBind(HttpServletRequest request, Object command) {
    Pet pet = (Pet) command;
    int typeId = Integer.parseInt(request.getParameter("typeId"));
    pet.setType((PetType) EntityUtils.getById(getClinic().getPetTypes(), PetType.class, typeId));
  }
View Full Code Here

    pet.setType((PetType) EntityUtils.getById(getClinic().getPetTypes(), PetType.class, typeId));
  }

  /** Method inserts a new Pet */
  protected ModelAndView onSubmit(Object command) throws ServletException {
    Pet pet = (Pet) command;
    // delegate the insert to the Business layer
    getClinic().storePet(pet);
    return new ModelAndView(getSuccessView(), "ownerId", pet.getOwner().getId());
  }
View Full Code Here

  public boolean supports(Class clazz) {
    return Pet.class.isAssignableFrom(clazz);
  }

  public void validate(Object obj, Errors errors) {
    Pet pet = (Pet) obj;

    String name = pet.getName();
    if (!StringUtils.hasLength(name)) {
      errors.rejectValue("name", "required", "required");
    }
    else if (pet.isNew() && pet.getOwner().getPet(name, true) != null) {
      errors.rejectValue("name", "duplicate", "already exists");
    }
  }
View Full Code Here

    loadPetsAndVisits(owner);
    return owner;
  }

  public Pet loadPet(int id) throws DataAccessException {
    Pet pet = (Pet) getBrokerTemplate().selectOne("loadPetById", "id", new Integer(id));
    if (pet == null) {
      throw new ObjectRetrievalFailureException(Pet.class, new Integer(id));
    }
    //load owner
    Owner owner = (Owner) getBrokerTemplate().selectOne("loadOwnerByPet", "id", pet.getId());
    owner.addPet(pet);
    // load visits
    loadVisits(pet);
    return pet;
  }
View Full Code Here

  protected void loadPetsAndVisits(Owner owner) {
    List pets = getBrokerTemplate().selectMany("loadPetsByOwner", "id", owner.getId());
    // load visits
    for (Iterator pi = pets.iterator(); pi.hasNext();) {
      Pet pet = (Pet) pi.next();
      loadVisits(pet);
      owner.addPet(pet);
    }
  }
View Full Code Here

TOP

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

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.