Monday, May 2, 2011

Dealing with JavaScript browser compatibility issue

The best way to deal with browser compatibility issue is to use following frameworks, which provide java script code that work well with most of the browsers

Dojo Toolkit is an open source modular JavaScript library (or more specifically JavaScript toolkit) designed to ease the rapid development of cross-platform, JavaScript/Ajax-based applications and web sites. More information about it can be found at the below links -

http://dojotoolkit.org/
http://dojotoolkit.org/api/
http://dojotoolkit.org/widgets
http://dojotoolkit.org/grids-charts
http://dojotoolkit.org/documentation/

Google Web Toolkit (GWT) -Google Web Toolkit (GWT) is an open source set of tools that allows web developers to create and maintain complex JavaScript front-end applications in Java. Other than a few native libraries, everything is Java source that can be built on any supported platform with the included GWT Ant build files
GWT emphasizes reusable, efficient solutions to recurring Ajax challenges, namely asynchronous remote procedure calls, history management, bookmarking, internationalization and cross-browser portability.

More information can be found at the blow links -
http://code.google.com/webtoolkit/
http://code.google.com/webtoolkit/gettingstarted.html



Monday, April 18, 2011

Must know java Concepts

Annotation  - Annotation is one of the features which (are being and) would be extensively used in various java frameworks and technologies.  Below links provide overview of Annotation -

http://download.oracle.com/javase/tutorial/java/javaOO/annotations.html
http://download.oracle.com/javase/1.5.0/docs/guide/language/annotations.html
http://download.oracle.com/javase/6/docs/technotes/guides/language/annotations.html
http://www.developer.com/java/other/article.php/3556176/An-Introduction-to-Java-Annotations.htm
http://www.programmingforfuture.com/2008/11/self-descriptive-coding-in-java.html
http://www.java2s.com/Code/Java/Language-Basics/JavaAnnotationAnnotationandReflection.htm

Annotation in EJB- http://www.oracle.com/technetwork/articles/javaee/jpa-137156.html
Metadata Annotation - http://download.oracle.com/javaee/6/tutorial/doc/girdd.html
Java ee 5 Annotation - http://download.oracle.com/javaee/5/tutorial/doc/idx-1.html

Wednesday, April 13, 2011

Using POSIX (Portable Operating System Interface [for Unix])



POSIX (Portable Operating System Interface [for Unix])  - http://en.wikipedia.org/wiki/POSIX

Cygwin - Cygwin is -
  • a collection of tools which provide a Linux look and feel environment for Windows.
  • a DLL (cygwin1.dll) which acts as a Linux API layer providing substantial Linux API functionality. 
more details for cygwin can be found in the below link - http://www.cygwin.com/


Setting path in Cygwin - http://cygwin.com/faq-nochunks.html#faq.using.path
Converting windows & unix paths - http://cygwin.com/faq-nochunks.html#faq.using.converting-paths
Why not install Cygwin in c - http://cygwin.com/faq-nochunks.html#faq.setup.c
Updating home variable - http://cygwin.com/faq-nochunks.html#faq.setup.home
Registry information of cygwin - http://cygwin.com/faq-nochunks.html#faq.setup.registry
Checking Cygwin version - http://cygwin.com/faq-nochunks.html#faq.what.version
Accessing drives using Cygwin - http://cygwin.com/faq-nochunks.html#faq.using.accessing-drives
Copy and paste in Cygwin - http://cygwin.com/faq-nochunks.html#faq.using.copy-and-paste
How does Cygwin work - http://cygwin.com/faq-nochunks.html#faq.api.everything
Updating log on information - http://cygwin.com/faq-nochunks.html#faq.setup.name-with-space

Cygwin/X "X Windows - on Windows!" -  More info about it can be found at below link - http://x.cygwin.com/
http://x.cygwin.com/screenshots/

Wednesday, April 6, 2011

Useful links for creating client side (web-browser) utilities

Links for tutorial -
Java Script -
http://www.devguru.com/technologies/JavaScript/home.asp
                     
http://krook.org/jsdom/
Links providing re-usable code


http://www.javascriptkit.com/cutpastejava.shtml
http://www.dynamicdrive.com/

Creating Sliding form effects using J-Query -
http://www.dynamicdrive.com/dynamicindex16/formwizard.htm

Dom drag and drop script -
http://www.dynamicdrive.com/dynamicindex11/domdrag/

Imbeding Google Map Selector-
http://www.dynamicdrive.com/dynamicindex11/googlemapselector.htm

Creating pi graph-
http://www.dynamicdrive.com/dynamicindex11/piegraph.htm

Creating line graph-
http://www.dynamicdrive.com/dynamicindex11/linegraph.htm

Tic Tak Toe-
http://www.dynamicdrive.com/dynamicindex12/tictactoe.htm

Zooming the image-
http://www.dynamicdrive.com/dynamicindex4/featuredzoomer.htm

gAjax RSS Pausing Scroller
http://www.dynamicdrive.com/dynamicindex18/gajaxpausescroller.htm

Performing get and post from Ajax-
http://www.javascriptkit.com/dhtmltutors/ajaxgetpost.shtml

Using Object detection to sniff out different browsers -
http://www.javascriptkit.com/javatutors/objdetect3.shtml

AutoSelect Increment Search
http://www.codeproject.com/KB/scripting/Auto_select_Dropdown.aspx

Dojo UI Widgets - 
http://dojotoolkit.org/widgets

Field selection or identifying the start/end position in text area
http://laboratorium.0xab.cd/jquery/fieldselection/0.1.0/test.html
http://web.archive.org/web/20080214051356/http://www.csie.ntu.edu.tw/~b88039/html/jslib/caret.html

Making the webpages non copiable
http://javascript.internet.com/page-details/disable-text-selection.html

Adding encrypt or decrypt capability in web app using java Script  -
http://javascript.about.com/library/blencrypt.htm

Implementing various widgets using Dojo - 
Tree - http://dojotoolkit.org/reference-guide/dijit/Tree.html
Grids & Chart  -http://dojotoolkit.org/grids-charts
Various Widgets - http://download.dojotoolkit.org/release-1.6.1/dojo-release-1.6.1/dijit/themes/themeTester.html

Other useful information -
  1. Changing the mouse cursor type in runtime using javascript
  2. Changing the mouse cursor type using CSS
 

Sunday, April 3, 2011

Setting up development environment

Spring Tool Suite - Spring tool suite is eclipse based IDE, which is 100% open source comes with integrated plugins to easy development of spring based apps, m2 eclipse and tomcat optimized for spring apps. As underlying platform is eclipse,one can integrate any plugins that they were fond of using in eclipse.
Download - http://www.springsource.org/sts
http://www.theserverside.com/news/thread.tss?thread_id=67452


Useful plugins -
MoreUnit - http://marketplace.eclipse.org/content/moreunit
Eclemma - http://marketplace.eclipse.org/content/eclemma-java-code-coverage
junithelper - http://code.google.comS/p/junithelper/
sql explorer - http://www.sqlexplorer.org/
               http://www.sqlexplorer.org/screenshots.php
Eclipse Bulk Import -http://code.nomad-labs.com/eclipse-bulk-import/
m2eclipse -http://marketplace.eclipse.org/content/maven-integration-eclipse
AnyEdit Tools - http://marketplace.eclipse.org/content/anyedit-tools
Spring IDE - http://marketplace.eclipse.org/content/spring-ide
Subclipse - http://marketplace.eclipse.org/content/subclipse
Eclipse Color Theme - http://marketplace.eclipse.org/content/eclipse-color-theme
Eclipse Metrics - http://marketplace.eclipse.org/content/eclipse-metrics
Tane (refactoring) - http://marketplace.eclipse.org/content/tane-eclipse-refactorings
Infinitest  - http://marketplace.eclipse.org/content/infinitest
Struts Tools - http://market.eclipsesource.com/yoxos/node/org.jboss.tools.struts_feature.feature.group
JBoss Tools (Helios - jsf, hibernate, Freemarker, ESB) -http://marketplace.eclipse.org/content/jboss-tools-1
WindowBuilder Pro GUI Designer -http://marketplace.eclipse.org/content/windowbuilder-pro-gui-designer
jd- eclipse (java decompiler) - http://java.decompiler.free.fr/?q=jdeclipse 
Google Web Toolkit SDK 2.0.0, Google Webtoolkit(GWT) Tooling, Google Plugin for Eclipse 2.2  - These are plugins for GWT, available at eclipse market places
Groovy eclipse plugin - http://groovy.codehaus.org/
Springsource tool suits

 JDT Decompiler


Selecting the jvm to be used to run eclipse -
 
eclipse -vm "C:\Program Files\Java\jdk1.7.0_06\bin\javaw"

It's generally a good idea to explicitly specify which Java VM to use when running Eclipse. This is achieved with the "-vm" command line argument as illustrated above. If you don't use "-vm", Eclipse will look on the O/S path. When you install other Java-based products, they may change your path and could result in a different Java VM being used when you next launch Eclipse.

Providing proxy settings in Helios- Settings can be edited at the following path - Windos -> Preferences  -> General -> Network Connections
Firefox - As a developer you will need the following add Ons - Fastest Fox, Firebug, IE Tab, IE View, iMacros , YSlow, JavaScript Debugger, View Source Chart,Web Developer,Toggle Web Developer Toolbar,ColorZilla,FlashFirebug,XPath Checker (For xpath with name space),FirePath (Xpath without name space),fox tab, themes menu, MacOSX Theme,printpdf, save as pdf., memory fox, Easy YouTube Video Downloader 6.4

MS DOS - Command to view the value of a system variable - echo %jvariable_name%
    Command to set the value of a system variable  - set  variable_name  "variable_value"
    Command to view the value of all the variables  - set

Tools - Fiddler (Tool to log Http(s) traffic), windows grep (To use grep in windows), sdedit (Tool to create sequence diagram)

Useful info -
  1. Converting html pages to PDF
  2. Creating eclipse templates of toString, equals, hashCode and compareTo implementation using org.apache.commons.lang
  3. Identifying whether RAM upgrade is needed


Friday, April 1, 2011

Creating mock objects for Test Driven Development

EasyMock - EasyMock provides Mock Objects for interfaces (and objects through the class extension) by generating them on the fly using Java's proxy mechanism. Due to EasyMock's unique style of recording expectations, most refactorings will not affect the Mock Objects. So EasyMock is a perfect fit for Test-Driven Development.

http://easymock.org/index.html
http://easymock.org/EasyMock3_0_Documentation.html

Mockito - Mockito library enables mocks creation, verification and stubbing.

http://mockito.org/
http://docs.mockito.googlecode.com/hg/org/mockito/Mockito.html

JMock- JMock is a library that supports test-driven development of Java code with mock objects.

http://www.jmock.org/
http://www.jmock.org/cheat-sheet.html
http://www.jmock.org/cookbook.html

Friday, March 25, 2011

Queries for debugging Oracle database issues

Accessing database as another user -
alter session set current_schema=schemaName;

Name of Users or Role having access to any database object
select * from USER_TAB_PRIVS_MADE where table_name='Object_name;
select * from DBA_TAB_PRIVS where table_name='Object_name';

Primary key columns of a table -
select * from all_cons_columns a join all_constraints c on a.constraint_name = c.constraint_name where c.table_name = 'table_name' and c.constraint_type = 'P'

Foreign key columns of a table -
select * from all_cons_columns a join all_constraings c on a.constraint_name = c.constraint_name where c.table_name = 'table_name' and c.constraint_type = 'R'

Query to compile the database objects
exec dbms_ddl.alter_compile ('Object_name','Schema_name','Object_name');
OR
alter object_type object_name compile;


Query to compile schema
exec dbms_utility.compile_schema('SchemaName');

Query to create compile statements for invalid objects in a schema-

Select  'alter '||object_type||'  '||object_name||' compile;'
From user_objects
Where status <> 'VALID'
And object_type IN ('VIEW','SYNONYM',
'PROCEDURE','FUNCTION',
'PACKAGE','TRIGGER');

SQL Block to empty the schema -

declare
  cursor c_obj
  is
    SELECT u1.object_type
    ,      u1.object_name
    FROM   user_objects u1
    where  u1.object_type not in ( 'PACKAGE BODY','TYPE BODY', 'INDEX', 'TRIGGER', 'UNDEFINED', 'LOB','TABLE PARTITION','LOB PARTITION','INDEX PARTITION')
    and    ( u1.object_type <> 'TABLE' or u1.object_name not like 'BIN%')
    and not EXISTS (select 'x' from  user_objects u2 where u1.object_type='TABLE' AND U2.OBJECT_TYPE='MATERIALIZED VIEW' AND U1.OBJECT_NAME=U2.OBJECT_NAME);

  l_execute varchar2(2000);
begin
  for r_obj in c_obj loop
     l_execute:= 'drop '||r_obj.object_type||' '||r_obj.object_name;
     if r_obj.object_type = 'TABLE'
     then
       l_execute:= l_execute || ' CASCADE CONSTRAINTS';
     end if;
     EXECUTE IMMEDIATE l_execute;
  end loop;
end;
/
purge recyclebin;
 SQL block to truncate all tables in schema

set serveroutput on size unlimited;
declare
begin

for c1 in (select y.table_name, y.constraint_name from user_constraints y, user_tables x where x.table_name = y.table_name and y.constraint_type='R') loop
    begin
        dbms_output.put_line('alter table '||c1.table_name||' disable constraint '||c1.constraint_name || ';');
        execute immediate  ('alter table '||c1.table_name||' disable constraint '||c1.constraint_name);
    end;
end loop;

for t1 in (select table_name from user_tables) loop
    BEGIN
        dbms_output.put_line('truncate table '||t1.table_name || ';');
        execute immediate ('truncate table '||t1.table_name);
    end;
end loop;

for c2 in (select y.table_name, y.constraint_name from user_constraints y, user_tables x where x.table_name = y.table_name and y.constraint_type='R') loop
    BEGIN
        dbms_output.put_line('alter table '||c2.table_name||' enable constraint '||c2.constraint_name || ';');
       execute immediate ('alter table '||c2.table_name||' enable constraint '||c2.constraint_name);
    end;
END loop;

end;
/
 SQL block to rebuild all indexes in schema

set serveroutput on size unliminited
declare 
 v_index_name VARCHAR2(200);
begin
  for v_index_name in (select OBJECT_NAME  index_name from user_objects where object_type='INDEX')
   LOOP
      BEGIN
--      dbms_output.put_line('ALTER INDEX '|| v_index_name.index_name ||' REBUILD'||' ;' );
        execute immediate('ALTER INDEX '|| v_index_name.index_name ||' REBUILD' );
      EXCEPTION WHEN OTHERS THEN
        dbms_output.put_line('ALTER INDEX '|| v_index_name.index_name ||' REBUILD'||' ; -------- failed');
        dbms_output.put_line('Error message = '||SQLERRM);
      END;
  end LOOP;
end;
/
 SQL block to check if any table in schema has records

set serveroutput on size unlimited;
DECLARE
v_record_count NUMBER;
begin
  for t1 in (select table_name from user_tables) loop
      BEGIN
          v_record_count:=0;
          EXECUTE IMMEDIATE ('select count(*) from '||t1.table_name) INTO v_record_count ;
          IF v_record_count>0
            THEN
            dbms_output.put_line('select count(*) from '||t1.table_name || ';');
            dbms_output.put_line( t1.table_name || ' has ' || v_record_count || ' records'); 
          END IF;
      end;
  end loop;
end;
/
 SQL Procedure, an alternate way to provide kill session privilege

create or replace procedure kill_session (pn_sid    number ,pn_serial number)
as
 lv_user varchar2(30);
begin
 select username into lv_user from v$session where sid = pn_sid and serial# = pn_serial;
 if lv_user is not null and lv_user not in ('SYS','SYSTEM') then
  execute immediate 'alter system kill session '''||pn_sid||','||pn_serial||'''';
 else
  raise_application_error(-20000,'Attempt to kill protected system session has been blocked.');
 end if;
end;
/

Checking the oracle version -  
select * from v$version where banner like 'Oracle%' ;

Checking available directory objects -
select * from all_directories 

Query to check the last refresh time of materialized view
SELECT owner, mview_name, to_char(last_refresh_date, 'dd/mm/yy hh24:mi:ss') Last_Refresh From   All_Mviews

Checking priviliges in directory object -
select  grantor, grantee, table_schema, table_name, privilege from all_tab_privs where table_name = upper('&directoryObjectName')

Checking the space occupied by a table -
select TABLE_NAME, ROUND((AVG_ROW_LEN * NUM_ROWS), 2) SIZE_BYTE, ROUND((AVG_ROW_LEN * NUM_ROWS / 1024), 2) SIZE_KB,ROUND((AVG_ROW_LEN * NUM_ROWS /(1024*1024)), 2) SIZE_MB from USER_TABLES where NUM_ROWS is not null order by SIZE_KB desc


Other useful info for debugging issues -
  1. Query to find blocking sessions
  2. Oracle system tables 
  3. Disable interactive prompts at SQL*Plus
  4. Setting materilized view to refresh on demand (manually)
  5. Refreshing materialized view manually
  6. Monitoring and managing temporary table spaces  
  7. Analyzing the table for faster insert and select
  8. Setting oracle server output on with unlimited size
  9. Managing oracle recycle bin and retrieve already dropped object
  10. Recycle bin data dictionary table (USER_RECYCLEBIN)
  11. When oracle index should be rebuild
  12. Debugging oracle units using SQL Developer 


Giving output number format of a query - http://ss64.com/ora/syntax-numfmt.html

Link to refer to take DB dump -
Taking DB dump (using expdp) -
http://www.oracle-base.com/articles/10g/OracleDataPump10g.php
Taking DB dump (using exp) -

http://www-it.desy.de/systems/services/databases/oracle/impexp/impexp.html.en
http://www.taooforacle.com/my-cool-tricks/how-to-handle-exp-00091-exporting-questionable-statistics-error.html
http://www.dba-oracle.com/t_exp_0002.htm

Thursday, March 24, 2011

Implementing connection pool in java

DBCP (Database Connection Pool API)
Many Apache projects support interaction with a relational database. Creating a new connection for each user can be time consuming (often requiring multiple seconds of clock time), in order to perform a database transaction that might take milliseconds. Opening a connection per user can be unfeasible in a publicly-hosted Internet application where the number of simultaneous users can be very large. Accordingly, developers often wish to share a "pool" of open connections between all of the application's current users. The number of users actually performing a request at any given time is usually a very small percentage of the total number of active users, and during request processing is the only time that a database connection is required. The application itself logs into the DBMS, and handles any user account issues internally.

There are several Database Connection Pools already available, both within Apache products and elsewhere. This Commons package provides an opportunity to coordinate the efforts required to create and maintain an efficient, feature-rich package under the ASF license.

Spring bean definition of DBCP -
    <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${JDBC_DRIVER_CLASSNAME}" />
        <property name="url" value="${JDBC_URL}" />
        <property name="username" value="${JDBC_USERNAME}"/>
        <property name="password" value="${JDBC_PASSWORD}" />
        <property name="initialSize" value="20" />
        <property name="maxIdle" value="30" />
        <property name="maxActive" value="50" />
        <property name="maxWait" value="120000" />
     <property name="removeAbandonedTimeout" value="10" />
        <property name="removeAbandoned" value="true" />
    </bean>

Maven Dependency
 <dependency>
  <groupId>commons-dbcp</groupId>
  <artifactId>commons-dbcp</artifactId>
  <version>1.4</version>
 </dependency>

http://commons.apache.org/dbcp/configuration.html

Wednesday, March 23, 2011

Implementing continuous integration process

Cruise Control - CruiseControl is both a continuous integration tool and an extensible framework for creating a custom continuous build process. It includes dozens of plugins for a variety of source controls, build technologies, and notifications schemes including email and instant messaging. A web interface provides details of the current and previous builds. And the standard CruiseControl distribution is augmented through a rich selection of 3rd Party Tools.

http://cruisecontrol.sourceforge.net/

Hudson -Hudson monitors executions of repeated jobs, such as building a software project or jobs run by cron. Among those things, current Hudson focuses on the following two jobs:
  1. Building/testing software projects continuously, just like CruiseControl or DamageControl. In a nutshell, Hudson provides an easy-to-use so-called continuous integration system, making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. The automated, continuous build increases the productivity.
  2. Monitoring executions of externally-run jobs, such as cron jobs and procmail jobs, even those that are run on a remote machine. For example, with cron, all you receive is regular e-mails that capture the output, and it is up to you to look at them diligently and notice when it broke. Hudson keeps those outputs and makes it easy for you to notice when something is wrong

http://download.oracle.com/otn_hosted_doc/jdeveloper/11gdemos/hudsonADF/hudsonADF.html
http://hudson-ci.org/
http://wiki.hudson-ci.org/display/HUDSON/Meet+Hudson
http://wiki.hudson-ci.org/display/HUDSON/Installing+Hudson


Apache Continuum (Continuous Integration and Build Server) - Apache Continuum is an enterprise-ready continuous integration server with features such as automated builds, release management, role-based security, and integration with popular build tools and source control management systems. Whether you have a centralized build team or want to put control of releases in the hands of developers, Continuum can help you improve quality and maintain a consistent build environment.

http://continuum.apache.org/
http://continuum.apache.org/docs/1.3.7/installation/build-agent.html
http://vmbuild.apache.org/continuum/

Luntbuild -Luntbuild is a powerful build automation and management tool. Continuous Integration or nightly builds can be easily set using a clean web interface. Executed builds are well managed using functions such as search, categorization, promotion, patching, deletion, etc. It also acts as a central build artifacts repository and download area for your whole team.

http://luntbuild.javaforge.com/
http://luntbuild.javaforge.com/luntbuild-demo.html

Which one to go for? - Each of these tools have their own pron and cons. You can refer to below link to find a summary of each tool, which would help you to choose the one that suites your need -

http://www.javaworld.com/javaworld/jw-11-2006/jw-1101-ci.html?page=1



Adding encription capability in java applications

Jasypt is a java library which allows the developer to add basic encryption capabilities to his/her projects with minimum effort, and without the need of having deep knowledge on how cryptography works.

http://www.jasypt.org/

Sample code encrypt values - You will need commons-lang-2.3.jar and jasypt-1.6.jar to compile and execute the below program.


import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.EnvironmentStringPBEConfig;

public class MaskPassword
{
    public static void main(String[] args)
    {
        EnvironmentStringPBEConfig conf = new EnvironmentStringPBEConfig();
        conf.setAlgorithm("PBEWithMD5AndDES");
        conf.setPassword("*&^P@ssw0rd*&^W");

        StandardPBEStringEncryptor enc = new StandardPBEStringEncryptor();
        enc.setConfig(conf);

        System.out.println("VLUE_TO_BE_ENCRIPTED Encrypted Value : [" + enc.encrypt("VLUE_TO_BE_ENCRIPTED") + "]");
        System.out.println("nQL5VtGIKhG4mcYg/6U3KJE7Fi7y/SfxsYp7VQIeD54= Decrypted Value : [" + enc.decrypt("toIc7aXUxn6yEHPSWSbYOv7XTbSK8Mjf1OU0JjujV/M=") + "]");
    }
}


Result -
VLUE_TO_BE_ENCRIPTED Encrypted Value : [0PyTACLyIpWoixZmpo7qgBdEkCX41Sw9GgG4gjq8rbQ=]
nQL5VtGIKhG4mcYg/6U3KJE7Fi7y/SfxsYp7VQIeD54= Decrypted Value : [VLUE_TO_BE_ENCRIPTED]


import org.jasypt.util.text.BasicTextEncryptor;

public class MaskPasswordWithBasicTextEncription
{
    public static void main(String[] args)
    {
        String text = "We are using PBEWithMD5AndDES algorithm for encryption";
        System.out.println("Text      = " + text);

        BasicTextEncryptor bte = new BasicTextEncryptor();
        bte.setPassword("*&^P@ssw0rd*&^W");

        String encrypted = bte.encrypt(text);

        System.out.println("Encrypted = " + encrypted);
       
        String original = bte.decrypt(encrypted);
        System.out.println("Original  = " + original);
    }
}

Result -
Text      = We are using PBEWithMD5AndDES algorithm for encryption
Encrypted = X5U1CiNtwaUw/fuXx5FIedALldrW5EUtL9YTQMuwwC4PqpD6bFOuQisc9+lGY3qjnvdKUUAV91owLv3csnSZEw==
Original  = We are using PBEWithMD5AndDES algorithm for encryption