Search This Blog

Friday 17 October 2014

JQuery Colorbox Demo

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
  <style>
body{font:12px/1.2 Verdana, sans-serif; padding:0 10px;}
a:link, a:visited{text-decoration:none; color:#416CE5; border-bottom:1px solid #416CE5;}
h2{font-size:13px; margin:15px 0 0 0;}
</style>
<script src="js/jquery-1.8.1.js"></script>
<script src="js/jquery.colorbox.js"></script>
<link rel="stylesheet" href="js/colorbox.css" />
  <SCRIPT LANGUAGE="JavaScript">
  <!--
  $(document).ready(function () {
   jQuery('<div id="close" style="cursor: pointer; position: absolute; top: 0; right: 2px;"><img src="close.png" alt="close"/></div>').appendTo('#contentdiv');
$("#close").click(function() {
            jQuery('#cboxClose').click();
        });

$('#colrboxanchor').click(function () {
$("div#contentdiv").colorbox({
'href':'div#contentdiv',
'top':50,
'left':100,
'inline':true,
'width':400,
'height':400,
'opacity':0.3,
overlayClose:false,
'open':true,
onComplete: function() {
$(this).focus();
},
onClosed:function(){
                    $.colorbox.remove();
                }
});
});
  $('#btn').click(function () {
  alert("1111111111111");
  });
  });

    //-->
  </SCRIPT>
 </HEAD>

 <BODY>
 <div>
<div style="display:none">
<div id="contentdiv">
          <p>div content from request.<br/>welcome to colorbox<br/>It is lightweight jquery box(popup)</br></p>
</div>
</div>
<a  href="#" id="colrboxanchor">Click here to get colorbox popup</a>
<INPUT TYPE="button" id="btn" value="Click"/>
</div>
 </BODY>
</HTML>

Monday 18 August 2014

Steps to Configure Tiles in Spring & Struts2 Applications



  Steps to Configure Tiles in Spring Application
  

Step 1: Add tiles Jars to lib folder
Step 2:  Create tiles.xml file

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
  "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"
  "http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd">
<tiles-definitions>
    <definition name="baseLayout" template="/jsp/baselayout.jsp">
        <put name="title" value="" />
        <put name="header" value="/jsp/header.jsp" />
        <put name="leftPannel" value="/jsp/leftPannel.jsp" />
        <put name="body" value="" />
        <put name="footer" value="/jsp/footer.jsp" />
    </definition>
    <definition name="homepage" extends="baseLayout">
        <put name="title" value="Welcome" />
        <put name="body" value="/jsp/welcome.jsp" />
    </definition>
    <definition name="searchpage" extends="baseLayout">
        <put name="title" value="Welcome" />
        <put name="body" value="/jsp/searchpage.jsp" />
    </definition>
</tiles-definitions>


Step 3: Spring beans configuration

 <!-- Configures the tiles defintions file -->
    <bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tile/tiles-def.xml</value>
            </list>
        </property>
    </bean>

    <!-- view mappings from localized classpath files -->
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass">
            <value>
                org.springframework.web.servlet.view.tiles.TilesJstlView
            </value>
        </property>
    </bean>

Step 4: Create baselayout.jsp and create all required jsp pages

<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><tiles:insert name="title" ignore="true" /></title>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%" align="center">
    <tr height="15%">
        <td><tiles:insert name="header" />
        </td>
    </tr>
    <tr height="75%">
    <td>
        <TABLE border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
        <TR>
            <td height="80%" width="20%"><tiles:insert name="leftPannel" /></td>
            <td width="80%">
                <table>
                    <tr  height="100%">
                        <td>
                            <tiles:insert name="body" />
                        </td>
                    </tr>
                </table>
            </td>
        </TR>
        </TABLE>
    </td>       
    </tr>
    <tr height="10%">
        <td><tiles:insert name="footer" />
        </td>
    </tr>
</table>
</body>
</html>







Step 5: Create & Return model and view object with tiles definition in controller class

            return new ModelAndView("homepage");

Steps to Configure Tiles in Struts 2 Application

Step 1: Add tiles Jars to lib folder


Step 2: web.xml configuration

   <listener>
        <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
    </listener>

    <context-param>
        <param-name>tilesDefinitions</param-name>
        <param-value>/WEB-INF/tiles.xml</param-value>
    </context-param>

Step 3: Struts 2 action configuration 

<package name="default" namespace="/" extends="struts-default">
<result-types>
    <result-type name="tiles"
        class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<action name="ajaxRequestForJsp">
            <result name="successtype="tiles">/ajaxRequestForJsp</result>
</action>
</package>

Step 4:  Create tiles.xml file

<?xml version="1.0" encoding="UTF-8" ?>  
<!DOCTYPE tiles-definitions PUBLIC       
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"       
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
    <definition name="baseLayout" template="/jsp/baselayout.jsp">
        <put-attribute name="title" value="" />
        <put-attribute name="header" value="/jsp/header.jsp" />
        <put-attribute name="leftPannel" value="/jsp/leftPannel.jsp" />
        <put-attribute name="contentbody" value="" />
        <put-attribute name="footer" value="/jsp/footer.jsp" />
    </definition>
    <definition name="/ajaxRequestForJsp" extends="
baseLayout">
        <put-attribute name="
contentbody" value="/jsp/ajaxJspResponse.jsp" />
    </definition>
</tiles-definitions>  


 Step 5: Create baselayout.jsp and create all required jsp pages


<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="css/ajaxdemocss.css" rel="stylesheet" type="text/css" />
<SCRIPT LANGUAGE="JavaScript" src="javascript/ajax_javascript.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" src="javascript/jquery-1.8.1.js"></SCRIPT>
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%" align="center">
    <tr height="15%">
        <td><tiles:insertAttribute name="header" />
        </td>
    </tr>
    <tr height="75%">
    <td>
        <TABLE border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
        <TR>
            <td height="80%" width="10%"><tiles:insertAttribute name="leftPannel" /></td>
            <td width="90%">
                <table border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">
                <tr height="70%"><td><tiles:insertAttribute name="contentbody" /></td></tr>
                </table>
            </td>
        </TR>
        </TABLE>
    </td>       
    </tr>
    <tr height="10%">
        <td><tiles:insertAttribute name="footer" />
        </td>
    </tr>
</table>
</body>
</html>

Thursday 31 July 2014

Steps to configure log4j in spring & struts 2 application

Steps to configure log4j in spring application
***********************************************

Step 1: log4j.properties - needs to place under class path
============================================


#loggging file details for Log4jProperties
log4j.rootCategory=DEBUG,fileAppender
log4j.appender.fileAppender=org.apache.log4j.RollingFileAppender
log4j.appender.fileAppender.File=${jboss.server.home.dir}/log/myAppLog.log
log4j.appender.fileAppender.Encoding=UTF-8
log4j.appender.fileAppender.layout.ConversionPattern=%-4d %-C : %M - %m%n
log4j.appender.fileAppender.layout=org.apache.log4j.PatternLayout


Step 2: Add jars to lib folder
=======================================


Step 3: web.xml - Log4jConfigListener configuration
=======================================


<listener>
   <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

Step 4: Declare Member Log variable in java calss
======================================

 private final Log       logger  = LogFactory.getLog(getClass());

Step 5: Following logger methods is used to log logger-messages
================================================
=
logger.debug("Controller method");
logger.error("Controller method");
logger.warn("Controller method");
logger.info("Controller method");



Struts 2 Application Log4j Configuration:
*****************************************

Do steps 1, 2, 4, 5

Thursday 24 July 2014

SQL_PL_SQL

Nth max salary query:

Select salary
From Employee E1
Where (N-1) = (
                                 Select Count(Distinct(E2.Salary))
                                 From Employee E2
                                 Where E2.Salary > E1.Salary

                              )

Partitioned tables:

Oracle allow to divide the rows of a table into multiple parts. Dividing a tables data in this manner is called partitioned table.

Creating table: To create a partitioned table, you have to specify how to set up the partitions of the tables data as part of the create command.

Typically tables are partitioned by range of values. To partition the tables records use the "partition by range" clause. The range will determine the values stored in each of the table partition.

Syntax:

create table table_name (column1 data_type(size), column2 data_type(size),.............)
partition by range (column1)
(partition partition_name1 values < some_value,
partition partition_name2 values < some_value,
partition partition_name2 values < some_value,
-----------------------------------------------
-----------------------------------------------);
You do not need to specify a maximum value for the last partition.

Syntax to select data from partition:

select * from table_name partition(partition_name);

Adding Partition:

Adding new partition to table.

Syntax: alert table table_name add partition partition_name values < value;


Dropping  partition:

Removing partition.

Syntax: alert table table_name drop partition partition_name

Splitting partition:

Splitting one partition into two partitions.

Syntax: alter table table_name split partition partition_name at (value) into (partition partition_name1,partition partition_name2);


Moving partitions:

The move clause of the alter table statement is used to move a partition from a most active table space to different table space in order to balance I/O operations.

Syntax: alter table table_name move partition partition_name tablespace table_space_name;


Work load capturing  

sys> begin
         dbms_wokload_capture.start_capture(name=>'Test_cature_1', dir=>'db_reply_1',     
         duration=>null)
         end;
         /
sys> create user test_1 identified by test_1;

sys> grant connect resource1.create table to test_1;

sys> conn test_1/test_1

test_1> create table db_replay(id number, description varchar2(50), constraint db_replay primary 
              key (id));

test_1> begin
              for i in 1..500000 loop
              insert into db_replay(id, description) values (i,'description_test');
              end loop;
              commit;
              end;
              /
Finishing capture process

conn as sysdba

sys> begin
         dbms_workload_capture.finish_capture;
         end;
         /

Selecting work load capture 

sys> dbms_workload_capture.get_capture_info('DB_REPLAY') from dual;

sys> select id,name from dba_workload_captures;


SQL * Loader
===================================

SQL Loader loads data from external files into tables in oracle data base.

It requires the following files.
1. Data file
2. Control file


Data File: It contains the information to be loaded
Control File: It tells oracle how to read and load the data. It contains the information on the format of the data, the records and fields within the file, The order in which they are to be loaded. It is created at the OS level.

SQL Loader creates the following files.
1. Log file
2. Bad file

Log File: It records the status of the load, such as the number of rows processed and the number of rows committed.

Bad File: It contains rows that are rejected during the load due to data errors.

Syntax:

LOAD DATA
INFILE 'file_name.extension'
BADFILE 'PATH/bad_file_name.bad'
[TRUNCATE | APPEND| INSERT | REPLACE]
INTO TABLE table_name  fields terminated by "," // instead of "," you can specify your delimiter
( column1, column2, column3,.................)

Here column1, column2, column3...................... are names of table column name.
These must be equal to table field names.

TRUNCATE: This clause truncates the table before starting.
APPEND: This clause adds the rows to the table.
INSERT:  This clause adds the rows to an empty table. The load will abort with an error if the table is not empty.
REPLACE: This clause empties the table and then adds the new rows. The user must have DELETE privilege on the table.


Checkpoint Process

CKPT updates the headers of all data files to record the details of the check point.

System Monitor Process  

It performs recovery and also responsible for clean up temporary segments that are no longer in use and for unite contiguous free extents within dictionary managed table spaces. It checks regularly to see whether recovery is needed.

BULK COLLECT AND FORALL

BULK COLLECT: It retrieve multiple rows at a time in single fetch
FORALL: it performes multiple INSERTs | UPDATEs | DELETEs at a time.
Example:
Procedure insertempproc() is
   CURSOR emp_cur IS
      SELECT employee_id
        FROM emp;
cur_limit PLS_INTEGER := 1000;
TYPE multi_cols_pslqltable IS RECORD
(
emp_id   emp.emp_id%TYPE,
emp_name emp.ename%TYPE,
sal        emp.sal%TYPE
);
TYPE multi_cols_pslqltab IS TABLE OF multi_cols_pslqltable;
multi_cols_pslqltab_varr   multi_cols_pslqltab;
BEGIN
open emp_cur;
LOOP
begin
FETCH employees_cur
BULK COLLECT INTO multi_cols_pslqltab_varr
LIMIT c_limit;
       EXIT WHEN multi_cols_pslqltab_varr.COUNT = 0;
FORALL IND IN multi_cols_pslqltab_varr.FIRST..multi_cols_pslqltab_varr.LAST  SAVE              EXCEPTIONS
INSERT INTO EMP_NEW(EMPID,NAM, SAL, CMANE ) VALUES
(multi_cols_pslqltab_varr(IND).emp_id,multi_cols_pslqltab_varr(IND).emp_name,multi_c                  ols_pslqltab_varr(IND).'xyz');
EXCEPTION
  WHEN DUP_VAL_ON_INDEX THEN
  NULL;
end;
   END LOOP;
insertempproc END;


Tuesday 22 July 2014

Hibernate Interceptor & query with parameter




Hibernate Interceptor



Hibernate interceptor allows application to change properties of a entity object before save, update, delete, or load. It allows to control follow or stop.
 
Attaching interceptor reference to hibernate session
==============================================

public int additeam(Item item) {
        Integer itemCode = 0;
        try {
            ItemInterceptor itemInterceptor = new ItemInterceptor();
            session = sessionFactory.openSession(itemInterceptor);

            transaction = session.beginTransaction();
            log.info("Before addItem - Dao");
            itemCode = (Integer) session.save(item);
            transaction.commit();
        } catch (HibernateException hibernateException) {
            transaction.rollback();
            log.info(hibernateException.getMessage());
        } finally {
            session.close();
        }
        return itemCode;
    }

Hibernate Interceptor -  Class Implementation:
=======================================
package com.xyz.interceptor;

import java.io.Serializable;
import org.hibernate.EmptyInterceptor;
import org.hibernate.type.Type;
import com.xyz.dto.Item;

public class ItemInterceptor extends EmptyInterceptor {
    /**
     * Pedababu M
     */
    private static final long serialVersionUID = 1L;
    private final Log   log  = LogFactory.getLog(getClass());
    public boolean onSave(Object entity, Serializable id, Object[] state,
            String[] propertyNames, Type[] types) {
        log.info("Before the  "+entity.getClass()+"   onSave....");
        log.info("getName "+entity.getClass().getName()+"   onSave....");
        log.info("getModifiers "+entity.getClass().getModifiers()+"   onSave....");
        log.info("S ID :" + id);
        for (int index = 0; index < state.length; index++) {
            log.info(state[index]);
        }
        //chnaging discount before saving - in interceptor
        if (entity instanceof Item) {
            ((Item) entity).setDiscount(10);
        }

        return super.onSave(entity, id, state, propertyNames, types);
    }
}



onDelete – This method is called before delete entity object
onLoad – This method is called before entity object initialization.
etc.


Query with parameter
================

        List<Item> itemList = null;
        Session session = null;
        try {
            session = sessionFactory.openSession();
            session.beginTransaction();
             Query query =session.createQuery("from Item item where item.itemId=:itemId");
             query.setParameter("itemId", itemNo);
             itemList =query.list();
            log.info("itemList size::::" + itemList.size());
            Iterator<Item> it = itemList.iterator();
            while (it.hasNext()) {
                Item t = it.next();
                log.info(t.getItemId() + "   " + t.getItemName());
            }
        } catch(Exception exception){
            exception.printStackTrace();
        }
        finally {
            session.close();
        }