Java Reference
In-Depth Information
13.3.3
Naming result maps
Result maps are bound to a single class type and the reusability of result maps is
quite high. For this reason, we recommend naming result maps using the type
they are bound against; also, append
Result
to the name. For example:
<resultMap id="PersonResult" type="com.domain.Person">
13.3.4
XML files
There are two kinds of
XML
files in i
BATIS
. The first is the master configuration
file and the others are the
SQL
mapping files.
The master configuration file
The master configuration file can be called whatever you like; however, we recom-
mend calling it
SqlMapConfig.xml
. If you have multiple configuration files for dif-
ferent parts of the application, then prefix the configuration filename with the
name of the application module. So if your application has a web client and a
GUI
client with different configurations, you might use
WebSqlMapConfig.xml
and
GuiSqlMapConfig.xml
. You may also have multiple environments in which you
deploy, such as production and test environments. In this case, prefix the filename
with the type of environment as well. Continuing with the previous example, you
might have
ProductionWebSqlMapConfig.xml
and
TestWebSqlMapConfig.xml
. These
names are descriptive, and the consistency creates opportunities to automate builds
to different environments.
The SQL mapping files
How you name the
SQL
mapping files will depend a lot on how you've organized
your mapped statements. Earlier in this topic we recommended that you organize
your mapped statements into separate
XML
files based on their return types and
parameters. If you've done that, naming the file after the return types and
parameters will also work. For example, if one mapping
XML
file contains
SQL
statements involving the
Person
class, then naming the mapping file
Person.xml
would be appropriate. Most applications will do fine with this naming approach.
There are other considerations, though.
Some applications may require multiple implementations of the same
statement to match different databases. For the most part,
SQL
can be written in a
portable way. For example, the original JPetStore application that was written with
i
BATIS
was compatible with 11 different databases. However, sometimes there are
features of the database that are not portable but that are ideal for the solution
being implemented. In cases like this, it becomes acceptable and even important
