added language element to programlisting for syntax highlighting

This commit is contained in:
Thomas Risberg 2009-04-13 13:12:38 +00:00
parent b7ab939d55
commit f4b4f28fc2
4 changed files with 171 additions and 180 deletions

View File

@ -228,23 +228,23 @@
<para>A simple query for getting the number of rows in a <para>A simple query for getting the number of rows in a
relation.</para> relation.</para>
<programlisting>int rowCount = this.jdbcTemplate.queryForInt("select count(0) from t_accrual");</programlisting> <programlisting language="java">int rowCount = this.jdbcTemplate.queryForInt("select count(0) from t_accrual");</programlisting>
<para>A simple query using a bind variable.</para> <para>A simple query using a bind variable.</para>
<programlisting>int countOfActorsNamedJoe = this.jdbcTemplate.queryForInt( <programlisting language="java">int countOfActorsNamedJoe = this.jdbcTemplate.queryForInt(
"select count(0) from t_actors where first_name = ?", new Object[]{"Joe"});</programlisting> "select count(0) from t_actors where first_name = ?", new Object[]{"Joe"});</programlisting>
<para>Querying for a <classname>String</classname>.</para> <para>Querying for a <classname>String</classname>.</para>
<programlisting>String surname = (String) this.jdbcTemplate.queryForObject( <programlisting language="java">String surname = (String) this.jdbcTemplate.queryForObject(
"select surname from t_actor where id = ?", "select surname from t_actor where id = ?",
new Object[]{new Long(1212)}, String.class);</programlisting> new Object[]{new Long(1212)}, String.class);</programlisting>
<para>Querying and populating a <emphasis>single</emphasis> domain <para>Querying and populating a <emphasis>single</emphasis> domain
object.</para> object.</para>
<programlisting>Actor actor = (Actor) this.jdbcTemplate.queryForObject( <programlisting language="java">Actor actor = (Actor) this.jdbcTemplate.queryForObject(
"select first_name, surname from t_actor where id = ?", "select first_name, surname from t_actor where id = ?",
new Object[]{new Long(1212)}, new Object[]{new Long(1212)},
new RowMapper() { new RowMapper() {
@ -259,7 +259,7 @@
<para>Querying and populating a number of domain objects.</para> <para>Querying and populating a number of domain objects.</para>
<programlisting>Collection actors = this.jdbcTemplate.query( <programlisting language="java">Collection actors = this.jdbcTemplate.query(
"select first_name, surname from t_actor", "select first_name, surname from t_actor",
new RowMapper() { new RowMapper() {
@ -279,7 +279,7 @@
by DAO methods as needed. For example, the last code snippet might by DAO methods as needed. For example, the last code snippet might
be better off written like so:</para> be better off written like so:</para>
<programlisting>public Collection findAllActors() { <programlisting language="java">public Collection findAllActors() {
return this.jdbcTemplate.query( "select first_name, surname from t_actor", new ActorMapper()); return this.jdbcTemplate.query( "select first_name, surname from t_actor", new ActorMapper());
} }
@ -297,15 +297,15 @@ private static final class ActorMapper implements RowMapper {
<section id="jdbc-JdbcTemplate-examples-update"> <section id="jdbc-JdbcTemplate-examples-update">
<title>Updating (INSERT/UPDATE/DELETE)</title> <title>Updating (INSERT/UPDATE/DELETE)</title>
<programlisting>this.jdbcTemplate.update( <programlisting language="java">this.jdbcTemplate.update(
"insert into t_actor (first_name, surname) values (?, ?)", "insert into t_actor (first_name, surname) values (?, ?)",
new Object[] {"Leonor", "Watling"});</programlisting> new Object[] {"Leonor", "Watling"});</programlisting>
<programlisting>this.jdbcTemplate.update( <programlisting language="java">this.jdbcTemplate.update(
"update t_actor set weapon = ? where id = ?", "update t_actor set weapon = ? where id = ?",
new Object[] {"Banjo", new Long(5276)});</programlisting> new Object[] {"Banjo", new Long(5276)});</programlisting>
<programlisting>this.jdbcTemplate.update( <programlisting language="java">this.jdbcTemplate.update(
"delete from actor where id = ?", "delete from actor where id = ?",
new Object[] {new Long.valueOf(actorId)});</programlisting> new Object[] {new Long.valueOf(actorId)});</programlisting>
</section> </section>
@ -318,13 +318,13 @@ private static final class ActorMapper implements RowMapper {
statements. It is heavily overloaded with variants taking callback statements. It is heavily overloaded with variants taking callback
interfaces, binding variable arrays, and suchlike.</para> interfaces, binding variable arrays, and suchlike.</para>
<programlisting>this.jdbcTemplate.execute("create table mytable (id integer, name varchar(100))");</programlisting> <programlisting language="java">this.jdbcTemplate.execute("create table mytable (id integer, name varchar(100))");</programlisting>
<para>Invoking a simple stored procedure (more sophisticated stored <para>Invoking a simple stored procedure (more sophisticated stored
procedure support is <link linkend="jdbc-StoredProcedure">covered procedure support is <link linkend="jdbc-StoredProcedure">covered
later</link>).</para> later</link>).</para>
<programlisting>this.jdbcTemplate.update( <programlisting language="java">this.jdbcTemplate.update(
"call SUPPORT.REFRESH_ACTORS_SUMMARY(?)", "call SUPPORT.REFRESH_ACTORS_SUMMARY(?)",
new Object[]{Long.valueOf(unionId)});</programlisting> new Object[]{Long.valueOf(unionId)});</programlisting>
</section> </section>
@ -356,7 +356,7 @@ private static final class ActorMapper implements RowMapper {
setter for the <interfacename>DataSource</interfacename>. This leads setter for the <interfacename>DataSource</interfacename>. This leads
to DAOs that look in part like this:</para> to DAOs that look in part like this:</para>
<programlisting>public class JdbcCorporateEventDao implements CorporateEventDao { <programlisting language="java">public class JdbcCorporateEventDao implements CorporateEventDao {
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
@ -369,7 +369,7 @@ private static final class ActorMapper implements RowMapper {
<para>The attendant configuration might look like this.</para> <para>The attendant configuration might look like this.</para>
<programlisting>&lt;?xml version="1.0" encoding="UTF-8"?&gt; <programlisting language="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans" &lt;beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans xsi:schemaLocation="http://www.springframework.org/schema/beans
@ -428,7 +428,7 @@ private static final class ActorMapper implements RowMapper {
the <classname>JdbcTemplate</classname> itself; namely, programming JDBC the <classname>JdbcTemplate</classname> itself; namely, programming JDBC
statements using named parameters.</para> statements using named parameters.</para>
<programlisting><lineannotation>// some JDBC-backed DAO class...</lineannotation> <programlisting language="java"><lineannotation>// some JDBC-backed DAO class...</lineannotation>
private NamedParameterJdbcTemplate namedParameterJdbcTemplate; private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
public void setDataSource(DataSource dataSource) { public void setDataSource(DataSource dataSource) {
@ -458,7 +458,7 @@ public int countOfActorsByFirstName(String firstName) {
implemented by the <classname>NamedParameterJdbcTemplate</classname> implemented by the <classname>NamedParameterJdbcTemplate</classname>
class) follow a similar pattern and will not be covered here.)</para> class) follow a similar pattern and will not be covered here.)</para>
<programlisting><lineannotation>// some JDBC-backed DAO class...</lineannotation> <programlisting language="java"><lineannotation>// some JDBC-backed DAO class...</lineannotation>
private NamedParameterJdbcTemplate namedParameterJdbcTemplate; private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
public void setDataSource(DataSource dataSource) { public void setDataSource(DataSource dataSource) {
@ -498,7 +498,7 @@ public int countOfActorsByFirstName(String firstName) {
conventions</ulink>), and uses the properties of the wrapped JavaBean as conventions</ulink>), and uses the properties of the wrapped JavaBean as
the source of named parameter values.</para> the source of named parameter values.</para>
<programlisting>public class Actor { <programlisting language="java">public class Actor {
private Long id; private Long id;
private String firstName; private String firstName;
@ -520,7 +520,7 @@ public int countOfActorsByFirstName(String firstName) {
}</programlisting> }</programlisting>
<programlisting><lineannotation>// some JDBC-backed DAO class...</lineannotation> <programlisting language="java"><lineannotation>// some JDBC-backed DAO class...</lineannotation>
private NamedParameterJdbcTemplate namedParameterJdbcTemplate; private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
public void setDataSource(DataSource dataSource) { public void setDataSource(DataSource dataSource) {
@ -581,7 +581,7 @@ public int countOfActors(Actor exampleActor) {
a code snippet that does the same job, only this time using the a code snippet that does the same job, only this time using the
<classname>SimpleJdbcTemplate</classname>.</para> <classname>SimpleJdbcTemplate</classname>.</para>
<programlisting><lineannotation>// classic <classname>JdbcTemplate</classname>-style...</lineannotation> <programlisting language="java"><lineannotation>// classic <classname>JdbcTemplate</classname>-style...</lineannotation>
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
public void setDataSource(DataSource dataSource) { public void setDataSource(DataSource dataSource) {
@ -611,7 +611,7 @@ public Actor findActor(long id) {
<classname>SimpleJdbcTemplate</classname>; notice how much 'cleaner' the <classname>SimpleJdbcTemplate</classname>; notice how much 'cleaner' the
code is.</para> code is.</para>
<programlisting><lineannotation>// <classname>SimpleJdbcTemplate</classname>-style...</lineannotation> <programlisting language="java"><lineannotation>// <classname>SimpleJdbcTemplate</classname>-style...</lineannotation>
private SimpleJdbcTemplate simpleJdbcTemplate; private SimpleJdbcTemplate simpleJdbcTemplate;
public void setDataSource(DataSource dataSource) { public void setDataSource(DataSource dataSource) {
@ -690,7 +690,7 @@ public Actor findActor(long id) {
used to connect to the database. Here is an example of how to configure used to connect to the database. Here is an example of how to configure
a <classname>DriverManagerDataSource</classname>:</para> a <classname>DriverManagerDataSource</classname>:</para>
<programlisting>DriverManagerDataSource dataSource = new DriverManagerDataSource(); <programlisting language="java">DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.hsqldb.jdbcDriver"); dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
dataSource.setUrl("jdbc:hsqldb:hsql://localhost:"); dataSource.setUrl("jdbc:hsqldb:hsql://localhost:");
dataSource.setUsername("sa"); dataSource.setUsername("sa");
@ -749,7 +749,7 @@ dataSource.setPassword("");</programlisting>
<para><classname>SQLErrorCodeSQLExceptionTranslator</classname> can be <para><classname>SQLErrorCodeSQLExceptionTranslator</classname> can be
extended the following way:</para> extended the following way:</para>
<programlisting>public class MySQLErrorCodesTranslator extends SQLErrorCodeSQLExceptionTranslator { <programlisting language="java">public class MySQLErrorCodesTranslator extends SQLErrorCodeSQLExceptionTranslator {
protected DataAccessException customTranslate(String task, String sql, SQLException sqlex) { protected DataAccessException customTranslate(String task, String sql, SQLException sqlex) {
if (sqlex.getErrorCode() == -12345) { if (sqlex.getErrorCode() == -12345) {
@ -769,7 +769,7 @@ dataSource.setPassword("");</programlisting>
processing where this translator is needed. Here is an example of how processing where this translator is needed. Here is an example of how
this custom translator can be used:</para> this custom translator can be used:</para>
<programlisting><lineannotation>// create a <classname>JdbcTemplate</classname> and set data source</lineannotation> <programlisting language="java"><lineannotation>// create a <classname>JdbcTemplate</classname> and set data source</lineannotation>
JdbcTemplate jt = new JdbcTemplate(); JdbcTemplate jt = new JdbcTemplate();
jt.setDataSource(dataSource); jt.setDataSource(dataSource);
<lineannotation>// create a custom translator and set the <interfacename>DataSource</interfacename> for the default translation lookup</lineannotation> <lineannotation>// create a custom translator and set the <interfacename>DataSource</interfacename> for the default translation lookup</lineannotation>
@ -799,7 +799,7 @@ su.update();</programlisting>
what you need to include for a minimal but fully functional class that what you need to include for a minimal but fully functional class that
creates a new table.</para> creates a new table.</para>
<programlisting>import javax.sql.DataSource; <programlisting language="java">import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
public class ExecuteAStatement { public class ExecuteAStatement {
@ -833,7 +833,7 @@ public class ExecuteAStatement {
an <classname>int</classname> and one that queries for a an <classname>int</classname> and one that queries for a
<classname>String</classname>.</para> <classname>String</classname>.</para>
<programlisting>import javax.sql.DataSource; <programlisting language="java">import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
public class RunAQuery { public class RunAQuery {
@ -867,7 +867,7 @@ public class RunAQuery {
above example to retrieve a list of all the rows, it would look like above example to retrieve a list of all the rows, it would look like
this:</para> this:</para>
<programlisting> <programlisting language="java">
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
public void setDataSource(DataSource dataSource) { public void setDataSource(DataSource dataSource) {
@ -893,7 +893,7 @@ public List getList() {
objects (and thus primitives have to be wrapped in the primitive wrapper objects (and thus primitives have to be wrapped in the primitive wrapper
classes).</para> classes).</para>
<programlisting>import javax.sql.DataSource; <programlisting language="java">import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
@ -929,7 +929,7 @@ public class ExecuteAnUpdate {
signature is the way it is). An example that works on Oracle and may not signature is the way it is). An example that works on Oracle and may not
work on other platforms is:</para> work on other platforms is:</para>
<programlisting>final String INSERT_SQL = "insert into my_test (name) values(?)"; <programlisting language="java">final String INSERT_SQL = "insert into my_test (name) values(?)";
final String name = "Rob"; final String name = "Rob";
KeyHolder keyHolder = new GeneratedKeyHolder(); KeyHolder keyHolder = new GeneratedKeyHolder();
@ -1169,7 +1169,7 @@ jdbcTemplate.update(
where we update the actor table based on entries in a list. The entire where we update the actor table based on entries in a list. The entire
list is used as the batch in his example.</para> list is used as the batch in his example.</para>
<para><programlisting>public class JdbcActorDao implements ActorDao { <para><programlisting language="java">public class JdbcActorDao implements ActorDao {
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
public void setDataSource(DataSource dataSource) { public void setDataSource(DataSource dataSource) {
@ -1220,7 +1220,7 @@ jdbcTemplate.update(
<para>This example shows a batch update using named parameters:</para> <para>This example shows a batch update using named parameters:</para>
<para><programlisting>public class JdbcActorDao implements ActorDao { <para><programlisting language="java">public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate; private SimpleJdbcTemplate simpleJdbcTemplate;
public void setDataSource(DataSource dataSource) { public void setDataSource(DataSource dataSource) {
@ -1244,7 +1244,7 @@ jdbcTemplate.update(
<para>The same example using classic JDBC "?" place holders:</para> <para>The same example using classic JDBC "?" place holders:</para>
<para><programlisting>public class JdbcActorDao implements ActorDao { <para><programlisting language="java">public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate; private SimpleJdbcTemplate simpleJdbcTemplate;
public void setDataSource(DataSource dataSource) { public void setDataSource(DataSource dataSource) {
@ -1301,7 +1301,7 @@ jdbcTemplate.update(
configuration methods. In this case there is only one configuration configuration methods. In this case there is only one configuration
method used but we will see examples of multiple ones soon.</para> method used but we will see examples of multiple ones soon.</para>
<programlisting>public class JdbcActorDao implements ActorDao { <programlisting language="java">public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate; private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcInsert insertActor; private SimpleJdbcInsert insertActor;
@ -1340,7 +1340,7 @@ jdbcTemplate.update(
generated key column using the generated key column using the
<classname>usingGeneratedKeyColumns</classname> method.</para> <classname>usingGeneratedKeyColumns</classname> method.</para>
<para><programlisting>public class JdbcActorDao implements ActorDao { <para><programlisting language="java">public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate; private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcInsert insertActor; private SimpleJdbcInsert insertActor;
@ -1381,7 +1381,7 @@ jdbcTemplate.update(
specifying a list of column names to be used. This is accomplished using specifying a list of column names to be used. This is accomplished using
the <classname>usingColumns</classname> method.</para> the <classname>usingColumns</classname> method.</para>
<para><programlisting>public class JdbcActorDao implements ActorDao { <para><programlisting language="java">public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate; private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcInsert insertActor; private SimpleJdbcInsert insertActor;
@ -1419,7 +1419,7 @@ jdbcTemplate.update(
contains your values. It will use the corresponding getter method to contains your values. It will use the corresponding getter method to
extract the parameter values. Here is an example:</para> extract the parameter values. Here is an example:</para>
<para><programlisting>public class JdbcActorDao implements ActorDao { <para><programlisting language="java">public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate; private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcInsert insertActor; private SimpleJdbcInsert insertActor;
@ -1443,7 +1443,7 @@ jdbcTemplate.update(
provides a more convenient <classname>addValue</classname> method that provides a more convenient <classname>addValue</classname> method that
can be chained.</para> can be chained.</para>
<para><programlisting>public class JdbcActorDao implements ActorDao { <para><programlisting language="java">public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate; private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcInsert insertActor; private SimpleJdbcInsert insertActor;
@ -1507,7 +1507,7 @@ END;</programlisting>As you can see there are four parameters. One is an in
subclass and we declare it in the initialization method. For this subclass and we declare it in the initialization method. For this
example, all we need to specify is the name of the procedure.</para> example, all we need to specify is the name of the procedure.</para>
<para><programlisting>public class JdbcActorDao implements ActorDao { <para><programlisting language="java">public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate; private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcCall procReadActor; private SimpleJdbcCall procReadActor;
@ -1562,7 +1562,7 @@ END;</programlisting>As you can see there are four parameters. One is an in
<classname>commons-collections.jar</classname> on your classpath for <classname>commons-collections.jar</classname> on your classpath for
this to work. Here is an example of this configuration:</para> this to work. Here is an example of this configuration:</para>
<para><programlisting>public class JdbcActorDao implements ActorDao { <para><programlisting language="java">public class JdbcActorDao implements ActorDao {
private SimpleJdbcCall procReadActor; private SimpleJdbcCall procReadActor;
public void setDataSource(DataSource dataSource) { public void setDataSource(DataSource dataSource) {
@ -1603,7 +1603,7 @@ END;</programlisting>As you can see there are four parameters. One is an in
<para>This is what a fully declared procedure call declaration of our <para>This is what a fully declared procedure call declaration of our
earlier example would look like:</para> earlier example would look like:</para>
<para><programlisting>public class JdbcActorDao implements ActorDao { <para><programlisting language="java">public class JdbcActorDao implements ActorDao {
private SimpleJdbcCall procReadActor; private SimpleJdbcCall procReadActor;
public void setDataSource(DataSource dataSource) { public void setDataSource(DataSource dataSource) {
@ -1644,7 +1644,7 @@ END;</programlisting>As you can see there are four parameters. One is an in
<classname>java.sql.Types</classname> constants. We have already seen <classname>java.sql.Types</classname> constants. We have already seen
declarations like:</para> declarations like:</para>
<para><programlisting> new SqlParameter("in_id", Types.NUMERIC), <para><programlisting language="java"> new SqlParameter("in_id", Types.NUMERIC),
new SqlOutParameter("out_first_name", Types.VARCHAR),</programlisting></para> new SqlOutParameter("out_first_name", Types.VARCHAR),</programlisting></para>
<para>The first line with the <classname>SqlParameter</classname> <para>The first line with the <classname>SqlParameter</classname>
@ -1710,7 +1710,7 @@ END;</programlisting></para>
<classname>SimpleJdbcCall</classname> in the initialization <classname>SimpleJdbcCall</classname> in the initialization
method.</para> method.</para>
<para><programlisting>public class JdbcActorDao implements ActorDao { <para><programlisting language="java">public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate; private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcCall funcGetActorName; private SimpleJdbcCall funcGetActorName;
@ -1768,7 +1768,7 @@ END;</programlisting>In order to call this procedure we need to declare the
created by passing in the required class to map to in the created by passing in the required class to map to in the
<classname>newInstance</classname> method.</para> <classname>newInstance</classname> method.</para>
<para><programlisting>public class JdbcActorDao implements ActorDao { <para><programlisting language="java">public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate; private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcCall procReadAllActors; private SimpleJdbcCall procReadAllActors;
@ -1852,7 +1852,7 @@ END;</programlisting>In order to call this procedure we need to declare the
customer relation to an instance of the <classname>Customer</classname> customer relation to an instance of the <classname>Customer</classname>
class.</para> class.</para>
<programlisting>private class CustomerMappingQuery extends MappingSqlQuery { <programlisting language="java">private class CustomerMappingQuery extends MappingSqlQuery {
public CustomerMappingQuery(DataSource ds) { public CustomerMappingQuery(DataSource ds) {
super(ds, "SELECT id, name FROM customer WHERE id = ?"); super(ds, "SELECT id, name FROM customer WHERE id = ?");
@ -1883,7 +1883,7 @@ END;</programlisting>In order to call this procedure we need to declare the
have been defined we call the <literal>compile()</literal> method so the have been defined we call the <literal>compile()</literal> method so the
statement can be prepared and later be executed.</para> statement can be prepared and later be executed.</para>
<programlisting>public Customer getCustomer(Integer id) { <programlisting language="java">public Customer getCustomer(Integer id) {
CustomerMappingQuery custQry = new CustomerMappingQuery(dataSource); CustomerMappingQuery custQry = new CustomerMappingQuery(dataSource);
Object[] parms = new Object[1]; Object[] parms = new Object[1];
parms[0] = id; parms[0] = id;
@ -1921,7 +1921,7 @@ END;</programlisting>In order to call this procedure we need to declare the
custom update method) it can easily be parameterized by setting SQL and custom update method) it can easily be parameterized by setting SQL and
declaring parameters.</para> declaring parameters.</para>
<programlisting>import java.sql.Types; <programlisting language="java">import java.sql.Types;
import javax.sql.DataSource; import javax.sql.DataSource;
@ -1972,7 +1972,7 @@ public class UpdateCreditRating extends SqlUpdate {
SQL type is specified using the <classname>java.sql.Types</classname> SQL type is specified using the <classname>java.sql.Types</classname>
constants. We have already seen declarations like:</para> constants. We have already seen declarations like:</para>
<para><programlisting> new SqlParameter("in_id", Types.NUMERIC), <para><programlisting language="java"> new SqlParameter("in_id", Types.NUMERIC),
new SqlOutParameter("out_first_name", Types.VARCHAR),</programlisting></para> new SqlOutParameter("out_first_name", Types.VARCHAR),</programlisting></para>
<para>The first line with the <classname>SqlParameter</classname> <para>The first line with the <classname>SqlParameter</classname>
@ -2012,7 +2012,7 @@ public class UpdateCreditRating extends SqlUpdate {
<literal>execute()</literal> method returns a map with an entry for each <literal>execute()</literal> method returns a map with an entry for each
declared output parameter using the parameter name as the key.</para> declared output parameter using the parameter name as the key.</para>
<programlisting>import java.sql.Types; <programlisting language="java">import java.sql.Types;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
@ -2071,7 +2071,7 @@ public class TestStoredProcedure {
<para>Find below an example of a <classname>StoredProcedure</classname> <para>Find below an example of a <classname>StoredProcedure</classname>
that has two output parameters (in this case Oracle REF cursors).</para> that has two output parameters (in this case Oracle REF cursors).</para>
<programlisting>import oracle.jdbc.driver.OracleTypes; <programlisting language="java">import oracle.jdbc.driver.OracleTypes;
import org.springframework.jdbc.core.SqlOutParameter; import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.object.StoredProcedure; import org.springframework.jdbc.object.StoredProcedure;
@ -2110,7 +2110,7 @@ public class TitlesAndGenresStoredProcedure extends StoredProcedure {
<classname>Title</classname> domain object for each row in the supplied <classname>Title</classname> domain object for each row in the supplied
<interfacename>ResultSet</interfacename>.</para> <interfacename>ResultSet</interfacename>.</para>
<programlisting>import com.foo.sprocs.domain.Title; <programlisting language="java">import com.foo.sprocs.domain.Title;
import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.RowMapper;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -2131,7 +2131,7 @@ public final class TitleMapper implements RowMapper {
<classname>Genre</classname> domain object for each row in the supplied <classname>Genre</classname> domain object for each row in the supplied
<interfacename>ResultSet</interfacename>.</para> <interfacename>ResultSet</interfacename>.</para>
<programlisting>import org.springframework.jdbc.core.RowMapper; <programlisting language="java">import org.springframework.jdbc.core.RowMapper;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
@ -2152,7 +2152,7 @@ public final class GenreMapper implements RowMapper {
superclass' (untyped) <literal>execute(Map parameters)</literal> (which superclass' (untyped) <literal>execute(Map parameters)</literal> (which
has <literal>protected</literal> access); for example:</para> has <literal>protected</literal> access); for example:</para>
<programlisting>import oracle.jdbc.driver.OracleTypes; <programlisting language="java">import oracle.jdbc.driver.OracleTypes;
import org.springframework.jdbc.core.SqlOutParameter; import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.object.StoredProcedure; import org.springframework.jdbc.object.StoredProcedure;
@ -2208,7 +2208,7 @@ public class TitlesAfterDateStoredProcedure extends StoredProcedure {
the appropriate run method repeatedly to execute the function. Here is the appropriate run method repeatedly to execute the function. Here is
an example of retrieving the count of rows from a table:</para> an example of retrieving the count of rows from a table:</para>
<programlisting>public int countRows() { <programlisting language="java">public int countRows() {
SqlFunction sf = new SqlFunction(dataSource, "select count(*) from mytable"); SqlFunction sf = new SqlFunction(dataSource, "select count(*) from mytable");
sf.compile(); sf.compile();
return sf.run(); return sf.run();
@ -2343,7 +2343,7 @@ public class TitlesAfterDateStoredProcedure extends StoredProcedure {
<area coords="13" id="jdbc.lobhandler.setBlob" /> <area coords="13" id="jdbc.lobhandler.setBlob" />
</areaspec> </areaspec>
<programlisting>final File blobIn = new File("spring2004.jpg"); <programlisting language="java">final File blobIn = new File("spring2004.jpg");
final InputStream blobIs = new FileInputStream(blobIn); final InputStream blobIs = new FileInputStream(blobIn);
final File clobIn = new File("large.txt"); final File clobIn = new File("large.txt");
final InputStream clobIs = new FileInputStream(clobIn); final InputStream clobIs = new FileInputStream(clobIn);
@ -2392,7 +2392,7 @@ clobReader.close();</programlisting>
<area coords="7" id="jdbc.lobhandler.getBlob" /> <area coords="7" id="jdbc.lobhandler.getBlob" />
</areaspec> </areaspec>
<programlisting>List l = jdbcTemplate.query("select id, a_clob, a_blob from lob_table", <programlisting language="java">List l = jdbcTemplate.query("select id, a_clob, a_blob from lob_table",
new RowMapper() { new RowMapper() {
public Object mapRow(ResultSet rs, int i) throws SQLException { public Object mapRow(ResultSet rs, int i) throws SQLException {
Map results = new HashMap(); Map results = new HashMap();
@ -2471,7 +2471,7 @@ clobReader.close();</programlisting>
interface is used as part of the declaration of an interface is used as part of the declaration of an
<classname>SqlOutParameter</classname>.</para> <classname>SqlOutParameter</classname>.</para>
<para><programlisting>declareParameter(new SqlOutParameter("item", OracleTypes.STRUCT, "ITEM_TYPE", <para><programlisting language="java">declareParameter(new SqlOutParameter("item", OracleTypes.STRUCT, "ITEM_TYPE",
new SqlReturnType() { new SqlReturnType() {
public Object getTypeValue(CallableStatement cs, int colIndx, int sqlType, String typeName) public Object getTypeValue(CallableStatement cs, int colIndx, int sqlType, String typeName)
throws SQLException { throws SQLException {
@ -2492,7 +2492,7 @@ clobReader.close();</programlisting>
specific objects like <classname>StructDescriptor</classname>s or specific objects like <classname>StructDescriptor</classname>s or
<classname>ArrayDescriptor</classname>s</para> <classname>ArrayDescriptor</classname>s</para>
<para><programlisting>SqlTypeValue value = new AbstractSqlTypeValue() { <para><programlisting language="java">SqlTypeValue value = new AbstractSqlTypeValue() {
protected Object createTypeValue(Connection conn, int sqlType, String typeName) throws SQLException { protected Object createTypeValue(Connection conn, int sqlType, String typeName) throws SQLException {
StructDescriptor itemDescriptor = new StructDescriptor(typeName, conn); StructDescriptor itemDescriptor = new StructDescriptor(typeName, conn);
Struct item = new STRUCT(itemDescriptor, conn, Struct item = new STRUCT(itemDescriptor, conn,

View File

@ -192,7 +192,7 @@
JDBC <classname>DataSource</classname> and a Hibernate JDBC <classname>DataSource</classname> and a Hibernate
<interfacename>SessionFactory</interfacename> on top of it:</para> <interfacename>SessionFactory</interfacename> on top of it:</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt; &lt;bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
&lt;property name="driverClassName" value="org.hsqldb.jdbcDriver"/&gt; &lt;property name="driverClassName" value="org.hsqldb.jdbcDriver"/&gt;
@ -222,7 +222,7 @@
<interfacename>DataSource</interfacename> (usually managed by an <interfacename>DataSource</interfacename> (usually managed by an
application server) is just a matter of configuration:</para> application server) is just a matter of configuration:</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="myDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"&gt; &lt;bean id="myDataSource" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
&lt;property name="jndiName" value="java:comp/env/jdbc/myds"/&gt; &lt;property name="jndiName" value="java:comp/env/jdbc/myds"/&gt;
@ -251,7 +251,7 @@
<interfacename>SessionFactory</interfacename>, and an example for a DAO <interfacename>SessionFactory</interfacename>, and an example for a DAO
method implementation.</para> method implementation.</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="myProductDao" class="product.ProductDaoImpl"&gt; &lt;bean id="myProductDao" class="product.ProductDaoImpl"&gt;
&lt;property name="sessionFactory" ref="mySessionFactory"/&gt; &lt;property name="sessionFactory" ref="mySessionFactory"/&gt;
@ -259,7 +259,7 @@
&lt;/beans&gt;</programlisting> &lt;/beans&gt;</programlisting>
<programlisting>public class ProductDaoImpl implements ProductDao { <programlisting language="java">public class ProductDaoImpl implements ProductDao {
private HibernateTemplate hibernateTemplate; private HibernateTemplate hibernateTemplate;
@ -280,7 +280,7 @@
that are not exposed on the <classname>HibernateTemplate</classname>, that are not exposed on the <classname>HibernateTemplate</classname>,
you can always drop down to a callback-based approach like so.</para> you can always drop down to a callback-based approach like so.</para>
<programlisting>public class ProductDaoImpl implements ProductDao { <programlisting language="java">public class ProductDaoImpl implements ProductDao {
private HibernateTemplate hibernateTemplate; private HibernateTemplate hibernateTemplate;
@ -319,7 +319,7 @@
combination, this allows for very simple DAO implementations for typical combination, this allows for very simple DAO implementations for typical
requirements:</para> requirements:</para>
<programlisting>public class ProductDaoImpl extends HibernateDaoSupport implements ProductDao { <programlisting language="java">public class ProductDaoImpl extends HibernateDaoSupport implements ProductDao {
public Collection loadProductsByCategory(String category) throws DataAccessException { public Collection loadProductsByCategory(String category) throws DataAccessException {
return this.getHibernateTemplate().find( return this.getHibernateTemplate().find(
@ -349,7 +349,7 @@
<interfacename>Session</interfacename>, as its lifecycle is managed by <interfacename>Session</interfacename>, as its lifecycle is managed by
the transaction).</para> the transaction).</para>
<programlisting>public class HibernateProductDao extends HibernateDaoSupport implements ProductDao { <programlisting language="java">public class HibernateProductDao extends HibernateDaoSupport implements ProductDao {
public Collection loadProductsByCategory(String category) throws DataAccessException, MyException { public Collection loadProductsByCategory(String category) throws DataAccessException, MyException {
Session session = getSession(false); Session session = getSession(false);
@ -391,7 +391,7 @@
DAO implementation looks like as follows, based on the plain Hibernate DAO implementation looks like as follows, based on the plain Hibernate
API:</para> API:</para>
<programlisting>public class ProductDaoImpl implements ProductDao { <programlisting language="java">public class ProductDaoImpl implements ProductDao {
private SessionFactory sessionFactory; private SessionFactory sessionFactory;
@ -424,7 +424,7 @@
with the desired factory reference. As a Spring bean definition, it with the desired factory reference. As a Spring bean definition, it
would look as follows:</para> would look as follows:</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="myProductDao" class="product.ProductDaoImpl"&gt; &lt;bean id="myProductDao" class="product.ProductDaoImpl"&gt;
&lt;property name="sessionFactory" ref="mySessionFactory"/&gt; &lt;property name="sessionFactory" ref="mySessionFactory"/&gt;
@ -480,7 +480,7 @@
a Spring application context, and an example for a business method a Spring application context, and an example for a business method
implementation.</para> implementation.</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="myTxManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt; &lt;bean id="myTxManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
&lt;property name="sessionFactory" ref="mySessionFactory"/&gt; &lt;property name="sessionFactory" ref="mySessionFactory"/&gt;
@ -493,7 +493,7 @@
&lt;/beans&gt;</programlisting> &lt;/beans&gt;</programlisting>
<programlisting>public class ProductServiceImpl implements ProductService { <programlisting language="java">public class ProductServiceImpl implements ProductService {
private TransactionTemplate transactionTemplate; private TransactionTemplate transactionTemplate;
private ProductDao productDao; private ProductDao productDao;
@ -533,7 +533,7 @@
configuration file and do not affect the business service configuration file and do not affect the business service
implementations.</para> implementations.</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="myTxManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt; &lt;bean id="myTxManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
&lt;property name="sessionFactory" ref="mySessionFactory"/&gt; &lt;property name="sessionFactory" ref="mySessionFactory"/&gt;
@ -555,7 +555,7 @@
&lt;/beans&gt;</programlisting> &lt;/beans&gt;</programlisting>
<programlisting>public class ProductServiceImpl implements ProductService { <programlisting language="java">public class ProductServiceImpl implements ProductService {
private ProductDao productDao; private ProductDao productDao;
@ -593,7 +593,7 @@
have not done so already prior to continuing.</para> have not done so already prior to continuing.</para>
</note> </note>
<programlisting>&lt;?xml version="1.0" encoding="UTF-8"?&gt; <programlisting language="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans" &lt;beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:aop="http://www.springframework.org/schema/aop"
@ -663,7 +663,7 @@
factories without special regard, as long as it is using factories without special regard, as long as it is using
<classname>JtaTransactionManager</classname> as the strategy.</para> <classname>JtaTransactionManager</classname> as the strategy.</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="myDataSource1" class="org.springframework.jndi.JndiObjectFactoryBean"&gt; &lt;bean id="myDataSource1" class="org.springframework.jndi.JndiObjectFactoryBean"&gt;
&lt;property name="jndiName value="java:comp/env/jdbc/myds1"/&gt; &lt;property name="jndiName value="java:comp/env/jdbc/myds1"/&gt;
@ -963,7 +963,7 @@
<interfacename>PersistenceManagerFactory</interfacename> within a Spring <interfacename>PersistenceManagerFactory</interfacename> within a Spring
application context:</para> application context:</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="myPmf" class="org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean"&gt; &lt;bean id="myPmf" class="org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean"&gt;
&lt;property name="configLocation" value="classpath:kodo.properties"/&gt; &lt;property name="configLocation" value="classpath:kodo.properties"/&gt;
@ -984,7 +984,7 @@
"connectionFactory" property. For example, for the open source JDO "connectionFactory" property. For example, for the open source JDO
implementation JPOX (<ulink url="http://www.jpox.org"></ulink>):</para> implementation JPOX (<ulink url="http://www.jpox.org"></ulink>):</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt; &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
&lt;property name="driverClassName" value="${jdbc.driverClassName}"/&gt; &lt;property name="driverClassName" value="${jdbc.driverClassName}"/&gt;
@ -1025,7 +1025,7 @@
usually rather be used with the Spring Framework's usually rather be used with the Spring Framework's
<classname>JdoTemplate</classname>:</para> <classname>JdoTemplate</classname>:</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="myProductDao" class="product.ProductDaoImpl"&gt; &lt;bean id="myProductDao" class="product.ProductDaoImpl"&gt;
&lt;property name="persistenceManagerFactory" ref="myPmf"/&gt; &lt;property name="persistenceManagerFactory" ref="myPmf"/&gt;
@ -1033,7 +1033,7 @@
&lt;/beans&gt;</programlisting> &lt;/beans&gt;</programlisting>
<programlisting>public class ProductDaoImpl implements ProductDao { <programlisting language="java">public class ProductDaoImpl implements ProductDao {
private JdoTemplate jdoTemplate; private JdoTemplate jdoTemplate;
@ -1073,7 +1073,7 @@
combination, this allows for very simple DAO implementations for typical combination, this allows for very simple DAO implementations for typical
requirements:</para> requirements:</para>
<programlisting>public class ProductDaoImpl extends JdoDaoSupport implements ProductDao { <programlisting language="java">public class ProductDaoImpl extends JdoDaoSupport implements ProductDao {
public Collection loadProductsByCategory(String category) throws DataAccessException { public Collection loadProductsByCategory(String category) throws DataAccessException {
return getJdoTemplate().find( return getJdoTemplate().find(
@ -1101,7 +1101,7 @@
<interfacename>PersistenceManagerFactory</interfacename>. A <interfacename>PersistenceManagerFactory</interfacename>. A
corresponding DAO implementation looks like as follows:</para> corresponding DAO implementation looks like as follows:</para>
<programlisting>public class ProductDaoImpl implements ProductDao { <programlisting language="java">public class ProductDaoImpl implements ProductDao {
private PersistenceManagerFactory persistenceManagerFactory; private PersistenceManagerFactory persistenceManagerFactory;
@ -1126,7 +1126,7 @@
it still fits nicely into a Spring container, just like it would if it still fits nicely into a Spring container, just like it would if
coded against Spring's <classname>JdoTemplate</classname>:</para> coded against Spring's <classname>JdoTemplate</classname>:</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="myProductDao" class="product.ProductDaoImpl"&gt; &lt;bean id="myProductDao" class="product.ProductDaoImpl"&gt;
&lt;property name="persistenceManagerFactory" ref="myPmf"/&gt; &lt;property name="persistenceManagerFactory" ref="myPmf"/&gt;
@ -1143,7 +1143,7 @@
<interfacename>PersistenceManagerFactory</interfacename>, passing the <interfacename>PersistenceManagerFactory</interfacename>, passing the
proxy into your DAOs.</para> proxy into your DAOs.</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="myPmfProxy" &lt;bean id="myPmfProxy"
class="org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy"&gt; class="org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy"&gt;
@ -1173,7 +1173,7 @@
call and thus the entire <literal>finally</literal> block, which you call and thus the entire <literal>finally</literal> block, which you
might prefer to keep your DAO implementations concise:</para> might prefer to keep your DAO implementations concise:</para>
<programlisting>public class ProductDaoImpl implements ProductDao { <programlisting language="java">public class ProductDaoImpl implements ProductDao {
private PersistenceManagerFactory persistenceManagerFactory; private PersistenceManagerFactory persistenceManagerFactory;
@ -1194,7 +1194,7 @@
<classname>TransactionAwarePersistenceManagerFactoryProxy</classname>'s <classname>TransactionAwarePersistenceManagerFactoryProxy</classname>'s
"allowCreate" flag off:</para> "allowCreate" flag off:</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="myPmfProxy" &lt;bean id="myPmfProxy"
class="org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy"&gt; class="org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy"&gt;
@ -1238,7 +1238,7 @@
<para>To execute service operations within transactions, you can use <para>To execute service operations within transactions, you can use
Spring's common declarative transaction facilities. For example:</para> Spring's common declarative transaction facilities. For example:</para>
<programlisting>&lt;?xml version="1.0" encoding="UTF-8"?&gt; <programlisting language="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans &lt;beans
xmlns="http://www.springframework.org/schema/beans" xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@ -1375,7 +1375,7 @@
Spring-managed JDBC <interfacename>DataSource</interfacename> to Spring-managed JDBC <interfacename>DataSource</interfacename> to
use.</para> use.</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt; &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
&lt;property name="driverClassName" value="${jdbc.driverClassName}"/&gt; &lt;property name="driverClassName" value="${jdbc.driverClassName}"/&gt;
@ -1391,7 +1391,7 @@
&lt;/beans&gt;</programlisting> &lt;/beans&gt;</programlisting>
<programlisting>&lt;toplink-configuration&gt; <programlisting language="xml">&lt;toplink-configuration&gt;
&lt;session&gt; &lt;session&gt;
&lt;name&gt;Session&lt;/name&gt; &lt;name&gt;Session&lt;/name&gt;
@ -1428,7 +1428,7 @@
<interfacename>SessionFactory</interfacename>, but will usually rather <interfacename>SessionFactory</interfacename>, but will usually rather
be used with Spring's <literal>TopLinkTemplate</literal>:</para> be used with Spring's <literal>TopLinkTemplate</literal>:</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="myProductDao" class="product.ProductDaoImpl"&gt; &lt;bean id="myProductDao" class="product.ProductDaoImpl"&gt;
&lt;property name="sessionFactory" ref="mySessionFactory"/&gt; &lt;property name="sessionFactory" ref="mySessionFactory"/&gt;
@ -1436,7 +1436,7 @@
&lt;/beans&gt;</programlisting> &lt;/beans&gt;</programlisting>
<programlisting>public class TopLinkProductDao implements ProductDao { <programlisting language="java">public class TopLinkProductDao implements ProductDao {
private TopLinkTemplate tlTemplate; private TopLinkTemplate tlTemplate;
@ -1482,7 +1482,7 @@
combination, this allows for simple DAO implementations for typical combination, this allows for simple DAO implementations for typical
requirements:</para> requirements:</para>
<programlisting>public class ProductDaoImpl extends TopLinkDaoSupport implements ProductDao { <programlisting language="java">public class ProductDaoImpl extends TopLinkDaoSupport implements ProductDao {
public Collection loadProductsByCategory(String category) throws DataAccessException { public Collection loadProductsByCategory(String category) throws DataAccessException {
ReadAllQuery findOwnersQuery = new ReadAllQuery(Product.class); ReadAllQuery findOwnersQuery = new ReadAllQuery(Product.class);
@ -1535,7 +1535,7 @@
<para>A corresponding DAO implementation looks like as follows:</para> <para>A corresponding DAO implementation looks like as follows:</para>
<programlisting>public class ProductDaoImpl implements ProductDao { <programlisting language="java">public class ProductDaoImpl implements ProductDao {
private Session session; private Session session;
@ -1564,7 +1564,7 @@
bean reference of type <interfacename>Session</interfacename>, to be bean reference of type <interfacename>Session</interfacename>, to be
passed into the DAO:</para> passed into the DAO:</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="mySessionAdapter" &lt;bean id="mySessionAdapter"
class="org.springframework.orm.toplink.support.TransactionAwareSessionAdapter"&gt; class="org.springframework.orm.toplink.support.TransactionAwareSessionAdapter"&gt;
@ -1627,7 +1627,7 @@
<para>To execute service operations within transactions, you can use <para>To execute service operations within transactions, you can use
Spring's common declarative transaction facilities. For example:</para> Spring's common declarative transaction facilities. For example:</para>
<programlisting>&lt;?xml version="1.0" encoding="UTF-8"?&gt; <programlisting language="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans &lt;beans
xmlns="http://www.springframework.org/schema/beans" xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@ -1730,7 +1730,7 @@
need to create the following SQL map need to create the following SQL map
<filename>'Account.xml'</filename>:</para> <filename>'Account.xml'</filename>:</para>
<programlisting>&lt;sqlMap namespace="Account"&gt; <programlisting language="xml">&lt;sqlMap namespace="Account"&gt;
&lt;resultMap id="result" class="examples.Account"&gt; &lt;resultMap id="result" class="examples.Account"&gt;
&lt;result property="name" column="NAME" columnIndex="1"/&gt; &lt;result property="name" column="NAME" columnIndex="1"/&gt;
@ -1751,7 +1751,7 @@
<para>The configuration file for iBATIS 2 looks like this:</para> <para>The configuration file for iBATIS 2 looks like this:</para>
<programlisting>&lt;sqlMapConfig&gt; <programlisting language="xml">&lt;sqlMapConfig&gt;
&lt;sqlMap resource="example/Account.xml"/&gt; &lt;sqlMap resource="example/Account.xml"/&gt;
@ -1767,7 +1767,7 @@
<classname>SqlMapClientFactoryBean</classname>, which enables lazy <classname>SqlMapClientFactoryBean</classname>, which enables lazy
loading.</para> loading.</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt; &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"&gt;
&lt;property name="driverClassName" value="${jdbc.driverClassName}"/&gt; &lt;property name="driverClassName" value="${jdbc.driverClassName}"/&gt;
@ -1792,7 +1792,7 @@
supporting class similar to the <classname>SqlMapDaoSupport</classname>. supporting class similar to the <classname>SqlMapDaoSupport</classname>.
We extend it to implement our DAO:</para> We extend it to implement our DAO:</para>
<programlisting>public class SqlMapAccountDao extends SqlMapClientDaoSupport implements AccountDao { <programlisting language="java">public class SqlMapAccountDao extends SqlMapClientDaoSupport implements AccountDao {
public Account getAccount(String email) throws DataAccessException { public Account getAccount(String email) throws DataAccessException {
return (Account) getSqlMapClientTemplate().queryForObject("getAccountByEmail", email); return (Account) getSqlMapClientTemplate().queryForObject("getAccountByEmail", email);
@ -1809,7 +1809,7 @@
application context and wiring it with our application context and wiring it with our
<literal>SqlMapClient</literal> instance:</para> <literal>SqlMapClient</literal> instance:</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="accountDao" class="example.SqlMapAccountDao"&gt; &lt;bean id="accountDao" class="example.SqlMapAccountDao"&gt;
&lt;property name="sqlMapClient" ref="sqlMapClient"/&gt; &lt;property name="sqlMapClient" ref="sqlMapClient"/&gt;
@ -1828,7 +1828,7 @@
<literal>SqlMapClientCallback</literal> implementation as argument. This <literal>SqlMapClientCallback</literal> implementation as argument. This
can, for example, be used for batching:</para> can, for example, be used for batching:</para>
<programlisting>public class SqlMapAccountDao extends SqlMapClientDaoSupport implements AccountDao { <programlisting language="java">public class SqlMapAccountDao extends SqlMapClientDaoSupport implements AccountDao {
public void insertAccount(Account account) throws DataAccessException { public void insertAccount(Account account) throws DataAccessException {
getSqlMapClientTemplate().execute(new SqlMapClientCallback() { getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
@ -1857,7 +1857,7 @@
<literal>SqlMapClient</literal>. A corresponding DAO implementation <literal>SqlMapClient</literal>. A corresponding DAO implementation
looks like as follows:</para> looks like as follows:</para>
<programlisting>public class SqlMapAccountDao implements AccountDao { <programlisting language="java">public class SqlMapAccountDao implements AccountDao {
private SqlMapClient sqlMapClient; private SqlMapClient sqlMapClient;
@ -1891,7 +1891,7 @@
that the plain iBATIS-based DAO still follows the Dependency Injection that the plain iBATIS-based DAO still follows the Dependency Injection
pattern:</para> pattern:</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="accountDao" class="example.SqlMapAccountDao"&gt; &lt;bean id="accountDao" class="example.SqlMapAccountDao"&gt;
&lt;property name="sqlMapClient" ref="sqlMapClient"/&gt; &lt;property name="sqlMapClient" ref="sqlMapClient"/&gt;
@ -1929,7 +1929,7 @@
and, in most cases, requires only the persistence unit name to be and, in most cases, requires only the persistence unit name to be
specified:</para> specified:</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="myEmf" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"&gt; &lt;bean id="myEmf" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"&gt;
&lt;property name="persistenceUnitName" value="myPersistenceUnit"/&gt; &lt;property name="persistenceUnitName" value="myPersistenceUnit"/&gt;
@ -1959,7 +1959,7 @@
from JNDI (for example in a Java EE 5 environment), is just a matter from JNDI (for example in a Java EE 5 environment), is just a matter
of changing the XML configuration:</para> of changing the XML configuration:</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;jee:jndi-lookup id="myEmf" jndi-name="persistence/myPersistenceUnit"/&gt; &lt;jee:jndi-lookup id="myEmf" jndi-name="persistence/myPersistenceUnit"/&gt;
@ -2013,7 +2013,7 @@
custom DataSources outside of JNDI and to control the weaving custom DataSources outside of JNDI and to control the weaving
process.</para> process.</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; &lt;bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
&lt;property name="dataSource" ref="someDataSource"/&gt; &lt;property name="dataSource" ref="someDataSource"/&gt;
@ -2026,7 +2026,7 @@
<para>A typical <literal>persistence.xml</literal> file looks as follows:</para> <para>A typical <literal>persistence.xml</literal> file looks as follows:</para>
<programlisting>&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"&gt; <programlisting language="xml">&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0"&gt;
&lt;persistence-unit name="myUnit" transaction-type="RESOURCE_LOCAL"> &lt;persistence-unit name="myUnit" transaction-type="RESOURCE_LOCAL">
&lt;mapping-file>META-INF/orm.xml&lt;/mapping-file&gt; &lt;mapping-file>META-INF/orm.xml&lt;/mapping-file&gt;
@ -2144,7 +2144,7 @@
of the default one) by editing the web application context of the default one) by editing the web application context
file:</para> file:</para>
<programlisting>&lt;Context path="/myWebApp" docBase="/my/webApp/location"&gt; <programlisting language="xml">&lt;Context path="/myWebApp" docBase="/my/webApp/location"&gt;
&lt;Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/&gt; &lt;Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/&gt;
&lt;/Context&gt;</programlisting> &lt;/Context&gt;</programlisting>
@ -2175,7 +2175,7 @@
<para>If you are using Tomcat 5.5.20+ you can set <para>If you are using Tomcat 5.5.20+ you can set
<emphasis>useSystemClassLoaderAsParent</emphasis> to <emphasis>useSystemClassLoaderAsParent</emphasis> to
<literal>false</literal> to fix the problem: <programlisting>&lt;Context path="/myWebApp" docBase="/my/webApp/location"&gt; <literal>false</literal> to fix the problem: <programlisting language="xml">&lt;Context path="/myWebApp" docBase="/my/webApp/location"&gt;
&lt;Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader" &lt;Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"
useSystemClassLoaderAsParent="false"/&gt; useSystemClassLoaderAsParent="false"/&gt;
&lt;/Context&gt;</programlisting></para> &lt;/Context&gt;</programlisting></para>
@ -2199,7 +2199,7 @@
of the default one) by editing the web application context of the default one) by editing the web application context
file:</para> file:</para>
<programlisting>&lt;Context path="/myWebApp" docBase="/my/webApp/location"&gt; <programlisting language="xml">&lt;Context path="/myWebApp" docBase="/my/webApp/location"&gt;
&lt;Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/&gt; &lt;Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/&gt;
&lt;/Context&gt;</programlisting> &lt;/Context&gt;</programlisting>
@ -2227,7 +2227,7 @@
configuring configuring
<classname>LocalContainerEntityManagerFactoryBean</classname>:</para> <classname>LocalContainerEntityManagerFactoryBean</classname>:</para>
<programlisting>&lt;bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; <programlisting language="xml">&lt;bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
&lt;property name="loadTimeWeaver"&gt; &lt;property name="loadTimeWeaver"&gt;
&lt;bean class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver"/&gt; &lt;bean class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver"/&gt;
&lt;/property&gt; &lt;/property&gt;
@ -2258,7 +2258,7 @@
a Spring-specific (but very general) VM agent (<filename a Spring-specific (but very general) VM agent (<filename
class="libraryfile">spring-agent.jar</filename>):</para> class="libraryfile">spring-agent.jar</filename>):</para>
<programlisting>&lt;bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; <programlisting language="xml">&lt;bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
&lt;property name="loadTimeWeaver"&gt; &lt;property name="loadTimeWeaver"&gt;
&lt;bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/&gt; &lt;bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/&gt;
&lt;/property&gt; &lt;/property&gt;
@ -2282,7 +2282,7 @@
autodetection of the platform (WebLogic, OC4J, GlassFish, Tomcat, Resin, VM agent) autodetection of the platform (WebLogic, OC4J, GlassFish, Tomcat, Resin, VM agent)
as well as automatic propagation of the weaver to all weaver-aware beans.</para> as well as automatic propagation of the weaver to all weaver-aware beans.</para>
<programlisting>&lt;context:load-time-weaver/&gt; <programlisting language="xml">&lt;context:load-time-weaver/&gt;
&lt;bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt; &lt;bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
... ...
@ -2309,7 +2309,7 @@
parsed and later on retrieved through the persistence unit parsed and later on retrieved through the persistence unit
name:</para> name:</para>
<programlisting>&lt;bean id="pum" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager"&gt; <programlisting language="xml">&lt;bean id="pum" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager"&gt;
&lt;property name="persistenceXmlLocation"&gt; &lt;property name="persistenceXmlLocation"&gt;
&lt;list&gt; &lt;list&gt;
&lt;value&gt;org/springframework/orm/jpa/domain/persistence-multi.xml&lt;/value&gt; &lt;value&gt;org/springframework/orm/jpa/domain/persistence-multi.xml&lt;/value&gt;
@ -2353,7 +2353,7 @@
given <interfacename>EntityManagerFactory</interfacename> or through given <interfacename>EntityManagerFactory</interfacename> or through
Spring's <classname>JpaTemplate</classname>:</para> Spring's <classname>JpaTemplate</classname>:</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
&lt;bean id="myProductDao" class="product.ProductDaoImpl"&gt; &lt;bean id="myProductDao" class="product.ProductDaoImpl"&gt;
&lt;property name="entityManagerFactory" ref="myEmf"/&gt; &lt;property name="entityManagerFactory" ref="myEmf"/&gt;
@ -2361,7 +2361,7 @@
&lt;/beans&gt;</programlisting> &lt;/beans&gt;</programlisting>
<programlisting>public class JpaProductDao implements ProductDao { <programlisting language="java">public class JpaProductDao implements ProductDao {
private JpaTemplate jpaTemplate; private JpaTemplate jpaTemplate;
@ -2401,7 +2401,7 @@
<methodname>getJpaTemplate()</methodname> to be used by <methodname>getJpaTemplate()</methodname> to be used by
subclasses:</para> subclasses:</para>
<programlisting>public class ProductDaoImpl extends JpaDaoSupport implements ProductDao { <programlisting language="java">public class ProductDaoImpl extends JpaDaoSupport implements ProductDao {
public Collection loadProductsByCategory(String category) throws DataAccessException { public Collection loadProductsByCategory(String category) throws DataAccessException {
Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;(); Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
@ -2457,7 +2457,7 @@
<classname>PersistenceAnnotationBeanPostProcessor</classname> is <classname>PersistenceAnnotationBeanPostProcessor</classname> is
enabled. A corresponding DAO implementation might look like this:</para> enabled. A corresponding DAO implementation might look like this:</para>
<programlisting>public class ProductDaoImpl implements ProductDao { <programlisting language="java">public class ProductDaoImpl implements ProductDao {
private EntityManagerFactory emf; private EntityManagerFactory emf;
@ -2487,7 +2487,7 @@
advantage of annotations to require the injection of the default advantage of annotations to require the injection of the default
<interfacename>EntityManagerFactory</interfacename>:</para> <interfacename>EntityManagerFactory</interfacename>:</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
<lineannotation>&lt;!-- bean post-processor for JPA annotations --&gt;</lineannotation> <lineannotation>&lt;!-- bean post-processor for JPA annotations --&gt;</lineannotation>
&lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/&gt; &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/&gt;
@ -2505,7 +2505,7 @@
(including <classname>CommonAnnotationBeanPostProcessor</classname> (including <classname>CommonAnnotationBeanPostProcessor</classname>
etc).</para> etc).</para>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
<lineannotation>&lt;!-- post-processors for all standard config annotations --&gt;</lineannotation> <lineannotation>&lt;!-- post-processors for all standard config annotations --&gt;</lineannotation>
&lt;context:annotation-config/&gt; &lt;context:annotation-config/&gt;
@ -2522,7 +2522,7 @@
transactional EntityManager) to be injected instead of the transactional EntityManager) to be injected instead of the
factory:</para> factory:</para>
<programlisting>public class ProductDaoImpl implements ProductDao { <programlisting language="java">public class ProductDaoImpl implements ProductDao {
@PersistenceContext @PersistenceContext
private EntityManager em; private EntityManager em;
@ -2597,14 +2597,14 @@
exception translation to be applied transparently through the exception translation to be applied transparently through the
<interfacename>@Repository</interfacename> annotation:</para> <interfacename>@Repository</interfacename> annotation:</para>
<programlisting>@Repository <programlisting language="java">@Repository
public class ProductDaoImpl implements ProductDao { public class ProductDaoImpl implements ProductDao {
<lineannotation>// class body here...</lineannotation> <lineannotation>// class body here...</lineannotation>
}</programlisting> }</programlisting>
<programlisting>&lt;beans&gt; <programlisting language="xml">&lt;beans&gt;
<lineannotation>&lt;!-- <classname>Exception</classname> translation bean post processor --&gt;</lineannotation> <lineannotation>&lt;!-- <classname>Exception</classname> translation bean post processor --&gt;</lineannotation>
&lt;bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/&gt; &lt;bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/&gt;
@ -2635,7 +2635,7 @@ public class ProductDaoImpl implements ProductDao {
<para>To execute service operations within transactions, you can use <para>To execute service operations within transactions, you can use
Spring's common declarative transaction facilities. For example:</para> Spring's common declarative transaction facilities. For example:</para>
<programlisting>&lt;?xml version="1.0" encoding="UTF-8"?&gt; <programlisting language="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans" &lt;beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:aop="http://www.springframework.org/schema/aop"

View File

@ -58,7 +58,7 @@
Spring abstracts all marshalling operations behind the Spring abstracts all marshalling operations behind the
<interfacename>org.springframework.oxm.Marshaller</interfacename> interface, the main methods of which <interfacename>org.springframework.oxm.Marshaller</interfacename> interface, the main methods of which
is listed below. is listed below.
<programlisting><![CDATA[ <programlisting language="java"><![CDATA[
public interface Marshaller { public interface Marshaller {
/** /**
@ -115,7 +115,7 @@ public interface Marshaller {
<para> <para>
Similar to the <interfacename>Marshaller</interfacename>, there is the Similar to the <interfacename>Marshaller</interfacename>, there is the
<interfacename>org.springframework.oxm.Unmarshaller</interfacename> interface. <interfacename>org.springframework.oxm.Unmarshaller</interfacename> interface.
<programlisting><![CDATA[ <programlisting language="java"><![CDATA[
public interface Unmarshaller { public interface Unmarshaller {
/** /**
@ -205,7 +205,7 @@ public interface Unmarshaller {
Spring's OXM can be used for a wide variety of situations. In the following example, we will use it to Spring's OXM can be used for a wide variety of situations. In the following example, we will use it to
marshal the settings of a Spring-managed application as an XML file. We will use a simple JavaBean to marshal the settings of a Spring-managed application as an XML file. We will use a simple JavaBean to
represent the settings: represent the settings:
<programlisting><![CDATA[ <programlisting language="java"><![CDATA[
public class Settings { public class Settings {
private boolean fooEnabled; private boolean fooEnabled;
@ -223,7 +223,7 @@ public class Settings {
methods: <methodname>saveSettings</methodname> saves the settings bean to a file named methods: <methodname>saveSettings</methodname> saves the settings bean to a file named
<filename>settings.xml</filename>, and <methodname>loadSettings</methodname> loads these settings again. A <filename>settings.xml</filename>, and <methodname>loadSettings</methodname> loads these settings again. A
<methodname>main</methodname> method constructs a Spring application context, and calls these two methods. <methodname>main</methodname> method constructs a Spring application context, and calls these two methods.
<programlisting><![CDATA[ <programlisting language="java"><![CDATA[
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -284,7 +284,7 @@ public class Application {
The <classname>Application</classname> requires both a <property>marshaller</property> The <classname>Application</classname> requires both a <property>marshaller</property>
and <property>unmarshaller</property> property to be set. We can do so using the following and <property>unmarshaller</property> property to be set. We can do so using the following
<filename>applicationContext.xml</filename>: <filename>applicationContext.xml</filename>:
<programlisting><![CDATA[ <programlisting language="xml"><![CDATA[
<beans> <beans>
<bean id="application" class="Application"> <bean id="application" class="Application">
<property name="marshaller" ref="castorMarshaller" /> <property name="marshaller" ref="castorMarshaller" />
@ -302,7 +302,7 @@ public class Application {
</para> </para>
<para> <para>
This sample application produces the following <filename>settings.xml</filename> file: This sample application produces the following <filename>settings.xml</filename> file:
<programlisting><![CDATA[ <programlisting language="xml"><![CDATA[
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<settings foo-enabled="false"/> <settings foo-enabled="false"/>
]]></programlisting> ]]></programlisting>
@ -315,7 +315,7 @@ public class Application {
To make these tags available, the appropriate schema has to be referenced first in the preamble of the XML configuration file. To make these tags available, the appropriate schema has to be referenced first in the preamble of the XML configuration file.
The emboldened text in the below snippet references the OXM schema: The emboldened text in the below snippet references the OXM schema:
</para> </para>
<programlisting><![CDATA[<?xml version="1.0" encoding="UTF-8"?> <programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
]]><emphasis role="bold"><![CDATA[xmlns:oxm="http://www.springframework.org/schema/oxm"]]></emphasis> ]]><emphasis role="bold"><![CDATA[xmlns:oxm="http://www.springframework.org/schema/oxm"]]></emphasis>
@ -342,7 +342,7 @@ public class Application {
Each tag will be explained in its respective marshaller's section. As an example though, here is how Each tag will be explained in its respective marshaller's section. As an example though, here is how
the configuration of a JAXB2 marshaller might look like: the configuration of a JAXB2 marshaller might look like:
</para> </para>
<programlisting><![CDATA[<oxm:jaxb2-marshaller id="marshaller" contextPath="org.springframework.ws.samples.airline.schema"/>]]></programlisting> <programlisting language="xml"><![CDATA[<oxm:jaxb2-marshaller id="marshaller" contextPath="org.springframework.ws.samples.airline.schema"/>]]></programlisting>
</section> </section>
<section id="oxm-jaxb"> <section id="oxm-jaxb">
<title>JAXB</title> <title>JAXB</title>
@ -368,7 +368,7 @@ public class Application {
classes to be supported by the marshaller. Schema validation is performed by specifying one or more classes to be supported by the marshaller. Schema validation is performed by specifying one or more
schema resource to the bean, like so: schema resource to the bean, like so:
</para> </para>
<programlisting><![CDATA[ <programlisting language="xml"><![CDATA[
<beans> <beans>
<bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"> <bean id="jaxb2Marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
@ -389,11 +389,11 @@ public class Application {
The <literal>jaxb2-marshaller</literal> tag configures a <classname>org.springframework.oxm.jaxb.Jaxb2Marshaller</classname>. The <literal>jaxb2-marshaller</literal> tag configures a <classname>org.springframework.oxm.jaxb.Jaxb2Marshaller</classname>.
Here is an example: Here is an example:
</para> </para>
<programlisting><![CDATA[<oxm:jaxb2-marshaller id="marshaller" contextPath="org.springframework.ws.samples.airline.schema"/>]]></programlisting> <programlisting language="xml"><![CDATA[<oxm:jaxb2-marshaller id="marshaller" contextPath="org.springframework.ws.samples.airline.schema"/>]]></programlisting>
<para> <para>
Alternatively, the list of classes to bind can be provided to the marshaller via the <literal>class-to-be-bound</literal> child tag: Alternatively, the list of classes to bind can be provided to the marshaller via the <literal>class-to-be-bound</literal> child tag:
</para> </para>
<programlisting><![CDATA[<oxm:jaxb2-marshaller id="marshaller"> <programlisting language="xml"><![CDATA[<oxm:jaxb2-marshaller id="marshaller">
<oxm:class-to-be-bound name="org.springframework.ws.samples.airline.schema.Airport"/> <oxm:class-to-be-bound name="org.springframework.ws.samples.airline.schema.Airport"/>
<oxm:class-to-be-bound name="org.springframework.ws.samples.airline.schema.Flight"/> <oxm:class-to-be-bound name="org.springframework.ws.samples.airline.schema.Flight"/>
... ...
@ -450,7 +450,7 @@ public class Application {
<interfacename>Marshaller</interfacename> and <interfacename>Unmarshaller</interfacename> interface. <interfacename>Marshaller</interfacename> and <interfacename>Unmarshaller</interfacename> interface.
It can be wired up as follows: It can be wired up as follows:
</para> </para>
<programlisting><![CDATA[ <programlisting language="xml"><![CDATA[
<beans> <beans>
<bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller" /> <bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller" />
@ -469,7 +469,7 @@ public class Application {
The mapping can be set using the <property>mappingLocation</property> resource property, indicated The mapping can be set using the <property>mappingLocation</property> resource property, indicated
below with a classpath resource. below with a classpath resource.
</para> </para>
<programlisting><![CDATA[ <programlisting language="xml"><![CDATA[
<beans> <beans>
<bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller" > <bean id="castorMarshaller" class="org.springframework.oxm.castor.CastorMarshaller" >
<property name="mappingLocation" value="classpath:mapping.xml" /> <property name="mappingLocation" value="classpath:mapping.xml" />
@ -500,7 +500,7 @@ public class Application {
and <interfacename>Unmarshaller</interfacename> and <interfacename>Unmarshaller</interfacename>
interfaces. It can be configured as follows: interfaces. It can be configured as follows:
</para> </para>
<programlisting><![CDATA[ <programlisting language="xml"><![CDATA[
<beans> <beans>
<bean id="xmlBeansMarshaller" class="org.springframework.oxm.xmlbeans.XmlBeansMarshaller" /> <bean id="xmlBeansMarshaller" class="org.springframework.oxm.xmlbeans.XmlBeansMarshaller" />
@ -520,7 +520,7 @@ public class Application {
The <literal>xmlbeans-marshaller</literal> tag configures a <classname>org.springframework.oxm.xmlbeans.XmlBeansMarshaller</classname>. The <literal>xmlbeans-marshaller</literal> tag configures a <classname>org.springframework.oxm.xmlbeans.XmlBeansMarshaller</classname>.
Here is an example: Here is an example:
</para> </para>
<programlisting><![CDATA[<oxm:xmlbeans-marshaller id="marshaller"/>]]></programlisting> <programlisting language="xml"><![CDATA[<oxm:xmlbeans-marshaller id="marshaller"/>]]></programlisting>
<para> <para>
Available attributes are: Available attributes are:
<informaltable> <informaltable>
@ -580,7 +580,7 @@ public class Application {
<property>bindingName</property> property. In the next sample, we bind the <property>bindingName</property> property. In the next sample, we bind the
<classname>Flights</classname> class: <classname>Flights</classname> class:
</para> </para>
<programlisting><![CDATA[ <programlisting language="xml"><![CDATA[
<beans> <beans>
<bean id="jibxFlightsMarshaller" class="org.springframework.oxm.jibx.JibxMarshaller"> <bean id="jibxFlightsMarshaller" class="org.springframework.oxm.jibx.JibxMarshaller">
@ -600,7 +600,7 @@ public class Application {
The <literal>jibx-marshaller</literal> tag configures a <classname>org.springframework.oxm.jibx.JibxMarshaller</classname>. The <literal>jibx-marshaller</literal> tag configures a <classname>org.springframework.oxm.jibx.JibxMarshaller</classname>.
Here is an example: Here is an example:
</para> </para>
<programlisting><![CDATA[<oxm:jibx-marshaller id="marshaller" target-class="org.springframework.ws.samples.airline.schema.Flight"/>]]></programlisting> <programlisting language="xml"><![CDATA[<oxm:jibx-marshaller id="marshaller" target-class="org.springframework.ws.samples.airline.schema.Flight"/>]]></programlisting>
<para> <para>
Available attributes are: Available attributes are:
<informaltable> <informaltable>
@ -656,7 +656,7 @@ public class Application {
in an application context directly. To further customize the XML, you can set an in an application context directly. To further customize the XML, you can set an
<emphasis>alias map</emphasis>, which consists of string aliases mapped to classes: <emphasis>alias map</emphasis>, which consists of string aliases mapped to classes:
</para> </para>
<programlisting><![CDATA[ <programlisting language="xml"><![CDATA[
<beans> <beans>
<bean id="xstreamMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller"> <bean id="xstreamMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller">

View File

@ -149,7 +149,7 @@
defined by the defined by the
<interfacename>org.springframework.transaction.PlatformTransactionManager</interfacename> <interfacename>org.springframework.transaction.PlatformTransactionManager</interfacename>
interface, shown below:</para> interface, shown below:</para>
<programlisting><![CDATA[public interface PlatformTransactionManager { <programlisting language="java"><![CDATA[public interface PlatformTransactionManager {
TransactionStatus getTransaction(TransactionDefinition definition) TransactionStatus getTransaction(TransactionDefinition definition)
throws TransactionException; throws TransactionException;
@ -223,7 +223,7 @@
way for transactional code to control transaction execution and query way for transactional code to control transaction execution and query
transaction status. The concepts should be familiar, as they are common to transaction status. The concepts should be familiar, as they are common to
all transaction APIs:</para> all transaction APIs:</para>
<programlisting><![CDATA[public interface TransactionStatus { <programlisting language="java"><![CDATA[public interface TransactionStatus {
boolean isNewTransaction(); boolean isNewTransaction();
@ -246,7 +246,7 @@
<para>We must define a JDBC <interfacename>DataSource</interfacename>, and <para>We must define a JDBC <interfacename>DataSource</interfacename>, and
then use the Spring <classname>DataSourceTransactionManager</classname>, giving then use the Spring <classname>DataSourceTransactionManager</classname>, giving
it a reference to the <interfacename>DataSource</interfacename>.</para> it a reference to the <interfacename>DataSource</interfacename>.</para>
<programlisting><![CDATA[<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <programlisting language="xml"><![CDATA[<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" /> <property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" /> <property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" /> <property name="username" value="${jdbc.username}" />
@ -254,7 +254,7 @@
</bean>]]></programlisting> </bean>]]></programlisting>
<para>The related <interfacename>PlatformTransactionManager</interfacename> bean <para>The related <interfacename>PlatformTransactionManager</interfacename> bean
definition will look like this:</para> definition will look like this:</para>
<programlisting><![CDATA[<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <programlisting language="xml"><![CDATA[<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/> <property name="dataSource" ref="dataSource"/>
</bean>]]></programlisting> </bean>]]></programlisting>
<para>If we use JTA in a J2EE container, as in the <filename>'dataAccessContext-jta.xml'</filename> <para>If we use JTA in a J2EE container, as in the <filename>'dataAccessContext-jta.xml'</filename>
@ -263,7 +263,7 @@
The <classname>JtaTransactionManager</classname> doesn't need to know about the The <classname>JtaTransactionManager</classname> doesn't need to know about the
<interfacename>DataSource</interfacename>, or any other specific resources, as <interfacename>DataSource</interfacename>, or any other specific resources, as
it will use the container's global transaction management infrastructure.</para> it will use the container's global transaction management infrastructure.</para>
<programlisting><![CDATA[<?xml version="1.0" encoding="UTF-8"?> <programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jee="http://www.springframework.org/schema/jee"
@ -301,7 +301,7 @@ xsi:schemaLocation="
<interfacename>DataSource</interfacename>, the <interfacename>DataSource</interfacename>, the
<classname>HibernateTransactionManager</classname> needs a reference to the <classname>HibernateTransactionManager</classname> needs a reference to the
<interfacename>SessionFactory</interfacename>.</para> <interfacename>SessionFactory</interfacename>.</para>
<programlisting><![CDATA[<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <programlisting language="xml"><![CDATA[<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" /> <property name="dataSource" ref="dataSource" />
<property name="mappingResources"> <property name="mappingResources">
<list> <list>
@ -320,7 +320,7 @@ xsi:schemaLocation="
</bean>]]></programlisting> </bean>]]></programlisting>
<para>With Hibernate and JTA transactions, we can simply use the <para>With Hibernate and JTA transactions, we can simply use the
<classname>JtaTransactionManager</classname> as with JDBC or any other resource strategy.</para> <classname>JtaTransactionManager</classname> as with JDBC or any other resource strategy.</para>
<programlisting><![CDATA[<bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>]]></programlisting> <programlisting language="xml"><![CDATA[<bean id="txManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>]]></programlisting>
<para>Note that this is identical to JTA configuration for any resource, <para>Note that this is identical to JTA configuration for any resource,
as these are global transactions, which can enlist any transactional as these are global transactions, which can enlist any transactional
resource.</para> resource.</para>
@ -377,7 +377,7 @@ xsi:schemaLocation="
<interfacename>DataSource</interfacename>, you would instead use Spring's <interfacename>DataSource</interfacename>, you would instead use Spring's
<classname>org.springframework.jdbc.datasource.DataSourceUtils</classname> <classname>org.springframework.jdbc.datasource.DataSourceUtils</classname>
class as follows:</para> class as follows:</para>
<programlisting><![CDATA[Connection conn = DataSourceUtils.getConnection(dataSource);]]></programlisting> <programlisting language="java"><![CDATA[Connection conn = DataSourceUtils.getConnection(dataSource);]]></programlisting>
<para>If an existing transaction exists, and already has a connection <para>If an existing transaction exists, and already has a connection
synchronized (linked) to it, that instance will be returned. Otherwise, synchronized (linked) to it, that instance will be returned. Otherwise,
the method call will trigger the creation of a new connection, which the method call will trigger the creation of a new connection, which
@ -543,7 +543,7 @@ xsi:schemaLocation="
(The intent is to convey the concepts, and using the rote <classname>Foo</classname> and (The intent is to convey the concepts, and using the rote <classname>Foo</classname> and
<classname>Bar</classname> tropes means that you can concentrate on the transaction <classname>Bar</classname> tropes means that you can concentrate on the transaction
usage and not have to worry about the domain model.)</para> usage and not have to worry about the domain model.)</para>
<programlisting><lineannotation>// the service interface that we want to make transactional</lineannotation><![CDATA[ <programlisting language="java"><lineannotation>// the service interface that we want to make transactional</lineannotation><![CDATA[
package x.y.service; package x.y.service;
@ -558,7 +558,7 @@ public interface FooService {
void updateFoo(Foo foo); void updateFoo(Foo foo);
}]]></programlisting> }]]></programlisting>
<programlisting><lineannotation>// an implementation of the above interface</lineannotation><![CDATA[ <programlisting language="java"><lineannotation>// an implementation of the above interface</lineannotation><![CDATA[
package x.y.service; package x.y.service;
@ -594,7 +594,7 @@ public class DefaultFooService implements FooService {
<literal>updateFoo(Foo)</literal>) have to execute in the context of a transaction <literal>updateFoo(Foo)</literal>) have to execute in the context of a transaction
with read-write semantics. Don't worry about taking the following configuration in with read-write semantics. Don't worry about taking the following configuration in
all at once; everything will be explained in detail in the next few paragraphs.</para> all at once; everything will be explained in detail in the next few paragraphs.</para>
<programlisting><lineannotation>&lt;!-- from the file <literal>'context.xml'</literal> --&gt;</lineannotation><![CDATA[ <programlisting language="xml"><lineannotation>&lt;!-- from the file <literal>'context.xml'</literal> --&gt;</lineannotation><![CDATA[
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@ -678,7 +678,7 @@ public class DefaultFooService implements FooService {
<para>A common requirement is to make an entire service layer transactional. <para>A common requirement is to make an entire service layer transactional.
The best way to do this is simply to change the pointcut expression to match The best way to do this is simply to change the pointcut expression to match
any operation in your service layer. For example:</para> any operation in your service layer. For example:</para>
<programlisting><![CDATA[<aop:config> <programlisting language="xml"><![CDATA[<aop:config>
<aop:pointcut id="fooServiceMethods" expression="execution(* x.y.service.*.*(..))"/> <aop:pointcut id="fooServiceMethods" expression="execution(* x.y.service.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceMethods"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceMethods"/>
</aop:config>]]></programlisting> </aop:config>]]></programlisting>
@ -696,7 +696,7 @@ public class DefaultFooService implements FooService {
be started, suspended, be marked as read-only, etc., depending on the be started, suspended, be marked as read-only, etc., depending on the
transaction configuration associated with that method. Consider the following transaction configuration associated with that method. Consider the following
program that test drives the above configuration.</para> program that test drives the above configuration.</para>
<programlisting><![CDATA[public final class Boot { <programlisting language="java"><![CDATA[public final class Boot {
public static void main(final String[] args) throws Exception { public static void main(final String[] args) throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml", Boot.class); ApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml", Boot.class);
@ -710,7 +710,7 @@ public class DefaultFooService implements FooService {
<methodname>insertFoo(..)</methodname> method of the <methodname>insertFoo(..)</methodname> method of the
<classname>DefaultFooService</classname> class have been truncated in <classname>DefaultFooService</classname> class have been truncated in
the interest of clarity.)</emphasis></para> the interest of clarity.)</emphasis></para>
<programlisting> <lineannotation><emphasis role="bold">&lt;!-- the Spring container is starting up... --&gt;</emphasis></lineannotation><![CDATA[ <programlisting language="xml"> <lineannotation><emphasis role="bold">&lt;!-- the Spring container is starting up... --&gt;</emphasis></lineannotation><![CDATA[
[AspectJInvocationContextExposingAdvisorAutoProxyCreator] - Creating implicit proxy [AspectJInvocationContextExposingAdvisorAutoProxyCreator] - Creating implicit proxy
for bean 'fooService' with 0 common interceptors and 1 specific interceptors for bean 'fooService' with 0 common interceptors and 1 specific interceptors
]]><lineannotation><emphasis role="bold">&lt;!-- the <classname>DefaultFooService</classname> is actually proxied --&gt;</emphasis></lineannotation><![CDATA[ ]]><lineannotation><emphasis role="bold">&lt;!-- the <classname>DefaultFooService</classname> is actually proxied --&gt;</emphasis></lineannotation><![CDATA[
@ -767,7 +767,7 @@ Exception in thread "main" java.lang.UnsupportedOperationException
for rollback can be configured. Find below a snippet of XML configuration that for rollback can be configured. Find below a snippet of XML configuration that
demonstrates how one would configure rollback for a checked, application-specific demonstrates how one would configure rollback for a checked, application-specific
<exceptionname>Exception</exceptionname> type.</para> <exceptionname>Exception</exceptionname> type.</para>
<programlisting><![CDATA[<tx:advice id="txAdvice" transaction-manager="txManager"> <programlisting language="xml"><![CDATA[<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes> <tx:attributes>
<tx:method name="get*" read-only="true" ]]><lineannotation><emphasis role="bold">rollback-for="NoProductInStockException"</emphasis></lineannotation><![CDATA[/> <tx:method name="get*" read-only="true" ]]><lineannotation><emphasis role="bold">rollback-for="NoProductInStockException"</emphasis></lineannotation><![CDATA[/>
<tx:method name="*"/> <tx:method name="*"/>
@ -778,7 +778,7 @@ Exception in thread "main" java.lang.UnsupportedOperationException
In the example configuration below, we effectively are telling the Spring Framework's transaction In the example configuration below, we effectively are telling the Spring Framework's transaction
infrastructure to commit the attendant transaction even in the face of an unhandled infrastructure to commit the attendant transaction even in the face of an unhandled
<exceptionname>InstrumentNotFoundException</exceptionname>.</para> <exceptionname>InstrumentNotFoundException</exceptionname>.</para>
<programlisting><![CDATA[<tx:advice id="txAdvice"> <programlisting language="xml"><![CDATA[<tx:advice id="txAdvice">
<tx:attributes> <tx:attributes>
<tx:method name="updateStock" ]]><lineannotation><emphasis role="bold">no-rollback-for="InstrumentNotFoundException"</emphasis></lineannotation><![CDATA[/> <tx:method name="updateStock" ]]><lineannotation><emphasis role="bold">no-rollback-for="InstrumentNotFoundException"</emphasis></lineannotation><![CDATA[/>
<tx:method name="*"/> <tx:method name="*"/>
@ -789,7 +789,7 @@ Exception in thread "main" java.lang.UnsupportedOperationException
<emphasis>strongest</emphasis> matching rule wins. So in the case of the following configuration, <emphasis>strongest</emphasis> matching rule wins. So in the case of the following configuration,
any exception other than an <exceptionname>InstrumentNotFoundException</exceptionname> would result in the any exception other than an <exceptionname>InstrumentNotFoundException</exceptionname> would result in the
attendant transaction being marked for rollback.</para> attendant transaction being marked for rollback.</para>
<programlisting><![CDATA[<tx:advice id="txAdvice"> <programlisting language="xml"><![CDATA[<tx:advice id="txAdvice">
<tx:attributes> <tx:attributes>
<tx:method name="*" rollback-for="Throwable" no-rollback-for="InstrumentNotFoundException"/> <tx:method name="*" rollback-for="Throwable" no-rollback-for="InstrumentNotFoundException"/>
</tx:attributes> </tx:attributes>
@ -797,7 +797,7 @@ Exception in thread "main" java.lang.UnsupportedOperationException
<para>The second way to indicate that a rollback is required is to do so <para>The second way to indicate that a rollback is required is to do so
<emphasis>programmatically</emphasis>. Although very simple, this way is quite invasive, and tightly couples <emphasis>programmatically</emphasis>. Although very simple, this way is quite invasive, and tightly couples
your code to the Spring Framework's transaction infrastructure, as can be seen below:</para> your code to the Spring Framework's transaction infrastructure, as can be seen below:</para>
<programlisting><![CDATA[public void resolvePosition() { <programlisting language="java"><![CDATA[public void resolvePosition() {
try { try {
]]><lineannotation>// some business logic...</lineannotation><![CDATA[ ]]><lineannotation>// some business logic...</lineannotation><![CDATA[
} catch (NoProductInStockException ex) { } catch (NoProductInStockException ex) {
@ -822,7 +822,7 @@ Exception in thread "main" java.lang.UnsupportedOperationException
defined in that package (or in subpackages) and that have names ending in defined in that package (or in subpackages) and that have names ending in
<literal>'Service'</literal> have the default transactional configuration, you would write <literal>'Service'</literal> have the default transactional configuration, you would write
the following:</para> the following:</para>
<programlisting><![CDATA[<?xml version="1.0" encoding="UTF-8"?> <programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:aop="http://www.springframework.org/schema/aop"
@ -863,7 +863,7 @@ Exception in thread "main" java.lang.UnsupportedOperationException
<para>Find below an example of configuring two distinct beans with totally different <para>Find below an example of configuring two distinct beans with totally different
transactional settings.</para> transactional settings.</para>
<programlisting><![CDATA[<?xml version="1.0" encoding="UTF-8"?> <programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:aop="http://www.springframework.org/schema/aop"
@ -1015,14 +1015,6 @@ Exception in thread "main" java.lang.UnsupportedOperationException
</tbody> </tbody>
</tgroup> </tgroup>
</table> </table>
</para>
<para>At the time of writing it is not possible to have explicit control over the
name of a transaction, where 'name' means the transaction name that will be shown
in a transaction monitor, if applicable (for example, WebLogic's transaction
monitor), and in logging output. For declarative transactions, the transaction
name is always the fully-qualified class name + "." + method name of the
transactionally-advised class. For example
<literal>'com.foo.BusinessService.handlePayment'</literal>.</para>
</section> </section>
<section id="transaction-declarative-annotations"> <section id="transaction-declarative-annotations">
@ -1041,7 +1033,7 @@ Exception in thread "main" java.lang.UnsupportedOperationException
<para>The ease-of-use afforded by the use of the <interfacename>@Transactional</interfacename> <para>The ease-of-use afforded by the use of the <interfacename>@Transactional</interfacename>
annotation is best illustrated with an example, after which all of the details annotation is best illustrated with an example, after which all of the details
will be explained. Consider the following class definition:</para> will be explained. Consider the following class definition:</para>
<programlisting><lineannotation>// the service class that we want to make transactional</lineannotation><![CDATA[ <programlisting language="java"><lineannotation>// the service class that we want to make transactional</lineannotation><![CDATA[
]]><emphasis role="bold">@Transactional</emphasis><![CDATA[ ]]><emphasis role="bold">@Transactional</emphasis><![CDATA[
public class DefaultFooService implements FooService { public class DefaultFooService implements FooService {
@ -1056,7 +1048,7 @@ public class DefaultFooService implements FooService {
<para>When the above POJO is defined as a bean in a Spring IoC container, the bean <para>When the above POJO is defined as a bean in a Spring IoC container, the bean
instance can be made transactional by adding merely <emphasis>one</emphasis> line of instance can be made transactional by adding merely <emphasis>one</emphasis> line of
XML configuration, like so:</para> XML configuration, like so:</para>
<programlisting><lineannotation>&lt;!-- from the file <literal>'context.xml'</literal> --&gt;</lineannotation><![CDATA[ <programlisting language="xml"><lineannotation>&lt;!-- from the file <literal>'context.xml'</literal> --&gt;</lineannotation><![CDATA[
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@ -1231,7 +1223,7 @@ public class DefaultFooService implements FooService {
<methodname>updateFoo(Foo)</methodname> method in the same class takes precedence <methodname>updateFoo(Foo)</methodname> method in the same class takes precedence
over the transactional settings defined at the class level.</para> over the transactional settings defined at the class level.</para>
<programlisting><![CDATA[@Transactional(readOnly = true) <programlisting language="java"><![CDATA[@Transactional(readOnly = true)
public class DefaultFooService implements FooService { public class DefaultFooService implements FooService {
public Foo getFoo(String fooName) { public Foo getFoo(String fooName) {
@ -1362,8 +1354,7 @@ public class DefaultFooService implements FooService {
transaction name is always the fully-qualified class name + "." + method name of the transaction name is always the fully-qualified class name + "." + method name of the
transactionally-advised class. For example, if the <methodname>handlePayment(..)</methodname> transactionally-advised class. For example, if the <methodname>handlePayment(..)</methodname>
method of the <classname>BusinessService</classname> class started a transaction, the name of the method of the <classname>BusinessService</classname> class started a transaction, the name of the
transaction would be:</para> transaction would be: <literal>com.foo.BusinessService.handlePayment</literal>.</para>
<programlisting><![CDATA[com.foo.BusinessService.handlePayment]]></programlisting>
</section> </section>
</section> </section>
@ -1476,7 +1467,7 @@ public class DefaultFooService implements FooService {
<para>Here is the code for a simple profiling aspect. The <para>Here is the code for a simple profiling aspect. The
ordering of advice is controlled via the <interfacename>Ordered</interfacename> ordering of advice is controlled via the <interfacename>Ordered</interfacename>
interface. For full details on advice ordering, see <xref linkend="aop-ataspectj-advice-ordering"/>.</para> interface. For full details on advice ordering, see <xref linkend="aop-ataspectj-advice-ordering"/>.</para>
<programlisting><![CDATA[package x.y; <programlisting language="java"><![CDATA[package x.y;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.util.StopWatch; import org.springframework.util.StopWatch;
@ -1510,7 +1501,7 @@ public class SimpleProfiler implements Ordered {
} }
} }
]]></programlisting> ]]></programlisting>
<programlisting><![CDATA[<?xml version="1.0" encoding="UTF-8"?> <programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:aop="http://www.springframework.org/schema/aop"
@ -1557,7 +1548,7 @@ public class SimpleProfiler implements Ordered {
aspects is effected in a similar fashion.</para> aspects is effected in a similar fashion.</para>
<para>Finally, find below some example configuration for effecting the same <para>Finally, find below some example configuration for effecting the same
setup as above, but using the purely XML declarative approach.</para> setup as above, but using the purely XML declarative approach.</para>
<programlisting><![CDATA[<?xml version="1.0" encoding="UTF-8"?> <programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:aop="http://www.springframework.org/schema/aop"
@ -1640,7 +1631,7 @@ public class SimpleProfiler implements Ordered {
<xref linkend="transaction-declarative-annotations"/> and <xref linkend="aop"/> <xref linkend="transaction-declarative-annotations"/> and <xref linkend="aop"/>
respectively.</para> respectively.</para>
</note> </note>
<programlisting><lineannotation>// construct an appropriate transaction manager </lineannotation><![CDATA[ <programlisting language="java"><lineannotation>// construct an appropriate transaction manager </lineannotation><![CDATA[
DataSourceTransactionManager txManager = new DataSourceTransactionManager(getDataSource()); DataSourceTransactionManager txManager = new DataSourceTransactionManager(getDataSource());
]]><lineannotation>// configure the <classname>AnnotationTransactionAspect</classname> to use it; this must be done before executing any transactional methods</lineannotation><![CDATA[ ]]><lineannotation>// configure the <classname>AnnotationTransactionAspect</classname> to use it; this must be done before executing any transactional methods</lineannotation><![CDATA[
@ -1709,7 +1700,7 @@ AnnotationTransactionAspect.aspectOf().setTransactionManager(txManager); ]]></pr
pass an instance of your custom <interfacename>TransactionCallback</interfacename> pass an instance of your custom <interfacename>TransactionCallback</interfacename>
to the <methodname>execute(..)</methodname> method exposed on the to the <methodname>execute(..)</methodname> method exposed on the
<classname>TransactionTemplate</classname>. </para> <classname>TransactionTemplate</classname>. </para>
<programlisting><![CDATA[public class SimpleService implements Service { <programlisting language="java"><![CDATA[public class SimpleService implements Service {
]]><lineannotation>// single <classname>TransactionTemplate</classname> shared amongst all methods in this instance</lineannotation><![CDATA[ ]]><lineannotation>// single <classname>TransactionTemplate</classname> shared amongst all methods in this instance</lineannotation><![CDATA[
private final TransactionTemplate transactionTemplate; private final TransactionTemplate transactionTemplate;
@ -1734,7 +1725,7 @@ AnnotationTransactionAspect.aspectOf().setTransactionManager(txManager); ]]></pr
<para>If there is no return value, use the convenient <para>If there is no return value, use the convenient
<classname>TransactionCallbackWithoutResult</classname> class via an <classname>TransactionCallbackWithoutResult</classname> class via an
anonymous class like so:</para> anonymous class like so:</para>
<programlisting><![CDATA[transactionTemplate.execute(new ]]><emphasis role="bold">TransactionCallbackWithoutResult</emphasis><![CDATA[() { <programlisting language="java"><![CDATA[transactionTemplate.execute(new ]]><emphasis role="bold">TransactionCallbackWithoutResult</emphasis><![CDATA[() {
protected void doInTransactionWithoutResult(TransactionStatus status) { protected void doInTransactionWithoutResult(TransactionStatus status) {
updateOperation1(); updateOperation1();
@ -1744,7 +1735,7 @@ AnnotationTransactionAspect.aspectOf().setTransactionManager(txManager); ]]></pr
<para>Code within the callback can roll the transaction back by calling <para>Code within the callback can roll the transaction back by calling
the <literal>setRollbackOnly()</literal> method on the supplied the <literal>setRollbackOnly()</literal> method on the supplied
<interfacename>TransactionStatus</interfacename> object.</para> <interfacename>TransactionStatus</interfacename> object.</para>
<programlisting><![CDATA[transactionTemplate.execute(new TransactionCallbackWithoutResult() { <programlisting language="java"><![CDATA[transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) { protected void doInTransactionWithoutResult(TransactionStatus status) {
try { try {
@ -1765,7 +1756,7 @@ AnnotationTransactionAspect.aspectOf().setTransactionManager(txManager); ]]></pr
Find below an example of programmatically customizing the Find below an example of programmatically customizing the
transactional settings for a specific <classname>TransactionTemplate</classname>. transactional settings for a specific <classname>TransactionTemplate</classname>.
</para> </para>
<programlisting><![CDATA[public class SimpleService implements Service { <programlisting language="java"><![CDATA[public class SimpleService implements Service {
private final TransactionTemplate transactionTemplate; private final TransactionTemplate transactionTemplate;
@ -1782,7 +1773,7 @@ AnnotationTransactionAspect.aspectOf().setTransactionManager(txManager); ]]></pr
<para>Find below an example of defining a <classname>TransactionTemplate</classname> with some custom <para>Find below an example of defining a <classname>TransactionTemplate</classname> with some custom
transactional settings, using Spring XML configuration. The '<literal>sharedTransactionTemplate</literal>' transactional settings, using Spring XML configuration. The '<literal>sharedTransactionTemplate</literal>'
can then be injected into as many services as are required.</para> can then be injected into as many services as are required.</para>
<programlisting><![CDATA[<bean id="sharedTransactionTemplate" <programlisting language="xml"><![CDATA[<bean id="sharedTransactionTemplate"
class="org.springframework.transaction.support.TransactionTemplate"> class="org.springframework.transaction.support.TransactionTemplate">
<property name="isolationLevelName" value="ISOLATION_READ_UNCOMMITTED"/> <property name="isolationLevelName" value="ISOLATION_READ_UNCOMMITTED"/>
<property name="timeout" value="30"/> <property name="timeout" value="30"/>
@ -1811,7 +1802,7 @@ AnnotationTransactionAspect.aspectOf().setTransactionManager(txManager); ]]></pr
<interfacename>TransactionDefinition</interfacename> and <interfacename>TransactionDefinition</interfacename> and
<interfacename>TransactionStatus</interfacename> objects you can <interfacename>TransactionStatus</interfacename> objects you can
initiate transactions, rollback and commit.</para> initiate transactions, rollback and commit.</para>
<programlisting><![CDATA[DefaultTransactionDefinition def = new DefaultTransactionDefinition(); <programlisting language="java"><![CDATA[DefaultTransactionDefinition def = new DefaultTransactionDefinition();
]]><lineannotation>// explicitly setting the transaction name is something that can only be done programmatically</lineannotation><![CDATA[ ]]><lineannotation>// explicitly setting the transaction name is something that can only be done programmatically</lineannotation><![CDATA[
def.setName("SomeTxName"); def.setName("SomeTxName");
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);