`

Java Persistence API to get properties files

    博客分类:
  • J2SE
阅读更多
package com;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;


/**
 * @author cnchenhl
 *
 */
public class InputPropertyFile {
    
    private final String DB_DRIVER_KEY = "openjpa.ConnectionDriverName";
    private final String DB_URL_KEY = "openjpa.ConnectionURL";
    private final String DB_USER_KEY = "openjpa.ConnectionUserName";
    private final String DB_PASSWORD_KEY = "openjpa.ConnectionPassword";
    private final String DB_SCHEMA_KEY = "openjpa.jdbc.Schema";
    private final String DB_LOG_KEY = "openjpa.Log";
    
    private String DB_DRIVER_VALUE = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
    private String DB_USER_VALUE = "abc";
    private String DB_PASSWORD_VALUE = "chenhailong";
    private String DB_SCHEMA_VALUE = "dbo";
    private String DB_LOG_VALUE = "DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE";
    
    public Map<String, Object> getProperties(String name,String file) {
        HashMap<String, Object> result = new HashMap<String, Object>();
        
        File propertyFile = new File(System.getProperty(file), name);
        Properties props = new Properties();
        
        String DB_URL_VALUE = null;
        try {
            props.load(new BufferedInputStream(new FileInputStream(propertyFile)));
            
            DB_URL_VALUE = "jdbc:sqlserver://" +
                props.getProperty("jp.co.fujixerox.awdm.db.server") + ":" +
                props.getProperty("jp.co.fujixerox.awdm.db.port") + ";databaseName=" +
                props.getProperty("jp.co.fujixerox.awdm.db.dbname");
                
            
        } catch (Exception e) {
           e.printStackTrace();
        } finally {}
        
        result.put(DB_DRIVER_KEY, DB_DRIVER_VALUE);
        result.put(DB_URL_KEY, DB_URL_VALUE);
        result.put(DB_USER_KEY, DB_USER_VALUE);
        result.put(DB_PASSWORD_KEY, DB_PASSWORD_VALUE);
        result.put(DB_SCHEMA_KEY, DB_SCHEMA_VALUE);
        result.put(DB_LOG_KEY, DB_LOG_VALUE);
        
        return result;
    }
    

}

 

0
0
分享到:
评论

相关推荐

    hibernate.docx

    除了Hibernate之外,还有其他一些持久层框架可供选择,如MyBatis(原名为iBatis)、NHibernate、Java Persistence API (JPA)等。不同的框架有着各自的特点和适用场景,但它们的核心目标都是为了提供更高效、更简洁的...

    testhibernate.zip

    4. **持久化操作(Persistence Operations)**:项目中可能包含多个Java类或方法,展示了如何执行CRUD(创建、读取、更新、删除)操作,例如使用`Session`的`save()`, `get()`, `update()`, `delete()`方法。...

    Python Cookbook, 2nd Edition

    Avoiding Boilerplate Accessors for Properties Recipe 6.9. Making a Fast Copy of an Object Recipe 6.10. Keeping References to Bound Methods Without Inhibiting Garbage Collection Recipe 6.11. ...

    python3.6.5参考手册 chm

    PEP 523: Adding a frame evaluation API to CPython PYTHONMALLOC environment variable DTrace and SystemTap probing support Other Language Changes New Modules secrets Improved Modules array ast ...

    ZendFramework中文文档

    1. Introduction to Zend Framework 1.1. 概述 1.2. 安装 2. Zend_Acl 2.1. 简介 2.1.1. 关于资源(Resource) 2.1.2. 关于角色(Role) 2.1.3. 创建访问控制列表(ACL) 2.1.4. 注册角色(Role) 2.1.5. 定义访问...

    Doctrine ORM for PHP.pdf

    Introduction to Connections...........................................................................25 DSN, the Data Source Name.........................................................................

Global site tag (gtag.js) - Google Analytics