Search This Blog

Sunday 30 June 2013

ExceptionUtils

One of the most commonly used features in Java is Exceptions. I have always used it- throwing, catching and sometimes crashing code with them. I recently had a requirement where I needed to convert a stack trace to a String.

Friday 28 June 2013

Result Transformers

In the previous post we saw the need for ResultTransformer, how using the value of Criteria.DISTINCT_ROOT_ENTITY filters duplicate records.

Monday 24 June 2013

Inheritance in xsd

In the last post we were able to map elements which included attributes. An alternative way of representing elements is to nest them. Consider the below schema definition:

Wednesday 19 June 2013

Why the need for ResultTransformers ?

Consider the below criteria example which simply loads the Entity records from the database with ids less than 6.

Monday 17 June 2013

JPA's GenerationType.TABLE

In the previous posts we saw the identifier generation strategies supported by JPA and their equivalent ones in Hibernate. There is however one in JPA - The TABLE GenerationType that is not there in Hibernate API. I decided to look at the same.

Saturday 15 June 2013

Using Spring's RestTemplate class

In an earlier post we saw how to work create REST services using Spring. For testing the same we used a RESTClient Plugin available with Firefox.
It is often the case that we need our test code to be in Java so that it can be reused by others too. Spring provides us with an easy to use Rest Service client that can be used in our code.

Monday 10 June 2013

@GeneratedValue

In our previous posts we saw how the GeneratedValue annotation was used to specify the identifier generator strategy. I decided to look at the various options available in detail

Thursday 6 June 2013

Interceptors and Logging

The CXF architecture provides us with interceptors – or the ability to intercept outgoing request and responses. One useful scenario could be logging. CXF in this case has stayed one step ahead and already built custom Log Interceptors.

Tuesday 4 June 2013

A LIFO Queue - like a Stack

The last of the queues is a LIFO queue. This queue behaves like a stack. It follows LIFO ordering.
public static void main(final String[] args) {

      final Deque<Integer> deQ = new ArrayDeque<Integer>();
      final Queue<Integer> asLifoQ = Collections.asLifoQueue(deQ);
      asLifoQ.offer(4);
      asLifoQ.offer(5);
      asLifoQ.offer(6);
      System.out.println("LifoQueue Contents : " + asLifoQ);
      // should behave like a stack
      System.out.println(asLifoQ.poll());
      System.out.println(asLifoQ.poll());
      System.out.println(asLifoQ.poll());
   }
There is no direct way to create the same. We need to use the asLifoQueue method of Collections class to create a LIFO queue. Further this method requires an instance of Deque to be available . It will not work with any queue. The output is :
LifoQueue Contents : [6, 5, 4]
6
5
4
Be sure to pass and empty Deque as the parameter. Any elements already present in the deque are not treated in the LIFO order.

Sunday 2 June 2013

Queues in Java

I first came across queues in Engineering. The very first chapter in data structures involved stacks and queues. So when I needed to implement one in my java project, I started recollecting the queue's working, recalling important points.I decided to build a generic structure and spend half a day coming up with a Queue interface based in generics. For good practice I decide to check the web and that is when it bombed.