Java Aspect-Oriented Programming with Annotations

Let’s imagine you want to log the time taken by some annoted methods using a @LogExecTime annotation. I first create an annotation LogExecTime: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface LogExecTime { } Then I define an aspect: @Component // For Spring AOP @Aspect public class LogTimeAspect { @Around(value = “@annotation(annotation)”) public Object LogExecutionTime(final ProceedingJoinPoint joinPoint, final LogExecTime … Read more

Getting UndeclaredThrowableException instead of my own exception

AccessException is a checked exception, but it was thrown from the method that doesn’t declare it in its throws clause (actually – from the aspect intercepting that method). It’s an abnormal condition in Java, so your exception is wrapped with UndeclaredThrowableException, which is unchecked. To get your exception as is, you can either declare it … Read more

What is the best implementation for AOP in .Net? [closed]

I think that Castle Dynamic Proxy is the solution of choice if dynamic interception can handle your needs. This framework is used internally by a lot of other frameworks that want to offer AOP capabilities. Typically, most of existing IoC containers now provide some dynamic interception mechanisms (Spring.NET, Castle Windsor, StructureMap, etc.) If you already … Read more

NOT using repository pattern, use the ORM as is (EF)

I’ve gone down many paths and created many implementations of repositories on different projects and… I’ve thrown the towel in and given up on it, here’s why. Coding for the exception Do you code for the 1% chance your database is going to change from one technology to another? If you’re thinking about your business’s … Read more

Spring AOP: What’s the difference between JoinPoint and PointCut?

Joinpoint: A joinpoint is a candidate point in the Program Execution of the application where an aspect can be plugged in. This point could be a method being called, an exception being thrown, or even a field being modified. These are the points where your aspect’s code can be inserted into the normal flow of … Read more

@AspectJ pointcut for all methods of a class with specific annotation

You should combine a type pointcut with a method pointcut. These pointcuts will do the work to find all public methods inside a class marked with an @Monitor annotation: @Pointcut(“within(@org.rejeev.Monitor *)”) public void beanAnnotatedWithMonitor() {} @Pointcut(“execution(public * *(..))”) public void publicMethod() {} @Pointcut(“publicMethod() && beanAnnotatedWithMonitor()”) public void publicMethodInsideAClassMarkedWithAtMonitor() {} Advice the last pointcut that combines … Read more

Cross cutting concern example

Before understanding the Crosscutting Concern, we have to understand the Concern. A Concern is a term that refers to a part of the system divided on the basis of the functionality. There are two types of concerns: The concerns representing single and specific functionality for primary requirements are known as core concerns. OR Primary functionality … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)