package com.sap.mdm.examples;
import com.sap.mdm.commands.AuthenticateRepositorySessionCommand;
import com.sap.mdm.commands.CommandException;
import com.sap.mdm.commands.CreateRepositorySessionCommand;
import com.sap.mdm.commands.DestroySessionCommand;
import com.sap.mdm.net.ConnectionException;
import com.sap.mdm.net.ConnectionPool;
import com.sap.mdm.net.ConnectionPoolFactory;
import com.sap.mdm.repository.commands.LoadRepositoryCommand;
import com.sap.mdm.server.DBMSType;
import com.sap.mdm.server.RepositoryIdentifier;
/*
* Copyright © 2004-2006 by SAP AG.
* All Rights Reserved.
*
* SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP
* products and services mentioned herein as well as their respective logos are
* trademarks or registered trademarks of SAP AG in Germany and in several other
* countries all over the world. All other product and service names mentioned
* are the trademarks of their respective companies. Data contained in this
* document serves informational purposes only. National product specifications
* may vary.
*
* These materials are subject to change without notice. These materials are
* provided by SAP AG and its affiliated companies (SAP Group) for informational
* purposes only, without representation or warranty of any kind, and SAP Group
* shall not be liable for errors or omissions with respect to the materials.
* The only warranties for SAP Group products and services are those that are
* set forth in the express warranty statements accompanying such products and
* services, if any. Nothing herein should be construed as constituting an
* additional warranty.
*
*/
/**
* This example demonstrates loading a repository. The steps are:
*
* - Establishes connection with the MDM server
* - Creates a repository session for the targeted repository
* - Authenticates the session
* - Loads the repository
* - Destroys the session
*
* Commands used:
* CreateRepositorySessionCommand
* AuthenticateRepositorySessionCommand
* LoadRepositoryCommand
* DestroySessionCommand
*
* Source code for LoadRepository.java
*/
public class LoadRepository {
private LoadRepository() {
}
public static void main(String[] args) {
// create connection pool
String connectionTag = "LOCALHOST";
ConnectionPool connections = null;
try {
connections = ConnectionPoolFactory.getInstance(connectionTag);
} catch (ConnectionException e) {
e.printStackTrace();
return;
}
// alternatively, a repository identifier can be obtain from the GetMountedRepositoryListCommand
RepositoryIdentifier reposId = new RepositoryIdentifier("EmptyRepos", "LOCALHOST", DBMSType.MS_SQL);
// create repository session
CreateRepositorySessionCommand sessionCommand = new CreateRepositorySessionCommand(connections);
sessionCommand.setRepositoryIdentifier(reposId);
try {
sessionCommand.execute();
} catch (CommandException e) {
e.printStackTrace();
return;
}
String sessionId = sessionCommand.getRepositorySession();
// authenticate the repository session
String userName = "Admin";
String userPassword = "";
AuthenticateRepositorySessionCommand authCommand = new AuthenticateRepositorySessionCommand(connections);
authCommand.setSession(sessionId);
authCommand.setUserName(userName);
authCommand.setUserPassword(userPassword);
try {
authCommand.execute();
} catch (CommandException e) {
e.printStackTrace();
return;
}
// load the repository
LoadRepositoryCommand loadReposCommand = new LoadRepositoryCommand(connections);
loadReposCommand.setSession(sessionId);
try {
loadReposCommand.execute();
} catch (CommandException e) {
e.printStackTrace();
return;
}
// finally destroy the repository session
DestroySessionCommand destroySessionCommand = new DestroySessionCommand(connections);
destroySessionCommand.setSession(sessionId);
try {
destroySessionCommand.execute();
} catch (CommandException e) {
e.printStackTrace();
return;
}
}
}