本文整理匯總了Java中org.springframework.samples.petclinic.PetType類的典型用法代碼示例。如果您正苦於以下問題:Java PetType類的具體用法?Java PetType怎麽用?Java PetType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PetType類屬於org.springframework.samples.petclinic包,在下文中一共展示了PetType類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: loadPet
import org.springframework.samples.petclinic.PetType; //導入依賴的package包/類
@Transactional(readOnly = true)
public Pet loadPet(int id) throws DataAccessException {
JdbcPet pet;
try {
pet = this.simpleJdbcTemplate.queryForObject(
"SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE id=?",
new JdbcPetRowMapper(),
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;
}
示例2: setAsText
import org.springframework.samples.petclinic.PetType; //導入依賴的package包/類
@Override
public void setAsText(String text) throws IllegalArgumentException {
for (PetType type : this.clinic.getPetTypes()) {
if (type.getName().equals(text)) {
setValue(type);
}
}
}
示例3: initBinder
import org.springframework.samples.petclinic.PetType; //導入依賴的package包/類
public void initBinder(WebDataBinder binder, WebRequest request) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
binder.registerCustomEditor(String.class, new StringTrimmerEditor(false));
binder.registerCustomEditor(PetType.class, new PetTypeEditor(this.clinic));
}
示例4: loadPetsAndVisits
import org.springframework.samples.petclinic.PetType; //導入依賴的package包/類
/**
* Loads the {@link Pet} and {@link Visit} data for the supplied
* {@link Owner}.
*/
private void loadPetsAndVisits(final Owner owner) {
final List<JdbcPet> pets = this.simpleJdbcTemplate.query(
"SELECT id, name, birth_date, type_id, owner_id FROM pets WHERE owner_id=?",
new JdbcPetRowMapper(),
owner.getId().intValue());
for (JdbcPet pet : pets) {
owner.addPet(pet);
pet.setType(EntityUtils.getById(getPetTypes(), PetType.class, pet.getTypeId()));
loadVisits(pet);
}
}
示例5: testGetPetTypes
import org.springframework.samples.petclinic.PetType; //導入依賴的package包/類
public void testGetPetTypes() {
Collection<PetType> petTypes = this.clinic.getPetTypes();
assertEquals("JDBC query must show the same number of pet types", super.countRowsInTable("TYPES"),
petTypes.size());
PetType t1 = EntityUtils.getById(petTypes, PetType.class, 1);
assertEquals("cat", t1.getName());
PetType t4 = EntityUtils.getById(petTypes, PetType.class, 4);
assertEquals("snake", t4.getName());
}
示例6: testLoadPet
import org.springframework.samples.petclinic.PetType; //導入依賴的package包/類
public void testLoadPet() {
Collection<PetType> types = this.clinic.getPetTypes();
Pet p7 = this.clinic.loadPet(7);
assertTrue(p7.getName().startsWith("Samantha"));
assertEquals(EntityUtils.getById(types, PetType.class, 1).getId(), p7.getType().getId());
assertEquals("Jean", p7.getOwner().getFirstName());
Pet p6 = this.clinic.loadPet(6);
assertEquals("George", p6.getName());
assertEquals(EntityUtils.getById(types, PetType.class, 4).getId(), p6.getType().getId());
assertEquals("Peter", p6.getOwner().getFirstName());
}
示例7: testInsertPet
import org.springframework.samples.petclinic.PetType; //導入依賴的package包/類
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());
}
示例8: afterPropertiesSet
import org.springframework.samples.petclinic.PetType; //導入依賴的package包/類
public void afterPropertiesSet() throws Exception {
Assert.notNull(clinic, "Clinic must be provided.");
petTypes = new LinkedHashMap();
for (Iterator i = clinic.getPetTypes().iterator(); i.hasNext();) {
PetType petType = (PetType)i.next();
petTypes.put(petType.getName(), petType);
}
}
示例9: PetTypeAdapter
import org.springframework.samples.petclinic.PetType; //導入依賴的package包/類
private PetTypeAdapter(ValueModel valueModel, final Map petTypes) {
super(valueModel, new Closure() {
public Object call(Object petType) {
return petType != null ? ((PetType)petType).getName() : "";
}
}, new Closure() {
public Object call(Object petTypeName) {
return petTypes.get(petTypeName);
}
});
}
示例10: populatePetTypes
import org.springframework.samples.petclinic.PetType; //導入依賴的package包/類
@ModelAttribute("types")
public Collection<PetType> populatePetTypes() {
return this.clinic.getPetTypes();
}
示例11: getPetTypes
import org.springframework.samples.petclinic.PetType; //導入依賴的package包/類
@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
public Collection<PetType> getPetTypes() {
return this.em.createQuery("SELECT ptype FROM PetType ptype ORDER BY ptype.name").getResultList();
}
示例12: getPetTypes
import org.springframework.samples.petclinic.PetType; //導入依賴的package包/類
@Transactional(readOnly = true)
public Collection<PetType> getPetTypes() throws DataAccessException {
return this.simpleJdbcTemplate.query(
"SELECT id, name FROM types ORDER BY name",
ParameterizedBeanPropertyRowMapper.newInstance(PetType.class));
}
示例13: getPetTypes
import org.springframework.samples.petclinic.PetType; //導入依賴的package包/類
@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
public Collection<PetType> getPetTypes() {
return sessionFactory.getCurrentSession().createQuery("from PetType type order by type.name").list();
}
示例14: PetTypeBinder
import org.springframework.samples.petclinic.PetType; //導入依賴的package包/類
public PetTypeBinder() {
super(PetType.class, new String[] {});
}