Donate : Link

WordPress Blog : Link

Applications… : Link

  • We use Pointcut class to apply condition.
  • To implement Pointcut we have 2 classes.
    - StaticMethodMatcherPointcut
    - NameMetchMethodPointcut
  • * We can add target in AOP using setTarget() method and service using setInterceptorNames() method. In case if we have Pointcut then it is not possible to add Service and Pointcut both in AOP. Then we need to add Service and Pointcut to Advisor and then add Advisor into an AOP. Advisor is combination of Pointcut and Advice.
  • We have 2 Advisor
    - DefaultPointcutAdvisor
    - RegexpMethodPointcutAdvisor
  • StaticMethodMatcherPointcut Example
  • Open Eclipse
  • Go to…


Donate : Link

WordPress Blog : Link

Applications… : Link

  • MethodBeforeAdvice, AfterReturningAdvice, MethodInterceptor example using XML
  • Open Eclipse
  • Go to File -> New -> Other… -> Java Project
  • Create AOP-Programmatic5 project
  • Right click on project -> Build Path -> Configure Build Path -> Libraries tab -> Add External JARs
    - aopalliance.jar
    - aspectjrt.jar
    - aspectjweaver.jar
    - cglib-nodep-X.X.jar
    - commons-logging-X.X.jar
    - spring-aop-X.X.X.jar
    - spring-beans-X.X.X.jar
    - spring-context-X.X.X.jar
    - spring-core-X.X.X.jar
    - aspectjlib-X.X.X.jar
    - spring-aspects-X.X.X.jar
  • * You can find dtd information from spring-beans-X.X.X.jar -> org -> springframework -> beans -> factory -> xml -> spring-beans.dtd (line no 36 & 37)

spring.xml

<!DOCTYPE beans PUBLIC…

Donate : Link

WordPress Blog : Link

Applications… : Link

  • ThrowsAdvice example using Programmatic approach.
  • ThrowsAdvice: Throws Advice it is executed if actual method throws exception.
  • Open Eclipse
  • Go to File -> New -> Other… -> Java Project
  • Create AOP-Programmatic4 project
  • Right click on project -> Build Path -> Configure Build Path -> Libraries tab -> Add External JARs
    - aopalliance.jar
    - aspectjrt.jar
    - aspectjweaver.jar
    - cglib-nodep-X.X.jar
    - commons-logging-X.X.jar
    - spring-aop-X.X.X.jar
    - spring-beans-X.X.X.jar
    - spring-context-X.X.X.jar
    - spring-core-X.X.X.jar
    - aspectjlib-X.X.X.jar
    - spring-aspects-X.X.X.jar
  • * You can find dtd information from spring-beans-X.X.X.jar -> org -> springframework -> beans -> factory -> xml ->…

Donate : Link

WordPress Blog : Link

Applications… : Link

  • MethodInterceptor example using Programmatic approach.
  • MethodInterceptor: Around Advice it is executed before and after the actual method call.
  • Open Eclipse
  • Go to File -> New -> Other… -> Java Project
  • Create AOP-Programmatic3 project
  • Right click on project -> Build Path -> Configure Build Path -> Libraries tab -> Add External JARs
    - aopalliance.jar
    - aspectjrt.jar
    - aspectjweaver.jar
    - cglib-nodep-X.X.jar
    - commons-logging-X.X.jar
    - spring-aop-X.X.X.jar
    - spring-beans-X.X.X.jar
    - spring-context-X.X.X.jar
    - spring-core-X.X.X.jar
    - aspectjlib-X.X.X.jar
    - spring-aspects-X.X.X.jar
  • * You can find dtd information from spring-beans-X.X.X.jar -> org -> springframework -> beans -> factory ->…

Donate : Link

WordPress Blog : Link

Applications… : Link

  • AfterReturningAdvice example using Programmatic approach
  • AfterReturningAdvice: After Advice it is executed after the actual method call. If method returns a value, it is executed after returning value.
  • Open Eclipse
  • Go to File -> New -> Other… -> Java Project
  • Create AOP-Programmatic2 project
  • Right click on project -> Build Path -> Configure Build Path -> Libraries tab -> Add External JARs
    - aopalliance.jar
    - aspectjrt.jar
    - aspectjweaver.jar
    - cglib-nodep-X.X.jar
    - commons-logging-X.X.jar
    - spring-aop-X.X.X.jar
    - spring-beans-X.X.X.jar
    - spring-context-X.X.X.jar
    - spring-core-X.X.X.jar
    - aspectjlib-X.X.X.jar
    - spring-aspects-X.X.X.jar
  • * You can find dtd information from spring-beans-X.X.X.jar…

Donate : Link

WordPress Blog : Link

Applications… : Link

  • MethodBeforeAdvice example using Programmatic approach
  • MethodBeforeAdvice: Before Advice it is executed before the actual method call.
  • Open Eclipse
  • Go to File -> New -> Other… -> Java Project
  • Create AOP-Programmatic1 project
  • Right click on project -> Build Path -> Configure Build Path -> Libraries tab -> Add External JARs
    - aopalliance.jar
    - aspectjrt.jar
    - aspectjweaver.jar
    - cglib-nodep-X.X.jar
    - commons-logging-X.X.jar
    - spring-aop-X.X.X.jar
    - spring-beans-X.X.X.jar
    - spring-context-X.X.X.jar
    - spring-core-X.X.X.jar
    - aspectjlib-X.X.X.jar
    - spring-aspects-X.X.X.jar
  • * You can find dtd information from spring-beans-X.X.X.jar -> org -> springframework -> beans -> factory -> xml ->…

Donate : Link

WordPress Blog : Link

Applications… : Link

  • * AOP means Aspect Oriented Programming. The main aim of AOP is maintain independent business layer and service layer, seperate services from business.
    - Aspect = A service.
    - Advice = Service provider.
    - Point cut = A point/condition to execute aspects for business methods.
    - Advisor = Point cut with advice combination. Point cut + Advice
    - Proxy = A weaver. It will combine services code along with your business code.
  • * To add services to business, AOP we have 3 approaches. …

Donate : Link

WordPress Blog : Link

Applications… : Link

  • * Below are the implementations provider and implementations for connection pool.
    - Sun -> DataSource ( I )
    - Apache -> BasicDataSource ( C )
    - Mchange c3p0 -> ComboPooledDataSource ( C )
    - Spring -> DriverManagerDataSource ( C )
    - WebLogic -> WebLogic Data Source
  • For small enterprice application if you want to use connection pool then ComboPooledDataSource and BasicDataSource is recommended.

BasicDataSourceTest.java

package com.codeFactory;import java.sql.Connection;
import java.util.Date;
import org.apache.tomcat.dbcp.dbcp.BasicDataSource;/**
* @author code.factory
*
*/
public class BasicDataSourceTest {
public static void main(String[] args) {
Date date1…

Donate : Link

WordPress Blog : Link

Applications… : Link

Difference between JDBC and Spring JDBC

JDBC

  • All the exceptions are compiletime exception (CE)
  • CE is java.sql.SQLException (It will print database exceptions).
  • User must need to close connection.
  • Jdbc PreparedStatement is type safe.
  • For select operation always it will return ResultSet.

Spring JDBC

  • All the exceptions are runtime exception (RE).
  • RE is DataAccessException (It will print database exceptions). It is in spring-dao.jar file.
  • User no need to close connection.
  • All JdbcTemplate methods are type safe using Types class.
  • Generic select methods for all type of select operations.

Donate : Link

WordPress Blog : Link

Applications… : Link

  • DAO — Data Access Object it will do data persistence operations. It will interact RDBMS machines, interact with XML files, interact with LDAP machines, interact with NoSQL machines.
  • The main aim of DAO is data access operation.
  • * In DAO we use Interface implementation pattern. So in future if we want to change DB then it is easy to do.
  • * Below are the implementations provider and implementations for connection pool.
    - Sun -> DataSource ( I )
    - Apache -> BasicDataSource ( C )
    - Mchange c3p0 -> ComboPooledDataSource ( C )

Code Factory

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store