How did Liferay help me in building my app?

In our current project we are building a portlet using Spring portlet MVC and liferay 5.2.3.

More details about how we configured spring Portlet MVC with Liferay can be found here.

Liferay has proved to be a boon for us in numerous ways. There were out of the box plugins, services and tag libraries which did hasten our development process. Whenever we got a new requirement we were able to identify some feature of the liferay to suffice our needs.

So let’s see in detail, how actually liferay has helped us in solving those problems:

Read More »

Why should I use JBoss AS7

In the last few months we have seen some aggressive marketing of JBoss AS 7 by RedHat. Red Hat has been praising its perfromance, parallelism, jee6 compatibility and other deployment issues. So I decided to explore the new application server and verify the truth behind them.

After downloading the app server I configured it with eclipse using M2Eclipse plugin, the details of how to configure it and deploy the quickstarts is given here. The homePage itself looks impressive to begin with and documentation is very good (for a change).

Below is my experience and analysis over the claims of the new JBoss AS7.
Read More »

JVM Tuning settings, the ultimate list

Let us begin with the very basic question, why do we need our JVM tuned up? And what exactly is JVM.

JVM, is the instance of Java Runtime Environment, which comes into action whenever you run your application

So, in order to make sure JVM runs fine we require that there is enough space for JVM to run programs. And hence we require timely check on the performance factors and space allotted to the JVM.

The crux of the matter: Heap and Garbage Collection
Read More »

Hibernate learnings

Few of the important key points to remember in Hibernate:

1.) Use Transactional boundaries in your service layer.

2.) Outside a transaction boundary if session gets closed, the proxy object gets detached and hence if there is a collection which is lazily loaded, it can not be fetched. Either make separate call for the collection or use OpenSessionViewFilter.
Read More »

Hibernate basics

NOTE : This is beginner level blog.

Sometimes We just forget the basic things if we get out of touch for some time. Hence I am writing down the basics to remind myself.

1.) One to Many mapping:
example : One User has many tasks
Screen Shot 2014-01-29 at 10.39.19 AM

@Entity
@Table(name = "user")
public class User {

        private Long id;
        ......
        private List<Task> tasks
        ......

  @OneToMany(fetch = FetchType.LAZY, mappedBy = "user", cascade = CascadeType.ALL)
        public List<Task> getTasks() {
                return tasks;
        }

        public void setTasks(List<Task> tasks) {
                this.tasks = tasks;
        }

Here, We need to tell hibernate which is the attribute in the referencing Java Class ( In this case, Task)
which can be used to map this class with referencing class. So, in class Task, “user” is the name of attribute which is representing relationship with User Table.
We do not have any field in User table, this mapping is for hibernate, so we do not have to write a query and apply join to find all the tasks of a user.
We can access all the tasks of a user by:

user.getTasks();

2.) Many to One Mappings:
Similarly, for Task ( Multiple tasks for one user)

@Entity
@Table(name = "task")
public class Task {
        
        private Long id;
        private String name;
        private User createdBy;
        ......

  @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name="createdBy")
        public User getCreatedBy() {
                return createdBy;
        }

Here, We need to join the column “createdBy” in table Task with primary key (id) of User table.
By default, it picks up the primary key of the referenced table. Also, note that I have put fetch type as lazy.

3.) One to One Mappings:
These mappings are generally useful when using composition, for example, a Task can have a Type, called as TaskType. Every task has one type, so in order to enable hibernate to fetch task type details from task without writing any query, we need to define mapping.
So, for Task Table :

@Entity
@Table(name = "task")
public class Task {

    private Long id;
    private String name;
    private TaskType taskType;
     ........
     ........
@OneToOne
    @JoinColumn(name="task_type_id")
    public TaskType getTaskType() {
        return taskType;
    }

There is no need to do define any mapping in TaskType class.

These are very basic, but helpful for a quick reference.

Setting up postgres on mac

This is a beginner blog.

1.) Install Postgres server.
Or, if it already installed; we can search (in mac )

Anirudhs-MacBook-Pro:~ anirudh$ mdfind postgres | grep include

2.) First time starting postgres server and initialise the space.
We need to initialise

Anirudhs-MacBook-Pro:bin anirudh$ ./initdb /usr/local/var/postgres -E utf8
The files belonging to this database system will be owned by user "anirudh".
This user must also own the server process.

The database cluster will be initialized with locales
  COLLATE:  C
  CTYPE:    UTF-8
  MESSAGES: C
  MONETARY: C
  NUMERIC:  C
  TIME:     C
initdb: could not find suitable text search configuration for locale "UTF-8"
The default text search configuration will be set to "simple".

Data page checksums are disabled.

creating directory /usr/local/var/postgres ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
creating configuration files ... ok
creating template1 database in /usr/local/var/postgres/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
syncing data to disk ... ok

WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.

Success. You can now start the database server using:

    ./postgres -D /usr/local/var/postgres
or
    ./pg_ctl -D /usr/local/var/postgres -l logfile start

3.)Start the server :

 ./postgres -D /usr/local/var/postgres

Documentation on starting postgres :
http://www.postgresql.org/docs/9.3/static/server-start.html

Difference between Factory and Abstract Factory

The main difference between the two is Inheritance vs Composition.
Abstract Factory uses composition whereas Factory like template uses inheritance.

Abstract factory pattern can use factory method to actulay implement different types of object creation, but it is not necessary.

I would say Abstract Factory Pattern is more into design product creations and how different variants of the product would be created , it is to supply a “kit” to create product and its different variants. It may use prototype/factory method and other builder pattern inside when actualy instantiating the object.

So In Abstract Factory Pattern ,we would provide an interface of product which can be used to create its families without specifying their concrete implementations. Lets try to understand this by example.
Read More »

Key to Optimization: Algorithm and Analysis

Every problem has solutions but the most important thing is to find the solution that best fits that scenario. So as we take a dig inside the algorithms and techniques we will investigate how we can analyse the complexity and conclude the correct optimized solution.

Let us begin with a simple example and try to find the time and complexity.

Example : We need the sum of n natural numbers starting from ‘a’ and ending at ‘b’. Read More »