X Tutup
Skip to content

Commit 70b2a4c

Browse files
committed
SESPRINGPYTHONPY-72: Merged changes from branch to trunk. All tests passed.
git-svn-id: https://src.springframework.org/svn/se-springpython-py/trunk/springpython@235 ce8fead1-4192-4296-8608-a705134b927f
1 parent f3cd570 commit 70b2a4c

File tree

16 files changed

+100
-180
lines changed

16 files changed

+100
-180
lines changed

.pydevproject

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.5</pydev_property>
66
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
77
<path>/springpython/src</path>
8+
<path>/springpython/samples/basic</path>
89
<path>/springpython/samples/petclinic</path>
910
<path>/springpython/samples/springirc</path>
1011
<path>/springpython/samples/springwiki</path>
1112
<path>/springpython/test</path>
12-
<path>/springpython/samples/basic</path>
1313
</pydev_pathproperty>
1414
</pydev_project>

dependencies/CherryPy-2.3.0.tar.gz

-236 KB
Binary file not shown.

dependencies/CherryPy-2.3.0.zip

-270 KB
Binary file not shown.

dependencies/Pyro-3.7.tar.gz

-238 KB
Binary file not shown.

dependencies/Pyro-3.7.win32.exe

-142 KB
Binary file not shown.

dependencies/Pyro-3.8.1.tar.gz

241 KB
Binary file not shown.

dependencies/Pyro-3.8.1.win32.exe

147 KB
Binary file not shown.

docs/reference/src/dao.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ return results
5454
<title>Database Template</title>
5555

5656
<para>The same query above can be written using a <classname>DatabaseTemplate</classname>. The only
57-
thing you must provide is the SQL and a <classname>RowCallbackHandler</classname> to process one row of
57+
thing you must provide is the SQL and a <classname>RowMapper</classname> to process one row of
5858
data. The template does the rest.</para>
5959

6060
<programlisting><![CDATA[
@@ -63,15 +63,15 @@ from springpython.database import *
6363
connectionFactory = MySQLConnectionFactory(username="me", password"secret", hostname="localhost", db="springpython")
6464
dt = DatabaseTemplate(connectionFactory)
6565
66-
class TvShowCallbackHandler(RowCallbackHandler):
66+
class TvShowMapper(RowCallbackHandler):
6767
"""This will handle one row of database. It can be reused for many queries if they
6868
are returning the same columns."""
69-
def process_row(self, row):
69+
def map_row(self, row):
7070
return TvShow(title=row[0], airDate=row[1], episodeNumber=row[2], writer=row[3])
7171
7272
7373
results = dt.query("select title, air_date, episode_number, writer from tv_shows where name = %s", \
74-
("Monty Python",), TvShowCallbackHandler())
74+
("Monty Python",), TvShowMapper())
7575
]]></programlisting>
7676

7777
<para>Well, no sign of a cursor anywhere. If you didn't have to worry about opening it,
@@ -81,11 +81,11 @@ results = dt.query("select title, air_date, episode_number, writer from tv_shows
8181

8282
<programlisting><![CDATA[
8383
results = dt.query("select title, air_date, episode_number, writer from tv_shows where episode_number < %s", \
84-
(100,), TvShowCallbackHandler())
84+
(100,), TvShowMapper())
8585
results = dt.query("select title, air_date, episode_number, writer from tv_shows where upper(title) like %s", \
86-
("%CHEESE%",), TvShowCallbackHandler())
86+
("%CHEESE%",), TvShowMapper())
8787
results = dt.query("select title, air_date, episode_number, writer from tv_shows where writer in ('Cleese', 'Graham')",
88-
rowhandler=TvShowCallbackHandler())
88+
rowhandler=TvShowMapper())
8989
]]></programlisting>
9090

9191
<para>You don't have to reimplement the rowhandler. For these queries, you can focus

samples/petclinic/cherrypy/controller.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from datetime import date
2020
from springpython.database.core import DaoSupport
2121
from springpython.database.core import DatabaseTemplate
22-
from springpython.database.core import RowCallbackHandler
22+
from springpython.database.core import RowMapper
2323
from springpython.security import UsernameNotFoundException
2424
from springpython.security.userdetails import UserDetailsService
2525
from model import Owner
@@ -46,7 +46,7 @@ def getVets(self):
4646
first_name,
4747
last_name
4848
FROM vets
49-
""", rowhandler=VetRowCallbackHandler())
49+
""", rowhandler=VetRowMapper())
5050

5151
def getOwners(self, lastName = ""):
5252
"""Return a list of owners, filtered by partial lastname."""
@@ -60,7 +60,7 @@ def getOwners(self, lastName = ""):
6060
telephone
6161
FROM owners
6262
WHERE upper(last_name) like ?
63-
""", ("%"+lastName.upper()+"%",), OwnerRowCallbackHandler())
63+
""", ("%"+lastName.upper()+"%",), OwnerRowMapper())
6464

6565
def getOwner(self, id):
6666
"""Return one owner."""
@@ -74,7 +74,7 @@ def getOwner(self, id):
7474
telephone
7575
FROM owners
7676
WHERE id = ?
77-
""", (id,), OwnerRowCallbackHandler())[0]
77+
""", (id,), OwnerRowMapper())[0]
7878

7979
def addOwner(self, **kwargs):
8080
"""Add an owner to the database."""
@@ -110,7 +110,7 @@ def getPets(self, owner):
110110
WHERE owners.id = ?
111111
AND owners.id = pets.owner_id
112112
AND types.id = pets.type_id
113-
""", (owner.id,), PetRowCallbackHandler())
113+
""", (owner.id,), PetRowMapper())
114114

115115
def getPet(self, id):
116116
"""Return pets belonging to a particular owner."""
@@ -123,7 +123,7 @@ def getPet(self, id):
123123
FROM pets, types
124124
WHERE pets.id = ?
125125
AND types.id = pets.type_id
126-
""", (id,), PetRowCallbackHandler())[0]
126+
""", (id,), PetRowMapper())[0]
127127

128128
def getVisits(self, pet):
129129
"""Return visits associated with a particular pet."""
@@ -134,7 +134,7 @@ def getVisits(self, pet):
134134
FROM pets, visits
135135
WHERE pets.id = ?
136136
AND pets.id = visits.pet_id
137-
""", (pet.id,), VisitRowCallbackHandler())
137+
""", (pet.id,), VisitRowMapper())
138138

139139
def addPet(self, id, name, birthDate, type):
140140
"""Store a new pet in the database."""
@@ -151,7 +151,7 @@ def getPetTypes(self):
151151
return self.database_template.query("""
152152
SELECT types.id, types.name
153153
FROM types
154-
""", rowhandler=PetTypeRowCallbackHandler())
154+
""", rowhandler=PetTypeRowMapper())
155155

156156
def visitClinic(self, petId, description):
157157
"""Record a visit to the clinic."""
@@ -173,7 +173,7 @@ def getVetSpecialties(self, vet):
173173
WHERE vets.id = vet_specialties.vet_id
174174
AND vet_specialties.specialty_id = specialties.id
175175
AND vets.id = ?
176-
""", (vet.id,), SpecialtyRowCallbackHandler())
176+
""", (vet.id,), SpecialtyRowMapper())
177177

178178
def getUsername(self, id):
179179
"""Look up the username associated with a user id"""
@@ -194,20 +194,20 @@ def getUsers(self):
194194
users[i] = (users[i][0], users[i][1], authorities, users[i][3])
195195
return users
196196

197-
class VetRowCallbackHandler(RowCallbackHandler):
197+
class VetRowMapper(RowMapper):
198198
"""This is a row callback handler used in a database template call. It is used to process
199199
one row of data from a Vet-oriented query by mapping a Vet-record."""
200-
def process_row(self, row):
200+
def map_row(self, row):
201201
vet = Vet()
202202
vet.id = row[0]
203203
vet.firstName = row[1]
204204
vet.lastName = row[2]
205205
return vet
206206

207-
class OwnerRowCallbackHandler(RowCallbackHandler):
207+
class OwnerRowMapper(RowMapper):
208208
"""This is a row callback handler used in a database template call. It is used to process
209209
one row of data from an owner-oriented query by mapping an Owner-record."""
210-
def process_row(self, row):
210+
def map_row(self, row):
211211
owner = Owner()
212212
owner.id = row[0]
213213
owner.firstName = row[1]
@@ -217,39 +217,39 @@ def process_row(self, row):
217217
owner.telephone = row[5]
218218
return owner
219219

220-
class PetRowCallbackHandler(RowCallbackHandler):
220+
class PetRowMapper(RowMapper):
221221
"""This is a row callback handler used in a database template call. It is used to process
222222
one row of data from a pet-oriented query by mapping an Pet-record."""
223-
def process_row(self, row):
223+
def map_row(self, row):
224224
pet = Pet()
225225
pet.id = row[0]
226226
pet.name = row[1]
227227
pet.birthDate = row[2]
228228
pet.type = row[3]
229229
return pet
230230

231-
class PetTypeRowCallbackHandler(RowCallbackHandler):
231+
class PetTypeRowMapper(RowMapper):
232232
"""This is a row callback handler used in a database template call. It is used to process
233233
one row of data from a visit-oriented query by mapping an Visit-record."""
234-
def process_row(self, row):
234+
def map_row(self, row):
235235
petType = PetType()
236236
petType.id = row[0]
237237
petType.name = row[1]
238238
return petType
239239

240-
class SpecialtyRowCallbackHandler(RowCallbackHandler):
240+
class SpecialtyRowMapper(RowMapper):
241241
"""This is a row callback handler used in a database template call. It is used to process
242242
one row of data from a visit-oriented query by mapping an Visit-record."""
243-
def process_row(self, row):
243+
def map_row(self, row):
244244
specialty = Specialty()
245245
specialty.id = row[0]
246246
specialty.name = row[1]
247247
return specialty
248248

249-
class VisitRowCallbackHandler(RowCallbackHandler):
249+
class VisitRowMapper(RowMapper):
250250
"""This is a row callback handler used in a database template call. It is used to process
251251
one row of data from a visit-oriented query by mapping an Visit-record."""
252-
def process_row(self, row):
252+
def map_row(self, row):
253253
visit = Visit()
254254
visit.date = row[0]
255255
visit.description = row[1]

samples/petclinic/cherrypy/petclinic-client-xml.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
"""
16+
1617
import cherrypy
1718
import logging
1819
import os
1920
import noxml
21+
from springpython.context import XmlApplicationContext
2022
from springpython.security.cherrypy31 import AuthenticationFilter, ContextSessionFilter, SecurityFilter
2123
from springpython.security.context import SecurityContextHolder
22-
from springpython.context import XmlApplicationContext
2324

2425
if __name__ == '__main__':
2526
"""This allows the script to be run as a tiny webserver, allowing quick testing and development.
@@ -36,6 +37,9 @@
3637
ch.setFormatter(formatter)
3738
logger.addHandler(ch)
3839

40+
# This sample loads the IoC container from an XML file. The XML-based application context
41+
# automatically resolves all dependencies and order of instantiation for you.
42+
3943
applicationContext = XmlApplicationContext(configLocation = "applicationContext-client.xml")
4044

4145
SecurityContextHolder.setStrategy(SecurityContextHolder.MODE_GLOBAL)

0 commit comments

Comments
 (0)
X Tutup