获取SAP连接

 

public class JcoProviderImpl implements DestinationDataProvider {

	
	private Map<String, Properties> proMap = new HashMap<String, Properties>();
	@Override
	public Properties getDestinationProperties(String destName) {
		// TODO Auto-generated method stub
		return proMap.get(destName);
	}

	@Override
	public void setDestinationDataEventListener(
			DestinationDataEventListener arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean supportsEvents() {
		// TODO Auto-generated method stub
		return false;
	}
	/**
     * 
     * 填充连接参数 <br>
     *
     * @param destName
     * @param p
     *            void
     */
    public void addProperty(DBSyncUtil dbSyncUtil) {
            Properties connectProperties = new Properties();
            try {
       	     connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, dbSyncUtil.getUrl());// 服务器
       	     connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, dbSyncUtil.getSysnr()); // 实例编号,系统编号 必须是两位数字
       	     connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, dbSyncUtil.getPort()); // SAP集团 三位字符
       	     connectProperties.setProperty(DestinationDataProvider.JCO_USER, dbSyncUtil.getUsername()); // SAP用户名
       	     connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, dbSyncUtil.getPwd()); // 密码
       	     connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "ZH"); // 登录语言:ZH EN
       	     connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3"); // 最大连接数
       	     connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10"); // 最大连接线程
       	     createDestinationDataFile(dbSyncUtil.getAppId(), connectProperties);
            } catch (Exception e) {
            	e.printStackTrace();
            }
        proMap.put(dbSyncUtil.getAppId(), connectProperties);
    }
    static void createDestinationDataFile(String destinationName, 
            Properties connectProperties) {
            File destCfg = new File(destinationName + ".jcoDestination");
            try {
                FileOutputStream fos = new FileOutputStream(destCfg, false);
                connectProperties.store(fos, "For SAP CONN !");
                fos.close();
            } catch (Exception e) {
                throw new RuntimeException("Unable to create the destination files", e);
            }
        }
}
public final class RfcManager {
 
    private JcoProviderImpl jcoProvider;
 
    /**
     * 
     * 注册 <br>
     * void
     * @throws Exception 
     */
    public void registProvider(Properties properties) throws Exception{
          try {
              Environment.registerDestinationDataProvider(jcoProvider);
          } catch (IllegalStateException e) {
        	  throw new Exception("注册Provider异常", e);
          }
   
    }
    
    /**
     * 
     * 取消注册 <br>
     * void
     * @throws Exception 
     */
    public void unRegistProvider() throws Exception {
        try {
            Environment.unregisterDestinationDataProvider(jcoProvider);
        } catch (Exception e) {
            throw new Exception("取消注册Provider异常", e);
        }
    }
    /**
     * 
     * 获取连接实例 <br>
     *
     * @param destinationName
     * @return JCoDestination
     */
    public JCoDestination creataDestination(String destinationName) {
        try {
            JCoDestination destination = JCoDestinationManager.getDestination(destinationName);
            destination.ping();
            return destination;
        } catch (Exception e) {
            throw new RuntimeException("获取SAP连接异常");
        }
    }
    public RfcManager(JcoProviderImpl jcoProvider) {
    	this.jcoProvider = jcoProvider;
		// TODO Auto-generated constructor stub
	}
 
}
JCoDestination destination = manager.creataDestination("服务编号");
JCoFunction lockFunction = destination.getRepository().getFunction(
					"methodName");
// 设置参数
JCoParameterList importParam = lockFunction
					.getImportParameterList();
JCoStructure IS_USER = importParam.getStructure("IS_USER");
IS_USER.setValue("USERNAME", userNo);
//执行
lockFunction.execute(destination);
//取消注册连接
manager.unRegistProvider();
// 获取返回值
JCoParameterList exportParam = lockFunction.getExportParameterList();

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值