15 April 2009

0 ANT Introduction

Ant is a Java based build tool, similar to make, but with better support for the cross platform issues involved with developing Java applications. Ant is the build tool of choice for all Java projects at Apache and many other Open Source Java projects. Ant can be configured to compile your java source code files, build your deployment JAR and WAR files, unit-test code and create projects javadoc documentation.

Ant 1.6.0 adds a lot of new features, most prominently support for XML namespaces as well as a new concept of Ant libraries that makes use of namespaces to avoid name clashes of custom tasks.

Advantages of Ant

  • Build IN Java, USING Java, and FOR Java
  • Supports Java Tools (javac, javadoc, etc.)
  • XML Build File is Easier to Build, Read, and Maintain than MAKE file
  • Easier to Extend
  • Supports Cross Platform Java Development
  • Ant is much faster than using MAKE ? Each command is a new process
  • Ant runs within the JVM
  • Each command is executed from within JVM
  • Tools like javac are new threads – not new process
  • Compiling large number of java source files is MUCH,MUCH faster with Ant
  • Ant's Debug Options are very helpful
  • XML much easier to read than MAKEFILE
  • User does not need to know all command line interface options to tools that can be called programmatically
  • Even OS-Specific commands can be setup in 'TaskDefs' and/or included from other sources


Installing Ant

Regardless of platform, downloading Ant is the first step to installing the software. The files can be downloaded to a temporary directory and then uncompressed to any desired directory. After the download step, the process differs depending on whether you've downloaded the binary distribution or the source distribution.
Ant does not provide an installation program; it runs from wherever you choose to copy the files and directories. It lists the directories that ultimately get created under your main Ant directory.

Directories provided with Ant
bin - Batch files, Perl scripts, and shell scripts for running Ant.
docs - Ant documentation.
lib - Libraries required by Ant to run.
src - Source code for Ant. Provided only in the source distribution.

BinaryInstallation
The term "binary" just means that everything is compiled and packaged into JAR files for easy execution — you don't need to compile Ant from source.
Steps to install Installation of the binary distribution:
1. Unzip (or untar) the distribution to the desired directory.
2. Set the ANT_HOME environment variable to point to to the ant installation directory.
3. Set the JAVA_HOME environment variable to point to the JDK location.
4. Add ANT_HOME/bin to your system's PATH environment variable.

The ant script uses the ANT_HOME and JAVA_HOME environment variables to configure the CLASSPATH used by the JVM running Ant. If these variables are not set, the startup script attempts to infer the correct values, subject to operating system limitations.

Source Installation

Installing the Ant source distribution requires a little more work than installing the binary distribution. As expected, downloading and uncompressing the distribution is the first step.
You generally want to place the source files in a directory separate from any existing Ant installations. Next, ensure that JAVA_HOME points to the JDK distribution. As with the binary installation, you should also set ANT_HOME and update your PATH.


Type the following command from the source distribution directory:
build -Ddist.dir=destination_directory dist (Windows)
build.sh -Ddist.dir=destination_directory dist (Unix)

The build script creates a complete binary distribution of Ant in the specified destination directory. When omitted, dist.dir defaults to build.

Read More...

0 Basics of DB2_1

Start an instance in DB2

As an instance owner on the host running db2, issue the following command

$ db2start

Stopping the instance in DB2

$ db2stop

Connect to the database as instance owner in DB2

$ db2

As a user of the database:

$source ~instance/sqllib/db2cshrc (csh users)

$ . ~instance/sqllib/db2profile (sh users)

$ db2 connect to databasename

Create a table in DB2

$ db2-> create table employee

(ID SMALLINT NOT NULL,

NAME VARCHAR(9),

DEPT SMALLINT CHECK (DEPT BETWEEN 10 AND 100),

JOB CHAR(5) CHECK (JOB IN ('Sales', 'Mgr', 'Clerk')),

HIREDATE DATE,

SALARY DECIMAL(7,2),

COMM DECIMAL(7,2),

PRIMARY KEY (ID),

CONSTRAINT YEARSAL CHECK (YEAR(HIREDATE) > 1986 OR SALARY > 40500) )


A simple version of create table in DB2

db2-> create table employee ( Empno smallint, Name varchar(30))

Create a schema in DB2

If a user has SYSADM or DBADM authority, then the user can create a schema with any valid name. When a database is created, IMPLICIT_SCHEMA authority is granted to PUBLIC (that is, to all users). The following example creates a schema for an individual user with the authorization ID 'joe'

CREATE SCHEMA joeschma AUTHORIZATION joe

Create an alias in DB2

The following SQL statement creates an alias WORKERS for the EMPLOYEE table:

CREATE ALIAS WORKERS FOR EMPLOYEE

You do not require special authority to create an alias, unless the alias is in a schema other than the one owned by your current authorization ID, in which case DBADM authority is required.

Create an Index in DB2

The physical storage of rows in a base table is not ordered. When a row is inserted, it is placed in the most convenient storage location that can accommodate it. When searching for rows of a table that meet a particular selection condition and the table has no indexes, the entire table is scanned. An index optimizes data retrieval without performing a lengthy sequential search. The following SQL statement creates a non-unique index called LNAME from the LASTNAME column on the EMPLOYEE table, sorted in ascending order:

CREATE INDEX LNAME ON EMPLOYEE (LASTNAME ASC)

The following SQL statement creates a unique index on the phone number column:

CREATE UNIQUE INDEX PH ON EMPLOYEE (PHONENO DESC)

Drop a database in DB2

Db2 drop database sample

Alter tablespace in DB2

Adding a Container to a DMS Table Space You can increase the size of a DMS table space (that is, one created with the MANAGED BY DATABASE clause) by adding one or more containers to the table

space. The following example illustrates how to add two new device containers (each with 40 000 pages) to a table space on a UNIX-based system:

ALTER TABLESPACE RESOURCE

ADD (DEVICE '/dev/rhd9' 10000,

DEVICE '/dev/rhd10' 10000)

The following SQL statement drops the table space ACCOUNTING:

DROP TABLESPACE ACCOUNTING

You can reuse the containers in an empty table space by dropping the table space but you must COMMIT the DROP TABLESPACE command, or have had AUTOCOMMIT on, before attempting to reuse the containers. The following SQL statement creates a new temporary table space called TEMPSPACE2:

CREATE TEMPORARY TABLESPACE TEMPSPACE2 MANAGED BY SYSTEM USING ('d')

Once TEMPSPACE2 is created, you can then drop the original temporary table space TEMPSPACE1 with the command: DROP TABLESPACE TEMPSPACE1

Add Columns to an Existing Table

When a new column is added to an existing table, only the table description in the system catalog is modified, so access time to the table is not affected immediately. Existing records are not physically altered until they are modified using an UPDATE statement. When retrieving an existing row from the table, a null or default value is provided for the new column, depending on how the new column was defined. Columns that are added after a table is created cannot be defined as NOT NULL: they must be defined as either NOT NULL WITH DEFAULT or as nullable. Columns can be added with an SQL statement. The following statement uses the ALTER TABLE statement to add three columns to the EMPLOYEE table:

ALTER TABLE EMPLOYEE

ADD MIDINIT CHAR(1) NOT NULL WITH DEFAULT

ADD HIREDATE DATE

ADD WORKDEPT CHAR(3)

GrantPermissions by Users in DB2

The following example grants SELECT privileges on the EMPLOYEE table to the user HERON:

GRANT SELECT ON EMPLOYEE TO USER HERON

The following example grants SELECT privileges on the EMPLOYEE table to the group HERON:

GRANT SELECT ON EMPLOYEE TO GROUP HERON

GRANT SELECT,UPDATE ON TABLE STAFF TO GROUP PERSONNL

If a privilege has been granted to both a user and a group with the same name, you must specify the GROUP or USER keyword when revoking the privilege. The following example revokes the SELECT privilege on the EMPLOYEE table from the user HERON:

REVOKE SELECT ON EMPLOYEE FROM USER HERON

To Check what permissions you have within the database

SELECT * FROM SYSCAT.DBAUTH WHERE GRANTEE = USER AND GRANTEETYPE = 'U'

SELECT * FROM SYSCAT.COLAUTH WHERE GRANTOR = USER

At a minimum, you should consider restricting access to the SYSCAT.DBAUTH, SYSCAT.TABAUTH, SYSCAT.PACKAGEAUTH, SYSCAT.INDEXAUTH, SYSCAT.COLAUTH, and SYSCAT.SCHEMAAUTH catalog views. This would prevent information on user privileges, which could be used to target an authorization name for break-in, becoming available to everyone with access to the database. The following statement makes the view available to every authorization name:


GRANT SELECT ON TABLE MYSELECTS TO PUBLIC

And finally, remember to revoke SELECT privilege on the base table:


REVOKE SELECT ON TABLE SYSCAT.TABAUTH FROM PUBLIC

Delete Records from a table in DB2

db2-> delete from employee where empno = '001'

db2-> delete from employee

The first example will delete only the records with emplno field = 001 The second example deletes all the records

Import Command in DB2

Requires one of the following options: sysadm, dbadm, control privileges on each participating table or view, insert or select privilege, example:

db2->import from testfile of del insert into workemployee

where testfile contains the following information 1090,Emp1086,96613.57,55,Secretary,8,1983-8-14

or your alternative is from the command line:

db2 " import from 'testfile' of del insert into workemployee"

db2 <>

db2 import from test file of del insert into workemployee

Load Command in DB2

Requires the following auithority: sysadm, dbadm, or load authority on the database:

example: db2 "load from 'testfile' of del insert into workemployee"

You may have to specify the full path of testfile in single quotes

Authorization Level:

One of the following:

sysadm

dbadm

load authority on the database and

INSERT privilege on the table when the load utility is invoked in INSERT mode, TERMINATE mode

(to terminate a previous load insert operation), or RESTART mode (to restart a previous load insert operation)

INSERT and DELETE privilege on the table when the load utility is invoked in REPLACE mode,

TERMINATE mode (to terminate a previous load replace operation), or RESTART mode (to restart a previous load replace operation)

INSERT privilege on the exception table, if such a table is used as part of the load operation.

Caveat:

If you are performing a load operation and you CTRL-C out of it, the tablespace is left in a load pending state. The only way to get out of it is to reload the data with a terminate statement

First to view tablestate:

Db2 list tablespaces show detail will display the tablespace is in a load pending state.

Db2tbst

Here is the original query

Db2 "load from '/usr/seela/a.del' of del insert into A";

If you break out of the load illegally (ctrl-c), the tablespace is left load pending.

To correct:

Db2 "load form '/usr/seela/a.del' of del terminate into A";

This will return the table to its original state and roll back the entries that you started loading.

If you try to reset the tablespace with quiesce, it will not work. It's an integrity issue 

Read More...

14 April 2009

0 JavaScript code for closing the main window in Mozilla Firefox

Simply window.close(); will not work with Mozilla Firefox, this window.close(); will not close the main window in Mozilla Firefox and similar browsers (Google Chrome, Opera). Only if it is a child window, window.close(); will work in Mozilla Firefox. Here is the JavaScript code for logging out (closing the main window) in Mozilla Firefox
// logout
function closeWindow(){
window.open('', '_parent','');
window.close();
}
Read More...

0 JavaScript code for ensuring that a selected item in a dropdown does not appear in other dropdown

Consider a series of dropdown.We need to ensure that the selection in any of the dropdown does not come in the other dropdowns. Here is the JavaScript code for ensuring that a selected item in a dropdown does not appear in other dropdown, Call the function onRowChange on change of the dropdown.
function onRowChange (rowId){
for( var i=0; i<getMaxEditableRows(); i++) {
if
(rowId==i)
continue;
var rowName = 'optAttr'+i;
var tempVal = document.getElementById(rowName).value;
document.getElementById(rowName).options.length = 0;
document.getElementById(rowName).options[0] = new Option("--Select--", '');
for(var j = 0; j <(allAttributesKeyArray.length); j++) {
var text = allAttributesKeyArray[j];
if (isSelectedInOthers(text,i))
continue ;
document.getElementById(rowName).options[1+count++] = new Option(text, text);
}
document.getElementById(rowName).value = tempVal;
}
}

getMaxEditableRows is the number of dropdowns
allAttributesKeyArray is an array of all items in dropdown
// checks whether the attribute is selected in other dropdowns or not
function isSelectedInOthers(text,rowId){
for
( var i=0;i<getMaxEditableRows();i++) {
var 
rowName = 'optAttr'+i;
if(rowId==i)
continue;
if(document.getElementById(rowName) .value==text) {
return true
;
}
}
return false;
}
The function is called on onChange of the dropdowns. The parameter rowId denotes which row was selected, i.e. which dropdown. The value selected in the dropdown is stored in a temporary variable – tempVal, after this the values in the dropdown is flushed by setting its length to zero. Again the dropdown is re-loaded with values from the allAttributesKeyArray. Before the actual setting another function isSelectedInOthers is called. The parameter ‘text’ denotes any value in the allAttributesKeyArray which will be compared with the values already selected. This function ensures that the value selected is not selected in other dropdowns. It returns true or false depending on this criterion. On basis of what isSelectedInOthers function returns the dropdown is populated with values other than one’s selected.
Read More...

0 JavaScript code for making tabs which expands and collapses on clicking

Tabs which expand or collapse on clicking are very useful and attractive from a user perspective .The idea behind this is that the user needs to see only those things which are relevant to him. Here is the JavaScript code for Tabs which expand or collapse on clicking.

function newFunction(id){

      if(document.getElementById(n).style.display == "none"){

            document.getElementById(n).style.display="";   

      }else if(document.getElementById(n).style.display == ""){

            document.getElementById(n).style.display = "none";

      }

}



Fig with tabs closed

 

Fig with tabs Open

 

 

The whole idea is to set an id to the div (or table) and this id is passed as the parameter to the function. To make the div hidden we set style.display to none. On clicking the tab the above function is called. If it is hidden, it is made visible by setting the display to “”. A common practice is to set the display to ‘block’. But this may lead to problems because block is container specific. In Mozilla it may affect the whole layout.                                     

One more way to make the div visible or hidden is by adjusting the height of the div. See the below code.

function showHideSects() {

      if (!document.getElementsByTagName) return false;

      var headings = document.getElementsByTagName("h2");

      for (var i=0; i

            headings[i].parentNode.className += " open";

            /*headings[i].parentNode.style.height = "3em";

            headings[i].parentNode.style.overflow = "hidden";*/

            headings[i].onmouseover = function() {

                  this.style.cursor = "pointer";

      }

}

Here the tag with name =h2 is made to disappear. The height is set to ‘3em’.To display the whole content we set the height to “”. But I would advise you to stick to the earlier method because it is easy to understand and reuse.

Read More...