David's blog

JPA 2.0 to better support Java Generics with Typesafe Support and Criteria Selection

With JPA 1.0 the @SuppressWarnings annotation seemed common whenever using a Query object to return collections using generics.

	@SuppressWarnings("unchecked")
	public List<Brand> getBrands() {
    		Query query = entityManager.createQuery("select b from Brand b");
    		List<Brand> s = (List<Brand>)query.getResultList();
    		return s; 
	}

Apache Ivy as a Enterprise Dependency Management Solution

When looking at both Apache Ant and Maven build systems, Apache Ant greatly suffered in that comparison battle when it came to dependency management. Ant had no answer to Maven's dependency management tool. This is where Apache Ivy comes into play. Ivy is Ant's answer to Maven for dependency management. The Ant/Ivy combination is becoming more popular and even became a Spring Framework default tool.

Method Caching with Annoations using Implementation Logic as Key

In a previous post I created an annotation based caching system using AspectJ

http://www.davidreepmeyer.com/AnnotationBasedCaching

Data Access Layer Architecture using Spring and JPA

High Level Data Access Layer Java Architecture

The java application architecture for this Data layer will be based on the Domain Driven Design. Domain ojbects can be mapped to Database tables via annotations. These domain objects can be queried via JPA in the DAO layer and passed up through the service layer and passed to the presentation layer.

Multiple Datasources using JPA, Spring Webflow and JSF

Many cases there is a need for multiple databases to be utilized within a web stack. When the web stack chosen is Spring Webflow + JPA + JSF, the configuration should be modified to look like the following.

Spring Webflow configuration

The Spring flow executor, Spring flow registry, and Spring flow listeners are defined below. The Spring xml configuration files will need to have multiple listeners for the web flow executor object.

<!--
	Executes flows: the central entry point 
	into the Spring Web Flow system 
-->

Servlet filter with Spring injection

To use a standard java filter with Spring beans injected utilize Spring's DelegatingFilterProxy. Create a java class that implements Filter. Inject any spring beans that you require.

public class InitializeSessionContextFilter 
  implements javax.servlet.Filter {
 
  @Autowired
  @Qualifier("MyInfo")
  private MyInformation myInfo;
 
  private FilterConfig filterConfig = null;
  private static org.apache.log4j.Logger log = 
    Logger.getLogger(InitializeSessionContextFilter.class);
 
  public void init(FilterConfig filterConfig) 

Customizing CAS - Central Authentication Service

After downloading CAS server from Jasig you will need to set it up in your environment for customization. Note that CAS is a maven based project.

Once in the CAS server folder you can type the following maven command to build all of CAS

mvn package install

To generate eclipse projects from the pom.xml run the following maven command from within the CAS server folder

mvn eclipse:eclipse

This will generate .project and .classpath files for all projects.

Spring Scoping

Creating objects via spring can have different scopes. This can be beneficial if you have a service that you want to manage state within a session/request.

The document page for Scoping using Spring 3 (although this was introduced in Spring 2)
http://static.springsource.org/spring/docs/3.0.x/reference/html/beans.ht...

Scopes and Design Patterns

Retrieve Request or Session information anywhere in a Spring Web Application

Spring uses ThreadLocal to allow for retrieving current session/request information within a web application. In fact, Spring MVC, Spring Webflow and Spring Security all have their own ways to retrieve information via a context holder. Each one mirrors one another. Spring MVC simply contains session and request information while Webflow has that as well as the current webflow object. Spring Security has a security object where you can get the username and authorizations.

Because Spring MVC and Spring Webflow even use the same class name, I will include the Package names as well

Enumerations with functionality

Enums allow functionality added just as a regular class. This allows adding functionality specific of the enum and allows a much more structured and object oriented design.

public enum Direction {
	NORTH, SOUTH, 
	EAST,
	WEST;
 
	private static Map<Direction, String> map;
 
	public static Map<Direction, String> getDirection() {
		if (map != null)
			return map;
		map = new HashMap<Direction, String>();
		map.put(NORTH, "UP");
		map.put(SOUTH, "DOWN");
		map.put(WEST, "LEFT");
		map.put(EAST, "RIGHT");
		return map;
	}
}

Syndicate content