From e1568a090ae0b5d6221a38f234945017e6d34c95 Mon Sep 17 00:00:00 2001
From: ulrich
Date: Mon, 28 Dec 2020 09:27:32 +0000
Subject: [PATCH] Logging angepasst

---
 src/de/uhilger/baselink/PersistenceManager.java |   26 ++++++++++++++++++--------
 1 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/de/uhilger/baselink/PersistenceManager.java b/src/de/uhilger/baselink/PersistenceManager.java
index f3f8786..eb12e31 100644
--- a/src/de/uhilger/baselink/PersistenceManager.java
+++ b/src/de/uhilger/baselink/PersistenceManager.java
@@ -121,6 +121,7 @@
    * @throws NamingException  when JNDI lookup fails
    */
   public void setDataSourceName(String dataSourceName) throws NamingException {
+    logger.finest(dataSourceName);
     Context initCtx = new InitialContext();
     Context envCtx = (Context) initCtx.lookup("java:comp/env");
     ds = (DataSource) envCtx.lookup(dataSourceName);
@@ -129,20 +130,23 @@
   /**
    * Get a database connection
    * @return  a database connection
-   * @throws SQLException
    */
   public Connection getConnection() {
     Connection c = null;
     try {
       if (dburl != null) {
+        logger.finest("getting Connection for URL " + dburl);
         c = DriverManager.getConnection(dburl);
       } else if(ds != null) {
+        logger.finest("getting Connection for DataSource " + ds.toString());
         c = ds.getConnection();
       } else {
         //throw new SQLException("Unable to get connection, DataSource and database URL are null.");
+        logger.finest("Unable to get connection, DataSource and database URL are null.");
       }
     } catch(Exception ex) {
-      ex.printStackTrace();
+      //ex.printStackTrace();
+      logger.log(Level.FINEST, ex.getLocalizedMessage(), ex);
     }
     return c;
   }
@@ -893,7 +897,7 @@
     try {
       c.setAutoCommit(false);
     } catch(SQLException ex) {
-      logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
+      logger.log(Level.SEVERE, ex.getMessage(), ex);
     } finally {
       // ..
     }
@@ -902,22 +906,28 @@
   public void commit(Connection c) {
     try {
       c.commit();
-      c.setAutoCommit(true);
     } catch(SQLException ex) {
-      logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
+      logger.log(Level.SEVERE, ex.getMessage(), ex);
     } finally {
-      // ... 
+      try {
+        c.setAutoCommit(true);
+      } catch (SQLException ex) {
+        logger.log(Level.SEVERE, ex.getMessage(), ex);
+      }
     }
   }
   
   public void rollback(Connection c) {
     try {
       c.rollback();
-      c.setAutoCommit(true);
     } catch(SQLException ex) {
       logger.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
     } finally {
-      // ...
+      try {
+        c.setAutoCommit(true);
+      } catch (SQLException ex) {
+        logger.log(Level.SEVERE, ex.getMessage(), ex);
+      }
     }
   }
   

--
Gitblit v1.9.3