This class is the main interaction point with the persistence
framework. Its main responsiblity is managing the connections used
for executing the SQL statements to map the enities to the
relational database and coordinating the UnitOfWork implementation.
Essentially, the JaxorSession can be used as a "smarter" UnitOfWork
implementation everwhere you would normally employ the UnitOfWork
design pattern as described in Fowler2003. For example, in a
servlet's doGet method, you could use:
final protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// we specify a transaction-aware implementation of UnitOfWork
// since the default version does not manage JDBC transactions
JaxorSession.begin(new TransUnitOfWork());
handleGet(request, response);
JaxorSession.flush();
}
The above example assumes that whatever connection retrieval
mechanism was previously configured in the servlet's init method
using the setDefaultConnectionFactory method.
Alternatively, for a command-line utility you would generally use
the following sequence of API calls:
public static void main(String[] args) {
JaxorSession.begin(new TransUnitOfWork(), new ConnectionFactoryImpl());
handleCommands(args);
JaxorSession.flush();
}
For a Java Swing client that uses Jaxor, the begin and
flush calls would be specified in each of the Action
implementations.
See Also: JaxorSession.begin() See Also: JaxorSession.commit() See Also: JaxorSession.setDefaultFactory |