当前位置: 首页>>代码示例>>Java>>正文


Java EntityUtils.getById方法代码示例

本文整理汇总了Java中org.springframework.samples.petclinic.util.EntityUtils.getById方法的典型用法代码示例。如果您正苦于以下问题:Java EntityUtils.getById方法的具体用法?Java EntityUtils.getById怎么用?Java EntityUtils.getById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.samples.petclinic.util.EntityUtils的用法示例。


在下文中一共展示了EntityUtils.getById方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testGetVets

import org.springframework.samples.petclinic.util.EntityUtils; //导入方法依赖的package包/类
public void testGetVets() {
	Collection<Vet> vets = this.clinic.getVets();
	// Use the inherited countRowsInTable() convenience method (from
	// AbstractTransactionalDataSourceSpringContextTests) to verify the
	// results.
	assertEquals("JDBC query must show the same number of vets", super.countRowsInTable("VETS"), vets.size());
	Vet v1 = EntityUtils.getById(vets, Vet.class, 2);
	assertEquals("Leary", v1.getLastName());
	assertEquals(1, v1.getNrOfSpecialties());
	assertEquals("radiology", (v1.getSpecialties().get(0)).getName());
	Vet v2 = EntityUtils.getById(vets, Vet.class, 3);
	assertEquals("Douglas", v2.getLastName());
	assertEquals(2, v2.getNrOfSpecialties());
	assertEquals("dentistry", (v2.getSpecialties().get(0)).getName());
	assertEquals("surgery", (v2.getSpecialties().get(1)).getName());
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:17,代码来源:AbstractJpaClinicTests.java

示例2: getVets

import org.springframework.samples.petclinic.util.EntityUtils; //导入方法依赖的package包/类
@Test
public void getVets() {
	Collection<Vet> vets = this.clinic.getVets();
	// Use the inherited countRowsInTable() convenience method (from
	// AbstractTransactionalJUnit4SpringContextTests) to verify the results.
	assertEquals("JDBC query must show the same number of vets", super.countRowsInTable("VETS"), vets.size());
	Vet v1 = EntityUtils.getById(vets, Vet.class, 2);
	assertEquals("Leary", v1.getLastName());
	assertEquals(1, v1.getNrOfSpecialties());
	assertEquals("radiology", (v1.getSpecialties().get(0)).getName());
	Vet v2 = EntityUtils.getById(vets, Vet.class, 3);
	assertEquals("Douglas", v2.getLastName());
	assertEquals(2, v2.getNrOfSpecialties());
	assertEquals("dentistry", (v2.getSpecialties().get(0)).getName());
	assertEquals("surgery", (v2.getSpecialties().get(1)).getName());
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:17,代码来源:AbstractClinicTests.java

示例3: findAll

import org.springframework.samples.petclinic.util.EntityUtils; //导入方法依赖的package包/类
/**
 * Refresh the cache of Vets that the ClinicService is holding.
 */
@Override
public Collection<Vet> findAll() throws DataAccessException {
    List<Vet> vets = new ArrayList<>();
    // Retrieve the list of all vets.
    vets.addAll(this.jdbcTemplate.query(
        "SELECT id, first_name, last_name FROM vets ORDER BY last_name,first_name",
        BeanPropertyRowMapper.newInstance(Vet.class)));

    // Retrieve the list of all possible specialties.
    final List<Specialty> specialties = this.jdbcTemplate.query(
        "SELECT id, name FROM specialties",
        BeanPropertyRowMapper.newInstance(Specialty.class));

    // Build each vet's list of specialties.
    for (Vet vet : vets) {
        final List<Integer> vetSpecialtiesIds = this.jdbcTemplate.query(
            "SELECT specialty_id FROM vet_specialties WHERE vet_id=?",
            new BeanPropertyRowMapper<Integer>() {
                @Override
                public Integer mapRow(ResultSet rs, int row) throws SQLException {
                    return rs.getInt(1);
                }
            },
            vet.getId());
        for (int specialtyId : vetSpecialtiesIds) {
            Specialty specialty = EntityUtils.getById(specialties, Specialty.class, specialtyId);
            vet.addSpecialty(specialty);
        }
    }
    return vets;
}
 
开发者ID:PacktPublishing,项目名称:DevOps-for-Web-Development,代码行数:35,代码来源:JdbcVetRepositoryImpl.java

示例4: shouldFindAllPetTypes

import org.springframework.samples.petclinic.util.EntityUtils; //导入方法依赖的package包/类
@Test
public void shouldFindAllPetTypes() {
    Collection<PetType> petTypes = this.clinicService.findPetTypes();

    PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1);
    assertThat(petType1.getName()).isEqualTo("cat");
    PetType petType4 = EntityUtils.getById(petTypes, PetType.class, 4);
    assertThat(petType4.getName()).isEqualTo("snake");
}
 
开发者ID:PacktPublishing,项目名称:DevOps-for-Web-Development,代码行数:10,代码来源:AbstractClinicServiceTests.java

示例5: shouldFindVets

import org.springframework.samples.petclinic.util.EntityUtils; //导入方法依赖的package包/类
@Test
public void shouldFindVets() {
    Collection<Vet> vets = this.clinicService.findVets();

    Vet vet = EntityUtils.getById(vets, Vet.class, 3);
    assertThat(vet.getLastName()).isEqualTo("Douglas");
    assertThat(vet.getNrOfSpecialties()).isEqualTo(2);
    assertThat(vet.getSpecialties().get(0).getName()).isEqualTo("dentistry");
    assertThat(vet.getSpecialties().get(1).getName()).isEqualTo("surgery");
}
 
开发者ID:PacktPublishing,项目名称:DevOps-for-Web-Development,代码行数:11,代码来源:AbstractClinicServiceTests.java

示例6: findById

import org.springframework.samples.petclinic.util.EntityUtils; //导入方法依赖的package包/类
@Override
public Pet findById(int id) throws DataAccessException {
    Integer ownerId;
    try {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        ownerId = this.namedParameterJdbcTemplate.queryForObject("SELECT owner_id FROM pets WHERE id=:id", params, Integer.class);
    } catch (EmptyResultDataAccessException ex) {
        throw new ObjectRetrievalFailureException(Pet.class, id);
    }
    Owner owner = this.ownerRepository.findById(ownerId);
    return EntityUtils.getById(owner.getPets(), Pet.class, id);
}
 
开发者ID:PacktPublishing,项目名称:DevOps-for-Web-Development,代码行数:14,代码来源:JdbcPetRepositoryImpl.java

示例7: refreshVetsCache

import org.springframework.samples.petclinic.util.EntityUtils; //导入方法依赖的package包/类
/**
 * Refresh the cache of Vets that the Clinic is holding.
 * @see org.springframework.samples.petclinic.Clinic#getVets()
 */
@ManagedOperation
@Transactional(readOnly = true)
public void refreshVetsCache() throws DataAccessException {
	synchronized (this.vets) {
		this.logger.info("Refreshing vets cache");

		// Retrieve the list of all vets.
		this.vets.clear();
		this.vets.addAll(this.simpleJdbcTemplate.query(
				"SELECT id, first_name, last_name FROM vets ORDER BY last_name,first_name",
				ParameterizedBeanPropertyRowMapper.newInstance(Vet.class)));

		// Retrieve the list of all possible specialties.
		final List<Specialty> specialties = this.simpleJdbcTemplate.query(
				"SELECT id, name FROM specialties",
				ParameterizedBeanPropertyRowMapper.newInstance(Specialty.class));

		// Build each vet's list of specialties.
		for (Vet vet : this.vets) {
			final List<Integer> vetSpecialtiesIds = this.simpleJdbcTemplate.query(
					"SELECT specialty_id FROM vet_specialties WHERE vet_id=?",
					new ParameterizedRowMapper<Integer>() {
						public Integer mapRow(ResultSet rs, int row) throws SQLException {
							return Integer.valueOf(rs.getInt(1));
						}},
					vet.getId().intValue());
			for (int specialtyId : vetSpecialtiesIds) {
				Specialty specialty = EntityUtils.getById(specialties, Specialty.class, specialtyId);
				vet.addSpecialty(specialty);
			}
		}
	}
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:38,代码来源:SimpleJdbcClinic.java

示例8: testGetPetTypes

import org.springframework.samples.petclinic.util.EntityUtils; //导入方法依赖的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());
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:10,代码来源:AbstractJpaClinicTests.java

示例9: getPetTypes

import org.springframework.samples.petclinic.util.EntityUtils; //导入方法依赖的package包/类
@Test
public void getPetTypes() {
	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());
}
 
开发者ID:cacheonix,项目名称:cacheonix-core,代码行数:11,代码来源:AbstractClinicTests.java

示例10: findAll

import org.springframework.samples.petclinic.util.EntityUtils; //导入方法依赖的package包/类
/**
 * Refresh the cache of Vets that the ClinicService is holding.
 *
 * @see org.springframework.samples.petclinic.model.service.ClinicService#shouldFindVets()
 */
@Override
public Collection<Vet> findAll() throws DataAccessException {
    List<Vet> vets = new ArrayList<Vet>();
    // Retrieve the list of all vets.
    vets.addAll(this.jdbcTemplate.query(
            "SELECT id, first_name, last_name FROM vets ORDER BY last_name,first_name",
            BeanPropertyRowMapper.newInstance(Vet.class)));

    // Retrieve the list of all possible specialties.
    final List<Specialty> specialties = this.jdbcTemplate.query(
            "SELECT id, name FROM specialties",
            BeanPropertyRowMapper.newInstance(Specialty.class));

    // Build each vet's list of specialties.
    for (Vet vet : vets) {
        final List<Integer> vetSpecialtiesIds = this.jdbcTemplate.query(
                "SELECT specialty_id FROM vet_specialties WHERE vet_id=?",
                new BeanPropertyRowMapper<Integer>() {
                    @Override
                    public Integer mapRow(ResultSet rs, int row) throws SQLException {
                        return Integer.valueOf(rs.getInt(1));
                    }
                },
                vet.getId().intValue());
        for (int specialtyId : vetSpecialtiesIds) {
            Specialty specialty = EntityUtils.getById(specialties, Specialty.class, specialtyId);
            vet.addSpecialty(specialty);
        }
    }
    return vets;
}
 
开发者ID:jenkinsci,项目名称:docker-workflow-plugin,代码行数:37,代码来源:JdbcVetRepositoryImpl.java

示例11: findAll

import org.springframework.samples.petclinic.util.EntityUtils; //导入方法依赖的package包/类
/**
 * Refresh the cache of Vets that the ClinicService is holding.
 */
@Override
public Collection<Vet> findAll() throws DataAccessException {
    List<Vet> vets = new ArrayList<>();
    // Retrieve the list of all vets.
    vets.addAll(this.jdbcTemplate.query(
            "SELECT id, first_name, last_name FROM vets ORDER BY last_name,first_name",
            BeanPropertyRowMapper.newInstance(Vet.class)));

    // Retrieve the list of all possible specialties.
    final List<Specialty> specialties = this.jdbcTemplate.query(
            "SELECT id, name FROM specialties",
            BeanPropertyRowMapper.newInstance(Specialty.class));

    // Build each vet's list of specialties.
    for (Vet vet : vets) {
        final List<Integer> vetSpecialtiesIds = this.jdbcTemplate.query(
                "SELECT specialty_id FROM vet_specialties WHERE vet_id=?",
                new BeanPropertyRowMapper<Integer>() {
                    @Override
                    public Integer mapRow(ResultSet rs, int row) throws SQLException {
                        return rs.getInt(1);
                    }
                },
                vet.getId());
        for (int specialtyId : vetSpecialtiesIds) {
            Specialty specialty = EntityUtils.getById(specialties, Specialty.class, specialtyId);
            vet.addSpecialty(specialty);
        }
    }
    return vets;
}
 
开发者ID:YoannBuch,项目名称:DependencyInjectionAgent,代码行数:35,代码来源:JdbcVetRepositoryImpl.java

示例12: findAll

import org.springframework.samples.petclinic.util.EntityUtils; //导入方法依赖的package包/类
/**
 * Refresh the cache of Vets that the ClinicService is holding.
 *
 * @see org.springframework.samples.petclinic.model.service.ClinicService#findVets()
 */
@Override
public Collection<Vet> findAll() throws DataAccessException {
    List<Vet> vets = new ArrayList<Vet>();
    // Retrieve the list of all vets.
    vets.addAll(this.jdbcTemplate.query(
            "SELECT id, first_name, last_name FROM vets ORDER BY last_name,first_name",
            ParameterizedBeanPropertyRowMapper.newInstance(Vet.class)));

    // Retrieve the list of all possible specialties.
    final List<Specialty> specialties = this.jdbcTemplate.query(
            "SELECT id, name FROM specialties",
            ParameterizedBeanPropertyRowMapper.newInstance(Specialty.class));

    // Build each vet's list of specialties.
    for (Vet vet : vets) {
        final List<Integer> vetSpecialtiesIds = this.jdbcTemplate.query(
                "SELECT specialty_id FROM vet_specialties WHERE vet_id=?",
                new ParameterizedRowMapper<Integer>() {
                    @Override
                    public Integer mapRow(ResultSet rs, int row) throws SQLException {
                        return Integer.valueOf(rs.getInt(1));
                    }
                },
                vet.getId().intValue());
        for (int specialtyId : vetSpecialtiesIds) {
            Specialty specialty = EntityUtils.getById(specialties, Specialty.class, specialtyId);
            vet.addSpecialty(specialty);
        }
    }
    return vets;
}
 
开发者ID:jptiancai,项目名称:spring-petclinic-study,代码行数:37,代码来源:JdbcVetRepositoryImpl.java

示例13: getPetTypes

import org.springframework.samples.petclinic.util.EntityUtils; //导入方法依赖的package包/类
@Test
public void getPetTypes() {
    Collection<PetType> petTypes = this.clinicService.findPetTypes();

    PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1);
    assertEquals("cat", petType1.getName());
    PetType petType4 = EntityUtils.getById(petTypes, PetType.class, 4);
    assertEquals("snake", petType4.getName());
}
 
开发者ID:jptiancai,项目名称:spring-petclinic-study,代码行数:10,代码来源:AbstractClinicServiceTests.java

示例14: findVets

import org.springframework.samples.petclinic.util.EntityUtils; //导入方法依赖的package包/类
@Test
public void findVets() {
    Collection<Vet> vets = this.clinicService.findVets();

    Vet v1 = EntityUtils.getById(vets, Vet.class, 2);
    assertEquals("Leary", v1.getLastName());
    assertEquals(1, v1.getNrOfSpecialties());
    assertEquals("radiology", (v1.getSpecialties().get(0)).getName());
    Vet v2 = EntityUtils.getById(vets, Vet.class, 3);
    assertEquals("Douglas", v2.getLastName());
    assertEquals(2, v2.getNrOfSpecialties());
    assertEquals("dentistry", (v2.getSpecialties().get(0)).getName());
    assertEquals("surgery", (v2.getSpecialties().get(1)).getName());
}
 
开发者ID:jptiancai,项目名称:spring-petclinic-study,代码行数:15,代码来源:AbstractClinicServiceTests.java


注:本文中的org.springframework.samples.petclinic.util.EntityUtils.getById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。