/** * PUBLIC: * <p> * Check if a message of the given level would actually be logged. * </p><p> * * @return true if the given message level will be logged * </p><p> * @param level the log request level * @param category the string representation of a TopLink category * </p> */ public boolean shouldLog(int Level, String category) { return getSessionLog().shouldLog(Level, category); }
/** Matches target to pattern specified regExp. Returns false if there is * any error compiling regExp. * @param regExp The regular expression. * @param target The target against which we are trying to match regExp. * @param logger * @return false if there is error compiling regExp or target does not * match regExp. true if regExp matches pattern. */ private static boolean matchPattern(String regExp, String target, SessionLog logger) { boolean matches = false; try { matches = Pattern.matches(regExp,target); } catch (PatternSyntaxException e){ if(logger.shouldLog(SessionLog.FINE)) { logger.log(SessionLog.FINE, "dbPlaformHelper_patternSyntaxException", e); // NOI18N } } return matches; }
/** * Match vendorName in properties specifieid by _nameToVendorPlatform. */ private static String matchVendorNameInProperties(String vendorName, Properties nameToVendorPlatform, SessionLog logger) { String dbPlatform = null; //Iterate over all properties till we find match. for( Iterator iterator = nameToVendorPlatform.entrySet().iterator(); dbPlatform == null && iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); String regExpr = (String) entry.getKey(); String value = (String) entry.getValue(); if(logger.shouldLog(SessionLog.FINEST)) { logger.log(SessionLog.FINEST, "dbPlaformHelper_regExprDbPlatform", regExpr, value); // NOI18N } if( matchPattern(regExpr, vendorName, logger) ) { dbPlatform = value; } } return dbPlatform; }
/** Get Database Platform from vendor name. * @param vendorName Input vendor name. Typically this is obtained by querying * <code>DatabaseMetaData</code>. * @param logger The logger. * @return Database platform that corresponds to <code>vendorName</code>. * If vendorName does not match any of predefined vendor names, <code> * DEFAULTPLATFORM </code> is returned. */ public static String getDBPlatform(String vendorName, SessionLog logger) { initializeNameToVendorPlatform(logger); String detectedDbPlatform = null; if(vendorName != null) { detectedDbPlatform = matchVendorNameInProperties(vendorName, _nameToVendorPlatform, logger); } if (logger.shouldLog(SessionLog.FINE) ) { logger.log(SessionLog.FINE, "dbPlaformHelper_detectedVendorPlatform", detectedDbPlatform ); // NOI18N } if (detectedDbPlatform == null) { if(logger.shouldLog(SessionLog.INFO)) { logger.log(SessionLog.INFO, "dbPlaformHelper_defaultingPlatform", vendorName, DEFAULTPLATFORM); // NOI18N } detectedDbPlatform = DEFAULTPLATFORM; } return detectedDbPlatform; }