cancel
Showing results for 
Search instead for 
Did you mean: 

synchronizewithBackend method

Former Member
0 Kudos

let's say i have a device which is offline. and i will go and collect warehouse info, after the day end, i will syncrhonized to the server.

this method, after will call the syncrhonized with backend after the value changed. but the device offline, what is the consequences, will it update the file I/O? or it will update the backend with RFC call but the device is offline ?


public void modifyRecord(String syncBoName,String syncKey){
			SyncBoDescriptor sbd=descriptorFacade.getSyncBoDescriptor(syncBoName);
			try {
				System.err.println("modify Record: " +syncKey);
				SyncBo sb=dataFacade.getSyncBo(sbd,syncKey);
				RowDescriptor tdes=sbd.getTopRowDescriptor();
				Row trow=sb.getTopRow();
				FieldDescriptor fd1=tdes.getFieldDescriptor("PROFESSION");
				trow.modifyFieldValue(fd1,"MOO");
			
				RowDescriptor trd=sbd.getRowDescriptor("010");
				Row[] item=getItemInstances(sb,"010");
				FieldDescriptor fd2=trd.getFieldDescriptor("CITY2");
				item[0].modifyFieldValue(fd2,"MU");  
				sb.modifyRow(trow);
				sb.modifyRow(item[0]);
				SyncManager smgr=SyncManager.getInstance();
				smgr.synchronizeWithBackend();
			
			} catch (PersistenceException e) {
				// TODO Auto-generated catch block
				System.out.println("Exception :" +e.getMessage());
				e.printStackTrace();
			}catch(Exception e){
				System.out.println("Exception: " +e.getMessage());
			}
			
		}

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

in addition to Siva's comments:

1) in case when your SyncBo instance doesn't have and item, your code will throw

an exception.

e.g. at line item was null or item[0] is null.

item[0].modifyFieldValue(fd2,"MU")

--> as an implication, the succeeding lines will not be called i.e. your modification

is not saved, and synchronization won't occur.

2) anothe implication of this coding is that you will be synchronizing upon every

modification you make for each record. when offline, the sync layer will still try to

test if the server is reachable or connectable and there is a timeout to consider

consider here. your function will return after a connection tests.

i would not recommend such coding. if you want the data to be implicitly

synchronized, try using the background sync feature.

regards

jo

Former Member
0 Kudos

2) it is better to leave the code without this

SyncManager smgr=SyncManager.getInstance();

smgr.synchronizeWithBackend();

right ?

Former Member
0 Kudos

Hi

Perfect. Just remove the above statements and you can do the way i had mentioned in my first reply.

Best Regards

Sivakumar

Former Member
0 Kudos

i want to remove the statement

and also eliminate the statement that you mentioned synchronizeData().

the data will be write to File I/O , after online, then sync.

just let's them sync as normal as mentioned by Jo.

Former Member
0 Kudos

Hi

I have few suggestions/modifications to your code and hope my modification is justified. First I suggest you not to include the statements

SyncManager smgr=SyncManager.getInstance();
smgr.synchronizeWithBackend();

within the modifyRecord method instead you could organize it in a separate method

public void synchronizeData(){
SyncManager smgr=SyncManager.getInstance();
smgr.synchronizeWithBackend();
}

The difference between your code and the suggestion i made is the following.

If the device is offline (i.e. there is no connectivity), <b>then your code will definitely save the record in File I/O</b> but will fail to send the data to the server since there is no connectivity. Also as per your code you would try to connect to the server every time the modifyRecord() is invoked. This is not the ideal way: For example if you modify 10 records, then you would be synchronizing 10 times which is not required at all. But if you adapt the changes i have mentioned, then you can sync once after all the records are saved i.e one sync even for 10 saved records and also you can ensure that the user synchronizes the data only when there is connectivity available. For convenience, you can map the synchronizeData() method to a button on the UI that will trigger a sync.

Hope this helps.

Best Regards

Sivakumar

Former Member
0 Kudos

create a button for trigger the syncrhonizeData();

but when we click the "sync"..it will be achieve the same ?

Former Member
0 Kudos

Hi

Since the modify logic and the sync logic have now been separated, you will not trigger sync on every modification of record. Now if you decide to have a separate button for sync, you wouldnt end up getting a sync error at the time you modify the record. You can very well enforce the user to press the sync button only when connectivity is available. But the same can never be true when you modify the record as per your implementation. Why should the user make sure there is online connectivity when he creates or modifies a record. In this case it becomes a online solution and not offline which is not what MI is meant for. Hence there is definite difference in the two implementations and hope my reply is more clear now.

Best Regards

Sivakumar