DBPlatformHelperpublic class DBPlatformHelper extends Object
Fields Summary |
---|
private static final String | DEFAULTPLATFORM | private static final String | PROPERTY_PATH | private static final String | VENDOR_NAME_TO_PLATFORM_RESOURCE_NAME | private static Properties | _nameToVendorPlatformHolds mapping between possible vendor names to internal platforms defined above.
vendor names are treated as regular expressions. |
Methods Summary |
---|
public static java.lang.String | getDBPlatform(java.lang.String vendorName, oracle.toplink.essentials.logging.SessionLog logger)Get Database Platform from vendor name.
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;
| private static java.util.Properties | initializeNameToVendorPlatform(oracle.toplink.essentials.logging.SessionLog logger)Allocate and initialize nameToVendorPlatform if not already done.
synchronized(DBPlatformHelper.class) {
if(_nameToVendorPlatform == null) {
_nameToVendorPlatform = new Properties();
try {
loadFromResource(_nameToVendorPlatform, VENDOR_NAME_TO_PLATFORM_RESOURCE_NAME,
DBPlatformHelper.class.getClassLoader() );
} catch (IOException e) {
logger.log(SessionLog.WARNING, "dbPlaformHelper_noMappingFound", VENDOR_NAME_TO_PLATFORM_RESOURCE_NAME);
}
}
}
return _nameToVendorPlatform;
| private static void | load(java.util.Properties properties, java.lang.String resourceName, java.lang.ClassLoader classLoader)Loads properties list from the specified resource
into specified Properties object.
InputStream bin = new BufferedInputStream(openResourceInputStream(resourceName,classLoader));
try {
properties.load(bin);
} finally {
try {
bin.close();
} catch (Exception e) {
// no action
}
}
| private static void | loadFromResource(java.util.Properties properties, java.lang.String resourceName, java.lang.ClassLoader classLoader)
load(properties, resourceName, classLoader);
| private static boolean | matchPattern(java.lang.String regExp, java.lang.String target, oracle.toplink.essentials.logging.SessionLog logger)Matches target to pattern specified regExp. Returns false if there is
any error compiling regExp.
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;
| private static java.lang.String | matchVendorNameInProperties(java.lang.String vendorName, java.util.Properties nameToVendorPlatform, oracle.toplink.essentials.logging.SessionLog logger)Match vendorName in properties specifieid by _nameToVendorPlatform.
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;
| private static java.io.InputStream | openResourceInputStream(java.lang.String resourceName, java.lang.ClassLoader classLoader)Open resourcenName as input stream inside doPriviledged block
return (InputStream) AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
if (classLoader != null) {
return classLoader.getResourceAsStream(resourceName);
} else {
return ClassLoader.getSystemResourceAsStream(resourceName);
}
}
}
);
|
|