private static void loadFromResource(List<String[]> properties, String resourceName, ClassLoader classLoader) throws IOException { load(properties, resourceName, classLoader); }
/** * Allocate and initialize nameToVendorPlatform if not already done. */ private static List<String[]> initializeNameToVendorPlatform(SessionLog logger) { synchronized(DBPlatformHelper.class) { if(_nameToVendorPlatform == null) { _nameToVendorPlatform = new ArrayList<String[]>(); try { loadFromResource(_nameToVendorPlatform, VENDOR_NAME_TO_PLATFORM_RESOURCE_NAME, DBPlatformHelper.class.getClassLoader() ); } catch (IOException e) { logger.log(SessionLog.WARNING, SessionLog.CONNECTION, "dbPlatformHelper_noMappingFound", VENDOR_NAME_TO_PLATFORM_RESOURCE_NAME); } } } return _nameToVendorPlatform; }
/** * Loads properties list from the specified resource * into specified Properties object. * @param properties Properties object to load * @param resourceName Name of resource. * If loadFromFile is true, this is fully qualified path name to a file. * param classLoader is ignored. * If loadFromFile is false,this is resource name. * @param classLoader The class loader that should be used to load the resource. If null,primordial * class loader is used. */ private static void load(List<String[]> properties, final String resourceName, final ClassLoader classLoader) throws IOException { try (BufferedReader bin = new BufferedReader( new InputStreamReader(openResourceInputStream(resourceName,classLoader)))) { for (String line = bin.readLine(); line != null; line = bin.readLine()) { String[] keyValue = validateLineForReturnAsKeyValueArray(line); if (keyValue != null) { properties.add(keyValue); } } } }
/** 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, SessionLog.CONNECTION, "dbPlatformHelper_detectedVendorPlatform", detectedDbPlatform ); // NOI18N } if (detectedDbPlatform == null) { if(logger.shouldLog(SessionLog.INFO)) { logger.log(SessionLog.INFO, SessionLog.CONNECTION, "dbPlatformHelper_defaultingPlatform", vendorName, DEFAULTPLATFORM); // NOI18N } detectedDbPlatform = DEFAULTPLATFORM; } return detectedDbPlatform; }
/** * Match vendorName in properties specified 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, "dbPlatformHelper_regExprDbPlatform", regExpr, value); // NOI18N } if( matchPattern(regExpr, vendorName, logger) ) { dbPlatform = value; } } return dbPlatform; }
getLogin().setPlatformClassName(DBPlatformHelper.getDBPlatform(vendorNameAndVersion, getSessionLog())); } else { Connection conn = null; DatabaseMetaData dmd = conn.getMetaData(); String vendorNameAndVersion = dmd.getDatabaseProductName() + dmd.getDatabaseMajorVersion() + dmd.getDatabaseProductVersion(); platformName = DBPlatformHelper.getDBPlatform(vendorNameAndVersion, getSessionLog()); getLogin().setPlatformClassName(platformName); } catch (EclipseLinkException classNotFound) {
/** * Loads properties list from the specified resource * into specified Properties object. * @param properties Properties object to load * @param resourceName Name of resource. * If loadFromFile is true, this is fully qualified path name to a file. * param classLoader is ignored. * If loadFromFile is false,this is resource name. * @param classLoader The class loader that should be used to load the resource. If null,primordial * class loader is used. */ private static void load(Properties properties, final String resourceName, final ClassLoader classLoader) throws IOException { InputStream bin = new BufferedInputStream(openResourceInputStream(resourceName,classLoader)); try { properties.load(bin); } finally { try { bin.close(); } catch (Exception e) { // no action } } }
/** 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, "dbPlatformHelper_detectedVendorPlatform", detectedDbPlatform ); // NOI18N } if (detectedDbPlatform == null) { if(logger.shouldLog(SessionLog.INFO)) { logger.log(SessionLog.INFO, "dbPlatformHelper_defaultingPlatform", vendorName, DEFAULTPLATFORM); // NOI18N } detectedDbPlatform = DEFAULTPLATFORM; } return detectedDbPlatform; }
/** * Match vendorName in properties specified by _nameToVendorPlatform. */ private static String matchVendorNameInProperties(String vendorName, List<String[]> nameToVendorPlatform, SessionLog logger) { String dbPlatform = null; //Iterate over all properties till we find match. for( Iterator<String[]> iterator = nameToVendorPlatform.iterator(); dbPlatform == null && iterator.hasNext();) { String[] entry = iterator.next(); String regExpr = entry[0]; String value = entry[1]; if (logger.shouldLog(SessionLog.FINEST)) { logger.log(SessionLog.FINEST, SessionLog.CONNECTION, "dbPlatformHelper_regExprDbPlatform", regExpr, value); // NOI18N } if( matchPattern(regExpr, vendorName, logger) ) { dbPlatform = value; } } return dbPlatform; }
platformName = DBPlatformHelper.getDBPlatform(vendorNameAndVersion, getSessionLog()); getLogin().setPlatformClassName(platformName); } catch (EclipseLinkException classNotFound) { platformName = DBPlatformHelper.getDBPlatform("core."+ vendorNameAndVersion, getSessionLog()); getLogin().setPlatformClassName(platformName); } catch (EclipseLinkException oracleClassNotFound) {
/** 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, SessionLog.CONNECTION, "dbPlatformHelper_detectedVendorPlatform", detectedDbPlatform ); // NOI18N } if (detectedDbPlatform == null) { if(logger.shouldLog(SessionLog.INFO)) { logger.log(SessionLog.INFO, SessionLog.CONNECTION, "dbPlatformHelper_defaultingPlatform", vendorName, DEFAULTPLATFORM); // NOI18N } detectedDbPlatform = DEFAULTPLATFORM; } return detectedDbPlatform; }
/** * Loads properties list from the specified resource * into specified Properties object. * @param properties Properties object to load * @param resourceName Name of resource. * If loadFromFile is true, this is fully qualified path name to a file. * param classLoader is ignored. * If loadFromFile is false,this is resource name. * @param classLoader The class loader that should be used to load the resource. If null,primordial * class loader is used. */ private static void load(List<String[]> properties, final String resourceName, final ClassLoader classLoader) throws IOException { BufferedReader bin = new BufferedReader(new InputStreamReader(openResourceInputStream(resourceName,classLoader))); try { for (String line = bin.readLine(); line != null; line = bin.readLine()) { String[] keyValue = validateLineForReturnAsKeyValueArray(line); if (keyValue != null) { properties.add(keyValue); } } } finally { try { bin.close(); } catch (Exception e) { // no action } } }
private static void loadFromResource(List<String[]> properties, String resourceName, ClassLoader classLoader) throws IOException { load(properties, resourceName, classLoader); }
/** * Allocate and initialize nameToVendorPlatform if not already done. */ private static List<String[]> initializeNameToVendorPlatform(SessionLog logger) { synchronized(DBPlatformHelper.class) { if(_nameToVendorPlatform == null) { _nameToVendorPlatform = new ArrayList<String[]>(); try { loadFromResource(_nameToVendorPlatform, VENDOR_NAME_TO_PLATFORM_RESOURCE_NAME, DBPlatformHelper.class.getClassLoader() ); } catch (IOException e) { logger.log(SessionLog.WARNING, SessionLog.CONNECTION, "dbPlatformHelper_noMappingFound", VENDOR_NAME_TO_PLATFORM_RESOURCE_NAME); } } } return _nameToVendorPlatform; }
/** * Match vendorName in properties specified by _nameToVendorPlatform. */ private static String matchVendorNameInProperties(String vendorName, List<String[]> nameToVendorPlatform, SessionLog logger) { String dbPlatform = null; //Iterate over all properties till we find match. for( Iterator<String[]> iterator = nameToVendorPlatform.iterator(); dbPlatform == null && iterator.hasNext();) { String[] entry = iterator.next(); String regExpr = entry[0]; String value = entry[1]; if (logger.shouldLog(SessionLog.FINEST)) { logger.log(SessionLog.FINEST, SessionLog.CONNECTION, "dbPlatformHelper_regExprDbPlatform", regExpr, value); // NOI18N } if( matchPattern(regExpr, vendorName, logger) ) { dbPlatform = value; } } return dbPlatform; }
String platformName = null; try { platformName = DBPlatformHelper.getDBPlatform(conn.getMetaData().getDatabaseProductName(), getSessionLog()); getLogin().setPlatformClassName(platformName); } catch (EclipseLinkException classNotFound) {
private static void loadFromResource(Properties properties, String resourceName, ClassLoader classLoader) throws IOException { load(properties, resourceName, classLoader); }
/** * Allocate and initialize nameToVendorPlatform if not already done. */ private static Properties initializeNameToVendorPlatform(SessionLog logger) { 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, "dbPlatformHelper_noMappingFound", VENDOR_NAME_TO_PLATFORM_RESOURCE_NAME); } } } return _nameToVendorPlatform; }