Saturday, April 17, 2010

WebServices with CXF - My Pojos & DAOs

First thing, is a good practice declaring methods equals and hashCode
You know what, I'll skip these methods on my code, eclipse can do it for you, don't be lazy!!!
And one more thing, as Architect it's a must declaring toString method, because when you're debugging these method it's going to be really helpful, and you know what... declare toString it's a must too.
The next step is explain what are those annotations, well they're Java 6 annotations, so we can skip some configurations and declare them into our code. I'll try to explain as simple as possible these annotations, let's analyze them:
What I'm doing here is just declaring that this POJO will be an Entity which maps to a table called EDITOR

Using Annotations, I declared that editorId is my PK which basically is AutoIncremental and to which column will be mapped. With columns is really easy.
But what about relations??? Like
BOOK >-- EDITOR
In this case I just declared what I needed to declare: One Editor has Many books using a List of Book, like in every mapping of Hibernate: the most common fetching strategy to be used will be LAZY; basically what I did was linking the current ENTITY by it's PK (mappedBy="editor") to Book
So in Book this is what we have to do (the inverse to OneToMany and define an Editor for each Book, so each child will have a reference to it's Dad):

The last thing is just declare which column & attribute will be used to do the JOIN between child and father


You can get more details if you look for that topic in Hibernate official documentation.
And these are my DAO's (I just included 1 as example), others should be similar. Always code oriented to interfaces! Later you'll thank me. In my next entry I will explain my Services and we'll be ready for using CXF.

Saturday, April 10, 2010

James Gosling leaves Oracle

It's sad, but James Gosling leaves Oracle.
I'm really curious about his next job...
An excerpt from his bio: "...He briefly worked for Oracle after the acquisition of Sun. He is now blissfully unemployed :-)..."

Saturday, April 3, 2010

WebServices with CXF - Preparing Worskpace - POM

I'm going to use the perfect combination: Spring + Spring MVC + Hibernate + more fancy stuff The first step is creating my pom.xml, and there you go:

If you read carefully my POM, you'd found something interesting. Or maybe not. Whatever!

  • I grouped my Spring & Hibernate dependencies other external pom.xml, I know, I already explained that concept before
  • What's going on with that plug-in if we already have the database built? Interesting question, but "In the beginning there was nothing. Then JuCa said: I just want to write Code, and I'm almost done with my POJO's". Then based on my pojo's I could create the tables and it's relations-referential integrity and some indexes :D

How could I achieve that? So simple. Let's code our Pojos and then I'll explain this: Based on our DDL's let's code!!!

WebServices with CXF - Our Database

Too many times I tried to look for some good examples for my padawans, but as always, incomplete stuff or not really clear. Anyway, that's why I'm going to develop a small app using a bunch of useful things, and one of these it's going to be Apache CXF The first and most important step is what kind of problem I'm going to solve using the app? Well, let's create a scenario: I have a small Database on MySQL 5.1.37. this is my schema: mysql> desc author; mysql> desc author_book; mysql> desc book; mysql> desc editor;

As you noticed the relations are like this:

AUTHOR --< AUTHOR_BOOK >-- BOOK >-- EDITOR