JpaEntityManagerFactory.java 文件源码

java
阅读 30 收藏 0 点赞 0 评论 0

项目:cloud-employeeslistapp 作者:
/**
 * Returns the singleton EntityManagerFactory instance for accessing the
 * default database.
 * 
 * @return the singleton EntityManagerFactory instance
 * @throws NamingException
 *             if a naming exception occurs during initialization
 * @throws SQLException
 *             if a database occurs during initialization
 * @throws IOException 
 */
public static synchronized EntityManagerFactory getEntityManagerFactory()
        throws NamingException, SQLException, IOException {
    if (entityManagerFactory == null) {
        InitialContext ctx = new InitialContext();
        BasicDataSource ds = new BasicDataSource();
        JsonNode credentials = readCredentialsFromEnvironment();
        ds.setDriverClassName(credentials.get("driver").asText());
        ds.setUrl(credentials.get("url").asText());
        ds.setUsername(credentials.get("user").asText());
        ds.setPassword(credentials.get("password").asText());
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE, ds);
        entityManagerFactory = Persistence.createEntityManagerFactory(
                PERSISTENCE_UNIT_NAME, properties);
    }
    return entityManagerFactory;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号