KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > in > co > daffodil > db > general > DaffodilDBExceptionHandler


1 package in.co.daffodil.db.general;
2
3 import java.sql.*;
4 import com.daffodilwoods.database.resource.*;
5 import java.io.*;
6 import java.util.Date JavaDoc;
7 import java.util.Locale JavaDoc;
8 import com.daffodilwoods.daffodildb.server.serversystem._Server;
9
10 public class DaffodilDBExceptionHandler {
11
12     public static final void handle(String JavaDoc reason,String JavaDoc code,Exception JavaDoc exc,Locale JavaDoc locale)throws SQLException {
13       if(exc instanceof BatchUpdateException || exc instanceof SQLException)
14         throw (SQLException)exc;
15       if( exc instanceof DException )
16         throw ((DException)exc).getSqlException(locale);
17 /*
18       getLogWriter();
19       if(printWriter != null){
20     printWriter.println(new com.daffodilwoods.daffodildb.utils.DBDate(System.currentTimeMillis()));
21         printWriter.flush();
22       }else{
23          ;//// Removed By Program ** exc.printStackTrace();
24       }
25 */

26       throw new in.co.daffodil.db.general.DaffodilDBExceptionWrapper(reason,exc);
27     }
28
29     public static final void handle(String JavaDoc reason,String JavaDoc code,Exception JavaDoc exc)throws SQLException {
30       if(exc instanceof BatchUpdateException || exc instanceof SQLException)
31         throw (SQLException)exc;
32       if( exc instanceof DException )
33         throw ((DException)exc).getSqlException(null);
34 /*
35       getLogWriter();
36       if(printWriter != null){
37     printWriter.println(new com.daffodilwoods.daffodildb.utils.DBDate(System.currentTimeMillis()));
38         printWriter.flush();
39       }else{
40          ;//// Removed By Program ** exc.printStackTrace();
41       }
42 */

43       throw new in.co.daffodil.db.general.DaffodilDBExceptionWrapper(reason,exc);
44     }
45
46   static PrintWriter printWriter;
47   private static PrintWriter getLogWriter(){
48      try {
49        if(printWriter == null){
50            String JavaDoc fileName = System.getProperty(_Server.DAFFODILDB_HOME,"C:" +File.separator+ "DaffodilDaffodilDB");
51            File f = new File(fileName);
52            if(!f.exists())
53                 f.mkdirs();
54            fileName += File.separator+"ErrorLog.log";
55            printWriter = new PrintWriter(new FileWriter(fileName,true));
56        }
57         return printWriter;
58     }catch(Exception JavaDoc ex) {
59         return null;
60      }
61    }
62
63
64    public void finalize(){
65     try {
66         if(printWriter!=null) {
67             printWriter.flush();
68             printWriter.close();
69           }
70       }catch(Exception JavaDoc e){
71       }
72    }
73
74 }
75
Popular Tags