processing where this translator is needed. Here is an example of how
this custom translator can be used:</para>
<programlisting><lineannotation>// create a <classname>JdbcTemplate</classname> and set data source</lineannotation>
<programlistinglanguage="java"><lineannotation>// create a <classname>JdbcTemplate</classname> and set data source</lineannotation>
JdbcTemplate jt = new JdbcTemplate();
jt.setDataSource(dataSource);
<lineannotation>// create a custom translator and set the <interfacename>DataSource</interfacename> for the default translation lookup</lineannotation>
provides a more convenient <classname>addValue</classname> method that
can be chained.</para>
<para><programlisting>public class JdbcActorDao implements ActorDao {
<para><programlistinglanguage="java">public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcInsert insertActor;
@ -1507,7 +1507,7 @@ END;</programlisting>As you can see there are four parameters. One is an in
@@ -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
example, all we need to specify is the name of the procedure.</para>
<para><programlisting>public class JdbcActorDao implements ActorDao {
<para><programlistinglanguage="java">public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcCall procReadActor;
@ -1562,7 +1562,7 @@ END;</programlisting>As you can see there are four parameters. One is an in
@@ -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
this to work. Here is an example of this configuration:</para>
<para><programlisting>public class JdbcActorDao implements ActorDao {
<para><programlistinglanguage="java">public class JdbcActorDao implements ActorDao {
private SimpleJdbcCall procReadActor;
public void setDataSource(DataSource dataSource) {
@ -1603,7 +1603,7 @@ END;</programlisting>As you can see there are four parameters. One is an in
@@ -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
earlier example would look like:</para>
<para><programlisting>public class JdbcActorDao implements ActorDao {
<para><programlistinglanguage="java">public class JdbcActorDao implements ActorDao {
private SimpleJdbcCall procReadActor;
public void setDataSource(DataSource dataSource) {
@ -1644,7 +1644,7 @@ END;</programlisting>As you can see there are four parameters. One is an in
@@ -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
declarations like:</para>
<para><programlisting> new SqlParameter("in_id", Types.NUMERIC),
<para><programlistinglanguage="java"> new SqlParameter("in_id", Types.NUMERIC),
new SqlOutParameter("out_first_name", Types.VARCHAR),</programlisting></para>
<para>The first line with the <classname>SqlParameter</classname>
<classname>SimpleJdbcCall</classname> in the initialization
method.</para>
<para><programlisting>public class JdbcActorDao implements ActorDao {
<para><programlistinglanguage="java">public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcCall funcGetActorName;
@ -1768,7 +1768,7 @@ END;</programlisting>In order to call this procedure we need to declare the
@@ -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
<classname>newInstance</classname> method.</para>
<para><programlisting>public class JdbcActorDao implements ActorDao {
<para><programlistinglanguage="java">public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcCall procReadAllActors;
@ -1852,7 +1852,7 @@ END;</programlisting>In order to call this procedure we need to declare the
@@ -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>
class.</para>
<programlisting>private class CustomerMappingQuery extends MappingSqlQuery {
<programlistinglanguage="java">private class CustomerMappingQuery extends MappingSqlQuery {
public CustomerMappingQuery(DataSource ds) {
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
@@ -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
statement can be prepared and later be executed.</para>
CustomerMappingQuery custQry = new CustomerMappingQuery(dataSource);
Object[] parms = new Object[1];
parms[0] = id;
@ -1921,7 +1921,7 @@ END;</programlisting>In order to call this procedure we need to declare the
@@ -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
@ -2110,7 +2110,7 @@ public class TitlesAndGenresStoredProcedure extends StoredProcedure {
@@ -2110,7 +2110,7 @@ public class TitlesAndGenresStoredProcedure extends StoredProcedure {
<classname>Title</classname> domain object for each row in the supplied
@ -2208,7 +2208,7 @@ public class TitlesAfterDateStoredProcedure extends StoredProcedure {
@@ -2208,7 +2208,7 @@ public class TitlesAfterDateStoredProcedure extends StoredProcedure {
the appropriate run method repeatedly to execute the function. Here is
an example of retrieving the count of rows from a table:</para>
<programlisting>public int countRows() {
<programlistinglanguage="java">public int countRows() {
SqlFunction sf = new SqlFunction(dataSource, "select count(*) from mytable");
sf.compile();
return sf.run();
@ -2343,7 +2343,7 @@ public class TitlesAfterDateStoredProcedure extends StoredProcedure {
@@ -2343,7 +2343,7 @@ public class TitlesAfterDateStoredProcedure extends StoredProcedure {
<areacoords="13"id="jdbc.lobhandler.setBlob"/>
</areaspec>
<programlisting>final File blobIn = new File("spring2004.jpg");
<programlistinglanguage="java">final File blobIn = new File("spring2004.jpg");
final InputStream blobIs = new FileInputStream(blobIn);
final File clobIn = new File("large.txt");
final InputStream clobIs = new FileInputStream(clobIn);
@ -696,7 +696,7 @@ public class DefaultFooService implements FooService {
@@ -696,7 +696,7 @@ public class DefaultFooService implements FooService {
be started, suspended, be marked as read-only, etc., depending on the
transaction configuration associated with that method. Consider the following
program that test drives the above configuration.</para>
<programlisting><![CDATA[public final class Boot {
<programlistinglanguage="java"><![CDATA[public final class Boot {
public static void main(final String[] args) throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("context.xml", Boot.class);
@ -710,7 +710,7 @@ public class DefaultFooService implements FooService {
@@ -710,7 +710,7 @@ public class DefaultFooService implements FooService {
<methodname>insertFoo(..)</methodname> method of the
<classname>DefaultFooService</classname> class have been truncated in
the interest of clarity.)</emphasis></para>
<programlisting><lineannotation><emphasisrole="bold"><!-- the Spring container is starting up... --></emphasis></lineannotation><![CDATA[
<programlistinglanguage="xml"><lineannotation><emphasisrole="bold"><!-- the Spring container is starting up... --></emphasis></lineannotation><![CDATA[
for bean 'fooService' with 0 common interceptors and 1 specific interceptors
]]><lineannotation><emphasisrole="bold"><!-- the <classname>DefaultFooService</classname> is actually proxied --></emphasis></lineannotation><![CDATA[
@ -767,7 +767,7 @@ Exception in thread "main" java.lang.UnsupportedOperationException
@@ -767,7 +767,7 @@ Exception in thread "main" java.lang.UnsupportedOperationException
for rollback can be configured. Find below a snippet of XML configuration that
demonstrates how one would configure rollback for a checked, application-specific
public class DefaultFooService implements FooService {
@ -1056,7 +1048,7 @@ 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
instance can be made transactional by adding merely <emphasis>one</emphasis> line of
XML configuration, like so:</para>
<programlisting><lineannotation><!-- from the file <literal>'context.xml'</literal> --></lineannotation><![CDATA[
<programlistinglanguage="xml"><lineannotation><!-- from the file <literal>'context.xml'</literal> --></lineannotation><![CDATA[
@ -1231,7 +1223,7 @@ public class DefaultFooService implements FooService {
@@ -1231,7 +1223,7 @@ public class DefaultFooService implements FooService {
<methodname>updateFoo(Foo)</methodname> method in the same class takes precedence
over the transactional settings defined at the class level.</para>
public class DefaultFooService implements FooService {
public Foo getFoo(String fooName) {
@ -1362,8 +1354,7 @@ public class DefaultFooService implements FooService {
@@ -1362,8 +1354,7 @@ public class DefaultFooService implements FooService {
transaction name is always the fully-qualified class name + "." + method name of the
transactionally-advised class. For example, if the <methodname>handlePayment(..)</methodname>
method of the <classname>BusinessService</classname> class started a transaction, the name of the
transaction would be: <literal>com.foo.BusinessService.handlePayment</literal>.</para>
</section>
</section>
@ -1476,7 +1467,7 @@ public class DefaultFooService implements FooService {
@@ -1476,7 +1467,7 @@ public class DefaultFooService implements FooService {
<para>Here is the code for a simple profiling aspect. The
ordering of advice is controlled via the <interfacename>Ordered</interfacename>
interface. For full details on advice ordering, see <xreflinkend="aop-ataspectj-advice-ordering"/>.</para>
@ -1640,7 +1631,7 @@ public class SimpleProfiler implements Ordered {
@@ -1640,7 +1631,7 @@ public class SimpleProfiler implements Ordered {
<xreflinkend="transaction-declarative-annotations"/> and <xreflinkend="aop"/>
respectively.</para>
</note>
<programlisting><lineannotation>// construct an appropriate transaction manager </lineannotation><![CDATA[
<programlistinglanguage="java"><lineannotation>// construct an appropriate transaction manager </lineannotation><![CDATA[
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[