Sunday, 7 December 2014

JMS and ActiveMQ

Sprint JMS and ActiveMQ
=======================
Ascronise message services 

JMS can be configured in two ways :- 
1.publich and subscriber
2.point to point model

http://icodingclub.blogspot.in/2011/07/introduction-of-spring-jms-with.html


JMS --
java messaging services 
client -- sender of message
Message hit that is MOM(message oriented middle ware) server it gets to the receiver from the mom server


RMI is a syncronize message
JMS is used to asyncronize message (no direct contact to sender to receiver means sender do not care to know the receiver receive the message or not)

DO -- destnation object


there are two typer os model for JMS
====================================


1.publischer and subscriber
2.point to point

in case of public subscriver the destination object is know as TOPIC
in case of point to point the destinatin object is know as Queue

BOTH the sender and receiver are the client to JMS
There are different type of messages can be send out here

Lets look out the difference between the 
Publish subscriber vs point to point
====================================
in case of public subscriber model, we have n number of sender sending messages to destination object (DO) 

its some thing brodcasting

where as point to point



=====================
there are 5 types of messages can be send my JMS
1.Text message
2.MAP message
3.String
4.Object
5.Byte message

====================
How this message difference the eMAIL
====================
Where do we should use JMS application
CRM,Inventry system. 
====================

JMS a Specification

need a factory object to send message
====================
JNDI to regiser the objects

JMS Specification
=================
did not said about security,factory object.
================
1.Fast context of JNDI ... fetch the JNDI context
2.Lookup for the connection factory, when i m looking for connection factory here , depending on here which modle i have been using here, either topic connection factory or Quck connection factory.
3.Using the factory object create the connection.
  need to open the connection so that we can send the message.
4.Session , create a session object using the connection object, when u create the session object
need to pass two parameeter
by passing 
a.transated or not -- boolean value
b.acknolodege type -- three type 1. Auto, 2.Client , 3.Dups OK

   Difference between three type ACKs
   By defeault Auto acks, once the msg send auto metic come to MOM server
  Clien acks is when u have to call 
  Dups ok acks it says its ok if i recive msg more then once

5.Once get session need to look for the DO (destination object) from the JNDI, thas the topic or Queq

6.Create a sender or publice, or recver or subscrive

7. For the Sender

8.Creater a publiscrer   


Saturday, 24 May 2014

SQL Query


SQL Query to find second highest salary of Employee

select MAX(Salary) from Employee WHERE Salary NOT IN (select MAX(Salary) from Employee );



SQL Query to find Max Salary from each department.


SELECT DeptID, MAX(Salary) FROM Employee GROUP BY DeptID.



Write a SQL Query to print the name of distinct  employee whose DOB is between 01/01/1960 to 31/12/1975.

SELECT DISTINCT EmpName FROM Employees WHERE DOB BETWEEN ‘01/01/1960’ AND ‘31/12/1975’;




Write an SQL Query to find employee whose Salary is equal or greater than 10000.

SELECT EmpName FROM Employees WHERE Salary>=10000;



Write an SQL Query to find name of employee whose name Start with ‘M’

SELECT * FROM Employees WHERE EmpName like 'M%';





Find all Employee records containing the word "Joe", regardless of whether it was stored as JOE, Joe, or
joe.


SELECT * from Employees WHERE upper(EmpName) like upper('joe%');





Finding nth highest salary example

SELECT *
FROM Employee Emp1
WHERE (1) = (
SELECT COUNT(DISTINCT(Emp2.Salary))
FROM Employee Emp2

WHERE Emp2.Salary > Emp1.Salary)


Delete multiple duplicate rows ?
OR
How to Delete Duplicate Records in Oracle ?



DELETE FROM your_table
WHERE rowid not in
(SELECT MIN(rowid)
FROM your_table
GROUP BY column1, column2, column3);


delete from emp a where rowid != (select max(rowid) from emp b where  a.empno=b.empno);


Sunday, 18 May 2014

Explain the use of the Join keyword and its various types.


The join keyword is very powerful in SQL. It can be used to combine rows from multiple tables by using
common values in certain fields. The type of join decides which rows are to be selected, while the
select statement specifies which fields to include in the combination table.


Inner Join
This is the default type of join. It picks all rows that have matching fields, or in other words, that meet the join condition.


Outer Join
A right outer join picks all rows from the table on the right, even if they do not meet the join condition. Some fields in such rows may have null values in the resulting table.A left outer join returns all rows of the left-side
table, irrespective of their match with the right-side table.


A full outer join returns all rows of the left- and
right-side tables.
Self Join

This is a special type of join where a table joins to
itself.

Cross Join
This is the Cartesian product of rows from the tables included in the join query statement. In other words,
every row from the first table is combined with every row of the second table, one at a time.


What is the SQL syntax for sorting, and which is the default order?


The default sorting order is ascending. These two statements are identical:
select from order by
select from order by asc
For descending order, simply replace “asc” with “desc.”

Wednesday, 14 May 2014

SQL is mainly divided into 4 sub languages


1. Data Definition Language (DDL).These commands are auto commit.
2. Data Manipulation Language (DML).
3. Transaction Control Language (TCL).
4. Data Control Language (DCL).


DDL(  DR CAT)
DML (SUDI)
TCL (CRS)
DCL (GR)
1.DROP
1.SELECT
1.COMMIT
1.GRANT
2.RENAME
2.UPDATE
2.ROLLBACK
2.RENAME
3.CREATE
3.DELETE
3.SAVEPOINT

4.ALTER
4.INSERT


5.TRUNCATE





There are 10 types  Database Objects in Oracle
6 in SQL and 4 in PL/SQL


6 Sql Database Object
1.TABLE
2.VIEWS
3.SYNONYMS
4.SEQUENCE
5.INDEX
6.CLUSTER


4  DATABASE OBJECT IN PL/SQL
1.FUNCTION
2.PROCEDURE
3.PACKAGE
4.TRIGGER

Wednesday, 25 December 2013

PL / SQL

--Veriable decleration
DECLARE
  eName1 VARCHAR2(10) := 'Hello';
BEGIN
  dbms_output.put_line(eName1);
END;
/
--Veriable decleration constant
--The value can not changed
DECLARE
  eName1 CONSTANT VARCHAR2(10) := 'Hello';
BEGIN
  dbms_output.put_line(eName1);
END;
/
--Not Null
DECLARE
  --A variable declared NOT NULL must have an initialization assignment
  eName1 VARCHAR2(10) NOT NULL:= 'Hello';
BEGIN
  dbms_output.put_line(eName1);
  --eName1 := null; -- Error -- Expression is of wrong type
END;
/
--------------------------------------------------------------------------
--Number type veriable
DECLARE
  eNumber NUMBER(10):= 4500;
BEGIN
  dbms_output.put_line(eNumber);
END;
/
--------------------------------------------------------------------------
--------------------------------------------------------------------------
--veriable Concatination||
DECLARE
  eNumber VARCHAR(10):= 'Hello';
BEGIN
  dbms_output.put_line('This Name is ' || eNumber);
END;
/
--------------------------------------------------------------------------
--------------------------------------------------------------------------
-- Convert number value to char string
DECLARE
  eSalary NUMBER(10):= 4560;
BEGIN
  dbms_output.put_line('This Emp Salary is ' || To_CHAR(eSalary));
END;
/
--------------------------------------------------------------------------
--------------------------------------------------------------------------
-- *SQL
-- For writing a programm in file and execute just "ed f1(file name)"
-- For getting out put in *SQL Command -- set serverout on
DECLARE
  eMsg Varchar(100);
BEGIN
  eMsg := 'Hello PL SQL World';
  dbms_output.put_line(eMsg);
END;
/
--------------------------------------------------------------------------
--Memory veriable
DECLARE
  VSalary NUMBER(10,2);
  EName   VARCHAR(50);
BEGIN
  SELECT SALARY,
    FIRST_NAME
  INTO VSalary,
    EName
  FROM EMPLOYEES
  WHERE FIRST_NAME = 'Lex';
  dbms_output.put_line('The Salary of '|| EName || TO_CHAR(VSalary));
END;
/
--------------------------------------------------------------------------
--------------------------------------------------------------------------
-- IF Condition
DECLARE
  vSalary NUMBER(10,2);
BEGIN
  SELECT salary INTO vSalary FROM employees WHERE first_name = 'Neena';
  IF(vSalary > 6000) THEN
    dbms_output.put_line('Earn more then tom' || vSalary);
  ELSE
    IF (vSalary = 17000) THEN
      dbms_output.put_line('Earn NO then tom' || vSalary);
    ELSE
      dbms_output.put_line('Earn LESS then tom' || vSalary);
    END IF;
  END;
  /
  --------------------------------------------------------------------------
  --------------------------------------------------------------------------
-- LOOP
-- Three kind of loop available in PL SQL 1. LOOP ... LOOP END , 2. While (Condition) Loop .. End Loop
-- FOR ... END LOOP
DECLARE
  c1 NUMBER := 0;
BEGIN
  LOOP
    dbms_output.put_line('Hello');
    c1:=c1 +1;
    EXIT
  WHEN c1 = 5;
  END LOOP;
END;
/
--------------------------------------------------------------------------
 --------------------------------------------------------------------------
-- LOOP
-- While (Condition) Loop .. End Loop
DECLARE
  c1 NUMBER := 10;
BEGIN
  WHILE (c1 < 13)
  LOOP
    dbms_output.put_line('Hello ' || c1);
    c1:=c1 +1;
  END LOOP;
END;
/
--------------------------------------------------------------------------
--------------------------------------------------------------------------
-- LOOP
-- FOR Loop .. End Loop
BEGIN
  FOR i IN 10..13
  LOOP
    dbms_output.put_line('Hello ');
  END LOOP;
END;
/
--------------------------------------------------------------------------
 --------------------------------------------------------------------------
-- Impliciti Cursors
BEGIN
  DELETE FROM employees WHERE employee_id = 120;
  IF SQL%FOUND THEN
    dbms_output.put_line('The row to be deleted was not found');
  ELSE
    dbms_output.put_line('The row was deleted');
  END IF;
END;
/
--------------------------------------------------------------------------
 --------------------------------------------------------------------------
-- Impliciti Cursors
BEGIN
  DELETE FROM employees WHERE employee_id = 120;
  IF SQL%NOTFOUND THEN
    dbms_output.put_line('The row to be deleted was not found');
  ELSE
    dbms_output.put_line('The row was deleted');
  END IF;
END;
/
--------------------------------------------------------------------------
--------------------------------------------------------------------------
-- Impliciti Cursors
BEGIN
  DELETE FROM employees WHERE employee_id = 120;
  IF SQL%FOUND THEN
    dbms_output.put_line('The row to be deleted was not found');
  ELSE
    dbms_output.put_line(SQL%ROWCOUNT ||'The row was deleted');
  END IF;
END;
/
--------------------------------------------------------------------------
--------------------------------------------------------------------------
-- Explicit Cursors (Work area for sql)
-- There are some steps need to follow to work on explicit cursor
-- 1.Declare a cursor
-- 2.open the cursor
-- 3.Fetching the cursor
-- 4.Close cursor
--
-- Proble raise and why we need to use explicit cursor please take a look on below query which return more then one row
-- If more then depno available wiht 20 then which row will be set in vName memory variable.
BEGIN
  DECLARE
    vName VARCHAR2(45);
  BEGIN
    SELECT ename INTO vName FROM employees WHERE deptno = 20;
    dbms_output.put_line(SQL%ROWCOUNT ||'The row was deleted');
  END;
  /
-- Correct SQL -------------------
BEGIN
  DECLARE
    vName VARCHAR2(45);
    CURSOR c1
    IS
      SELECT FIRST_NAME FROM employees WHERE DEPARTMENT_ID = 50;
  BEGIN
    OPEN c1;
    LOOP
      FETCH c1 INTO vName;
      --statement to exit loop
      dbms_output.put_line(vName);
    END LOOP;
  END;
  /
--------------------------------------------------------------------------
--------------------------------------------------------------------------
-- Data type and row type
BEGIN
  DECLARE
    vEmp employees%ROWTYPE;
  BEGIN
    SELECT * INTO vEmp FROM employees WHERE EMPLOYEE_ID = 101;
    dbms_output.put_line(vEmp.FIRST_NAME);
    dbms_output.put_line(vEmp.EMPLOYEE_ID);
  END;
  /
--------------------------------------------------------------------------

Friday, 1 March 2013

Java Collections

 
 
The core collection interfaces.
 


Collection represents the group of objects. Depending on the method of storing and retrieving
Collections are basically divided into three parts – Set, Map and List.
Where Set does not contain duplicate values, Map contains key value type of data whereas List can have a duplicate values stored in it sequentially.

Collection
The root of the collection hierarchy.
A collection represents a group of objects known as its elements.
Some types of collections allow duplicate elements, and others do not.
Some are ordered and others are unordered.
The Java platform doesn’t provide any direct implementations of this interface but provides implementations of more specific sub interfaces, such as Set and List.

Set — a collection that cannot contain duplicate elements

List
An ordered collection (sometimes called a sequence).
Lists can contain duplicate elements.
The user of a List generally has precise control over where in the list each element is inserted and can access elements by their integer index (position).

Queue
A collection used to hold multiple elements prior to processing.
Besides basic Collection operations, a Queue provides additional insertion, extraction, and inspection operations.
Queues typically, but do not necessarily, order elements in a FIFO (first-in, first-out) manner.
Among the exceptions are priority queues, which order elements according to a supplied comparator or the elements’ natural ordering.

Map
An object that maps keys to values.
A Map cannot contain duplicate keys; each key can map to at most one value.
If you’ve used Hashtable, you’re already familiar with the basics of Map.


HashSet :
This class implements the Set interface, backed by a hash table (actually a HashMap instance).
It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time.
This class permits the null element.

LinkedHashSet :
Hash table and linked list implementation of the Set interface, with predictable iteration order.
This implementation differs from HashSet in that it maintains a doubly-linked list running through all of its entries.
This linked list defines the iteration ordering, which is the order in which elements were inserted into the set (insertion-order).
Note that insertion order is not affected if an element is re-inserted into the set. (An element e is reinserted into a set s if s.add(e) is invoked when s.contains(e) would return true immediately prior to the invocation).

Interface SortedSet:
A set that further guarantees that its iterator will traverse the set in ascending element order, sorted according to the natural ordering of its elements (see Comparable), or by a Comparator provided at sorted set creation time.
Several additional operations are provided to take advantage of the ordering. (This interface is the set analogue of SortedMap).

TreeSet:
This class implements the Set interface, backed by a TreeMap instance. This class guarantees that the sorted set will be in ascending element order, sorted according to the natural order of the elements (seeComparable), or by the comparator provided at set creation time, depending on which constructor is used.

ArrayList:
Resizable-array implementation of the List interface.
Implements all optional list operations, and permits all elements, including null. In addition to implementing the List interface, this class provides methods to manipulate the size of the array that is used internally to store the list.

Vector:
This class is roughly equivalent to ArrayList except it is Synchronized.

LinkedList:
Linked list implementation of the List and Queue interfaces. Implements all optional operations, and permits all elements (including null).




 HashMap:
The HashMap class is roughly equivalent toHashtable, except that it is unsynchronized and permits nulls

HashTable:
Hash table based implementation of the Map interface.
This implementation provides all of the optional map operations, and permits null values and the null key. This class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time.

LinkedHashMap:
Hash table and linked list implementation of the Map interface, with predictable iteration order.
This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries.
This linked list defines the iteration ordering, which is normally the order in which keys were inserted into the map (insertion-order).
Note that insertion order is not affected if a key is re-inserted into the map.

TreeMap:
This class guarantees that the map will be in ascending key order, sorted according to the natural order for the key’s class (seeComparable), or by the comparator provided at creation time, depending on which constructor is used.

Note :To synchronize the Set Concrete classes, use below code:

Set s = Collections.synchronizedSet(CONCREATECLASS_OBJECT);

To Synchronize the List Concreate classes :

List list = Collections.synchronizedList(CONCREATECLASS_OBJECT);




Note:- http://www.cs.cmu.edu/~adamchik/15-121/lectures/Collections/collections.html

Basic approach to choosing a collection

List-:
Most cases where you just need to store or iterate through a "bunch of things" and later iterate through them.

Set:-
  • Remembering "which items you've already processed", e.g. when doing a web crawl;
  • Making other yes-no decisions about an item, e.g. "is the item a word of English", "is the item in the database?" , "is the item in this category?" etc.
Map:-
Used in cases where you need to say "for a given X, what is the Y"? It is often useful for implementing in-memory caches or indexes. For example:
  • For a given user ID, what is their cached name/User object?
  • For a given IP address, what is the cached country code?
  • For a given string, how many instances have I seen?
Queue:-
  • Often used in managing tasks performed by different threads in an application (e.g. one thread receives incomming connections and puts them on a queue; other "worker" threads take connections off the queue for processing);
  • For traversing hierarchical structures such as a filing system, or in general where you need to remember "what data to process next", whilst also adding to that list of data;
  • Related to the previous point, queues crop up in various algorithms, e.g. build the encoding tree for Huffman compression.