Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* 
   * Copyright (C) 2010---2013 星星(wuweixing)<349446658@qq.com>
   * 
   * This file is part of Wabacus 
   * 
   * Wabacus is free software: you can redistribute it and/or modify
   * it under the terms of the GNU Lesser General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 package com.wabacus.config.database.datasource;
 
 import java.util.List;
 
 
 
 
 //$ByQXO 
 public class JNDIDataSource extends AbstractJdbcDataSource
 { //ByQXO$
     private static Log log=LogFactory.getLog(JNDIDataSource.class);
 
     private String jndi;
 
     private DataSource ds;
 
     public String getJndi()
     {
         return ;
     }
 
     public void setJndi(String jndi)
     {
         this.=jndi;
     }
 
     public Connection getConnection()
     {
         Connection conn=null;
         try
         {
             .debug("从数据源"+this.getName()+"获取数据库连接");
             conn=getDataSource().getConnection();
         }catch(SQLException e)
         {
             .error("获取数据源发生异常",e);
         }
         return conn;
     }
 
     public DataSource getDataSource()
     {
         Context context=null;
         try
         {
             if(!=null)
             {
                 return ;
             }
             context=new InitialContext();
             =(DataSource)context.lookup();
             return ;
         }catch(Exception e)
         {
             .error("获取数据源发生异常",e);
             return null;
         }finally
         {
             try
             {
                 if(context!=null)
                 {
                     context.close();
                 }
             }catch(Exception ex)
             {
                 .error("获取数据源发生异常",ex);
             }
         }
 
     }
     
    public void loadConfig(Element eleDataSource)
    {
        super.loadConfig(eleDataSource);
        List lstEleProperties=eleDataSource.elements("property");
        if(lstEleProperties==null||lstEleProperties.size()==0)
        {
            throw new WabacusConfigLoadingException("没有为数据源:"+this.getName()
                    +"配置jndi参数");
        }
        Element eleChild;
        String name;
        String value;
        for(int i=0;i<lstEleProperties.size();i++)
        {
            eleChild=(Element)lstEleProperties.get(i);
            name=eleChild.attributeValue("name");
            //$ByQXO 全局配置优先
            valuegetOverridePropertyValue(name,eleChild.getText());
            //ByQXO$
            
            name=name==null?"":name.trim();
            value=value==null?"":value.trim();
            if(name.equals("jndi"))
            {
                =value;
                break;
            }
        }
        if(==null||.trim().equals(""))
        {
            throw new WabacusConfigLoadingException("数据源:"+this.getName()+"配置的jndi值为空");
        }
    }
New to GrepCode? Check out our FAQ X