Introducing Spring Framework
Introducing Spring Framework Introducing Spring Framework
Chapter 9 ■ Adding Persistence to Your Spring Application Listing 9-10 shows a new method called initialize, where you read the resource files, the schema.sql and data.sql files, and you inject the query through the queryAll property. Also, you are exposing a better way to build the Document object because you are adding the type; just remember that the Document contains this relationship. Look at Figure 9-1 and Listing 9-8 where you have this relationship between the documents and types, and the users and documents. But wait! How do you tell Spring to call the initialize method? Let’s see how by reviewing the XML file in Listing 9-11. Listing 9-11. mydocuments-jdbc-context.xml select d.documentId, d.name, d.location, d.description as doc_desc, d.typeId, d.created, d.modified, t.name as type_name, t.description as type_desc, t.extension from documents d join types t on d.typeId = t.typeId 125
Chapter 9 ■ Adding Persistence to Your Spring Application If you run Listing 9-7 with gradle :ch09:test then the test will pass, because you have added the initialize method and you can count on the data being there. Embedding a Database In the XML configuration (see Listing 9-11) you can see the DocumentRepository class and the initialize method; there should be a better way to initialize your database, right? Well, the Spring Framework offers different ways to use the JDBC; for test purposes it provides a way to use the HSQLDB in an embedded way through an xmlns:jdbc namespace. Let’s modify the XML configuration to use these new features from the xmlns:jdbc namespace (see Listing 9-12). Listing 9-12. mydocuments-jdbc-embedded-context.xml
- Page 73 and 74: Chapter 6 ■ Using Resource Files
- Page 75 and 76: Chapter 6 ■ Using Resource Files
- Page 77 and 78: Chapter 7 Testing Your Spring Appli
- Page 79 and 80: Chapter 7 ■ Testing Your Spring A
- Page 81 and 82: Chapter 7 ■ Testing Your Spring A
- Page 83 and 84: Chapter 7 ■ Testing Your Spring A
- Page 85 and 86: Chapter 7 ■ Testing Your Spring A
- Page 87 and 88: Chapter 7 ■ Testing Your Spring A
- Page 89 and 90: Chapter 8 Give Advice to Your Sprin
- Page 91 and 92: Chapter 8 ■ Give Advice to Your S
- Page 93 and 94: Chapter 8 ■ Give Advice to Your S
- Page 95 and 96: Chapter 8 ■ Give Advice to Your S
- Page 97 and 98: Chapter 8 ■ Give Advice to Your S
- Page 99 and 100: Chapter 8 ■ Give Advice to Your S
- Page 101 and 102: Chapter 8 ■ Give Advice to Your S
- Page 103 and 104: Chapter 8 ■ Give Advice to Your S
- Page 105 and 106: Chapter 8 ■ Give Advice to Your S
- Page 107 and 108: Chapter 8 ■ Give Advice to Your S
- Page 109 and 110: Chapter 8 ■ Give Advice to Your S
- Page 111 and 112: Chapter 9 ■ Adding Persistence to
- Page 113 and 114: Chapter 9 ■ Adding Persistence to
- Page 115 and 116: Chapter 9 ■ Adding Persistence to
- Page 117 and 118: Chapter 9 ■ Adding Persistence to
- Page 119 and 120: Chapter 9 ■ Adding Persistence to
- Page 121 and 122: Chapter 9 ■ Adding Persistence to
- Page 123: Chapter 9 ■ Adding Persistence to
- Page 127 and 128: Chapter 9 ■ Adding Persistence to
- Page 129 and 130: Chapter 9 ■ Adding Persistence to
- Page 131 and 132: Chapter 9 ■ Adding Persistence to
- Page 133 and 134: Chapter 10 ■ Showing Your Spring
- Page 135 and 136: Chapter 10 ■ Showing Your Spring
- Page 137 and 138: Chapter 10 ■ Showing Your Spring
- Page 139 and 140: Chapter 10 ■ Showing Your Spring
- Page 141 and 142: Chapter 10 ■ Showing Your Spring
- Page 143 and 144: Chapter 10 ■ Showing Your Spring
- Page 145 and 146: Chapter 11 ■ Integrating Your Spr
- Page 147 and 148: Chapter 11 ■ Integrating Your Spr
- Page 149 and 150: Chapter 11 ■ Integrating Your Spr
- Page 151 and 152: Chapter 11 ■ Integrating Your Spr
- Page 153 and 154: Chapter 11 ■ Integrating Your Spr
- Page 155 and 156: Chapter 11 ■ Integrating Your Spr
- Page 157 and 158: Chapter 11 ■ Integrating Your Spr
- Page 159 and 160: Chapter 11 ■ Integrating Your Spr
- Page 161 and 162: Chapter 11 ■ Integrating Your Spr
- Page 163 and 164: Chapter 11 ■ Integrating Your Spr
- Page 165 and 166: Chapter 11 ■ Integrating Your Spr
- Page 167 and 168: Chapter 12 Exposing a REST API Nowa
- Page 169 and 170: Chapter 12 ■ Exposing a REST API
- Page 171 and 172: Chapter 12 ■ Exposing a REST API
- Page 173 and 174: Chapter 12 ■ Exposing a REST API
Chapter 9 ■ Adding Persistence to Your <strong>Spring</strong> Application<br />
Listing 9-10 shows a new method called initialize, where you read the resource files, the schema.sql and<br />
data.sql files, and you inject the query through the queryAll property. Also, you are exposing a better way to build<br />
the Document object because you are adding the type; just remember that the Document contains this relationship.<br />
Look at Figure 9-1 and Listing 9-8 where you have this relationship between the documents and types, and the users<br />
and documents.<br />
But wait! How do you tell <strong>Spring</strong> to call the initialize method? Let’s see how by reviewing the XML file in<br />
Listing 9-11.<br />
Listing 9-11. mydocuments-jdbc-context.xml<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
select d.documentId, d.name, d.location, d.description as doc_desc, d.typeId,<br />
d.created, d.modified,<br />
t.name as type_name, t.description as type_desc, t.extension from documents d<br />
join types t<br />
on d.typeId = t.typeId<br />
<br />
<br />
<br />
<br />
125