diff --git a/spring-framework-reference/src/jdbc.xml b/spring-framework-reference/src/jdbc.xml
index 8625254c52d..9ca4477294a 100644
--- a/spring-framework-reference/src/jdbc.xml
+++ b/spring-framework-reference/src/jdbc.xml
@@ -228,23 +228,23 @@
A simple query for getting the number of rows in a
relation.
- int rowCount = this.jdbcTemplate.queryForInt("select count(0) from t_accrual");
+ int rowCount = this.jdbcTemplate.queryForInt("select count(0) from t_accrual");A simple query using a bind variable.
- int countOfActorsNamedJoe = this.jdbcTemplate.queryForInt(
+ int countOfActorsNamedJoe = this.jdbcTemplate.queryForInt(
"select count(0) from t_actors where first_name = ?", new Object[]{"Joe"});Querying for a String.
- String surname = (String) this.jdbcTemplate.queryForObject(
+ String surname = (String) this.jdbcTemplate.queryForObject(
"select surname from t_actor where id = ?",
new Object[]{new Long(1212)}, String.class);Querying and populating a single domain
object.
- Actor actor = (Actor) this.jdbcTemplate.queryForObject(
+ Actor actor = (Actor) this.jdbcTemplate.queryForObject(
"select first_name, surname from t_actor where id = ?",
new Object[]{new Long(1212)},
new RowMapper() {
@@ -259,7 +259,7 @@
Querying and populating a number of domain objects.
- Collection actors = this.jdbcTemplate.query(
+ Collection actors = this.jdbcTemplate.query(
"select first_name, surname from t_actor",
new RowMapper() {
@@ -279,7 +279,7 @@
by DAO methods as needed. For example, the last code snippet might
be better off written like so:
- public Collection findAllActors() {
+ public Collection findAllActors() {
return this.jdbcTemplate.query( "select first_name, surname from t_actor", new ActorMapper());
}
@@ -297,15 +297,15 @@ private static final class ActorMapper implements RowMapper {
Updating (INSERT/UPDATE/DELETE)
- this.jdbcTemplate.update(
+ this.jdbcTemplate.update(
"insert into t_actor (first_name, surname) values (?, ?)",
new Object[] {"Leonor", "Watling"});
- this.jdbcTemplate.update(
+ this.jdbcTemplate.update(
"update t_actor set weapon = ? where id = ?",
new Object[] {"Banjo", new Long(5276)});
- this.jdbcTemplate.update(
+ this.jdbcTemplate.update(
"delete from actor where id = ?",
new Object[] {new Long.valueOf(actorId)});
@@ -318,13 +318,13 @@ private static final class ActorMapper implements RowMapper {
statements. It is heavily overloaded with variants taking callback
interfaces, binding variable arrays, and suchlike.
- this.jdbcTemplate.execute("create table mytable (id integer, name varchar(100))");
+ this.jdbcTemplate.execute("create table mytable (id integer, name varchar(100))");Invoking a simple stored procedure (more sophisticated stored
procedure support is covered
later).
- this.jdbcTemplate.update(
+ this.jdbcTemplate.update(
"call SUPPORT.REFRESH_ACTORS_SUMMARY(?)",
new Object[]{Long.valueOf(unionId)});
@@ -356,7 +356,7 @@ private static final class ActorMapper implements RowMapper {
setter for the DataSource. This leads
to DAOs that look in part like this:
- public class JdbcCorporateEventDao implements CorporateEventDao {
+ public class JdbcCorporateEventDao implements CorporateEventDao {
private JdbcTemplate jdbcTemplate;
@@ -369,7 +369,7 @@ private static final class ActorMapper implements RowMapper {
The attendant configuration might look like this.
- <?xml version="1.0" encoding="UTF-8"?>
+ <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
@@ -428,7 +428,7 @@ private static final class ActorMapper implements RowMapper {
the JdbcTemplate itself; namely, programming JDBC
statements using named parameters.
- // some JDBC-backed DAO class...
+ // some JDBC-backed DAO class...
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
public void setDataSource(DataSource dataSource) {
@@ -458,7 +458,7 @@ public int countOfActorsByFirstName(String firstName) {
implemented by the NamedParameterJdbcTemplate
class) follow a similar pattern and will not be covered here.)
- // some JDBC-backed DAO class...
+ // some JDBC-backed DAO class...
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
public void setDataSource(DataSource dataSource) {
@@ -498,7 +498,7 @@ public int countOfActorsByFirstName(String firstName) {
conventions), and uses the properties of the wrapped JavaBean as
the source of named parameter values.
- public class Actor {
+ public class Actor {
private Long id;
private String firstName;
@@ -520,7 +520,7 @@ public int countOfActorsByFirstName(String firstName) {
}
- // some JDBC-backed DAO class...
+ // some JDBC-backed DAO class...
private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
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
SimpleJdbcTemplate.
- // classic JdbcTemplate-style...
+ // classic JdbcTemplate-style...
private JdbcTemplate jdbcTemplate;
public void setDataSource(DataSource dataSource) {
@@ -611,7 +611,7 @@ public Actor findActor(long id) {
SimpleJdbcTemplate; notice how much 'cleaner' the
code is.
- // SimpleJdbcTemplate-style...
+ // SimpleJdbcTemplate-style...
private SimpleJdbcTemplate simpleJdbcTemplate;
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
a DriverManagerDataSource:
- DriverManagerDataSource dataSource = new DriverManagerDataSource();
+ DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("org.hsqldb.jdbcDriver");
dataSource.setUrl("jdbc:hsqldb:hsql://localhost:");
dataSource.setUsername("sa");
@@ -749,7 +749,7 @@ dataSource.setPassword("");SQLErrorCodeSQLExceptionTranslator can be
extended the following way:
- public class MySQLErrorCodesTranslator extends SQLErrorCodeSQLExceptionTranslator {
+ public class MySQLErrorCodesTranslator extends SQLErrorCodeSQLExceptionTranslator {
protected DataAccessException customTranslate(String task, String sql, SQLException sqlex) {
if (sqlex.getErrorCode() == -12345) {
@@ -769,7 +769,7 @@ dataSource.setPassword("");
processing where this translator is needed. Here is an example of how
this custom translator can be used:
- // create a JdbcTemplate and set data source
+ // create a JdbcTemplate and set data source
JdbcTemplate jt = new JdbcTemplate();
jt.setDataSource(dataSource);
// create a custom translator and set the DataSource for the default translation lookup
@@ -799,7 +799,7 @@ su.update();
what you need to include for a minimal but fully functional class that
creates a new table.
- import javax.sql.DataSource;
+ import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
public class ExecuteAStatement {
@@ -833,7 +833,7 @@ public class ExecuteAStatement {
an int and one that queries for a
String.
- import javax.sql.DataSource;
+ import javax.sql.DataSource;
import org.springframework.jdbc.core.JdbcTemplate;
public class RunAQuery {
@@ -867,7 +867,7 @@ public class RunAQuery {
above example to retrieve a list of all the rows, it would look like
this:
-
+
private JdbcTemplate jdbcTemplate;
public void setDataSource(DataSource dataSource) {
@@ -893,7 +893,7 @@ public List getList() {
objects (and thus primitives have to be wrapped in the primitive wrapper
classes).
- import javax.sql.DataSource;
+ import javax.sql.DataSource;
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
work on other platforms is:
- final String INSERT_SQL = "insert into my_test (name) values(?)";
+ final String INSERT_SQL = "insert into my_test (name) values(?)";
final String name = "Rob";
KeyHolder keyHolder = new GeneratedKeyHolder();
@@ -1169,7 +1169,7 @@ jdbcTemplate.update(
where we update the actor table based on entries in a list. The entire
list is used as the batch in his example.
- public class JdbcActorDao implements ActorDao {
+ public class JdbcActorDao implements ActorDao {
private JdbcTemplate jdbcTemplate;
public void setDataSource(DataSource dataSource) {
@@ -1220,7 +1220,7 @@ jdbcTemplate.update(
This example shows a batch update using named parameters:
- public class JdbcActorDao implements ActorDao {
+ public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate;
public void setDataSource(DataSource dataSource) {
@@ -1244,7 +1244,7 @@ jdbcTemplate.update(
The same example using classic JDBC "?" place holders:
- public class JdbcActorDao implements ActorDao {
+ public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate;
public void setDataSource(DataSource dataSource) {
@@ -1301,7 +1301,7 @@ jdbcTemplate.update(
configuration methods. In this case there is only one configuration
method used but we will see examples of multiple ones soon.
- public class JdbcActorDao implements ActorDao {
+ public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcInsert insertActor;
@@ -1340,7 +1340,7 @@ jdbcTemplate.update(
generated key column using the
usingGeneratedKeyColumns method.
- public class JdbcActorDao implements ActorDao {
+ public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcInsert insertActor;
@@ -1381,7 +1381,7 @@ jdbcTemplate.update(
specifying a list of column names to be used. This is accomplished using
the usingColumns method.
- public class JdbcActorDao implements ActorDao {
+ public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcInsert insertActor;
@@ -1419,7 +1419,7 @@ jdbcTemplate.update(
contains your values. It will use the corresponding getter method to
extract the parameter values. Here is an example:
- public class JdbcActorDao implements ActorDao {
+ public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcInsert insertActor;
@@ -1443,7 +1443,7 @@ jdbcTemplate.update(
provides a more convenient addValue method that
can be chained.
- public class JdbcActorDao implements ActorDao {
+ public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcInsert insertActor;
@@ -1507,7 +1507,7 @@ END;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.
- public class JdbcActorDao implements ActorDao {
+ public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcCall procReadActor;
@@ -1562,7 +1562,7 @@ END;As you can see there are four parameters. One is an in
commons-collections.jar on your classpath for
this to work. Here is an example of this configuration:
- public class JdbcActorDao implements ActorDao {
+ public class JdbcActorDao implements ActorDao {
private SimpleJdbcCall procReadActor;
public void setDataSource(DataSource dataSource) {
@@ -1603,7 +1603,7 @@ END;As you can see there are four parameters. One is an in
This is what a fully declared procedure call declaration of our
earlier example would look like:
- public class JdbcActorDao implements ActorDao {
+ public class JdbcActorDao implements ActorDao {
private SimpleJdbcCall procReadActor;
public void setDataSource(DataSource dataSource) {
@@ -1644,7 +1644,7 @@ END;As you can see there are four parameters. One is an in
java.sql.Types constants. We have already seen
declarations like:
- new SqlParameter("in_id", Types.NUMERIC),
+ new SqlParameter("in_id", Types.NUMERIC),
new SqlOutParameter("out_first_name", Types.VARCHAR),The first line with the SqlParameter
@@ -1710,7 +1710,7 @@ END;SimpleJdbcCall in the initialization
method.
- public class JdbcActorDao implements ActorDao {
+ public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcCall funcGetActorName;
@@ -1768,7 +1768,7 @@ END;In order to call this procedure we need to declare the
created by passing in the required class to map to in the
newInstance method.
- public class JdbcActorDao implements ActorDao {
+ public class JdbcActorDao implements ActorDao {
private SimpleJdbcTemplate simpleJdbcTemplate;
private SimpleJdbcCall procReadAllActors;
@@ -1852,7 +1852,7 @@ END;In order to call this procedure we need to declare the
customer relation to an instance of the Customer
class.
- private class CustomerMappingQuery extends MappingSqlQuery {
+ private class CustomerMappingQuery extends MappingSqlQuery {
public CustomerMappingQuery(DataSource ds) {
super(ds, "SELECT id, name FROM customer WHERE id = ?");
@@ -1883,7 +1883,7 @@ END;In order to call this procedure we need to declare the
have been defined we call the compile() method so the
statement can be prepared and later be executed.
- public Customer getCustomer(Integer id) {
+ public Customer getCustomer(Integer id) {
CustomerMappingQuery custQry = new CustomerMappingQuery(dataSource);
Object[] parms = new Object[1];
parms[0] = id;
@@ -1921,7 +1921,7 @@ END;In order to call this procedure we need to declare the
custom update method) it can easily be parameterized by setting SQL and
declaring parameters.
- import java.sql.Types;
+ import java.sql.Types;
import javax.sql.DataSource;
@@ -1972,7 +1972,7 @@ public class UpdateCreditRating extends SqlUpdate {
SQL type is specified using the java.sql.Types
constants. We have already seen declarations like:
- new SqlParameter("in_id", Types.NUMERIC),
+ new SqlParameter("in_id", Types.NUMERIC),
new SqlOutParameter("out_first_name", Types.VARCHAR),The first line with the SqlParameter
@@ -2012,7 +2012,7 @@ public class UpdateCreditRating extends SqlUpdate {
execute() method returns a map with an entry for each
declared output parameter using the parameter name as the key.
- import java.sql.Types;
+ import java.sql.Types;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@@ -2071,7 +2071,7 @@ public class TestStoredProcedure {
Find below an example of a StoredProcedure
that has two output parameters (in this case Oracle REF cursors).
- import oracle.jdbc.driver.OracleTypes;
+ import oracle.jdbc.driver.OracleTypes;
import org.springframework.jdbc.core.SqlOutParameter;
import org.springframework.jdbc.object.StoredProcedure;
@@ -2110,7 +2110,7 @@ public class TitlesAndGenresStoredProcedure extends StoredProcedure {
Title domain object for each row in the supplied
ResultSet.
- import com.foo.sprocs.domain.Title;
+ import com.foo.sprocs.domain.Title;
import org.springframework.jdbc.core.RowMapper;
import java.sql.ResultSet;
@@ -2131,7 +2131,7 @@ public final class TitleMapper implements RowMapper {
Genre domain object for each row in the supplied
ResultSet.
- import org.springframework.jdbc.core.RowMapper;
+ import org.springframework.jdbc.core.RowMapper;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -2152,7 +2152,7 @@ public final class GenreMapper implements RowMapper {
superclass' (untyped) execute(Map parameters) (which
has protected access); for example:
- import oracle.jdbc.driver.OracleTypes;
+ import oracle.jdbc.driver.OracleTypes;
import org.springframework.jdbc.core.SqlOutParameter;
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
an example of retrieving the count of rows from a table:
- public int countRows() {
+ 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 {
- final File blobIn = new File("spring2004.jpg");
+ 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);
@@ -2392,7 +2392,7 @@ clobReader.close();
- List l = jdbcTemplate.query("select id, a_clob, a_blob from lob_table",
+ List l = jdbcTemplate.query("select id, a_clob, a_blob from lob_table",
new RowMapper() {
public Object mapRow(ResultSet rs, int i) throws SQLException {
Map results = new HashMap();
@@ -2471,7 +2471,7 @@ clobReader.close();
interface is used as part of the declaration of an
SqlOutParameter.
- declareParameter(new SqlOutParameter("item", OracleTypes.STRUCT, "ITEM_TYPE",
+ declareParameter(new SqlOutParameter("item", OracleTypes.STRUCT, "ITEM_TYPE",
new SqlReturnType() {
public Object getTypeValue(CallableStatement cs, int colIndx, int sqlType, String typeName)
throws SQLException {
@@ -2492,7 +2492,7 @@ clobReader.close();
specific objects like StructDescriptors or
ArrayDescriptors
- SqlTypeValue value = new AbstractSqlTypeValue() {
+ SqlTypeValue value = new AbstractSqlTypeValue() {
protected Object createTypeValue(Connection conn, int sqlType, String typeName) throws SQLException {
StructDescriptor itemDescriptor = new StructDescriptor(typeName, conn);
Struct item = new STRUCT(itemDescriptor, conn,
diff --git a/spring-framework-reference/src/orm.xml b/spring-framework-reference/src/orm.xml
index ca47abcd19f..a33def81f65 100644
--- a/spring-framework-reference/src/orm.xml
+++ b/spring-framework-reference/src/orm.xml
@@ -192,7 +192,7 @@
JDBC DataSource and a Hibernate
SessionFactory on top of it:
- <beans>
+ <beans>
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
@@ -222,7 +222,7 @@
DataSource (usually managed by an
application server) is just a matter of configuration:
- <beans>
+ <beans>
<bean id="myDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/myds"/>
@@ -251,7 +251,7 @@
SessionFactory, and an example for a DAO
method implementation.
- <beans>
+ <beans>
<bean id="myProductDao" class="product.ProductDaoImpl">
<property name="sessionFactory" ref="mySessionFactory"/>
@@ -259,7 +259,7 @@
</beans>
- public class ProductDaoImpl implements ProductDao {
+ public class ProductDaoImpl implements ProductDao {
private HibernateTemplate hibernateTemplate;
@@ -280,7 +280,7 @@
that are not exposed on the HibernateTemplate,
you can always drop down to a callback-based approach like so.
- public class ProductDaoImpl implements ProductDao {
+ public class ProductDaoImpl implements ProductDao {
private HibernateTemplate hibernateTemplate;
@@ -319,7 +319,7 @@
combination, this allows for very simple DAO implementations for typical
requirements:
- public class ProductDaoImpl extends HibernateDaoSupport implements ProductDao {
+ public class ProductDaoImpl extends HibernateDaoSupport implements ProductDao {
public Collection loadProductsByCategory(String category) throws DataAccessException {
return this.getHibernateTemplate().find(
@@ -349,7 +349,7 @@
Session, as its lifecycle is managed by
the transaction).
- public class HibernateProductDao extends HibernateDaoSupport implements ProductDao {
+ public class HibernateProductDao extends HibernateDaoSupport implements ProductDao {
public Collection loadProductsByCategory(String category) throws DataAccessException, MyException {
Session session = getSession(false);
@@ -391,7 +391,7 @@
DAO implementation looks like as follows, based on the plain Hibernate
API:
- public class ProductDaoImpl implements ProductDao {
+ public class ProductDaoImpl implements ProductDao {
private SessionFactory sessionFactory;
@@ -424,7 +424,7 @@
with the desired factory reference. As a Spring bean definition, it
would look as follows:
- <beans>
+ <beans>
<bean id="myProductDao" class="product.ProductDaoImpl">
<property name="sessionFactory" ref="mySessionFactory"/>
@@ -480,7 +480,7 @@
a Spring application context, and an example for a business method
implementation.
- <beans>
+ <beans>
<bean id="myTxManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory"/>
@@ -493,7 +493,7 @@
</beans>
- public class ProductServiceImpl implements ProductService {
+ public class ProductServiceImpl implements ProductService {
private TransactionTemplate transactionTemplate;
private ProductDao productDao;
@@ -533,7 +533,7 @@
configuration file and do not affect the business service
implementations.
- <beans>
+ <beans>
<bean id="myTxManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="mySessionFactory"/>
@@ -555,7 +555,7 @@
</beans>
- public class ProductServiceImpl implements ProductService {
+ public class ProductServiceImpl implements ProductService {
private ProductDao productDao;
@@ -593,7 +593,7 @@
have not done so already prior to continuing.
- <?xml version="1.0" encoding="UTF-8"?>
+ <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
@@ -663,7 +663,7 @@
factories without special regard, as long as it is using
JtaTransactionManager as the strategy.
- <beans>
+ <beans>
<bean id="myDataSource1" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName value="java:comp/env/jdbc/myds1"/>
@@ -963,7 +963,7 @@
PersistenceManagerFactory within a Spring
application context:
- <beans>
+ <beans>
<bean id="myPmf" class="org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean">
<property name="configLocation" value="classpath:kodo.properties"/>
@@ -984,7 +984,7 @@
"connectionFactory" property. For example, for the open source JDO
implementation JPOX ():
- <beans>
+ <beans>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
@@ -1025,7 +1025,7 @@
usually rather be used with the Spring Framework's
JdoTemplate:
- <beans>
+ <beans>
<bean id="myProductDao" class="product.ProductDaoImpl">
<property name="persistenceManagerFactory" ref="myPmf"/>
@@ -1033,7 +1033,7 @@
</beans>
- public class ProductDaoImpl implements ProductDao {
+ public class ProductDaoImpl implements ProductDao {
private JdoTemplate jdoTemplate;
@@ -1073,7 +1073,7 @@
combination, this allows for very simple DAO implementations for typical
requirements:
- public class ProductDaoImpl extends JdoDaoSupport implements ProductDao {
+ public class ProductDaoImpl extends JdoDaoSupport implements ProductDao {
public Collection loadProductsByCategory(String category) throws DataAccessException {
return getJdoTemplate().find(
@@ -1101,7 +1101,7 @@
PersistenceManagerFactory. A
corresponding DAO implementation looks like as follows:
- public class ProductDaoImpl implements ProductDao {
+ public class ProductDaoImpl implements ProductDao {
private PersistenceManagerFactory persistenceManagerFactory;
@@ -1126,7 +1126,7 @@
it still fits nicely into a Spring container, just like it would if
coded against Spring's JdoTemplate:
- <beans>
+ <beans>
<bean id="myProductDao" class="product.ProductDaoImpl">
<property name="persistenceManagerFactory" ref="myPmf"/>
@@ -1143,7 +1143,7 @@
PersistenceManagerFactory, passing the
proxy into your DAOs.
- <beans>
+ <beans>
<bean id="myPmfProxy"
class="org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy">
@@ -1173,7 +1173,7 @@
call and thus the entire finally block, which you
might prefer to keep your DAO implementations concise:
- public class ProductDaoImpl implements ProductDao {
+ public class ProductDaoImpl implements ProductDao {
private PersistenceManagerFactory persistenceManagerFactory;
@@ -1194,7 +1194,7 @@
TransactionAwarePersistenceManagerFactoryProxy's
"allowCreate" flag off:
- <beans>
+ <beans>
<bean id="myPmfProxy"
class="org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy">
@@ -1238,7 +1238,7 @@
To execute service operations within transactions, you can use
Spring's common declarative transaction facilities. For example:
- <?xml version="1.0" encoding="UTF-8"?>
+ <?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -1375,7 +1375,7 @@
Spring-managed JDBC DataSource to
use.
- <beans>
+ <beans>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
@@ -1391,7 +1391,7 @@
</beans>
- <toplink-configuration>
+ <toplink-configuration>
<session>
<name>Session</name>
@@ -1428,7 +1428,7 @@
SessionFactory, but will usually rather
be used with Spring's TopLinkTemplate:
- <beans>
+ <beans>
<bean id="myProductDao" class="product.ProductDaoImpl">
<property name="sessionFactory" ref="mySessionFactory"/>
@@ -1436,7 +1436,7 @@
</beans>
- public class TopLinkProductDao implements ProductDao {
+ public class TopLinkProductDao implements ProductDao {
private TopLinkTemplate tlTemplate;
@@ -1482,7 +1482,7 @@
combination, this allows for simple DAO implementations for typical
requirements:
- public class ProductDaoImpl extends TopLinkDaoSupport implements ProductDao {
+ public class ProductDaoImpl extends TopLinkDaoSupport implements ProductDao {
public Collection loadProductsByCategory(String category) throws DataAccessException {
ReadAllQuery findOwnersQuery = new ReadAllQuery(Product.class);
@@ -1535,7 +1535,7 @@
A corresponding DAO implementation looks like as follows:
- public class ProductDaoImpl implements ProductDao {
+ public class ProductDaoImpl implements ProductDao {
private Session session;
@@ -1564,7 +1564,7 @@
bean reference of type Session, to be
passed into the DAO:
- <beans>
+ <beans>
<bean id="mySessionAdapter"
class="org.springframework.orm.toplink.support.TransactionAwareSessionAdapter">
@@ -1627,7 +1627,7 @@
To execute service operations within transactions, you can use
Spring's common declarative transaction facilities. For example:
- <?xml version="1.0" encoding="UTF-8"?>
+ <?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -1730,7 +1730,7 @@
need to create the following SQL map
'Account.xml':
- <sqlMap namespace="Account">
+ <sqlMap namespace="Account">
<resultMap id="result" class="examples.Account">
<result property="name" column="NAME" columnIndex="1"/>
@@ -1751,7 +1751,7 @@
The configuration file for iBATIS 2 looks like this:
- <sqlMapConfig>
+ <sqlMapConfig>
<sqlMap resource="example/Account.xml"/>
@@ -1767,7 +1767,7 @@
SqlMapClientFactoryBean, which enables lazy
loading.
- <beans>
+ <beans>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
@@ -1792,7 +1792,7 @@
supporting class similar to the SqlMapDaoSupport.
We extend it to implement our DAO:
- public class SqlMapAccountDao extends SqlMapClientDaoSupport implements AccountDao {
+ public class SqlMapAccountDao extends SqlMapClientDaoSupport implements AccountDao {
public Account getAccount(String email) throws DataAccessException {
return (Account) getSqlMapClientTemplate().queryForObject("getAccountByEmail", email);
@@ -1809,7 +1809,7 @@
application context and wiring it with our
SqlMapClient instance:
- <beans>
+ <beans>
<bean id="accountDao" class="example.SqlMapAccountDao">
<property name="sqlMapClient" ref="sqlMapClient"/>
@@ -1828,7 +1828,7 @@
SqlMapClientCallback implementation as argument. This
can, for example, be used for batching:
- public class SqlMapAccountDao extends SqlMapClientDaoSupport implements AccountDao {
+ public class SqlMapAccountDao extends SqlMapClientDaoSupport implements AccountDao {
public void insertAccount(Account account) throws DataAccessException {
getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
@@ -1857,7 +1857,7 @@
SqlMapClient. A corresponding DAO implementation
looks like as follows:
- public class SqlMapAccountDao implements AccountDao {
+ public class SqlMapAccountDao implements AccountDao {
private SqlMapClient sqlMapClient;
@@ -1891,7 +1891,7 @@
that the plain iBATIS-based DAO still follows the Dependency Injection
pattern:
- <beans>
+ <beans>
<bean id="accountDao" class="example.SqlMapAccountDao">
<property name="sqlMapClient" ref="sqlMapClient"/>
@@ -1929,7 +1929,7 @@
and, in most cases, requires only the persistence unit name to be
specified:
- <beans>
+ <beans>
<bean id="myEmf" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
<property name="persistenceUnitName" value="myPersistenceUnit"/>
@@ -1959,7 +1959,7 @@
from JNDI (for example in a Java EE 5 environment), is just a matter
of changing the XML configuration:
- <beans>
+ <beans>
<jee:jndi-lookup id="myEmf" jndi-name="persistence/myPersistenceUnit"/>
@@ -2013,7 +2013,7 @@
custom DataSources outside of JNDI and to control the weaving
process.
- <beans>
+ <beans>
<bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="someDataSource"/>
@@ -2026,7 +2026,7 @@
A typical persistence.xml file looks as follows:
- <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
+ <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="myUnit" transaction-type="RESOURCE_LOCAL">
<mapping-file>META-INF/orm.xml</mapping-file>
@@ -2144,7 +2144,7 @@
of the default one) by editing the web application context
file:
- <Context path="/myWebApp" docBase="/my/webApp/location">
+ <Context path="/myWebApp" docBase="/my/webApp/location">
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
</Context>
@@ -2175,7 +2175,7 @@
If you are using Tomcat 5.5.20+ you can set
useSystemClassLoaderAsParent to
- false to fix the problem: <Context path="/myWebApp" docBase="/my/webApp/location">
+ false to fix the problem: <Context path="/myWebApp" docBase="/my/webApp/location">
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"
useSystemClassLoaderAsParent="false"/>
</Context>
@@ -2199,7 +2199,7 @@
of the default one) by editing the web application context
file:
- <Context path="/myWebApp" docBase="/my/webApp/location">
+ <Context path="/myWebApp" docBase="/my/webApp/location">
<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>
</Context>
@@ -2227,7 +2227,7 @@
configuring
LocalContainerEntityManagerFactoryBean:
- <bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+ <bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver"/>
</property>
@@ -2258,7 +2258,7 @@
a Spring-specific (but very general) VM agent (spring-agent.jar):
- <bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
+ <bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="loadTimeWeaver">
<bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver"/>
</property>
@@ -2282,7 +2282,7 @@
autodetection of the platform (WebLogic, OC4J, GlassFish, Tomcat, Resin, VM agent)
as well as automatic propagation of the weaver to all weaver-aware beans.
- <context:load-time-weaver/>
+ <context:load-time-weaver/>
<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
...
@@ -2309,7 +2309,7 @@
parsed and later on retrieved through the persistence unit
name:
- <bean id="pum" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
+ <bean id="pum" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager">
<property name="persistenceXmlLocation">
<list>
<value>org/springframework/orm/jpa/domain/persistence-multi.xml</value>
@@ -2353,7 +2353,7 @@
given EntityManagerFactory or through
Spring's JpaTemplate:
- <beans>
+ <beans>
<bean id="myProductDao" class="product.ProductDaoImpl">
<property name="entityManagerFactory" ref="myEmf"/>
@@ -2361,7 +2361,7 @@
</beans>
- public class JpaProductDao implements ProductDao {
+ public class JpaProductDao implements ProductDao {
private JpaTemplate jpaTemplate;
@@ -2401,7 +2401,7 @@
getJpaTemplate() to be used by
subclasses:
- public class ProductDaoImpl extends JpaDaoSupport implements ProductDao {
+ public class ProductDaoImpl extends JpaDaoSupport implements ProductDao {
public Collection loadProductsByCategory(String category) throws DataAccessException {
Map<String, String> params = new HashMap<String, String>();
@@ -2457,7 +2457,7 @@
PersistenceAnnotationBeanPostProcessor is
enabled. A corresponding DAO implementation might look like this:
- public class ProductDaoImpl implements ProductDao {
+ public class ProductDaoImpl implements ProductDao {
private EntityManagerFactory emf;
@@ -2487,7 +2487,7 @@
advantage of annotations to require the injection of the default
EntityManagerFactory:
- <beans>
+ <beans>
<!-- bean post-processor for JPA annotations -->
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>
@@ -2505,7 +2505,7 @@
(including CommonAnnotationBeanPostProcessor
etc).
- <beans>
+ <beans>
<!-- post-processors for all standard config annotations -->
<context:annotation-config/>
@@ -2522,7 +2522,7 @@
transactional EntityManager) to be injected instead of the
factory:
- public class ProductDaoImpl implements ProductDao {
+ public class ProductDaoImpl implements ProductDao {
@PersistenceContext
private EntityManager em;
@@ -2597,14 +2597,14 @@
exception translation to be applied transparently through the
@Repository annotation:
- @Repository
+ @Repository
public class ProductDaoImpl implements ProductDao {
// class body here...
}
- <beans>
+ <beans>
<!-- Exception translation bean post processor -->
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
@@ -2635,7 +2635,7 @@ public class ProductDaoImpl implements ProductDao {
To execute service operations within transactions, you can use
Spring's common declarative transaction facilities. For example:
- <?xml version="1.0" encoding="UTF-8"?>
+ <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
diff --git a/spring-framework-reference/src/oxm.xml b/spring-framework-reference/src/oxm.xml
index 7be0e401be5..ef39710475d 100644
--- a/spring-framework-reference/src/oxm.xml
+++ b/spring-framework-reference/src/oxm.xml
@@ -58,7 +58,7 @@
Spring abstracts all marshalling operations behind the
org.springframework.oxm.Marshaller interface, the main methods of which
is listed below.
-
Similar to the Marshaller, there is the
org.springframework.oxm.Unmarshaller interface.
- saveSettings saves the settings bean to a file named
settings.xml, and loadSettings loads these settings again. A
main method constructs a Spring application context, and calls these two methods.
- Application requires both a marshaller
and unmarshaller property to be set. We can do so using the following
applicationContext.xml:
-
@@ -302,7 +302,7 @@ public class Application {
This sample application produces the following settings.xml file:
-
]]>
@@ -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.
The emboldened text in the below snippet references the OXM schema:
-
+
@@ -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
the configuration of a JAXB2 marshaller might look like:
- ]]>
+ ]]>JAXB
@@ -368,7 +368,7 @@ public class Application {
classes to be supported by the marshaller. Schema validation is performed by specifying one or more
schema resource to the bean, like so:
-
@@ -389,11 +389,11 @@ public class Application {
The jaxb2-marshaller tag configures a org.springframework.oxm.jaxb.Jaxb2Marshaller.
Here is an example:
- ]]>
+ ]]>
Alternatively, the list of classes to bind can be provided to the marshaller via the class-to-be-bound child tag:
-
+
...
@@ -450,7 +450,7 @@ public class Application {
Marshaller and Unmarshaller interface.
It can be wired up as follows:
-
@@ -469,7 +469,7 @@ public class Application {
The mapping can be set using the mappingLocation resource property, indicated
below with a classpath resource.
-
@@ -500,7 +500,7 @@ public class Application {
and Unmarshaller
interfaces. It can be configured as follows:
-
@@ -520,7 +520,7 @@ public class Application {
The xmlbeans-marshaller tag configures a org.springframework.oxm.xmlbeans.XmlBeansMarshaller.
Here is an example:
- ]]>
+ ]]>
Available attributes are:
@@ -580,7 +580,7 @@ public class Application {
bindingName property. In the next sample, we bind the
Flights class:
-
@@ -600,7 +600,7 @@ public class Application {
The jibx-marshaller tag configures a org.springframework.oxm.jibx.JibxMarshaller.
Here is an example:
- ]]>
+ ]]>
Available attributes are:
@@ -656,7 +656,7 @@ public class Application {
in an application context directly. To further customize the XML, you can set an
alias map, which consists of string aliases mapped to classes:
-
diff --git a/spring-framework-reference/src/transaction.xml b/spring-framework-reference/src/transaction.xml
index 6200a9a0ad5..64a8e86ecc6 100644
--- a/spring-framework-reference/src/transaction.xml
+++ b/spring-framework-reference/src/transaction.xml
@@ -149,7 +149,7 @@
defined by the
org.springframework.transaction.PlatformTransactionManager
interface, shown below:
-
- We must define a JDBC DataSource, and
then use the Spring DataSourceTransactionManager, giving
it a reference to the DataSource.
-
+
@@ -254,7 +254,7 @@
]]>The related PlatformTransactionManager bean
definition will look like this:
-
+ ]]>If we use JTA in a J2EE container, as in the 'dataAccessContext-jta.xml'
@@ -263,7 +263,7 @@
The JtaTransactionManager doesn't need to know about the
DataSource, or any other specific resources, as
it will use the container's global transaction management infrastructure.
-
+
+
@@ -320,7 +320,7 @@ xsi:schemaLocation="
]]>With Hibernate and JTA transactions, we can simply use the
JtaTransactionManager as with JDBC or any other resource strategy.
- ]]>
+ ]]>Note that this is identical to JTA configuration for any resource,
as these are global transactions, which can enlist any transactional
resource.
@@ -377,7 +377,7 @@ xsi:schemaLocation="
DataSource, you would instead use Spring's
org.springframework.jdbc.datasource.DataSourceUtils
class as follows:
-
+ If an existing transaction exists, and already has a connection
synchronized (linked) to it, that instance will be returned. Otherwise,
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 Foo and
Bar tropes means that you can concentrate on the transaction
usage and not have to worry about the domain model.)
- // the service interface that we want to make transactional// the service interface that we want to make transactional
- // an implementation of the above interface// an implementation of the above interfaceupdateFoo(Foo)) have to execute in the context of a transaction
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.
- <!-- from the file 'context.xml' --><!-- from the file 'context.xml' -->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
any operation in your service layer. For example:
-
+
]]>
@@ -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.
- insertFoo(..) method of the
DefaultFooService class have been truncated in
the interest of clarity.)
- <!-- the Spring container is starting up... --><!-- the Spring container is starting up... --><!-- the DefaultFooService is actually proxied -->Exception type.
-
+ rollback-for="NoProductInStockException"
@@ -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
infrastructure to commit the attendant transaction even in the face of an unhandled
InstrumentNotFoundException.
-
+ no-rollback-for="InstrumentNotFoundException"
@@ -789,7 +789,7 @@ Exception in thread "main" java.lang.UnsupportedOperationException
strongest matching rule wins. So in the case of the following configuration,
any exception other than an InstrumentNotFoundException would result in the
attendant transaction being marked for rollback.
-
+
@@ -797,7 +797,7 @@ Exception in thread "main" java.lang.UnsupportedOperationException
The second way to indicate that a rollback is required is to do so
programmatically. 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:
- // some business logic...'Service' have the default transactional configuration, you would write
the following:
-
+ Find below an example of configuring two distinct beans with totally different
transactional settings.
-
+
-
- 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
- 'com.foo.BusinessService.handlePayment'.
-
+
Using @Transactional
@@ -1041,7 +1033,7 @@ Exception in thread "main" java.lang.UnsupportedOperationException
The ease-of-use afforded by the use of the @Transactional
annotation is best illustrated with an example, after which all of the details
will be explained. Consider the following class definition:
- // the service class that we want to make transactional// the service class that we want to make transactional@TransactionalWhen the above POJO is defined as a bean in a Spring IoC container, the bean
instance can be made transactional by adding merely one line of
XML configuration, like so:
- <!-- from the file 'context.xml' --><!-- from the file 'context.xml' -->updateFoo(Foo) method in the same class takes precedence
over the transactional settings defined at the class level.
- handlePayment(..)
method of the BusinessService class started a transaction, the name of the
- transaction would be:
-
+ transaction would be: com.foo.BusinessService.handlePayment.
@@ -1476,7 +1467,7 @@ public class DefaultFooService implements FooService {
Here is the code for a simple profiling aspect. The
ordering of advice is controlled via the Ordered
interface. For full details on advice ordering, see .
-
-
+ Finally, find below some example configuration for effecting the same
setup as above, but using the purely XML declarative approach.
-
+ and
respectively.
- // construct an appropriate transaction manager // construct an appropriate transaction manager // configure the AnnotationTransactionAspect to use it; this must be done before executing any transactional methodsTransactionCallback
to the execute(..) method exposed on the
TransactionTemplate.
- // single TransactionTemplate shared amongst all methods in this instanceIf there is no return value, use the convenient
TransactionCallbackWithoutResult class via an
anonymous class like so:
- TransactionCallbackWithoutResultTransactionCallbackWithoutResultCode within the callback can roll the transaction back by calling
the setRollbackOnly() method on the supplied
TransactionStatus object.
- TransactionTemplate.
- Find below an example of defining a TransactionTemplate with some custom
transactional settings, using Spring XML configuration. The 'sharedTransactionTemplate'
can then be injected into as many services as are required.
-
@@ -1811,7 +1802,7 @@ AnnotationTransactionAspect.aspectOf().setTransactionManager(txManager); ]]>TransactionDefinition and
TransactionStatus objects you can
initiate transactions, rollback and commit.
- // explicitly setting the transaction name is something that can only be done programmatically