git introduction


git can be founded from

Git and Github

  • Signup for Github Account
  • Go to Account Setting –> SSH Public Keys
  • Click Add public key and paste your public key

Cloning an existing Repository

$ git clone <repository-uri>

Create new Repository

$ git init

$ git add .

$ git commit -m ‘initial project version’

$ git remote add origin <repository-uri>

$ git push -u origin master

Checking the Status of your file

$ git status

Create a new Branch

$ git branch <NameofBranch>

Move on to a Branch

$ git checkout <NameofBranch>


REST in rails

Rails introduced support for designing APIs consistent with the REST style. Representational State Transfer (REST) is complex topic in Information theory. Basically, you start with the general proposition of machines that can talk to each other, and you start ruling some practice in and others out by imposing constraints that include:

  • Use of a client-server architecture
  • Stateless communication
  • Expicit signaling of response cacheability
  • Use of HTTP request methods such as GET, POST, PUT and DELETE

REST in Rails

the REST support in Rails consists of methods to define resources in the routing system, designed to impose a particular style and order and logic on your controllers and, consequently, on the way the world sees your application.

The story of REST and Rails starts with CRUD

Routing and CRUD

CRUD ( Create Read Update Delete) is the classic summary of the spectrum of database operations. the routing system does not force you to implement your app’s CRUD functionality in any consistent manner.

Here’s the logic. It’s good to give CRUD-based names to your actions. It’s convenient and elegant to use named routes.  The REST support in rails gives you named routes that point to CRUD-based action names. if you put into your config/routes.rb file,n you will have created for named routes.

by creating a route like bellow:


  root :to => 'pages#home'
  match '/about', :to => 'pages#about'
  match '/contact', :to => 'pages#contact'

what’s the meaning?

This code maps the root URL / to /pages/home, and also gives URL helpers as follows:
root_path => ‘/’
root_url => ‘http://localhost:3000/&#8217;

Named route

<%= link_to "Home", root_path %>
<%= link_to "About", about_path %>

JPQL (Java Persistence Query Language)

The simple JPQL query selects all the instances of single entiity type.

SELECT e FROM Employee e

if you want just the names of the Employee, the following query this bellow.

SELECT FROM Employee e

filtering query

SELECT e FROM Employee e WHERE = 'sl54' AND e.address.state IN ('JKT','SMG')

Join between entity

SELECT p.number
FROM Employee e, Phone p
WHERE e=p.employee AND ='sa90' AND
p.type ='cell'

Query parameters

Positional parameter notation

SELECT e FROM Employee e
WHERE e.dapartment = ?2 AND e.salary > ?4

Named Parameter notation

SELECT e FROM Employee e
WHERE e.department = :dept AND
      e.salary > :base

using namedQuery

value=SELECT s FROM Student s WHERE s:grade = "3"

Working with @NamedQueries


JEE-persistence API (JPA)

JEE/ Java enterprise edition

JPA Java persistence

@CollectionTable is used to mapping of collections of basic or embeddable types.@Entity is allows collections of simple objects to be easily defined.

The entity’s persistent state is defined by four field, the identity id defined by the field id and is annotated with @id. A composite primary key may also be defined where the primary key corresponds to ome or more fields of the entity class. 

the implements  Serializable interface, and that allows it to be passed by value through a remote interface.

The relationships between different entities are defined using @OneToOne, @OneToMany, @ManyToOne and @ManyToMany annotation on the corresponding field of the referencing entity.

Validating the Entities.

validation has some predefined constraints like @Min, @Max, @Pattern and @Size.

public class Student implements serializable {

private int id;

private String name;

@Size(min=3, max=10)
private String grade;

protected String email;