#216 Improve naming in Repository example
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 9.5 KiB |
@ -3,15 +3,15 @@
|
||||
realizations="true" associations="true" dependencies="false" nesting-relationships="true">
|
||||
<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">
|
||||
<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"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||
</display>
|
||||
</class>
|
||||
<interface id="2" language="java" name="com.iluwatar.repository.PersonDao" project="repository"
|
||||
file="/repository/src/main/java/com/iluwatar/repository/PersonDao.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<interface id="2" language="java" name="com.iluwatar.repository.PersonRepository" project="repository"
|
||||
file="/repository/src/main/java/com/iluwatar/repository/PersonRepository.java" binary="false" corner="BOTTOM_RIGHT">
|
||||
<position height="-1" width="-1" x="350" y="67"/>
|
||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||
sort-features="false" accessors="true" visibility="true">
|
||||
|
@ -24,39 +24,39 @@ public class App {
|
||||
public static void main(String[] args) {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"applicationContext.xml");
|
||||
PersonDao dao = context.getBean(PersonDao.class);
|
||||
PersonRepository repository = context.getBean(PersonRepository.class);
|
||||
|
||||
Person peter = new Person("Peter", "Sagan");
|
||||
Person nasta = new Person("Nasta", "Kuzminova");
|
||||
|
||||
// Add new Person records
|
||||
dao.save(peter);
|
||||
dao.save(nasta);
|
||||
repository.save(peter);
|
||||
repository.save(nasta);
|
||||
|
||||
// Count Person records
|
||||
System.out.println("Count Person records: " + dao.count());
|
||||
System.out.println("Count Person records: " + repository.count());
|
||||
|
||||
// Print all records
|
||||
List<Person> persons = (List<Person>) dao.findAll();
|
||||
List<Person> persons = (List<Person>) repository.findAll();
|
||||
for (Person person : persons) {
|
||||
System.out.println(person);
|
||||
}
|
||||
|
||||
// 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
|
||||
nasta.setName("Barbora");
|
||||
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
|
||||
dao.delete(2L);
|
||||
repository.delete(2L);
|
||||
|
||||
// And finally count records
|
||||
System.out.println("Count Person records: " + dao.count());
|
||||
System.out.println("Count Person records: " + repository.count());
|
||||
|
||||
context.close();
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import org.springframework.stereotype.Repository;
|
||||
*
|
||||
*/
|
||||
@Repository
|
||||
public interface PersonDao extends CrudRepository<Person, Long> {
|
||||
public interface PersonRepository extends CrudRepository<Person, Long> {
|
||||
|
||||
public List<Person> findBySurname(String surname);
|
||||
}
|
Reference in New Issue
Block a user