Thursday, September 30, 2010

Create Zip file of resources using Maven Assembly Plugin

If you have some resources (xml files, properties files etc) that contains project properties to be substituted before generating the zip package of those resources. Probably Maven is pretty helpful to create it. For example you have some paths of DTD schema in your xml files that you need to resolve before generating the deployable resource package.
You need to use Maven Assembly plugin to generate a zip file. You have to create an assembly descriptor file that you will include in your POM file.
The assembly descriptor will look like. you can save it as (zip-descriptor.xml)


<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd " >

<includeBaseDirectory >false </includeBaseDirectory >
<formats >
<format >zip </format >
</formats >
<fileSets >
<fileSet >
<directory >directory-name </directory >
<outputDirectory > </outputDirectory >
<filtered >true </filtered >
</fileSet >
</fileSets >
</assembly >

your POM file will look like. (POM.xml)


<project xmlns="http://maven.apache.org/POM/4.0.0 " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd " >

<modelVersion >4.0.0 </modelVersion >
<groupId >iceland-picking </groupId >
<artifactId >iceland-picking </artifactId >
<version >0.0.1-SNAPSHOT </version >
<packaging >pom </packaging >
<name >iceland-picking </name >

<prerequisites >
<maven >2.2.0 </maven >
</prerequisites >

<properties >
<product.codename >codename </product.codename >
<product.name >product name </product.name >
<product.version >${project.version} </product.version >

<model.codename >${product.codename} </model.codename >
<model.name >${product.name } </model.name >
<model.version >${project.version} </model.version >

<metabase.version >1 </metabase.version >
<database.version >1 </database.version >
</properties >

<build >
<plugins >
<plugin >
<groupId >org.apache.maven.plugins </groupId >
<artifactId >maven-assembly-plugin </artifactId >
<configuration >
<descriptors >
<descriptor >zip-descriptor.xml </descriptor >
</descriptors >
<finalName >this will be the name of the output zip file </finalName >
<appendAssemblyId >false </appendAssemblyId >
</configuration >
<executions >
<execution >
<id >make-assembly </id >
<phase >package </phase >
<goals >
<goal >single </goal >
</goals >
</execution >
</executions >
</plugin >
</plugins >
</build >
</project >

For more details please visit the following Maven link:
1) http://maven.apache.org/guides/mini/guide-assemblies.html
2) http://maven.apache.org/plugins/maven-assembly-plugin/descriptor-refs.html

Friday, September 24, 2010

ORA-01000: maximum open cursors limit exceeded

If you are getting ORA-01000 exception, it means you need to review your design or you need to optimize your code. You need to make sure that all the open cursors are being closed after they are finished being used in application.

To check amount of open cursors in Oracle simple run this query:

select count(*) from v$open_cursor;

To increase/decrease the amount of open cursors limit run the following query:

ALTER SYSTEM SET open_cursors = 1000 SCOPE=BOTH;

OPEN_CURSORS sets the maximum number of cursors each session can have open, per session. For example, if OPEN_CURSORS is set to 1000, then each session can have up to 1000 cursors open at one time. If a single session has OPEN_CURSORS # of cursors open, it will get an ora-1000 error when it tries to open one more cursor.

The default value for OPEN_CURSORS is 50, but Oracle recommends that you set this to at least 500 for most applications. Some applications may need more, eg. High volume web applications.

Only increase the OPEN CURSOR limit if your application really needs it, otherwise focus on releasing the unused cursors in your code. For example, In Java close ResultSet or Statement or Connection object as soon as you are finished with them.

Friday, September 3, 2010

Default Argument Value for Methods

Like in C++, C#, PHP or SQL we can provide the default value for the argument that will be used in case when value is not supplied during method/function call. For example the following function declaration in C++:


void int someFun(int a, int b =0) {
// some implementation here...
}

In the above function the last argument has a default value of 0, and it will be used when we will call this function by providing only one parameter, like;
someFun(5);
The above function call will give value 5 to argument “a” and 0 for argument “b”.
The same function can be called to provide both of the values, like:
someFun(5,10);
Fortunately/Unfortunately you can not declare a function/constructor with default values for arguments because experts say this is a bad implementation design. If you have to achieve the same kind of functionality the better way is to declare overloaded methods and call one with default value in other. For example:

void int someMethod(int a, int b ) {
// some implementation here...
}
void int someMethod(int a) {
// call overloaded method with default value of the argument
someMethod(a, 0);
}