25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 9 ■ Adding Persistence to Your <strong>Spring</strong> Application<br />

}<br />

116<br />

public String getEmail() {<br />

return email;<br />

}<br />

public void setEmail(String email) {<br />

this.email = email;<br />

}<br />

public String getPassword() {<br />

return password;<br />

}<br />

public void setPassword(String password) {<br />

this.password = password;<br />

}<br />

public String getName() {<br />

return name;<br />

}<br />

public void setName(String name) {<br />

this.name = name;<br />

}<br />

public List getDocuments() {<br />

return documents;<br />

}<br />

public void setDocuments(List documents) {<br />

this.documents = documents;<br />

}<br />

Listing 9-3 shows the User class, which has several properties, such as the userId that will be part of the<br />

relationship of the document. You also added a list of documents.<br />

For purposes of the application and just for this chapter, these relationships will be enough to show how to use<br />

persistence in My Documents. In later chapters, you are going to use a different mechanism of persistence.<br />

Remember the DocumentDAO interface and its implementation? It contained some examples of only the<br />

implementation of the interface methods, and in another example it had a storage method that provided all the data.<br />

Now you are going to modify it in order to use JDBC; see Listing 9-4.<br />

Listing 9-4. DocumentRepository.java<br />

package com.apress.isf.spring.data;<br />

import java.sql.Connection;<br />

import java.sql.ResultSet;<br />

import java.sql.SQLException;<br />

import java.sql.Statement;<br />

import java.util.ArrayList;<br />

import java.util.List;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!