Friday, March 14, 2008

Spring Framework

Question:
I remember watching a presentation from Rod Johnson about two years ago ... this one looks very (too) similar. I think that the Java world owes a lot to Spring, they brought a lot of common sense back when things where going crazy with EJB 1/2.

However, EJB 3 took a lot of those lessons from Spring (dependency injection, simplicity, etc). Is Spring a victim of its own success? Will it keep growing as EJB 3 gets more open source app servers?

Answer:

Spring is an integration framework. While EJB3 is not.
Transaction demarcation in Spring is done much better.
With Spring you can work same way with JDO,Toplink,Hibernate,Plain JDBC. With EJB3 you provides only very restricted subset of Hibernate featues (e.g. no Criteria API at all).
Spring provides AOP out of the box. EJB3 guys usually don't even know what it means.
Spring provides ACEGI for Security while EJB3 has only JAAS.
Have a look at Spring remoting and compare it to EJB3.
And the last Spring provides IoC while EJB3 only uses IoC.

Now tell is Spring a victim or a winner ;-)
_________________________________
Inroduction to SpringFramework - dated May 2006Yet another framework?You may be thinking "not another framework." Why should you read this article, or download the Spring Framework (if you haven't already), when there are so many J2EE frameworks, or when you could build your own framework? The sustained high level of interest in the community is one indication that Spring must offer something valuable; there are also numerous technical reasons.

I believe that Spring is unique, for several reasons:

It addresses important areas that many other popular frameworks don't. Spring focuses around providing a way to manage your business objects.
Spring is both comprehensive and modular. Spring has a layered architecture, meaning that you can choose to use just about any part of it in isolation, yet its architecture is internally consistent. So you get maximum value from your learning curve. You might choose to use Spring only to simplify use of JDBC, for example, or you might choose to use Spring to manage all your business objects. And it's easy to introduce Spring incrementally into existing projects.
Spring is designed from the ground up to help you write code that's easy to test. Spring is an ideal framework for test driven projects.
Spring is an increasingly important integration technology, its role recognized by several large vendors.

______________________________________________

The Spring Framework - Reference Documentation

Using the JDBC Core classes to control basic JDBC processing and error handling
11.2.1. JdbcTemplateThe JdbcTemplate class is the central class in the JDBC core package. It simplifies the use of JDBC since it handles the creation and release of resources. This helps to avoid common errors such as forgetting to always close the connection. It executes the core JDBC workflow like statement creation and execution, leaving application code to provide SQL and extract results. This class executes SQL queries, update statements or stored procedure calls, imitating iteration over ResultSets and extraction of returned parameter values. It also catches JDBC exceptions and translates them to the generic, more informative, exception hierarchy defined in the org.springframework.dao package.

11.2.1.1. Examples
Find below some examples of using the JdbcTemplate class. (These examples are not an exhaustive list of all of the functionality exposed by the JdbcTemplate; see the attendant Javadocs for that).

11.2.1.1.1. Querying (SELECT)
A simple query for getting the number of rows in a relation.
int rowCount = this.jdbcTemplate.queryForInt("select count(0) from t_accrual");
A simple query using a bind variable.
int countOfActorsNamedJoe
= this.jdbcTemplate.queryForInt("select count(0) from t_actors where first_name = ?", new Object[]{"Joe"});


11.4. Modeling JDBC operations as Java objects
private class CustomerMappingQuery extends MappingSqlQuery {

public CustomerMappingQuery(DataSource ds) {
super(ds, "SELECT id, name FROM customer WHERE id = ?");
super.declareParameter(new SqlParameter("id", Types.INTEGER));
compile();
}

public Object mapRow(ResultSet rs, int rowNumber) throws SQLException {
Customer cust = new Customer();
cust.setId((Integer) rs.getObject("id"));
cust.setName(rs.getString("name"));
return cust;
}
}

public Customer getCustomer(Integer id) {
CustomerMappingQuery custQry = new CustomerMappingQuery(dataSource);
Object[] parms = new Object[1];
parms[0] = id;
List customers = custQry.execute(parms);
if (customers.size() > 0) {
return (Customer) customers.get(0);
}
else {
return null;
}
}

Chapter 12. Object Relational Mapping (ORM) data access
The Spring Framework provides integration with Hibernate, JDO, Oracle TopLink, iBATIS SQL Maps and JPA: in terms of resource management, DAO implementation support, and transaction strategies. For example for Hibernate, there is first-class support with lots of IoC convenience features, addressing many typical Hibernate integration issues

______________________________________________________________________________
Spring 2.0: What's New and Why it Matters - Posted by Rod Johnson on Jan 15, 2007

Most important, it has developed a large and loyal user base, which understands its key values and has contributed feedback that has helped it to advance rapidly. Spring's mission always been clear:

- To provide a non-invasive programming model. As far as possible, application code should be decoupled from the framework.
- To provide a superior solution to in-house infrastructure, so that developers can focus on delivering business value rather than solving generic problems.
- To make developing enterprise applications as simple as possible, but enhancing, rather than sacrificing, power

As work on Spring 2.0 progressed through 10 months of development, we also needed to take into account several trends that became evident in Spring usage in 2005-2006:

An increasing number of prominent third party software products are using Spring internally, and need the optimum in configurability and flexibility from the container. Examples here are many. To choose just a few:
The upcoming BEA WebLogic Server 10, which uses Spring and the Pitchfork Project to perform injection and interception.
BEA WebLogic Real Time (WLRT)-a high-end product from BEA targeted at applications such as front office trading, requiring low latency.
Numerous widely used open source products such as Mule, ServiceMix and the Apache JetSpeed portal container.
Enterprise vendors integrating their products with Spring such as GigaSpaces, Terracotta and Tangosol. Vendors in the grid space, in particular, are increasingly embracing Spring as the programming model of choice.
Oracle's SCA implementation and various other Oracle products.

________________________________________________
spring frame work
A Primer on Spring's Data Access Object (DAO) Framework - by Dhrubojyoti Kayal - 11/29/2006

The business components in J2EE applications typically use the JDBC API to access and change persistent data in relational databases. This often leads to the mixing of persistence code with business logic—a bad idea. The Data Access Object (DAO) design pattern addresses this problem by separating the persistence logic into data access classes.

This article is a primer on DAO design pattern, highlighting its merits and demerits. It then introduces the Spring 2.0 JDBC/DAO framework and demonstrates how it elegantly addresses the drawbacks in traditional DAO design.

Spring books
Spring in Action - 2 nd edition seems good book with Spring 2.0






___________________________________________________

No comments: