May 24, 2009

carpentry tools

Hey ppl after a long gap i am back with one more update on carpentry tools and furnitures. To know about it more just feel free to explore the post below...

If you want to keep your place filled with furniture and stuffs then i am sure you all will like this post. patio chairs is the latest buzz among many these days. The chair is designed with special carving and is available with various color and designs. To read the entire catalog just go and visit the forum and experience the fascinating home decoration stuff. What for you waiting still ? just go and grab the opportunity now... Enjoy the festive season offer... Don't forget to spread the word to all your friends... keep reading my blog for more latest updates on furniture and fashion accessories..

kindly leave your comments if any below... have fun and Enjoy life...

cheers karthik ;-)


May 17, 2009

Interface

Interface: Interfaces can be used to implement the Inheritance relationship between the non-related classes that do not belongs to the same hierarchy, i.e. any Class and any where in hierarchy.   Using Interface, you can specify what a class must do but not how it does.
A class can implement more than one Interface.
An Interface can extend one or more interfaces, by using the keyword extends.
All the data members in the interface are public, static and Final by default.
An Interface method can have only Public, default and Abstract modifiers.
An Interface is loaded in memory only when it is needed for the first time.
A Class, which implements an Interface, needs to provide the implementation of all the methods in that Interface.
If the Implementation for all the methods declared in the Interface are not provided , the class itself has to declare abstract, other wise the Class will not compile.
If a class Implements two interface and both the Intfs have identical method declaration, it is totally valid.  
If a class implements two interfaces both have identical method name and argument list, but different return types, the code will not compile.
An Interface can’t be instantiated. Intf Are designed to support dynamic method resolution at run time.
An interface can not be native, static, synchronize, final, protected or private.
The Interface fields can’t be Private or Protected.
A Transient variables and Volatile variables can not be members of  Interface.
The extends keyword should not used after the Implements keyword, the Extends must always come before the Implements keyword.
A top level Interface can not be declared as static or final.
If an Interface species an exception list for a method, then the  class implementing the interface need not declare the method with  the exception list.
If an Interface can’t specify an exception list for a method, the class can’t throw an exception. 
If an Interface does not specify the exception list for a method, he class can not throw any exception list.
The general form of Interface is 
Access interface name {
         return-type method-name1(parameter-list);
            type final-varname1=value;
          }
-----------------------
Marker Interfaces :  Serializable, Clonable, Remote, EventListener,

Java.lang is the Package of all classes and is automatically imported into all Java Program
Interfaces:  Clonable , Comparable, Runnable


OOPS concept of JAVA



Abstraction:  Showing the essential and hiding the non-Essential is known as Abstraction.

Encapsulation: The Wrapping up of data and functions into a single unit is known as Encapsulation.
     Encapsulation is the term given to the process of hiding the implementation details of the object. Once an object is encapsulated, its implementation details are not immediately accessible any more. Instead they are packaged and are only indirectly accessed via the interface of the object.

Inheritance: is the Process by which the Obj of one class acquires the properties of Obj’s another Class.
 A reference variable of a Super Class  can be assign to any Sub class derived from the Super class.
         Inheritance is the method of creating the new class based on already existing class , the new class derived is called Sub class which has all the features of existing class and its own, i.e sub class.
Adv: Reusability of code , accessibility of variables and methods of the Base class by the Derived class.

Polymorphism: The ability to take more that one form, it supports Method Overloading &  Method Overriding.

Method overloading: When a method in a class having the same method name with different arguments (diff Parameters or Signatures) is said to be Method Overloading. This is Compile time Polymorphism.
Using one identifier to refer to multiple items in the same scope.

Method Overriding: When a method in a Class having same method name with same arguments is said to be Method overriding. This is Run time Polymorphism.
Providing a different implementation of a method in a subclass of the class that originally defined the method.
 1.  In Over loading there is a relationship between the methods available in the same class ,where as in Over riding there is relationship between the Super class method and Sub class method.
 2.  Overloading  does not block the Inheritance from the Super class , Where as in Overriding blocks Inheritance from the Super Class.
 3.  In Overloading separate methods share the same name, where as in Overriding Sub class method replaces the Super Class.
4. Overloading  must have different method Signatures , Where as Overriding methods must have same Signatures.




May 2, 2009

TRIGGERS

3 TYPES

1.DATABASE TRIGGERS (TABLE)  CLASSIFIED INTO STATEMENT LEVEL AND ROW LEVEL

2.SYSTEM TRIGGERS(SYSTEM)

3.INSTEAD OF TRIGGERS(VIEW)



DATABASE TRIGGERS

commit,rollback and savepoint are not allowed within trigger
only update,insert,delete can be used


STATEMENT LEVEL  TRIGGERS 


SQL> SELECT *FROM STUDENT;

    ROLLNO NAME                STD
---------- ---------- ----------
     12345    KAR                     11
      2345     joe                       10
     12346    tarun                      9
      7890     MARIE                 12
      1357     VIMAL                  10

 1   CREATE OR REPLACE TRIGGER INTIMATE
 2   AFTER INSERT OR UPDATE OR DELETE
 3   ON STUDENT
 4   BEGIN
 5   DBMS_OUTPUT.PUT_LINE('DML INSERT OR UPDATE OR DELETE EXECUTED');
 6  END;
 7  /

TRIGGER CREATED 

SQL> UPDATE STUDENT SET NAME='KAR'  WHERE STD=10;

DML INSERT OR UPDATE OR DELETE EXECUTED

2 rows updated.




ROW LEVEL TRIGGERS


 CREATE OR REPLACE TRIGGER INTIMATE
 AFTER INSERT OR UPDATE OR DELETE
 ON STUDENT
 FOR EACH ROW
 BEGIN
 DBMS_OUTPUT.PUT_LINE('DML INSERT OR UPDATE OR DELETE EXECUTED');
 END;

SQL>  UPDATE STUDENT SET NAME='KAR'  WHERE STD=10;

DML INSERT OR UPDATE OR DELETE EXECUTED

DML INSERT OR UPDATE OR DELETE EXECUTED

2 rows updated.


USING OLD and NEW Keyword

  1  CREATE OR REPLACE TRIGGER NAMECHANGE
  2  AFTER UPDATE ON STUDENT
  3  FOR EACH ROW
  4  BEGIN
  5  DBMS_OUTPUT.PUT_LINE(:OLD.NAME  || '  CHANGED TO '|| :NEW.NAME);
  6* END;
SQL> /

Trigger created.

SQL> SELECT *FROM STUDENT;

    ROLLNO  NAME         STD
---------- ---------- ----------
     12346   tarun               9
      7890   MARIE           12
      1357   KARTHIK        10



SQL> UPDATE STUDENT SET NAME='TARUN' WHERE NAME='tarun';

tarun  CHANGED TO TARUN

1 row updated.

Note : OLD and NEW can be used only with row level triggers
               
               old value                 new value
update       before                     after 
insert         null                         after
delete       before                      null

 
Using with when clause and referencing

 CREATE OR REPLACE TRIGGER NOTIFY
 AFTER INSERT ON STUDENT
 REFERENCING OLD AS PREV NEW AS CURR
 FOR EACH ROW
 WHEN(CURR.NAME='KARTHIK')
 BEGIN
 DBMS_OUTPUT.PUT_LINE('Student KARTHIK already exists but however it is 2nd time inserted');
 END;

SQL>  insert into  student values(3934,'KARTHIK',11);

Student KARTHIK already exists but however it is 2nd time inserted

1 row created.


To drop a trigger

drop trigger triggername;


MANAGING TRIGGERS

SQL> ALTER TRIGGER NOTIFY COMPILE;

Trigger altered.

SQL> ALTER TRIGGER NOTIFY DISABLE;

Trigger altered.

insert into  student values(5034,'KARTHIK',11);

1 row created.

SQL>  ALTER TRIGGER NOTIFY ENABLE;

Trigger altered.

SQL> insert into  student values(5035,'KARTHIK',11);
Student KARTHIK already exists but however it is 2nd time inserted

1 row created.

SQL> ALTER TABLE STUDENT DISABLE ALL TRIGGERS;

Table altered.

SQL> ALTER TABLE STUDENT ENABLE ALL TRIGGERS;

Table altered.


MUTATION ERROR occurs in Row level Triggers only. There are two possible ways to find it

1. create trigger before update of sal on emp .. blah blah begin ..modify emp then mutation results
2. A special case: create trigger before update on sal ... blah blah foreign key ref...


SYSTEM TRIGGERS


CREATE,ALTER,DROP,LOGON,LOGOFF,STARTUP,SHUTDOWN are used i.e DDL and system events are considered. Refer book for eg.



INSTEAD OF

for views to restrict insert,delete or update

SQL> CREATE OR REPLACE TRIGGER TRG1
  2  INSTEAD OF INSERT ON EMPLOC
  3  BEGIN
  4  DBMS_OUTPUT.PUT_LINE('INSERTING DATA ON VIEW EMPLOC RESTRICTED');
  5  END;
  6  /

Trigger created.

Eg.

insert into emploc('jose','japan');

INSERTING DATA ON VIEW EMPLOC RESTRICTED

1 row created.

though it says '1 row created' in the view no new value get inserted.




CURSORS



IMPLICIT CURSOR

DELETE

 begin
 delete from worker where deptno=20;
 delete from worker where deptno=90;
 delete from worker where deptno=10;  // this is taken as SQL in the next line
 if(sql%found) then
 dbms_output.put_line('The deleted rows are'||SQL%ROWCOUNT);
 else
 dbms_output.put_line('There is no such department');
 end if;
 end;
/

output:

The deleted rows are 3  ( there are 3 rows that has deptno as 10)

INSERT

 begin 
 insert into worker(empno,ename,sal) values(3489,'joe',2300);
 if(sql%found) then
 dbms_output.put_line('A new row has been inserted');
 end if;
 if(sql%notfound) then
 dbms_output.put_line('Prob during insertion');
 end if;
 end;
 /

A new row has been inserted

PL/SQL procedure successfully completed

Similarly we can use update…

Using loops

SQL>  begin
  2   for indx in 1..3
  3   loop
  4   delete from worker where sal>1000;
  5    if(sql%found) then
  6    dbms_output.put_line('The deleted rows are'||SQL%ROWCOUNT);
  7    else
  8  dbms_output.put_line('Already deleted');
  9  end if;
 10  end loop;
 11  end;
 12  /



Output:

The deleted rows are20
Already deleted
Already deleted

PL/SQL procedure successfully completed.

SQL> set serveroutput on;
SQL> begin 
  2  insert into worker(empno,ename,sal) values(3489,'joe',2300);
  3  insert into worker(empno,ename,sal) values(1234,'vithya',3400);
  4  insert into worker(empno,ename,sal) values(4689,'kar',7890); //this is taken as SQL in the next line
       if(sql%found) then
  5   dbms_output.put_line(sql%rowcount);
  6  else
  7   dbms_output.put_line('Prob during insertion');
  8   end if;
  9  end;
 10  /

1

PL/SQL procedure successfully completed.



SQL>  declare 
  2   myemp worker%rowtype;
  3   Begin
  4   select *into myemp from worker where ename='smith';
  5    if(sql%found) then
  6   dbms_output.put_line(sql%rowcount);
  7   elsif(SQL%notfound)
  8   then  
  9   dbms_output.put_line('error');     /there can be if elsif with out else part
 10  end if;
 11  end;
 12  /

 /exception thrown... if no rows selected.... so ‘error’ not printed as in 9th statement /

 declare   
*
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at line 4


SQL>  declare 
  2   myemp worker%rowtype;
  3   Begin
  4   select *into myemp from worker where ename='SMITH';  /use into clause  for select statement here otherwise it will show error 
  5    if(sql%found) then
  6   dbms_output.put_line(sql%rowcount);
  7   end if;
  8   end;
  9  /

Output:

1

PL/SQL procedure successfully completed.


EXPLICIT CURSOR

SQL>  declare
  2   cursor c is select *from worker where deptno=10;
  3   c1 c%rowtype;
  4   begin
  5   open c;
  6   loop
  7   fetch c into c1;
  8   if(c%found) then
  9   dbms_output.put_line(c%rowcount);
 10   else
 11   exit;
 12   end if;
 13   end loop;
 14   close c;
 15   end;
 16  /
1
2
3

SQL>  declare
  2   cursor c is select *from worker where deptno=10;
  3   c1 c%rowtype;
  4   begin
  5   open c;
  6   loop
  7   fetch c into c1;
  8   if(c%found) then
  9   dbms_output.put_line(c%rowcount);
 10  dbms_output.put_line(c1.ename);
 11   else
 12   exit;
 13   end if;
 14   end loop;
 15   close c;
 16   end;
 17  /


1
CLARK
2
KING
3
MILLER

PL/SQL procedure successfully completed.



 1   declare
 2   cursor c is select *from worker where deptno=10;
 3   c1 c%rowtype;
 4   begin
 5   open c;
 6   dbms_output.put_line(c%rowcount);
 7   end;

Output:

0


SQL>  declare
  2   cursor c is select *from worker where deptno=10;
  3   c1 c%rowtype;
  4   begin
  5   open c;
  6   loop
  7   fetch c into c1;
  8   if(c%found) then
  9   dbms_output.put_line(c%rowcount);dbms_output.put_line(c.ename);
 10   else
 11   exit;
 12   end if;
 13   end loop;
 14   close c;
 15   end;
 16  /
 dbms_output.put_line(c%rowcount);dbms_output.put_line(c.ename);
                                                         *
ERROR at line 9:
ORA-06550: line 9, column 58:
PLS-00225: subprogram or cursor 'C' reference is out of scope
ORA-06550: line 9, column 35:
PL/SQL: Statement ignored


C  is  the cursor pointing to the each fields in a row of a table and C1 is like temporary storage here C is fetched to C1 so C1.ename works not c.ename …


USING CURSOR TO FETCH EACH ROWS TO A RECORD

SQL>  declare
  2   type rec is record(n worker.empno%type,name worker.ename%type,sal worker.sal%type);
  3    r rec;
  4  cursor c is select empno,ename,sal from worker where ename='SMITH';
  5   begin
  6   open c;
  7  fetch c into r;
  8  if(c%found) then
  9  dbms_output.put_line(c%rowcount);
 10  dbms_output.put_line(r.n||' '||r.name||' '||r.sal);
 11  end if;
 12  end;
 13  /


1
7369 SMITH 3500

PL/SQL procedure successfully completed.

  1   declare
  2   type rec is record(name emp.ename%type,salary emp.sal%type);
  3   cursor c is select ename,sal from emp where deptno=10;
  4   r rec;
  5   begin
  6   open c;
  7   loop
  8   fetch c into r;
  9   if(c%found) then
 10   dbms_output.put_line(c%rowcount);
 11   dbms_output.put_line(r.name ||'  '||r.salary);
 12   else
 13   exit;
 14   end if;
 15   end loop;
 16   close c;
 17*  end;


SQL> /
1
CLARK  2450
2
KING  5000
3
karthik  1300


USING CURSOR FOR LOOP


  1   DECLARE
  2   CURSOR C IS SELECT ENAME,SAL,DEPTNO FROM EMP;
  3   REC  C%ROWTYPE; // R is of rowtype Cursor C
  4   BEGIN
  5   FOR REC IN C
  6   LOOP
  7   IF(REC.DEPTNO=10) THEN
  8   DBMS_OUTPUT.PUT_LINE(REC.ENAME ||'   '||REC.SAL);
  9   END IF;
 10   END LOOP;
 11*  END;
SQL> /
CLARK   2450
KING   5000
karthik   1300

open,fetch,close everything did implicitly here...


  1   DECLARE
  2   CURSOR C IS SELECT ENAME,SAL,DEPTNO FROM EMP;
  3   BEGIN
  4   FOR REC IN C
  5   LOOP
  6   IF(REC.DEPTNO=10) THEN
  7   DBMS_OUTPUT.PUT_LINE(REC.ENAME ||'   '||REC.SAL);
  8   END IF;
  9   END LOOP;
 10*  END;
SQL> /
CLARK   2450
KING   5000
karthik   1300

in the above case statement 3   REC  EMP%ROWTYPE is missing but still it works fine as it invokes REC implicitly from previous execution


Further simplification...

  1   BEGIN
  2   FOR REC IN (SELECT ENAME,SAL,DEPTNO FROM EMP)
  3   LOOP
  4   IF(REC.DEPTNO=10) THEN
  5   DBMS_OUTPUT.PUT_LINE(REC.ENAME ||'   '||REC.SAL);
  6   END IF;
  7   END LOOP;
  8*  END;
SQL> /
CLARK   2450
KING   5000
karthik   1300


CURSOR WITH PARAMETERS

  1   DECLARE
  2   CURSOR C(INPUT NUMBER) IS SELECT COUNT(*) CNT FROM EMP WHERE DEPTNO=INPUT;
  3   R  C%ROWTYPE; 
  4   BEGIN
  5   OPEN C(10);
  6   FETCH C INTO R;
  7   DBMS_OUTPUT.PUT_LINE('No of emp in deptno 10 is  ' ||R.CNT);
  8   CLOSE C;
  9   OPEN C(20);
 10   FETCH C  INTO R;
 11   DBMS_OUTPUT.PUT_LINE('No of emp in deptno 20 is  ' ||R.CNT);
 12   CLOSE C;
 13*  END;

SQL> /
No of emp in deptno 10 is  3
No of emp in deptno 20 is  5


LOCKING


1.ROW LEVEL
2.TABLE LEVEL


ROW LEVEL

FOR UPDATE [OF COLUMN] [NOWAIT]

refer pg no.49 in book


SESSION 1:
SELECT *FROM EMP WHERE DEPTNO=10 FOR UPDATE NOWAIT;
SESSION 2: it's not possi for us to update emp details of deptno=10 till session 1 releases lock


TABLE LEVEL

1.SHARE - This mode is for read only on entire table.we can not make changes to table.
2.SHARE UPDATE - This mode is used to lock the selected rows for update.This mode acquires lock on selected rows only,not entire table.Other user can have lock on other rows on the same table but not on the rows you have locked.
3.EXCLUSIVE  - High priority mode if this lock is enabled then one cant do nothing on the table.


SQL> LOCK TABLE STUDENT IN SHARE MODE;

Table(s) Locked.


SQL> LOCK TABLE STUDENT IN SHARE UPDATE MODE;

Table(s) Locked.


SQL> LOCK TABLE STUDENT IN EXCLUSIVE MODE;




WHERE CURRENT OF

should be used only with cursors and locked with for update option



is the latest craze. for more info explore the link above...

you can even look at www.annuniv.edu for more info