You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.6 KiB
69 lines
2.6 KiB
2 years ago
|
package com.fr.plugin.utils;
|
||
|
|
||
|
|
||
|
import java.io.File;
|
||
|
import java.io.FileOutputStream;
|
||
|
import java.util.Properties;
|
||
|
|
||
|
import com.fanruan.api.log.LogKit;
|
||
|
import com.fr.plugin.GUANJIAConfig;
|
||
|
import com.sap.conn.jco.JCoDestination;
|
||
|
import com.sap.conn.jco.JCoDestinationManager;
|
||
|
import com.sap.conn.jco.JCoException;
|
||
|
import com.sap.conn.jco.ext.DestinationDataProvider;
|
||
|
|
||
|
public class ConnectSAPServer {
|
||
|
static String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";
|
||
|
|
||
|
static {
|
||
|
Properties connectProperties = new Properties();
|
||
|
GUANJIAConfig config = GUANJIAConfig.getInstance();
|
||
|
connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST,
|
||
|
config.getSapIp());
|
||
|
LogKit.info("SAP接口地址:{}", config.getSapIp());
|
||
|
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, config.getSysCode());
|
||
|
connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "01");
|
||
|
|
||
|
connectProperties
|
||
|
.setProperty(DestinationDataProvider.JCO_CLIENT, config.getCusCode());
|
||
|
LogKit.info("SAPCUSCODE:{}", config.getCusCode());
|
||
|
connectProperties.setProperty(DestinationDataProvider.JCO_USER,
|
||
|
config.getUserName());
|
||
|
LogKit.info("SAP用户名:{}", config.getUserName());
|
||
|
|
||
|
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD,
|
||
|
config.getPwd());
|
||
|
connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD,
|
||
|
config.getPwd());
|
||
|
connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "EN");
|
||
|
connectProperties.setProperty(
|
||
|
DestinationDataProvider.JCO_POOL_CAPACITY, "10");
|
||
|
connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT,
|
||
|
"10");
|
||
|
createDataFile(ABAP_AS_POOLED, "jcoDestination", connectProperties);
|
||
|
}
|
||
|
|
||
|
static void createDataFile(String name, String suffix, Properties properties) {
|
||
|
File cfg = new File(name + "." + suffix);
|
||
|
try {
|
||
|
FileOutputStream fos = new FileOutputStream(cfg, false);
|
||
|
properties.store(fos, "SAP连接配置文件");
|
||
|
fos.close();
|
||
|
} catch (Exception e) {
|
||
|
throw new RuntimeException(
|
||
|
"Unable to create the destination file "
|
||
|
+ cfg.getName(), e);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static JCoDestination Connect() {
|
||
|
JCoDestination destination = null;
|
||
|
try {
|
||
|
destination = JCoDestinationManager.getDestination(ABAP_AS_POOLED);
|
||
|
} catch (JCoException e) {
|
||
|
LogKit.error("链接数据库:", e);
|
||
|
}
|
||
|
return destination;
|
||
|
}
|
||
|
}
|