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/GenericRecord.java      |   31 +++++++++++++++++--------------
 src/de/uhilger/baselink/PersistenceManager.java |    7 ++++++-
 2 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/src/de/uhilger/baselink/GenericRecord.java b/src/de/uhilger/baselink/GenericRecord.java
index cfcb2f4..06eb984 100644
--- a/src/de/uhilger/baselink/GenericRecord.java
+++ b/src/de/uhilger/baselink/GenericRecord.java
@@ -43,6 +43,7 @@
  * the <a href="http://www.gnu.org/licenses/" target="_blank">GNU General Public License</a>
  */
 public class GenericRecord implements Record {
+  private static final Logger logger = Logger.getLogger(GenericRecord.class.getName());
   
 	/** default getter method indicator */
 	public static final String GETTER_NAME = "get";
@@ -63,15 +64,15 @@
 	 * @param c  the class to persist
 	 */
 	public GenericRecord(Class<?> c) {		
-		Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).finest(c.getName());
+		logger.finest(c.getName());
 		this.recordClass = c;
 		
 		DBTable table = c.getAnnotation(DBTable.class);
 		if(table != null) {
-			Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).finest(tableName);
+			logger.finest(tableName);
 			tableName = table.name();
 		} else {
-			Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).severe("missing table annotation");
+			logger.severe("missing table annotation");
 		}
 		
 		primaryKeyColNames = new ArrayList<String>();
@@ -79,11 +80,11 @@
 		if(primaryKey != null) {
 			String[] names = primaryKey.value();
 			for(int i = 0; i < names.length; i++) {
-				Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).finest(names[i]);
+				logger.finest(names[i]);
 				primaryKeyColNames.add(names[i]);
 			}
 		} else {
-			Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).severe("missing primary key annotation");
+			logger.severe("missing primary key annotation");
 		}
 
 		columns = new Hashtable<String,Field>();
@@ -96,16 +97,16 @@
 				String fieldName = field.name();
 				mapper.setColumnType(field.type());
 				mapper.setColumnName(fieldName);
-				Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).finest(fieldName);
+				logger.finest(fieldName);
 				String methodName = method.getName();
 				if(methodName.startsWith(GETTER_NAME)) {
 					String fieldMethod = methodName.substring(3);
-					Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).finest(fieldMethod);
+					logger.finest(fieldMethod);
 					Class<?> returnType = method.getReturnType();
 					try {
 						mapper.setSetter(c.getMethod(SETTER_NAME + fieldMethod, returnType));
 					} catch (Exception e) {
-						Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.SEVERE, e.getLocalizedMessage(), e);
+						logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
 					}
 					mapper.setGetter(method);
 				}
@@ -127,7 +128,7 @@
 		sql.append(tableName);
 		sql.append(" where ");
 		appendPrimaryKeyFields(sql);
-		Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).finest(sql.toString());
+		logger.finest(sql.toString());
 		PreparedStatement ps = c.prepareStatement(sql.toString());
 		prepareFields(0, primaryKeyColNames, ps, record);
 		return ps;
@@ -163,7 +164,7 @@
 		sql.append(" values (");//?, ?)");
 		sql.append(valueList);
 		sql.append(")");
-		Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).finest(sql.toString());
+		logger.finest(sql.toString());
 		PreparedStatement ps = c.prepareStatement(sql.toString(), autoGeneratedKeys);
 		prepareFields(0, ps, record);
 		return ps;
@@ -204,7 +205,7 @@
 		sql.append(fieldList);
 		sql.append(" where ");
 		appendPrimaryKeyFields(sql);		
-		Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).finest(sql.toString());
+		logger.finest(sql.toString());
 		PreparedStatement ps = c.prepareStatement(sql.toString());
 		prepareFields(0, ps, record);
 		prepareFields(columns.size(), primaryKeyColNames, ps, record);
@@ -219,12 +220,12 @@
 	 * @throws Exception
 	 */
 	public Object toObject(ResultSet resultSet, boolean includeBlobs) throws Exception {
-		Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).finest(recordClass.getName());
+		logger.finest(recordClass.getName());
 		Object o = recordClass.newInstance();
 		Enumeration<String> fieldNames = columns.keys();
 		while(fieldNames.hasMoreElements()) {
 			String columnName = fieldNames.nextElement();
-			Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).finest(columnName);
+			logger.finest(columnName);
 			Field mapper = columns.get(columnName);
 			Method setter = mapper.getSetter();
 			if(setter != null) {
@@ -237,7 +238,7 @@
 					}
 				} else {
 					data = resultSet.getObject(columnName);
-					Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).finest(data.toString());
+					logger.finest(data.toString());
 					setter.invoke(o, data);
 				}
 			}
@@ -278,6 +279,8 @@
 				ps.setBinaryStream(i+offset, new ByteArrayInputStream(content.getBytes()), content.length());
 			} else {
 				ps.setObject(i+offset, o);
+        int nr = i + offset;
+        logger.finest(nr + " " + o.toString());
 			}
 			i++;
 		}
diff --git a/src/de/uhilger/baselink/PersistenceManager.java b/src/de/uhilger/baselink/PersistenceManager.java
index 66d2147..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);
@@ -134,14 +135,18 @@
     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;
   }

--
Gitblit v1.9.3