Java Reference
In-Depth Information
The configuration API
The configuration file in listing A.1 is used to configure an instance of SqlMapper ,
the class that you'll be using to work with your mapped statements. The SqlMapper
instance is created by a factory class called DomSqlMapBuilder , which reads
through the XML configuration file to build the SqlMapper . The following is an
example of what this configuration looks like:
ISqlMapper sqlMap =
new DomSqlMapBuilder().Configure("SqlMap.config");
This single line of code (split in this example) is all you need.
We now have a configured ISqlMapper instance that we can use to call the state-
ments in Employee.xml . The next section takes a look at what's inside Employee.xml .
SQL mapping files
Like the configuration file in listing A.1, the SQL mapping files are also a bit dif-
ferent, but they are similar enough to make any i BATIS user comfortable. i BA-
TIS.NET supports all of the same types of statements, including stored procedures.
Here is a simple query statement from Employee.xml :
<select id="SelectEmployee" parameterClass="int"
EmployeeID as ID,
EmployeeID = #value#
The select statement takes an integer as a parameter, and returns an Employee
object populated with some of the data from the Employees table from the North-
wind database. As you might recognize, this particular statement is making use of
automapping. That is, no result map is specified. Instead, columns are mapped to
class properties by their names. Notice how EmployeeID is aliased to ID , as that is
the name of the property in the Employee class. We could have defined an explicit
result map, which would have changed the listing as follows:
<resultMap id="EmployeeResult" class="Employee">
<result property="ID" column="EmployeeId"/>
<result property="FirstName" column="FirstName"/>
<result property="LastName" column="LastName "/>
Search WWH ::

Custom Search