Java Reference
In-Depth Information
to name your mapping files so that they include the database for which they were
specifically written. For instance, if we had an Oracle-specific file for Person , we'd
name it OraclePerson.xml . Another approach is to use a separate directory for
each database, named after the database. Don't go crazy with these approaches.
Only specifically name the files or directories that you have to, and make sure
there's enough Oracle-specific matter in the mapping file to make the name
appropriate. If there's only a single statement that is Oracle dependent, then you
might be better off naming the one statement to include the word Oracle .
13.4 Beans, maps, or XML?
i BATIS supports many types for parameter and result mappings. You have a choice
of JavaBeans, Maps (such as HashMap), XML , and of course primitive types.
Which should you choose to map your statements to? Our default position is
always JavaBeans.
JavaBeans provide the highest performance, the greatest amount of flexibility,
and type safety. JavaBeans are fast because they use simple, low-level method calls
for property mappings. JavaBeans won't degrade performance as you add more
properties, and they are more memory efficient than the alternatives. A more
important consideration is that JavaBeans are type safe. This type safety allows i BA-
TIS to determine the appropriate type of value that should be returned from the
database and binds it tightly. There is not the guesswork that you experience with
maps or XML . You also have more flexibility with JavaBeans because you are able
to customize your getters and setters to fine-tune your data.
i BATIS supports maps for two purposes. First, i BATIS uses maps as the mechanism
for sending multiple complex parameters to mapped statements. Second, maps
are supported because sometimes a table in a database represents just that—a set
of keyed values.
However, maps make horrible domain models, and therefore you should not
use maps to represent your business objects. This is not an i BATIS -specific recom-
mendation; you shouldn't use maps to model your domain regardless of your per-
sistence layer. Maps are slow, they are not type-safe, they use up more memory
than JavaBeans, and they can become unpredictable and difficult to maintain.
Use maps judiciously.
Search WWH ::

Custom Search