cancel
Showing results for 
Search instead for 
Did you mean: 

MDM Java API (Creation of table)

Former Member
0 Kudos

Hi,

can anyone help me for creation of tables in repository using MDM java API .

Can u Provide sample code for this.

Edited by: Srikanth Josyula on Jun 26, 2008 8:52 AM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Srikanth,

Check with this code.It may be useful.

/*

  • createflattable.java

*

  • Created on June 25, 2008, 5:08 PM

*

  • To change this template, choose Tools | Options and locate the template under

  • the Source Creation and Management node. Right-click the template and choose

  • Open. You can then make changes to the template in the Source Editor.

*/

package tabletype;

import com.sap.mdm.commands.AuthenticateRepositorySessionCommand;

import com.sap.mdm.commands.CommandException;

import com.sap.mdm.commands.CreateRepositorySessionCommand;

import com.sap.mdm.commands.GetRepositoryRegionListCommand;

import com.sap.mdm.data.MultilingualString;

import com.sap.mdm.data.RegionProperties;

import com.sap.mdm.data.RegionalString;

import com.sap.mdm.net.ConnectionException;

import com.sap.mdm.net.ConnectionPool;

import com.sap.mdm.net.ConnectionPoolFactory;

import com.sap.mdm.schema.TableProperties;

import com.sap.mdm.schema.commands.CreateTableCommand;

import com.sap.mdm.schema.commands.GetFieldListCommand;

import com.sap.mdm.schema.commands.GetTableListCommand;

import com.sap.*;

import com.sap.mdm.server.DBMSType;

import com.sap.mdm.server.RepositoryIdentifier;

import java.util.Locale;

public class createflattable {

/** Creates a new instance of createflattable */

public createflattable() {

}

private static MultilingualString createMultilingualString(RegionProperties[] regionPropertiesList, String baseString)

{

MultilingualString mlString = new MultilingualString();

for (int i = 0; i < regionPropertiesList.length; i++)

{

Locale locale = regionPropertiesList<i>.getLocale();

//Locale locale = regionPropertiesList<i>.getLocale();

String regionCode = regionPropertiesList<i>.getRegionCode();

String string = baseString + "_" + locale.getLanguage() + "_" + locale.getCountry();

RegionalString regionalstring = new RegionalString(string, regionCode);

mlString.set(regionalstring);

}

return mlString;

}

private static TableProperties createFlatTable(RegionProperties[] regionPropertiesList)

{

//MultilingualString tableName = createMultilingualString(regionPropertiesList, "NewTable" + System.currentTimeMillis());

MultilingualString tableName = createMultilingualString(regionPropertiesList, "first"+System.currentTimeMillis());

System.out.println("table is" +tableName);

TableProperties table = new TableProperties(TableProperties.FLAT);

table.setName(tableName);

table.setCode("NewCode" + System.currentTimeMillis());

table.setKeyMappable(true);

table.setDescription("");

return table;

}

public static void main(String[] args) {

// System Name

String tag = "";

ConnectionPool connections = null;

try {

connections = ConnectionPoolFactory.getInstance(tag);

}

catch (ConnectionException e)

{

e.printStackTrace();

return;

}

//////////////// specify the repository to use

//RepositoryName

String repositoryName = "";

//DataBase Name

String dbmsName = "";

RepositoryIdentifier reposId = new RepositoryIdentifier(repositoryName, dbmsName, DBMSType.MS_SQL);

/////// create a repository session

CreateRepositorySessionCommand sessionCommand = new CreateRepositorySessionCommand(connections);

sessionCommand.setRepositoryIdentifier(reposId);

try {

sessionCommand.execute();

}

catch (CommandException e) {

e.printStackTrace();

return;

}

System.out.println("Currently connected to "+reposId);

String sessionId = sessionCommand.getRepositorySession();

/////////// authenticate the repository session

String userName = "";

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;

}

//////////////////// retrieve the list of tables

GetTableListCommand tableListCommand = new GetTableListCommand(connections);

tableListCommand.setSession(sessionId);

try {

tableListCommand.execute();

}

catch (CommandException e) {

e.printStackTrace();

return;

}

// get change stamp

// this is required when we make any kind of changes to the repository

int changeStamp = tableListCommand.getChangeStamp();

//////get repository regionlist

//A command for retrieving the list of regions supported by the repository.

// retrieve the available regions (languages) for the repository

// we need this to set up the table name for each region

GetRepositoryRegionListCommand gm = new GetRepositoryRegionListCommand(connections);

gm.setRepositoryIdentifier(reposId);

try {

gm.execute();

}

catch (CommandException e) {

e.printStackTrace();

return;

}

// RegionProperties[] rs = gm.getRegions();

RegionProperties[] regionPropertiesList = gm.getRegions();

TableProperties newtable = createFlatTable(regionPropertiesList);

CreateTableCommand c = new CreateTableCommand (connections);

c.setSession(sessionId);

c.setTable(newtable);

c.setInChangeStamp(changeStamp);

try {

c.execute();

System.out.println("sdf");

}

catch (CommandException e) {

e.printStackTrace();

return;

}

}

}

Answers (1)

Answers (1)

Former Member
0 Kudos

hi santosh,

i got the solution by using this code

thank you.