Thursday, August 6, 2009

How do you know whether the index is analyzed or not in a table ...?

Many of times we create indexes and forget to analyze them. Here is a simple way to find out whether your indexes or tables have been analyzed alteast once or not ...

- To find if a table is analyzed, check the "AVG_ROW_LEN" column of the USER_TABLES table. If it is non-zero, the 'analyze' or 'dbms_stats' command has been run at least once on this table.

- To find if an index is analyzed, check the "COLUMN_LENGTH " column of the USER_IND_COLUMNS table. If it is non-zero, the 'analyze' or 'dbms_stats' command has been run at least once on this index.

But why do we need to analyze the indexes or tables ??
Because oracle uses the cost based optimizer to give the best performance in most of the cases. And the cost based optimizer needs data to decide the access plan, and this data is generated by the analyze command or the newer dbms_stats package.

So always analyze or dbms_stats the table and indexes.
If you analyze a table, then its current indexes are automatically analyzed too. If you analyze a index, then the table is not analyzed.

Monday, August 3, 2009

JBoss still uses old .class files even after replacing them with new class files....

Was facing an issue with jboss when i tried to redeploy an ear by replacing few .class files with new compiled .class files (the class files are mostly interfaces containing constants defined in it). But the jboss failed to pickup the new .class files, rather it was referring to the old class files still.

I tried every possibility like redeploying the ear, clearing the cache of jboss, etc but it didn't helped out. But if updating the class which is 'implementing' the interface, it would then refer to new .class files.

The possible reasons could be
- Jboss compiler is possibly failing to recognize the changed interfaces as the implemented class is not been updated.
- The Jboss is not cleaning it weekly hashmapped reference of the classes.

But the point what i learned is that defining constants in an interface is a bad practice as you can end up in such trouble. Interfaces are meant to expose the method definitions.

Tuesday, June 9, 2009

Changing the ip address on Oracle server.

Recently my system's ip got changed and the after effect is when i tried to up my applications, it was unable to connect to the oracle database.

If your system's ip address have been changed then you got to test whether your oracle db is properly starting up or not and whether your applications which connect to Oracle are able to connect to oracle.
If you got a problem then you got to change the ip address of Oracle.

For changing the ip address on the oracle server, we need to change the following 2 files.
1. tnsnames.ora
2. listener.ora

You can find both the files in "oracle\product\10.2.0\db_1\NETWORK\ADMIN" path.
Replace the old ip address to new one.

Tuesday, June 2, 2009

URL Encoder.

Here is the perfect link which help you to find the encoding special characters which can exists in the url like a space,^,<,>, etc.

http://www.blooberry.com/indexdot/html/topics/urlencoding.htm

In this site, you got a live encoding converter too which tell whether the char is safe string or need to encode :)

Thursday, May 21, 2009

Getting "registry editing has been disabled by your Administrator" error ?

Getting "registry editing has been disabled by your Administrator" error ?

When you try to Start -> Run -> regedit and if you get this error the just go to the following link and follow the steps :
http://www.online-tech-tips.com/windows-xp/registry-disabled-by-administrator/

Friday, May 15, 2009

Differences between Weblogic 8.1 and Weblogic 9.X

Well if you don't want to read the entire documentation provided by the BEA but wanted to know few major differences between WL 8.1 and 9.X , you can have a glance on my blog. Else you get an excellent documentation from BEA :)

Following are very few major differences between Weblogic 8.1 and 9.2 :
1. Weblogic 9.0 handles the Cachefull Exception more effectively than 8.1. WL 9.0 does "Dynamic Entity Cache". It provides improved caching and pooling than 8.1. So hopefully no more cachefull exceptions on the cmps :)
2. Weblogic 9.X has resolved many OutOfMemory scenario exceptions.
3. WL 9.X supports following related to JMS
- Unit of Group JMS Messages
- Store and Forward JMS Messages
- Unit of Order jms messages
- Improved Message Paging

Refer http://edocs.bea.com/ for more info.

Thursday, May 14, 2009

Compiler failed executable.exec

When deploying an application in Weblogic Server 8.1, got the following error :
'Compiler failed executable.exec' .

This error occurs because of the incompatibility with the JDK version used to build the application with the Weblogic's JDK version.

Well i have faced this error not once, not twice but many times. For fixing this error, did the following actions. But note, I can't promise that this would fix your error too. So if you are getting this error, you should definitely give a try, by doing the following

1. Check which jdk you are using to build your application.
For e.g. if it is "jdk142_05".
2. Check the jdk version of your Weblogic server.
For e.g. if it is " jdk142_11".

If both the jdk versions are different, then change the JAVA_HOME to "jdk142_05" in the Weblogic server from the following files :
1. user_projects/domains/domainname/StartWeblogic.cmd
2. user_projects/domains/domainname/setEnv.cmd

If this doesn't work, try to do vice-versa i.e, build your application with Weblogic JDK by setting the JAVA_HOME of the system to Weblogic's JDK. (Though, this didn't worked for me but the first fix definitely did worked).

Tuesday, April 21, 2009

How to post a URL from a simple Pojo

Here is a simple example how to post a URL to an application deployed somewhere in an application server from a simple java class. You just need to have jdk installed to run this program.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
public class XMLLoader {

public void sendPostRequest() throws Exception {
try {
// create a URL to be fired
URL url = new URL("http://10.10.99.19:8000/Test/StudentData");
// open a Connection
URLConnection connection = url.openConnection();
// set the username:pwd
String encoding = new sun.misc.BASE64Encoder().encode("username:password".getBytes());
// set the authorization as Basic
connection.setRequestProperty("Authorization", "Basic " + encoding);
// get the inputstream from the connection
InputStream inputStream = connection.getInputStream();
// Parse the stream to get the text of it
String responseXml = new XMLLoader().readAllAsText(inputStream);
System.out.println("The response is --- " +responseXml );
} catch(Exception e) {
e.printStackTrace();
}
}
/**
* Starts the program
*/
public static void main(String[] args) throws Exception {
new XMLLoader().sendPostRequest();
}

public final static char EOL='\n';
/**
* Helper methods
*/
public String readAllAsText(InputStream stream) throws Exception {
InputStreamReader reader=null;
try {
reader=new InputStreamReader(stream);
return readAllAsText(reader);
} finally {
if(reader != null)
reader.close();
}
}

public String readAllAsText(Reader reader) throws Exception {
BufferedReader bReader=null;
try {
bReader=new BufferedReader(reader);
StringBuffer buf=new StringBuffer();
String line=bReader.readLine();
if (null!=line) {
buf.append(line);
}
while ((line=bReader.readLine()) != null) {
buf.append(EOL);
buf.append(line);
}
return buf.toString();
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if(bReader != null)
bReader.close();
}
}
}

Thursday, March 19, 2009

iBATIS Vs Hibernate Vs JPA

While i started my knowledge sessions for myself to learn something apart of my work, have picked up iBATIS, its understanding and when to use it.

When brushing up the fundamentals of iBatis and its pros and cons ... first question popped up to my mind was 'Why iBatis ... Why not any other framework?'. So my track automatically took a side turn for comparing the iBATIS with other existing persistence frameworks.

So now i am gonna talk about three know persistence frameworks
1. iBATIS
2, Hibernate
3. JPA

About iBATIS :
1. iBATIS is a persistence framework that provides the benefits of SQL but avoids the complexity of JDBC.
2. iBATIS encourages the direct use of SQL and ensures that all the benefits of SQL are not overridden by the framework itself.
3. Simplicity is iBATIS's greatest advantage, as it provides a simple mapping and API layer that can be used to build data-access code.
4. iBATIS enables the data model and the object model to be independent of each other.

When to use iBATIS :
1. iBATIS is best used when you need complete control of the SQL.
2. It is also useful when the SQL queries need to be fine-tuned.

When Not to Use iBATIS:
1. iBATIS should not be used when you have full control over both the application and the database design, because in such cases the application could be modified to suit the database, or vice versa.
2. iBATIS is also inappropriate for non-relational databases, because such databases do not support transactions and other key features that iBATIS uses.

About Hibernate :
1. Hibernate is an open source, lightweight object-relational mapping solution.
2. Hibernate includes a very powerful query language called Hibernate Query Language, or HQL.
3. HQL is very similar to SQL, and also defines some additional conventions.
4. HQL also supports many advanced features of pagination and dynamic profiling that SQL has never supported.
5. HQL does not require any explicit joins when working with multiple tables.
6. Hibernate makes object-relational mapping simple by mapping the metadata in an XML file that defines the table in the database that needs to be mapped to a particular class.

When to use Hibernate :
1. Hibernate is best used to leverage end-to-end OR mapping. It provides a complete ORM solution, but leaves you control over queries.
2. Hibernate is the best option for object-oriented programmers who are less familiar with SQL.


About Java Persistence API :
1. The Java Persistence API is the standard object-relational mapping and persistence management interface for the Java EE 5 platform. As part of the EJB 3 specification effort, it is supported by all major Java vendors.
2. JPA is a POJO-based standard persistence model for ORM. It is part of the EJB 3 specification and replaces entity beans.
3. JPA uses metadata annotations and/or XML descriptor files to configure the mapping between Java objects in the application domain and tables in the relational database.
4. Defines an SQL-like query language, JPQL (Java Persistence Query Language), which is different from EJB-QL (EJB Query Language), the language used by entity beans.

When to use JPA :
1. JPA should be used when you need a standard Java-based persistence solution.
2. JPA supports inheritance and polymorphism, both features of object-oriented programming.

When not to use JPA :
1. Caching, which is not clearly defined in JPA but is well supported by Hibernate.
2. JPA is defined to work with relational databases only.
3. If your persistence solution needs to be extended to other types of data stores, like XML databases, then JPA is not the answer to your persistence problem.

Wednesday, March 11, 2009

Understanding Sessions in Weblogic

While i was working on the Session timeout of our application in Weblogic , first thought its just an configuration settings that need to be done. But later when we started investigating on it, we faced few issues and limitations related to session timeout.

Listing out few important key points that one must known if using WebLogic server (related to sessions):

1. In Weblogic, one cannot share the session data across multiple EAR applications (i.e, different contexts).
(Refer http://e-docs.bea.com/wls/docs92/webapp/sessions.html)

2. Sessions can be shared within web applications in an application by setting sharing-enabled tag to true.
(Refer http://edocs.bea.com/wls/docs90/webapp/weblogic_xml.html)

3. On a session invalidate, WL will clean the session data only, it does not cleans up the authentication data.
(Refer http://books.google.co.in/books?id=TiAKHpPHpHIC&pg=PA429&lpg=PA429&dq=delete+authentication+data+of+a+session+in+weblogic&source=bl&ots=ciKPPJ-u3s&sig=zNHD1d7DOZbbKM7O8EraRmdgU10&hl=en&ei=i1-eSfXMKJKwkAXB5onLCw&sa=X&oi=book_result&resnum=2&ct=result#PPA429,M1)

4. To cleanup the authentication data, use weblogic.servlet.security.ServletAuthentication class.