Java Reference
In-Depth Information
13.2.3
Organize mostly by return type
The most common question with regard to mapping file organization is what to
organize them by. Should you organize them by database table? How about by
class? Perhaps organize them by the type of statement?
The answer depends on your environment. Although there is no “right”
answer, don't get too fancy about it. i
BATIS
is very flexible, and you can always
move the statements around later.
As a starting point, it's best to organize your maps by the type that the statements
return and the types they take as a parameter. This generally creates a nice organi-
zation of maps that you can navigate based on what you're looking for. So for exam-
ple, in a
Person.xml
mapping file, you should expect to find mapped statements
that return
Person
objects (or collections of
Person
objects), as well as statements
that take a
Person
object as a parameter (like
insertPerson
or
updatePerson
).
13.3 Naming conventions
There can be a lot of things to name in i
BATIS
: statements, result maps, parame-
ter maps,
SQL
maps, and
XML
files all need names. Therefore, it's a good idea to
have some sort of convention. We'll discuss one convention here, but feel free to
use your own. As long as you're consistent within your application, you won't
have any trouble.
13.3.1
Naming statements
Statements should generally follow the same naming convention as methods in the
language in which you're programming. That is, in a Java application, use state-
ment names like
loadPerson
or
getPerson
. In C#, use statement names like
Save-
Person
or
UpdatePerson
. Using this convention will help you maintain consistency,
but it also will help with method-binding features and code-generation tools.
13.3.2
Naming parameter maps
Most of the time parameter maps will not have to be named, because inline
parameter maps are much more common than explicitly defined ones. Due to the
nature of
SQL
statements, parameter maps have limited reusability. You generally
can't use the same one for both an
INSERT
statement and an
UPDATE
statement. For
this reason, if you do use an explicitly defined parameter map, we recommend
adding the suffix
Param
to the name of the statement that uses it. For example:
<select id="getPerson" parameterMap="
getPersonParam
" ... >



