Wednesday, 27 July 2016

Web Storage API : Local Storage


I am going to explain web storage API specially Local Storage today. Its just awesome.

There are three types of storage :

1) Session Storage : available for your websites only and valid till browser is open or reloads or restores/

2) Local Storage : available for your website only and valid while browser is closed and opened again.

3) There is global storage also which is accessed by all of the websites in your browser.

Testing for support vs availability :
Browsers which support localStorage will have a property with the window object named localStorage. But, for various reasons, just asserting that property exists may throw exceptions. so you might want to check it in a try catch so that it does not break the flow.

Like :
function storageAvailable(type) {
 try {
  var storage = window[type],
   x = '__storage_test__';
  storage.setItem(x, x);
  storage.removeItem(x);
  return true;
 }
 catch(e) {
  return false;
 }
}

Then you do a check and do your work.
if (storageAvailable('localStorage')) {
   var storage = window['localStorage'];
      storage.clear(); storage.setItems("test", "test");
}
else {
 // Too bad, no localStorage for us
}

And other things which you should keep in mind while working with local storage :
1) You can only store strings in the local storage. If you need to store objects use JSON.Stringify.
2) clear your local storage by clear() method.
3) When you put data into local storage by usingstorage.setItems("test", "test"), you should do it in a try catch as it can also give exception if not enough memory.
4) You can run the web storage test to find out how much memory you have with your browser.
Run Test for Storage
5) When you clear the history , it calls storage.clear(), something you can do in production environment.

GraphQL : WOW

GraphQL : easy to understand, go away with the pain of REST API, tight coupling, low cohesion.
-Ability to use fragment.
-Query structure is almost like resultset returns what is asked and nothing else
-validation on columns.
-declarative and hierarchical data requirements
-No round trips and joins as compared to REST
-documentation updates

https://www.youtube.com/watch?v=Wq02BNrN1dU

Sunday, 24 July 2016

GTT Global Temporary table : Java Interview

What are Global temporary tables and its uses :

 I worked on Global temporary table functionality recently and wanted to share a few experience.

Temporary tables are tables which live for a session only.The data for them is available for a session. There are various other options available with them which we will discuss below by taking an example of IBM DB2.

There are two ways of creating a Temporary table.

1) Declaring Global temporary table.
2) Creating Global Temporary table :


1) Declare GTT : Declare GTT is like a table created for a session only and its description is dropped
after session ends with DB. It has various advantages over Create GTT like

  • It does not need to worry about dropping it after our work is done.
  • The description can unique per session.
  • Constraints and Indexes can be created on Declared GTT.
  • Its like a table created per session and lives only for that session. The same is applicable for its data also.
2) Create GTT : Create GTT is a table which is created as a table , you will find its definition and description after the session ends and we connect to the DB again.
  • It needs to be dropped of you do not need it forward.
  • The description resides in DB after the session ends , so it is not unique per session. The data in it is unique per session.
  • Constraints and indexes can NOT be created.
  • Its like a table created in DB only and the data is created per session. So data from one session is unique instead on description as compared to DGTT. The data entered in one session will not be seen by other.

Example :


 DECLARE GLOBAL TEMPORARY TABLE MY_TEMP
    (ID BIGINT NOT NULL,
    AGE INTEGER
    ON COMMIT PRESERVE ROWS
    NOT LOGGED WITH REPLACE ON ROLLBACK DELETE ROWS ; 

Let me explain the main features which are used mostly : 
 ON COMMIT PRESERVE ROWS : On Committing the data the rows are preserve in session.

 I found this pretty useful in  case  of you are doing batch save and sending transaction in batches while saving large amount of data.

 ON COMMIT PRESERVE ROWS : save a result set in it and use it then delete.

WITH REPLACE : If a table with that name exists already, it will be deleted and created again. You can say it as truncate. This is not able if you are using CREATE  GLOBAL TEMPORARY TABLE

ON ROLLBACK DELETE ROWS : Once a  Rollback to a save point, the rows will be deleted.

GTT are  also used in Store procedure if you dont want to make a query to fetch something you have already fetched once, store it in a GTT .

Happy Coding.







Friday, 15 July 2016

Common HR interview questions.

best interview questions :

Hammer and Nail

crossing the dessert

These are some of the best interview questions, top companies ceo ask, do prepare for it. Never go all technically prepared. Some times interviews go out of syllabus too, lol.

Tuesday, 12 July 2016

SQL Best Practices : Java Interview

Best read for any SQL developer and how to optimize and increase your performance :

1) 10 Best Practices : SQL

2) 7 DO and DONTS : SQL

Please comment down below in case if you have more good articles.

Friday, 8 July 2016

Java Interview Questions : CTE Common Table Expression.

Q: What is CTE and how does it help in Improving the performance.

A : CTE as Common Table Expression. They are also called disposable Views. But there are some difference too. Like CTE can be recursive and can not be indexed. They tend to use the Existing indexes.

Syntax :

With cte as (select * from table1)

select * from table2  join cte on cte.key1 = table2.key2

----------------------------------------------------------------------

They are just like a table, so you can join on them and can not use them in where clause.
They can basically used to write neat SQL. But if you have some table calls written repetitive in lots of joins , you can put them in a CTE and use CTE. I have seen lots of performance in SQL optimization in this case.
 For any questions i can help you with CTE problems, please comment down below.