on 08-08-2007 3:51 AM
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
<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>
}
....
......
.........
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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.
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.
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...
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...
{
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();
}
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
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
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.