[Schmitzm-commits] r2362 - trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Thu Jul 18 13:38:48 CEST 2013


Author: mojays
Date: 2013-07-18 13:38:48 +0200 (Thu, 18 Jul 2013)
New Revision: 2362

Modified:
   trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/HibernateSessionFactory.java
Log:
HibernateSessionFactory: method to determine current database user

Modified: trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/HibernateSessionFactory.java
===================================================================
--- trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/HibernateSessionFactory.java	2013-07-18 11:02:28 UTC (rev 2361)
+++ trunk/schmitzm-hibernate/src/main/java/de/schmitzm/db/hibernate/HibernateSessionFactory.java	2013-07-18 11:38:48 UTC (rev 2362)
@@ -516,7 +516,28 @@
         }
 
     }
-    
+
+    /**
+     * Returns the currently connected database user.
+     * 
+     * @return {@code null} if there is no database connection
+     */
+    public String getCurrentUser() {
+        if ( !isConnected() )
+            return null;
+
+//      HibernateSessionFactory.beginTransactionIfNeeded();
+        try {
+            DatabaseMetaData connMetaData = getConnectionMetadata();
+            if (connMetaData == null)
+                return null;
+            return connMetaData.getUserName();
+        } catch (Exception err) {
+            LOGGER.error("Error determining current database user.", err);
+            return null;
+        }
+    }
+
 //    /**
 //     * Liefert die Anzahl der offenen Sessions fuer die aktuelle
 //     * Verbindung des Users.



More information about the Schmitzm-commits mailing list