⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex7_8.txt

📁 j2ee core design patterns
💻 TXT
字号:
Example 7.8 	ServiceLocator.java: Implementing JDBC DataSource Service Locator Strategy
package com.corej2eepatterns.servicelocator;

// imports
public class ServiceLocator {
    . . . 

    public DataSource getDataSource(String dataSourceName) 
    throws ServiceLocatorException {
        DataSource dataSource = null;
        try {
            if (cache.containsKey(dataSourceName)) {
                dataSource =
                    (DataSource) cache.get(dataSourceName);
            } else {
                dataSource = (DataSource) 
                    initialContext.lookup(dataSourceName);
                cache.put(dataSourceName, dataSource );
            }
        } catch (NamingException nex) {
            throw new ServiceLocatorException(nex);
        } catch (Exception ex) {
            throw new ServiceLocatorException(ex);
        }
        return dataSource;
    }
    . . .
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -