mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-19 14:05:50 +00:00
Added Hash Map Store for owner entity
Added a hash map store for the owner database table as well as static data object definitions.
This commit is contained in:
parent
4ea915cbfc
commit
267fbb9d9d
3 changed files with 67 additions and 0 deletions
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
* Software property of Acquisio. Copyright 2003-2018.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.newDataStore;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.springframework.samples.petclinic.owner.Owner;
|
||||||
|
import org.springframework.samples.petclinic.owner.OwnerRepository;
|
||||||
|
import org.springframework.samples.petclinic.owner.StaticOwner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gibran
|
||||||
|
*/
|
||||||
|
public class NewOwnerStore {
|
||||||
|
|
||||||
|
public Map<Integer, StaticOwner> ownerStore;
|
||||||
|
private final OwnerRepository owners;
|
||||||
|
|
||||||
|
public NewOwnerStore(OwnerRepository owners) {
|
||||||
|
this.owners = owners;
|
||||||
|
this.ownerStore = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void populateStore() {
|
||||||
|
Collection<Owner> ownerRepositoryData = this.owners.findAll();
|
||||||
|
for(Owner owner : ownerRepositoryData) {
|
||||||
|
ownerStore.put(owner.getId(), convertToStaticOwner(owner));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public StaticOwner convertToStaticOwner(Owner ownerEntity) {
|
||||||
|
return new StaticOwner(ownerEntity.getAddress(), ownerEntity.getCity(), ownerEntity.getTelephone());
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,8 @@ import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.Repository;
|
import org.springframework.data.repository.Repository;
|
||||||
import org.springframework.data.repository.query.Param;
|
import org.springframework.data.repository.query.Param;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Repository class for <code>Owner</code> domain objects All method names are compliant with Spring Data naming
|
* Repository class for <code>Owner</code> domain objects All method names are compliant with Spring Data naming
|
||||||
|
@ -53,6 +55,15 @@ public interface OwnerRepository extends Repository<Owner, Integer> {
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
Owner findById(@Param("id") Integer id);
|
Owner findById(@Param("id") Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve all <code>Owner</code>s from the data store.
|
||||||
|
*
|
||||||
|
* @return a <code>Collection</code> of <code>Owner</code>s
|
||||||
|
*/
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
@Cacheable("owner")
|
||||||
|
Collection<Owner> findAll() throws DataAccessException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save an {@link Owner} to the data store, either inserting or updating it.
|
* Save an {@link Owner} to the data store, either inserting or updating it.
|
||||||
* @param owner the {@link Owner} to save
|
* @param owner the {@link Owner} to save
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
* Software property of Acquisio. Copyright 2003-2018.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Gibran
|
||||||
|
*/
|
||||||
|
public class StaticOwner {
|
||||||
|
|
||||||
|
private String address;
|
||||||
|
private String city;
|
||||||
|
private String telephone;
|
||||||
|
|
||||||
|
public StaticOwner(String address, String city, String telephone){
|
||||||
|
this.address = address;
|
||||||
|
this.city = city;
|
||||||
|
this.telephone = telephone;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue