The example provided in this document is provided “as-is” to the user and assumes that the user:
PREREQUISITES
For the sample to work, the Strategy Web JAR files must be accessible by the Java Runtime
Environment. The Strategy Web JAR files can be found under:
Note:
More elaborate programs will require additional library files and are out of the scope of this document.
package com.Strategy.sdk.samples.webobjects;
import java.util.Date;
import com.Strategy.web.objects.WebDBConnection;
import com.Strategy.web.objects.WebDBLogin;
import com.Strategy.web.objects.WebDBMS;
import com.Strategy.web.objects.WebDBRole;
import com.Strategy.web.objects.WebFolder;
import com.Strategy.web.objects.WebObjectSource;
import com.Strategy.web.objects.WebObjectsFactory;
import com.Strategy.web.objects.WebIServerSession;
import com.Strategy.web.objects.WebObjectsException;
import com.Strategy.webapi.EnumDSSXMLObjectTypes;
public class DatabaseInstance {
private static WebObjectsFactory factory = null;
private static WebIServerSession serverSession = null;
public static void main (String[] args) {
if(serverSession == null) {
//create factory object
factory = WebObjectsFactory.getInstance();
serverSession = factory.getIServerSession();
//Set up session properties
serverSession.setServerName("localhost"); //Should be replaced with the name of an Intelligence Server
serverSession.setServerPort(0);
serverSession.setProjectName("Strategy Tutorial"); //Project where the session should be created
serverSession.setLogin("administrator"); //User ID
serverSession.setPassword(""); //Password
WebObjectSource wos = serverSession.getFactory().getObjectSource();
try {
Date dt = new Date();
//new database login
//metadata folder ID for DBLogin config object: 73F7482911D3596C60001B8F67019608
WebDBLogin dbLogin = (WebDBLogin)wos.getNewObject(EnumDSSXMLObjectTypes.DssXmlTypeDBLogin);
dbLogin.setLogin("DBLogin" + dt);
dbLogin.setPassword("DBPass");
WebFolder folderDBL = (WebFolder)wos.getObject("73F7482911D3596C60001B8F67019608", EnumDSSXMLObjectTypes.DssXmlTypeFolder);
wos.save(dbLogin, "CustomDBLogin" + dt, folderDBL);
//new database connection
//DBConnection folder ID: 73F7482811D3596C60001B8F67019608
WebDBConnection dbConnection = (WebDBConnection)wos.getNewObject(EnumDSSXMLObjectTypes.DssXmlTypeDBConnection);
dbConnection.setDBLogin(dbLogin);
dbConnection.setConnectionString("DSN=Strategy_Tutorial_Data;"); //datasource
WebFolder folderDBC = (WebFolder) wos.getObject("73F7482811D3596C60001B8F67019608", EnumDSSXMLObjectTypes.DssXmlTypeFolder);
wos.save(dbConnection, "TestDBConnection" + dt, folderDBC);
//get dbms
//You can get the corresponding ID for the connection types through DBQuery Tool or Command Manager
//For example, database connection type: Microsoft Access 2000/2002/2003 has ID: 1D076B3F099F11D4800100C04F780688
WebDBMS dbms = (WebDBMS) wos.getObject("1D076B3F099F11D4800100C04F780688", EnumDSSXMLObjectTypes.DssXmlTypeDBMS);
dbms.populate();
//new database instance
//DBInstance foler ID: 73F7482711D3596C60001B8F67019608
WebDBRole dbRole = (WebDBRole)wos.getNewObject(EnumDSSXMLObjectTypes.DssXmlTypeDBRole);
dbRole.setDBMS(dbms);
dbRole.setDefaultDBConnection(dbConnection);
WebFolder folderDBR = (WebFolder)wos.getObject("73F7482711D3596C60001B8F67019608", EnumDSSXMLObjectTypes.DssXmlTypeFolder);
wos.save(dbRole, "TestDBI" + dt, folderDBR);
} catch (WebObjectsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}