1 16 17 package org.springframework.orm.toplink.support; 18 19 import oracle.toplink.sessions.DefaultSessionLog; 20 import oracle.toplink.sessions.Session; 21 import oracle.toplink.sessions.SessionLogEntry; 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 49 public class CommonsLoggingSessionLog904 extends DefaultSessionLog { 50 51 public static final String NAMESPACE = "oracle.toplink.session"; 52 53 public static final String DEFAULT_SEPARATOR = "--"; 54 55 56 private final Log logger = LogFactory.getLog(NAMESPACE); 57 58 private String separator = DEFAULT_SEPARATOR; 59 60 61 65 public void setSeparator(String separator) { 66 this.separator = separator; 67 } 68 69 73 public String getSeparator() { 74 return separator; 75 } 76 77 78 public void log(SessionLogEntry entry) { 79 if (entry.hasException()) { 80 if (shouldLogExceptions() && logger.isWarnEnabled()) { 81 this.logger.warn(getMessageString(entry), entry.getException()); 82 } 83 } 84 else if (entry.isDebug()) { 85 if (shouldLogDebug() && logger.isTraceEnabled()) { 86 this.logger.trace(getMessageString(entry)); 87 } 88 } 89 else { 90 if (logger.isDebugEnabled()) { 91 this.logger.debug(getMessageString(entry)); 92 } 93 } 94 } 95 96 101 protected String getMessageString(SessionLogEntry entry) { 102 StringBuffer buf = new StringBuffer (); 103 if (shouldPrintSession()) { 104 buf.append(getSessionName(entry.getSession())); 105 buf.append("("); 106 buf.append(String.valueOf(System.identityHashCode(entry.getSession()))); 107 buf.append(")"); 108 buf.append(getSeparator()); 109 } 110 if (shouldPrintConnection() && entry.getConnection() != null) { 111 buf.append("Connection"); 112 buf.append("("); 113 buf.append(String.valueOf(System.identityHashCode(entry.getConnection()))); 114 buf.append(")"); 115 buf.append(getSeparator()); 116 } 117 buf.append(entry.getMessage()); 118 return buf.toString(); 119 } 120 121 125 protected String getSessionName(Session session) { 126 if (session.isUnitOfWork()) { 127 return "UnitOfWork"; 128 } 129 if (session.isServerSession()) { 130 return "ServerSession"; 131 } 132 if (session.isClientSession()) { 133 return "ClientSession"; 134 } 135 if (session.isSessionBroker()) { 136 return "SessionBroker"; 137 } 138 if (session.isRemoteSession()) { 139 return "RemoteSession"; 140 } 141 if (session.isDatabaseSession()) { 142 return "DatabaseSession"; 143 } 144 return "Session"; 145 } 146 147 } 148 | Popular Tags |