cancel
Showing results for 
Search instead for 
Did you mean: 

code for modifying syncBo

Former Member
0 Kudos

I have a scenario where in the syncBo i have MODIFY bapi wrappers

with following structure

<b>Import</b>

CARRID

CONNID

<b>Tables</b>

FLDATE

CITY

CITYFROM

SEATSOCC

PAYMENTSUM

I need to modify the PaymentSum column


public void modifyRecordAmt(String syncBoName,String syncKey){
		  System.out.println("modifyRecordAmount");
		  SyncBoDescriptor sbd=descriptorFacade.getSyncBoDescriptor(syncBoName);
		  SyncBo sb=null;
		  try{
			  sb=dataFacade.getSyncBo(sbd,syncKey);
		  }catch(PersistenceException pex){
			  System.out.println("Exception in modifyRecordLoc:" +pex.getMessage());
		  }
		
		  SmartSyncTransactionManager transactionManager;
		  try{
			  transactionManager=dataFacade.getSmartSyncTransactionManager();
			  if(!transactionManager.isTransactionStarted()){
				  transactionManager.beginTransaction();
boolean b1,b2,b3,b4,b5;
b1=setHeaderFieldValue2(sb,"FLDATE","2007-10-10");
b2=setHeaderFieldValue2(sb,"CITY","NW");
b3=setHeaderFieldValue2(sb,"CITYFROM","NEW JERSEY");
b4=setHeaderFieldValue2(sb,"SEATSOCC","375");
b5=setHeaderFieldValue2(sb,"PAYMENTSUM","1500");

System.out.println(b1 +b2 + b3 +b4 +b5);				  transactionManager.commit();
			  }
		  }catch(Exception e){
			  System.out.println("Exception in modifyRecordLoc2:" +e.getMessage());
		  }
		
	  }
	
	public boolean setHeaderFieldValue2(
		SyncBo sb,
		String headerFieldName,
		Object value) {
		SyncBoDescriptor sbd = sb.getSyncBoDescriptor();
		RowDescriptor trd = sbd.getTopRowDescriptor();
		FieldDescriptor fd = trd.getFieldDescriptor(headerFieldName);
		if (fd != null) {
		BasisFieldType bft = fd.getFieldType();
		Row header = sb.getTopRow();
		try {
//		   Integer operator
		if (bft == BasisFieldType.N) {
		NumericField nf = header.getNumericField(fd);
		if (nf != null) {
		BigInteger ii = new BigInteger(value.toString());
		nf.setValue(ii);
		return true;
		} else {
		return false;
		}
		}
//		   Character operator
		if (bft == BasisFieldType.C) {
		CharacterField cf = header.getCharacterField(fd);
		if (cf != null) {
		cf.setValue(value.toString());
		return true;
		} else {
		return false;
		}
 
		}
//		   Decimal operator
		if (bft == BasisFieldType.P) {
		DecimalField df = header.getDecimalField(fd);
		if (df != null) {
		BigDecimal bd = new BigDecimal(value.toString());
		df.setValue(bd);
		return true;
		} else {
		return false;
		}
 
		}
//		   Similar operation for time and date operator fields
		if (bft == BasisFieldType.D) {
		DateField df = header.getDateField(fd);
		if (df != null) {
		if (value.toString().equals("0")) {
		Date dat = Date.valueOf("0000-00-00");
		df.setValue(dat);
		} else if (!value.toString().equals("")) {
		Date dat = Date.valueOf(value.toString());
		df.setValue(dat);
		} else {
		Calendar cal = Calendar.getInstance();
 
		java.sql.Date bd =
		new java.sql.Date(cal.getTime().getTime());
 
		df.setValue(bd);
		}
		return true;
		} else {
		return false;
		}
 
		}
 
//		   Similar operation for time and date operator fields
		} catch (SmartSyncException ex) {
		System.out.println(ex.getMessage());
		} catch (PersistenceException e) {
		System.out.println(e.getMessage());
		}
		}
		return false;
		}

b1 b2 b3 b4 b5 all return <b>false </b>

pls advice.

Message was edited by:

yzme yzme

Message was edited by:

yzme yzme

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

<b>Import </b> [header]

CARRID

CONNID

<b>Tables</b> [Item]

FLDATE

CITY

CITYFROM

SEATSOCC

PAYMENTSUM

anyone can help me on this

the code above is to modifying header

but what if i have header and items , and i want to modify the items

how do i modify this code to get the item row

Is there a method to setItemFieldValue instead of setHeaderFieldValue

public boolean setHeaderFieldValue(SyncBo sb,String headerFieldName,Object value){

SyncBoDescriptor sbd=sb.getSyncBoDescriptor();

<b>RowDescriptor trd=sbd.getTopRowDescriptor();</b>

FieldDescriptor fd=trd.getFieldDescriptor(headerFieldName);

if(fd!=null){

BasisFieldType bft=fd.getFieldType();

<b>Row header=sb.getTopRow();</b>

}

....

......

.........

}

Former Member
0 Kudos

Hi yzme,

In the first place, there is no such method 'setHeaderFieldValue()' in MDK. it is an autogenerated one.

so similarly you will have to write code if you wan tot modify the data in an item.

1. The Header is referred to as TOP row.

RowDescriptor trd = sbd.getTopRowDescriptor();

Here TopRow indicates the Header.

2. and subsequent rows are referred to as 010...and such

a) you can fetch all Rows and iterate though them like this:

RowDescriptor rd = sbd.getRowDescriptor(itemName);

FieldDescriptorIterator fdi = rd.getAllFieldDescriptors();

...

while (fdi.hasNext()) {

fdi.next();

i++;

}

...

b) else fetch exactly by the Row, where you already know the level of the item

SyncBoDescriptor sbd = syncBo.getSyncBoDescriptor();

...

RowDescriptor trd = sbd.getRowDescriptor("010");

which is an item field...

see whats suits you.

Hope this helps

Regards

Divya

Former Member
0 Kudos

public boolean setHeaderFieldValue(SyncBo sb,String headerFieldName,Object value){

SyncBoDescriptor sbd=sb.getSyncBoDescriptor();

//RowDescriptor trd=sbd.getTopRowDescriptor();

<b>RowDescriptor trd=sbd.getRowDescriptor("010")</b>

FieldDescriptor fd=trd.getFieldDescriptor(headerFieldName);

if(fd!=null){

BasisFieldType bft=fd.getFieldType();

//Row header=sb.getTopRow();

<b>Row item=sb.getRow("0001208277");</b>

}

in mdk api it is stated that

sb.getRow("primary key");

does it means the syncKey of the row ?

sync log error:

• Synchronization started

• Connection set up (without proxy) to: http://pc1:50100/meSync/servlet/meSync?~sysid=N01&;

• Successfully connected with server.

• Processing of inbound data began.

<b>

• Exception while proccessing method SMARTSYNC : java.lang.RuntimeException: Inbound processing of container with index 12 failed: Cannot insert as entity already exists for IClassDescriptor/Key: sZFLIGHT_010/1211196 : r0001211195 : Inbound processing of container with index 12 failed: Cannot insert as entity already exists for IClassDescriptor/Key: sZFLIGHT_010/1211196 : r0001211195

• Exception while proccessing method SMARTSYNC : java.lang.IllegalStateException: No Context available for ConversationId 15F232A35E945449A7B4BDA97C666D13 : No Context available for ConversationId 15F232A35E945449A7B4BDA97C666D13

• Exception while proccessing method SMARTSYNC : java.lang.IllegalStateException: No Context available for ConversationId 93F8B7BB4B3499478E9F4DE9126AC53F : No Context available for ConversationId 93F8B7BB4B3499478E9F4DE9126AC53F

</b>

Message was edited by:

yzme yzme

Former Member
0 Kudos

This is not a good approach yzme,

//Row header=sb.getTopRow();

Row item=sb.getRow("0001208277");

better enumerate and choose the one you need, else look for specific item like 010

Divya

Former Member
0 Kudos

you mean

<b>Row item=sb.getRow("010");</b>

or

<b>Row item=sb.getRow(trd,"010");</b>

both return "null exception"

1)

in the api saying

<b>sb.getRow("primary key"); </b> meaning what ?????????

2)

enumerate meaning pass in the syncKey when i choose the row ??

Message was edited by:

yzme yzme

Former Member
0 Kudos

I mean this:

SyncBoDescriptor sbd = syncBo.getSyncBoDescriptor();

RowDescriptor trd = sbd.getRowDescriptor("010"); //Item field

FieldDescriptor fd = trd.getFieldDescriptor(fieldName);

'trd' will contain the first item.

for second item u can use "020"

Former Member
0 Kudos

if <b>item</b> is are getting NullPointerExcp then your sb might not be initialized.

1. try this to get all rows.

RowCollection[] getRows()

Returns the array of static collections of all the child Row objects of this SyncBo.

2. Donot use sb.getRow("primary key"); its depricated,

the primary key of SyncBo generated by Middleware.

Former Member
0 Kudos

if <b>item</b> is are getting NullPointerExcp then your sb might not be initialized.

1. try this to get all rows.

RowCollection[] getRows()

Returns the array of static collections of all the child Row objects of this SyncBo.

2. Donot use sb.getRow("primary key"); its depricated,

the primary key of SyncBo generated by Middleware.

Former Member
0 Kudos

try to see this

i have code like this...same as what you told

SyncBoDescriptor sbd = sb.getSyncBoDescriptor();

RowDescriptor trd=sbd.getRowDescriptor("010");

FieldDescriptor fd = trd.getFieldDescriptor(headerFieldName);

but at the lower part

//Row header=sb.getRow("primarykey");

Row header=sb.getRow(trd,"<what should i input here>");

if i have 1 header 2 items i will get 1 TOP , 1 "010" , 1 "020"..right...

Former Member
0 Kudos

if <b>item</b> is are getting NullPointerExcp then your sb might not be initialized.

1. try this to get all rows.

RowCollection[] getRows()

Returns the array of static collections of all the child Row objects of this SyncBo.

2. Donot use sb.getRow("primary key"); its depricated,

the primary key of SyncBo generated by Middleware.

yes, you can have only 1 header row (TOP) and several items rows "010" , "020"..right...

Former Member
0 Kudos

i have initialize by syncBO...

my intention is set the values of the row i select

Header

customerid, customer name

0001 john

0002 ali

Items

productid , paymentsum

A880 100

A990 150

if getting the toprow

Row header=sb.getTopRow();

tell me how do i get this

Row item=sb.getRow(trd,"<what to INPUT>");

Former Member
0 Kudos

{

SmartSyncTransactionManager transactionManager;

SyncBo syncBo = getSyncBoInstance(syBName, syncKey); //get the instance of current SyncBO

//before modifying check the status of the SyncBO it sould be Global, else you cannot modify the SyncBO

if(syncBo.getStatus() == StatusType.GLOBAL){

transactionManager = dataFacade.getSmartSyncTransactionManager();

transactionManager.beginTransaction();

RowDescriptor trd = sbd.getRowDescriptor("010"); //Item field

FieldDescriptor fd = trd.getFieldDescriptor(fieldName);

try{

if (fd != null) {

BasisFieldType bft = fd.getFieldType();

Row header = rowGlobal;

Field ff1 = header.getField(fd);

if (bft == BasisFieldType.N) {

CharacterField cf = header.getCharacterField(fd);

if (nf != null) {

//newValue = productid = B880 you wll change like this

nf.setValue(newValue.toString());

}

}

transactionManager.commit();

}

Former Member
0 Kudos

this code is already there autogenerated, you just have to understand the flow and usage of APIs

Former Member
0 Kudos

if (fd != null) {

BasisFieldType bft = fd.getFieldType();

<b>Row header = rowGlobal; //rowGlobal cannot be resolved </b>

the autogenerated code is for method

setHeaderFieldValue -


Row header = sb.getTopRow();

it is to set the Top Row NOT the item row

so i have to modify setItemFieldValue()

Message was edited by:

yzme yzme

Former Member
0 Kudos

Row header = rowGlobal; //rowGlobal cannot be resolved

that is a user variable which is a global reference for rowHeader. you create the definition of Row type.

Former Member
0 Kudos

In this method

public void modifyItemOfSyncBo(String syncBoName,String headerSyncKey,String itemName,String itemFieldNames[],String itemFieldValues[])throws SmartSyncException, PersistenceException

SyncBo syncBo = getSyncBoInstance(syncBoName, headerSyncKey);

Row [] itemRows = getItemInstances(syncBo,itemName);//this is the standard method.

// itemRows[0] is the one and only item instance

SyncBoDescriptor sbd =

descriptorFacade.getSyncBoDescriptor(syncBoName);

RowDescriptor rd = sbd.getRowDescriptor(itemName);

SmartSyncTransactionManager transactionManager;

transactionManager = dataFacade.getSmartSyncTransactionManager();

if (!transactionManager.isTransactionStarted())

transactionManager.beginTransaction();

for (int c = 0; c < itemFieldNames.length; c++) {

FieldDescriptor fdDesc = rd.getFieldDescriptor(itemFieldNames[c]);

setItemFieldValue(fdDesc, itemRow[0], itemFieldValues); // this method is given below

}

transactionManager.commit();

}

ItemName is "010" right

Row[] itemRow=getItemInstances(sb,"010");

when i try to sync i receive the following error :

• Synchronization started

• Connection set up (without proxy) to: http://pc1:50100/meSync/servlet/meSync?~sysid=N01&;

• Successfully connected with server.

• Processing of inbound data began.

• Exception while proccessing method SMARTSYNC : java.lang.RuntimeException: Inbound processing of container with index 22 failed: Cannot insert as entity already exists for IClassDescriptor/Key: sZFLIGHT_010/1211211 : r0001211210 : Inbound processing of container with index 22 failed: Cannot insert as entity already exists for IClassDescriptor/Key: sZFLIGHT_010/1211211 : r0001211210

Message was edited by:

yzme yzme

Message was edited by:

yzme yzme

Message was edited by:

yzme yzme

Message was edited by:

yzme yzme

Answers (0)