Answer-
Spring does following things:
Opens connection
Prepare and execute statement.
Iterate the results
Process exception if any
Handle transaction
Close connection
Answer-
Following template is provided.
JdbcTemplate
NamedParameterJdbcTemplate
SimpleJdbcTemplate
Answer-
Write @Repository at class level. Entity manager can be configured by @PersistenceContext at property level.
Answer-
For using servlet container configured JNDI DataSource, we need to configure it in the spring bean configuration file and then inject it to spring beans as dependencies. Then we can use it with JdbcTemplate to perform database operations.
Sample configuration would be:
<beans:bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<beans:property name="jndiName" value="java:comp/env/jdbc/MyLocalDB"/>
</beans:bean>
Answer-
Spring DAO support is provided to work with data access technologies like JDBC, Hibernate in a consistent and easy way. For example we have JdbcDaoSupport, HibernateDaoSupport, JdoDaoSupport and JpaDaoSupport for respective technologies.
Spring DAO also provides consistency in exception hierarchy and we don’t need to catch specific exceptions.
Answer-
Spring Framework is using a lot of design patterns, some of the common ones are:
Singleton Pattern : Creating beans with default scope.
Factory Pattern : Bean Factory classes
Prototype Pattern : Bean scopes
Adapter Pattern : Spring Web and Spring MVC
Proxy Pattern : Spring Aspect Oriented Programming support
Template Method Pattern : JdbcTemplate, HibernateTemplate etc
Front Controller : Spring MVC DispatcherServlet
Data Access Object : Spring DAO support
Dependency Injection and Aspect Oriented Programming