Java Reference
In-Depth Information
When using the
resource
attribute, the classloader will attempt to locate that
resource on the application's classpath. This is called a
resource
, because we are using
a classloader to read it. The Java documentation refers to resources when accessing
data this way, because while it may just be a file on the local files system, it is just as
possible that it is an entry in a
JAR
file, possibly even on a different computer.
The
url
attribute is handled by the
java.net.URL
class, so it can be any valid
URL
that it understands and can use to load data.
In our earlier example, we used the
<properties>
element to keep the data-
base configuration details out of our
XML
file and put them in a simple properties
file called
db.properties
that exits on our classpath. This separation is useful for a
number of reasons, not the least of which is simplicity. Let's assume that our
db.properties
file contained the following four property definitions:
driver=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost/test
user=root
pword=apple
We refer to the properties file with the following line taken from our previous
example:
<properties resource="db.properties" />
Finally, we use the properties by name using a syntax that will be familiar to many
people:
<property name="JDBC.Driver" value="
${driver}
"/>
<property name="JDBC.ConnectionURL" value="
${url}
"/>
<property name="JDBC.Username" value="
${user}
"/>
<property name="JDBC.Password" value="
${pword}
"/>
At this point you should be thinking to yourself, “Gee, that looks just like the way
every other tool uses properties!”
3.6.3
The <settings> element
The
<settings>
element is a bit of a grab bag of configuration options. You set
these options by inserting attributes into the
<settings>
element. Several settings
are available, and each of them is global to this
SQL
Map instance.
lazyLoadingEnabled
Lazy loading
is a technique in which you load only the information that is essential,
and defer the loading of other data until it is specifically requested. In other words,
you want to have the application do as little as possible until it is absolutely required.
