Spring Data – Book Review

Posted: January 7, 2013 in Uncategorized

Spring Data is a Spring sub project trying to simplify the implementation of data access layer in Spring applications. The Spring Data JPA sub module simplifies the implementation of a generic CRUD repository. It provides a generic interface which is then implemented using proxies. It eliminates the repetitive boiler plate code required for performing CRUD operations. Other sub modules simplify the implementation of noSQL data stores like redis or mongo.

There is a comprehensive reference documentation for Spring Data but for people who are new to spring or not very experienced with spring it can be a bit difficult. The book Spring Data from Packt Publishing can be a good start in programming of the data access layer using the Spring Data. The book focuses on the JPA and redis sub projects.

The first chapters introduce the concepts of Spring Data and Spring Redis. There are also covered the advantages of using frameworks like JPA or Redis. They explain how to setup a basic web application to use the Spring Data framework. The second chapter gives the reader receipes how to setup the project using the programmatic configuration, the techniques of how to configurea web application and explains the design patterns like the builder to build a new object. The chapter contrasts the traditional way of how to implement the data access layer with the advantages offered by Spring Data. The chapter shows the boiler plate code required to implement the data access using the traditional way and how that can be abstracted by implementing of a generic repository. This shows how Spring Data is able to generate the complete implementation using only an interface.

The next chapter explores several strategies available to build queries with Spring Data and explains the advantages and disadvantages of each option. It covers all the main approaches for building static and dynamic queries:

  • JPA Criteria API
  • convention based method name
  • named query
  • query annotation
  • Query DSL

There is also a complete example application that is built from ground up. For each strategy there are samples for queries using JPQL and Standard SQL providing the reader a good hold on how to use this for building a real application. This chapter includes also sections on sorting and pagination.

The fourth chapter explains how to refactor the application by adding custom functionality to the repository to keep the architecture of the application clean.

The last chapters explain the design principles of a Redis data model and the key components of Spring Data Redis – template and serializers. They discuss how the CRUD application can be implemented using this sub module end explain and different storage approaches, e.g. using JSON with a string serializer to store objects as strings in JSON format. The sample contact applications is now implemented using the Redis framework. The last chapter explains also how can we use Spring Data Redis to implement the publish/subscribe messaging pattern and how it can be used as an implementation of the cache abstraction provided by Spring Framework 3.1.

This is a very simple book with simple examples. The samples are built form scratch and all the steps are clearly explained in form of tutorial (step by step). I’ve never been using Spring Data before. I was provided a copy of this book to make this review and it took me a few hours to read and understand the basic concepts of Spring Data. This book is compact and gives the basic knowledge of Spring Data. This book can be used as a quick start into this technology. The big advantage of this book are links to resources with more detailed informations about each discussed topic. This can be especially very useful for Spring beginners.

Posted: July 17, 2012 in Uncategorized

David Valeri's Blog

While testing and security are often the last to get invited to the party, they are integral parts of well written software.  Two new features in Camel 2.10 help to ease debugging of TLS related security issues and to provide full support for writing unit tests of Camel routes in Spring Test.  While these two new features aren’t likely to make TLS configuration and unit testing the king and queen of prom, they will make you a more productive Camel rider.

View original post 873 more words

New address for my blog

Posted: June 17, 2011 in Uncategorized

Hi. I have moved my blog on my private server. Please see my Software Development & Integration Site.

It is possible that Oracle 11gR1 goes crazy with 100% CPU loading when working with Debian sid (see here). Perform following steps to solve this problem:

  • Login as oracle and shut down the OEM
    $ sudo su - oracle
    $ emctl stop dbconsole
  • Login as SYSMAN:
    $ sqlplus SYSMAN
  • Then execute the following PL/SQL commands:
    SQL> exit
  • Restart the OEM
    $ emctl start dbconsole

Check the CPU loading and it should be fine now

Check your hardware setup

First of all, you need to have AT LEAST 1GB of physical memory. Check it with:

$ grep MemTotal /proc/meminfo

On the other hand, it is suggest to have swap with 1.5 time of your physical memory, e.g. around 2GB. Check it with:

$ grep SwapTotal /proc/meminfo

Shared memory is very important, too. Or else you may face the ORA-00845 error message. First check it with:

$ df -kh /dev/shm/

If you have less than 512MB (I will suggest for 1GB), edit your /etc/fstab and add/modify the following line:

tmpfs           /dev/shm        tmpfs   defaults,size=1024M    0       0

Then remount it and check the size once again:

$ mount -o remount /dev/shm
$ df -kh /dev/shm/
Prepare network connection

Oracle 11g is highly depend on a correct network connection setup, especially the hostname and domain must be a valid value. On the other hand, I will suggest bind your Debian as localhost only, so you will even able to migrate the installation to other IP without reconfigure the Oracle installation. Configure your /etc/hostname as below. Be careful that you MUST have a valid domain name (e.g. localdomain):


Also make sure your /etc/hosts have this line:       localhost.localdomain           localhost
Installing Pre-requisite Packages

Install these software packages on your Ubuntu 10.04 system:

$ sudo apt-get install gcc make binutils gawk x11-utils rpm alien ksh lsb-rpm unzip build-essential libaio1 lesstif2 libmotif3

Ubuntu 10.04 comes with libstdc++6 installed. However, Oracle 11gR2 requires libstdc++5. If you do not install libstdc++5, you will see errors as described in this OTN thread. The fix, as described in that thread, is to download and manually shoehorn the libstdc++5 library files onto Ubuntu 10.04:

$ cd /tmp
$ wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-3.3/libstdc++5_3.3.6-17ubuntu1_i386.deb
$ dpkg-deb -x libstdc++5_3.3.6-17ubuntu1_i386.deb i386-libs
$ sudo cp i386-libs/usr/lib/libstdc++.so.5.0.7 /usr/lib/
$ cd /usr/lib
$ sudo ln -s libstdc++.so.5.0.7 libstdc++.so.5

Now we’re ready to move on.

Create User and Groups

Check your existing setup with:

$ sudo grep oinstall /etc/group
$ sudo grep dba /etc/group
$ sudo grep nobody /etc/group
$ sudo id oracle
$ sudo id nobody

Most likely, you should run the following command for create the required system groups and users. Latest Debian sid already come with user nobody so we don’t need to retouch it:

$ sudo addgroup --system oinstall
$ sudo addgroup --system dba
$ sudo useradd -r -g oinstall -G dba -m -s /bin/bash -d  /home/oracle oracle
Fake Oracle installer

Debian/Ubuntu is not listed as Oracle officially support platform and so we need to fake it. Create some symbolic links to give the Ubuntu system a more Red Hat-ish layout

$ sudo ln -s /usr/bin/awk /bin/awk
$ sudo ln -s /usr/bin/rpm /bin/rpm
$ sudo ln -s /usr/bin/basename /bin/basename
$ sudo mkdir /etc/rc.d
$ for i in 0 1 2 3 4 5 6 S ; do sudo ln -s /etc/rc$i.d /etc/rc.d/rc$i.d ; done

Also mask ourself as RedHat

$ sudo echo 'Red Hat Linux release 4' > /etc/redhat-release

make sure Bash is your default replacement for sh:

$ cd /bin
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 2008-11-02 21:33 /bin/sh -> dash
$ sudo ln -sf /bin/bash /bin/sh
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 2008-11-02 22:34 /bin/sh -> bash
Configure kernel parameters

Check your existing setup with:

$ sysctl -a | grep sem
$ sysctl -a | grep shm
$ sysctl -a | grep file-max
$ sysctl -a | grep ip_local_port_range

Then edit /etc/sysctl.d/oracle.conf and add the following lines

fs.file-max = 6815744
fs.aio-max-nr = 1048576
kernel.shmall = 2097152
kernel.shmmax = 2147483648
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 1048576
net.core.wmem_max = 1048576
net.ipv4.ip_local_port_range = 9000 65500

Note that these values are different from what was needed in 11gR1.

Make sure that the value of net.ipv6.bindv6only is set to 0. Whith this parameter set to 1, all networks operations of Java virtual machine failed. Also don’t work JDownloader, Azureus, etc.

Run the following command to reload these kernel parameters:

$ sudo sysctl -p

Add the following to /etc/security/limits.conf as below:

oracle          soft    nproc           2047
oracle          hard    nproc           16384
oracle          soft    nofile          1024
oracle          hard    nofile          65536

Check (or add) if the following line exits within /etc/pam.d/login:

session    required     /lib/security/pam_limits.so

Check (or add) if the following line exits within /etc/pam.d/su:

session    required   pam_limits.so
Create required directories

Create required directory and change permission:

$ sudo mkdir -p /opt/ora/app/oracle
$ sudo mkdir -p /opt/ora/oradata
$ sudo chown -R oracle:oinstall /opt/ora/
$ sudo chmod -R 775 /opt/ora/
Configuring the oracle user’s environment

Add following content to ~oracle/.profile

umask 022
export ORACLE_BASE=/opt/ora/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=orcl
export NLS_LANG=.AL32UTF8
if [ -d "$ORACLE_HOME/bin" ]; then
    export PATH="$ORACLE_HOME/bin:$PATH"

if [ -d "$ORACLE_HOME/lib" ]; then
Last step before installation start

First of all, login with your new oracle user, with X enabled (if you are using PuTTY + Xming, for sure that the X11 forward is enabled.)

$ xhost +
$ sudo su - oracle

Copy the installation files to oracle’s home directory, then unzip them:

$ cp linux_11gR2_database_*.zip ~oracle
$ unzip linux_11gR2_database_1of2.zip
$ unzip linux_11gR2_database_2of2.zip
Install Oracle

Now you simply cd into the database directory and run the runInstaller program:

$ cd database
$ ./runInstaller

This will launch the Oracle Universal Installer, or OUI, program. The rest is pretty straight forward.

Now you can access the EM page with https://localhost.localdomain:1158/em

Autostart Oracle during system boot

There is almost for sure that you will hope to start your Oracle automatically during system boot. Even you may turn this feature off, but the init.d script is very useful, too. First of all, specify which database instant will be started together with Oracle. Edit /etc/oratab as below:


Next, create init.d script as /etc/init.d/oracle:

# Run-level Startup script for the Oracle Instance and Listener
# chkconfig: 345 91 19
# description: Startup/Shutdown Oracle listener and instance

export ORACLE_BASE=/opt/ora/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORA_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORA_OWNR=oracle

# if the executables do not exist -- display error

if [ ! -f $ORA_HOME/bin/dbstart -o ! -d $ORA_HOME ]
        echo "Oracle startup: cannot start"

        exit 1

# depending on parameter -- startup, shutdown, restart
# of the instance and listener or usage display

case "$1" in
        # Oracle listener and instance startup
        echo -n "Starting Oracle: "
        su - $ORA_OWNR -c "$ORA_HOME/bin/dbstart $ORA_HOME"
        su - $ORA_OWNR -c "$ORA_HOME/bin/lsnrctl start"

        #Optional : for Enterprise Manager software only
        su - $ORA_OWNR -c "$ORA_HOME/bin/emctl start dbconsole"

        touch /var/lock/oracle
        echo "OK"
        # Oracle listener and instance shutdown
        echo -n "Shutdown Oracle: "

        #Optional : for Enterprise Manager software only
        su - $ORA_OWNR -c "$ORA_HOME/bin/emctl stop dbconsole"

        su - $ORA_OWNR -c "$ORA_HOME/bin/lsnrctl stop"
        su - $ORA_OWNR -c "$ORA_HOME/bin/dbshut $ORA_HOME"

        rm -f /var/lock/oracle
        echo "OK"
        $0 stop
        $0 start
        echo "Usage: $0 start|stop|restart|reload"
        exit 1
exit 0

Permission is very important, too:

chmod 755 /etc/init.d/oracle

Finally, install the script so Oracle will start during system bootup:

update-rc.d oracle defaults 99 01