#216 Improve naming in Repository example

This commit is contained in:
Ilkka Seppala
2015-08-17 18:34:17 +03:00
parent adbb4ac4de
commit 0d2df99013
4 changed files with 14 additions and 14 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

After

Width:  |  Height:  |  Size: 9.5 KiB

View File

@ -3,15 +3,15 @@
realizations="true" associations="true" dependencies="false" nesting-relationships="true"> realizations="true" associations="true" dependencies="false" nesting-relationships="true">
<class id="1" language="java" name="com.iluwatar.repository.Person" project="repository" <class id="1" language="java" name="com.iluwatar.repository.Person" project="repository"
file="/repository/src/main/java/com/iluwatar/repository/Person.java" binary="false" corner="BOTTOM_RIGHT"> file="/repository/src/main/java/com/iluwatar/repository/Person.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="109" y="166"/> <position height="-1" width="-1" x="109" y="67"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true"> sort-features="false" accessors="true" visibility="true">
<attributes public="true" package="true" protected="true" private="true" static="true"/> <attributes public="true" package="true" protected="true" private="true" static="true"/>
<operations public="true" package="true" protected="true" private="true" static="true"/> <operations public="true" package="true" protected="true" private="true" static="true"/>
</display> </display>
</class> </class>
<interface id="2" language="java" name="com.iluwatar.repository.PersonDao" project="repository" <interface id="2" language="java" name="com.iluwatar.repository.PersonRepository" project="repository"
file="/repository/src/main/java/com/iluwatar/repository/PersonDao.java" binary="false" corner="BOTTOM_RIGHT"> file="/repository/src/main/java/com/iluwatar/repository/PersonRepository.java" binary="false" corner="BOTTOM_RIGHT">
<position height="-1" width="-1" x="350" y="67"/> <position height="-1" width="-1" x="350" y="67"/>
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true" <display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
sort-features="false" accessors="true" visibility="true"> sort-features="false" accessors="true" visibility="true">

View File

@ -24,39 +24,39 @@ public class App {
public static void main(String[] args) { public static void main(String[] args) {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"applicationContext.xml"); "applicationContext.xml");
PersonDao dao = context.getBean(PersonDao.class); PersonRepository repository = context.getBean(PersonRepository.class);
Person peter = new Person("Peter", "Sagan"); Person peter = new Person("Peter", "Sagan");
Person nasta = new Person("Nasta", "Kuzminova"); Person nasta = new Person("Nasta", "Kuzminova");
// Add new Person records // Add new Person records
dao.save(peter); repository.save(peter);
dao.save(nasta); repository.save(nasta);
// Count Person records // Count Person records
System.out.println("Count Person records: " + dao.count()); System.out.println("Count Person records: " + repository.count());
// Print all records // Print all records
List<Person> persons = (List<Person>) dao.findAll(); List<Person> persons = (List<Person>) repository.findAll();
for (Person person : persons) { for (Person person : persons) {
System.out.println(person); System.out.println(person);
} }
// Find Person by surname // Find Person by surname
System.out.println("Find by surname 'Sagan': " + dao.findBySurname("Sagan")); System.out.println("Find by surname 'Sagan': " + repository.findBySurname("Sagan"));
// Update Person // Update Person
nasta.setName("Barbora"); nasta.setName("Barbora");
nasta.setSurname("Spotakova"); nasta.setSurname("Spotakova");
dao.save(nasta); repository.save(nasta);
System.out.println("Find by id 2: " + dao.findOne(2L)); System.out.println("Find by id 2: " + repository.findOne(2L));
// Remove record from Person // Remove record from Person
dao.delete(2L); repository.delete(2L);
// And finally count records // And finally count records
System.out.println("Count Person records: " + dao.count()); System.out.println("Count Person records: " + repository.count());
context.close(); context.close();
} }

View File

@ -11,7 +11,7 @@ import org.springframework.stereotype.Repository;
* *
*/ */
@Repository @Repository
public interface PersonDao extends CrudRepository<Person, Long> { public interface PersonRepository extends CrudRepository<Person, Long> {
public List<Person> findBySurname(String surname); public List<Person> findBySurname(String surname);
} }