关闭

通过JAVA、VB访问SAS IOM服务器

标签: javavbimport服务器stringserver
4327人阅读 评论(29) 收藏 举报
分类:


通过IOM(“Integrated Object Model” )服务器,没有必要使SAS安装在本地系统,通过Management Console和Enterprise Guide工具可以完美的连接到远端的SAS主机上

需要注意的是IOM服务器并不是代表一个具体的服务器,在SAS IT中,有下面4中类型的IOM服务器
 Metadata 服务器 – 存储和管理元数据库,包含哪些SAS服务器、库、和存储过程可用
 工作空间服务器 – 维护SAS程序环境;
 存储过程服务器 – 运行 “canned” SAS程序
 OLAP服务器 – 驱动CUBE数据到SAS Enterprise Guide或者其它OLAP客户端

工作空间服务器有下面3中类型
 JAVA客户端连接到IOM服务器使用JAVA-IOM桥
 WIN客户端连接到IOM服务器使用COM/DCOM技术,
 WIN客户端可以连接到运行在UNXI上的IOM服务器,通过使用COM-IOM桥

对于WIN应用,IOM支持ADO通过OLEDB访问SAS数据
对应JAVA,JDBC2.0访问是被支持的

工作空间服务器包含下面接口
 工作空间Workspace – SAS会话
 语言服务Language Service –提交SAS DATA步和过程步,接收LOG和LIST输出,运行存储过程
 数据服务Data Service – 管理SAS库
 文件服务File Service – 管理文件标识
 实用工具Utilities – formats, options, result packages, host system information

存储过程服务器
 用于存放存储过程,其结果可以被WEB(Information Delivery Portal,BI WEB服务)、OFFICE(OFFICE插件)或者Enterprise Guide 3.0使用

假设在SAS服务器上存在下面文件
 C:/temp>type IOMTest.sas
 %let cond=;
 *ProcessBody;
 proc print data=sashelp.class;
 title "Test Stored Process";
 where &cond;
 run;  
 
VB例子:
 必须引用下面库
  SAS: Integrated Object Model (SAS System 9.1)
   SASWorkspaceManager 1.1 Type Library 
   
Connecting with DCOM in Visual Basic
Option Explicit
' define a global workspace
Dim obSAS As SAS.Workspace
Dim obWSMgr As New SASWorkspaceManager.WorkspaceManager
Private Sub Form_Load()
Dim xmlInfo As String
' create Workspace server
Dim obServer As New SASWorkspaceManager.ServerDef
obServer.MachineDNSName = "hunding"
Set obSAS = obWSMgr.Workspaces.CreateWorkspaceByServer _
("", VisibilityProcess, obServer, "", "", xmlInfo)
End Sub
Private Sub cmdTest1_Click()
' use LanguageService to submit code
obSAS.LanguageService.Submit _
"%include 'c:/temp/IOMTest.sas'; run;"
MsgBox obSAS.LanguageService.FlushLog(100000)
MsgBox obSAS.LanguageService.FlushList(100000)
End Sub
Private Sub cmdTest2_Click()
'run the stored SAS program
Dim obStoredProcessService As SAS.StoredProcessService
Set obStoredProcessService = _
obSAS.LanguageService.StoredProcessService
obStoredProcessService.Repository = "file:c:/temp"
obStoredProcessService.Execute "IOMtest", "cond='sex eq ""M""'"
MsgBox obSAS.LanguageService.FlushLog(100000)
MsgBox obSAS.LanguageService.FlushList(1000000)
End Sub
Private Sub Form_Unload(Cancel As Integer)
obWSMgr.Workspaces.RemoveWorkspaceByUUID _
obSAS.UniqueIdentifier
obSAS.Close
End Sub
  
VC例子
#include <iostream>
#include <stdexcept>
#include <windows.h>
using namespace std;
#import "C:/Program Files/SAS Institute/Shared Files/Integration
Technologies/sas.tlb"
#import "C:/Program Files/SAS Institute/Shared Files/Integration
Technologies/SASWMan.dll"
int main()
{
SASWorkspaceManager::IWorkspaceManager2Ptr pIWorkspaceManager;
SASWorkspaceManager::IServerDef2Ptr pIServerDef = NULL;
SAS::IWorkspacePtr pIWorkspace;
BSTR xmlInfo;
HRESULT hr = CoInitialize(NULL);
hr = pIWorkspaceManager.CreateInstance(
"SASWorkspaceManager.WorkspaceManager.1");
pIServerDef.CreateInstance("SASWorkspaceManager.ServerDef");
pIServerDef->PutMachineDNSName("hygelac");
pIServerDef->Protocol = SASWorkspaceManager::ProtocolBridge;
pIServerDef->put_Port(8591);
pIWorkspace = pIWorkspaceManager->Workspaces->CreateWorkspaceByServer(
_bstr_t(""), //workspace name
SASWorkspaceManager::VisibilityProcess,
pIServerDef, // server
_bstr_t("sassrv"), // login
_bstr_t("sasuser"), // password
&xmlInfo // connection log
);
pIWorkspace->LanguageService->Submit(
"%include '/home/sasadm/IOMTest.sas'; run;");
MessageBox(NULL,
pIWorkspace->LanguageService->FlushLog(10000),
"SAS Log",
MB_OK
);
MessageBox(NULL,
pIWorkspace->LanguageService->FlushList(10000),
"List Output",
MB_OK
);
pIWorkspace->Close();
return(0);
}
JAVA客户端

 编译时使用下面命令
 javac -classpath ".:C:/Program Files/SAS/SAS 9.1/core/sasmisc/sas.svc.connection.jar" IOMTest.java
 sas.svc.connection.jar文件位于 C:/Program Files/SAS/SAS 9.1/core/sasmisc 下
 
 例子代码如下:
import com.sas.services.connection.Server;
import com.sas.services.connection.BridgeServer;
import com.sas.services.connection.ConnectionFactoryConfiguration;
import com.sas.services.connection.ConnectionFactoryManager;
import com.sas.services.connection.ConnectionFactoryInterface;
import com.sas.services.connection.ConnectionFactoryException;
import com.sas.services.connection.ConnectionInterface;
import com.sas.services.connection.ManualConnectionFactoryConfiguration;
import com.sas.iom.SAS.IWorkspace;
import com.sas.iom.SAS.IWorkspaceHelper;
import com.sas.iom.SAS.ILanguageService;
import com.sas.iom.SAS.ILanguageServicePackage.CarriageControlSeqHolder;
import com.sas.iom.SAS.ILanguageServicePackage.LineTypeSeqHolder;
import com.sas.iom.SASIOMDefs.GenericError;
import com.sas.iom.SASIOMDefs.StringSeqHolder;
import javax.swing.JOptionPane;
public class IOMTest{
public IOMTest() throws ConnectionFactoryException, GenericError
{
// connection parameters
String classID = Server.CLSID_SAS;
String host = "hunding";
int port = 8591;
String userName = "sassrv";
String password = "sasuser";
// identify the IOM Bridge server (the Workspace server)
Server server = new BridgeServer(classID,host,port);
// make a manual connection factory configuration to the server
ConnectionFactoryConfiguration cxfConfig =
new ManualConnectionFactoryConfiguration(server);
// get a connection factory manager
ConnectionFactoryManager cxfManager =
new ConnectionFactoryManager();
// get a connection factory interface from the manager
ConnectionFactoryInterface cxf = cxfManager.getFactory(cxfConfig);
// get a connection from the interface
ConnectionInterface cx = cxf.getConnection(userName,password);
// create a workspace by "narrowing" the connection to the ORB
IWorkspace iWorkspace = IWorkspaceHelper.narrow( cx.getObject() );
// Submit batch SAS code
ILanguageService sasLanguage = iWorkspace.LanguageService();
sasLanguage.Submit("%include 'c://temp//IOMtest.sas'; run;");
// flush log file to string array
StringSeqHolder logHldr = new StringSeqHolder();
sasLanguage.FlushLogLines(
Integer.MAX_VALUE,
new CarriageControlSeqHolder(),
16
new LineTypeSeqHolder(),
logHldr);
// display log file
String[] logLines = logHldr.value;
JOptionPane.showMessageDialog(null, logLines);
// flush list file to string array
StringSeqHolder listHldr = new StringSeqHolder();
sasLanguage.FlushListLines(
Integer.MAX_VALUE,
new CarriageControlSeqHolder(),
new LineTypeSeqHolder(),
listHldr);
// display list file
String[] listLines = listHldr.value;
JOptionPane.showMessageDialog(null, listLines);
iWorkspace.Close();
cx.close();
}
public static void main(String args[]) {
try {
new IOMTest();
System.exit(0);
}
catch(Exception ex) {
ex.printStackTrace();
System.exit(1);
}
}
}  
  
  
详情参考下面链接

· SAS OnlineDoc (includes links to all the separate product documentation).
<http://support.sas.com/91doc/docMainpage.jsp>
· SAS Integration Technologies: Version 9 Documentation.
<http://support.sas.com/rnd/itech/library/library9.html.>
· SAS Integration Technologies: Release 8.2 Documentation.
<http://support.sas.com/rnd/itech/library/library82.html>
· SAS 9.1 Open Metadata Architecture: Best Practices Guide.
<http://support.sas.com/rnd/eai/openmeta/v9/bestpractices/>
· SAS 9.1.2 Metadata Server: Setup Guide. <http://support.sas.com/rnd/eai/openmeta/v9/setup/>  

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:603396次
    • 积分:8328
    • 等级:
    • 排名:第2353名
    • 原创:185篇
    • 转载:6篇
    • 译文:3篇
    • 评论:402条
    文章分类
    最新评论