Multilevel Insert (MLI)

Multilevel insert allows a single synchronization to execute a chain of related insert operations. This example demonstrates a multilevel insert:

-(void)TestCreate
{
 	long key1 = [SampleApp_KeyGenerator generateId];
	 long key2 = [SampleApp_KeyGenerator generateId];
	 [SampleApp_KeyGenerator submitPendingOperations];
	 while ([SampleApp_SampleAppDB hasPendingOperations])
	 {
	 	[NSThread sleepForTimeInterval:1];
	 }     
 	SampleApp_Customer *c = [[ SampleApp_Customer alloc] init]; 
	 c.id_ = [SampleApp_LocalKeyGenerator generateId];
	 c.fname = @"Dorothi"; 
	 c.lname = @"Scranton";
	 c.address = @"One Money Street";
	 c.city = @"smallVille";
	 c.state = @"MA";
	 c.zip = @"97429";
	 c.phone = @"2112222345";
	 c.company_name = @"iAnywhere";
	 c.surrogateKey = key1;
	 SUPObjectList *orderlist = [ SampleApp_Sales_orderList getInstance];
	 SampleApp_Sales_order *o1 = [[SampleApp_Sales_order alloc] init];
	 o1.id_ = [SampleApp_LocalKeyGenerator generateId];
	 o1.order_date = [NSDate date];
	 o1.fin_code_id = @"r1";
	 o1.region = @"Eastern";
	 o1.sales_rep = 902;
	 o1.surrogateKey = key2;
	 [ o1 setCustomer:c];
	 [orderlist add:o1];
 	[c setSalesOrders:orderlist];
 	[c save];
 	[c refresh];
 	[c submitPending];
	 assert(c.pending == YES);
	 while ([SampleApp_SampleAppDB hasPendingOperations])
	 {
		  [NSThread sleepForTimeInterval:1];
	 }     
}