Skip to main content

Posts

Showing posts from September, 2014

Spring 4 + Hibernate 4 / Java configuration / rest service example with gradle

In this post I'll explain the required work to create a rest API utilizing both spring and hibernate version 4, and the configuration will be using java configuration classes not XML.

I'll use gradle to build and for dependency management, it's way easier than maven and keeps you focused on the application, if you are not familiar with gradle and interested in it see my previous post about it.

The first part which is dependency management is covered in gradle post mentioned above.
I'll skip to explain each tier of the project and its configurations:


As you can see we have 4 tiers:

1) DAO tier / data tier
In this tier we configure the datasource and hibernate, I used HSQL in memory db it can be easily substituted with other db engine providing the right dependencies


The DaoConfig defines the data source, transaction manager, session factory and  hibernate properties

The most important part is the annotations :
1) @Configuration : to tell spring that this is a configurat…

Gradle : Next-gen build tool introduction

I've been recently reading about maven 3 and from a page to another I read a bit about gradle, and got interested in it, so I want to try it now and see how it feels and works in practice

so to get started you need to download gradle from here: http://www.gradle.org/downloads
then add the path to gradle bin directory to the PATH system variable and go to CMD/shell then run:

> gradle

if it worked and you got build successful let's move to setup our project structure.

a word about gradle first, is that it promises to keep the great conventions Maven provided but with the flexibility ANT  had since Maven can give you a hard time if you need to customize something.
it's a convention over configuration, yet flexible.

so back to the track, what I want to do in this project is to setup a full spring-mvc rest API server, with multiple tiers (projects) that contains DAOs, Business Entities, Services, and REST tier.

o---[ REST ] -- uses --> [Services] -- uses --> [DAOs] ---…

Using git hub with eclipse (EGit)

UPDATE: the first section talks about dealing with existing local repo
I added a new section to clone a repo from the scratch by EGit without using any external tool like Git Bash


Section 1 : Working with existing Repo

Today I'm going to try EGit to integrate a local and remote repository with eclipse

let's start by running eclipse > File > Import :









Then I added a Class called Tester to this project and committed it through git bash ( to test if eclipse will sync if I use git bash)




 Until then the project didn't look like it was connected with my local repository, I right-clicked the project in eclipse > Team > share project :




After I clicked finish the source control icons in eclipse appeared :

so eclipse connected well to the local repository without loosing any info as you can see 'Tester.java' is appearing as committed.
Now we will start using EGit, and to do that I added another class 'Tester2' and committed it:

Now the file is committed, le…

Java 8 top features - part 1

First to try the features we are going to use Eclipse Luna because it supports Java 8 out of the box.
So after you download lets open a new project and try some of the new features

1- Lambdas, Functional interfaces, method references
https://gist.github.com/blabadi/b38d4186efe80681b7ef



In this gist, we can see three different ways java 8 allows us to use the three features :

a) Lambdas :
Lambdas are a short way to write a function on this form:
(param1, param2,...) -> { /* function body */ }
there is no need for a return statement if the function body is one statement (i.e. no bracelet brackets are used) examples:
map(name -> name.length()) , can also be written as : map(name-> {return name.length();})
filter(x -> x.length() > 2)

b) Functional interfaces
In Java 8 a functional interface is defined as an interface with exactly one abstract method. [1]
Consumer<String> myPrint = (x) -> {
System.out.println(x);
System.out.println("---");
};
names.stream().f…

Git & Git hub 101

step by step on using git hub for first time

create an account on GitHub.com :

1- create a repository

2- create a new branch on the remote repository

if you don't have a read me file, you will not see the branches so click on README


a
b c
the new branch is to avoid messing the master branch (default branch) this is a good practice to create branches for every feature you work on then merge these branches to master after everything is tested on the branch itself to keep master working and clean.


3- install git bash (http://git-scm.com/downloads) on your machine and create a directory to host the remote repository locally


> mkdir newDir
> git clone repository_name /path/to/localrepo/
in my case it will be  > git clone git@github.com:blabadi/hello-world.git ./newDir
Info : to paste in git bash use ctrl + Insert

from the first try this command failed with me, because I haven't generated an SSH key
to fix that I had to verify my email address to git hub, they sent u an ema…