metadataengine/server/src/mdsnamespacedef.cpp
changeset 21 50bf9db68373
parent 0 c53acadfccc6
equal deleted inserted replaced
20:6dfc5f825351 21:50bf9db68373
    99 		User::Leave( KErrAlreadyExists );
    99 		User::Leave( KErrAlreadyExists );
   100 		}
   100 		}
   101 	CMdsObjectDef* parent = GetObjectDef( aParentName );
   101 	CMdsObjectDef* parent = GetObjectDef( aParentName );
   102 	if ( !parent )
   102 	if ( !parent )
   103 		{
   103 		{
   104 		/* testing */
       
   105 		// found namespace in default schema
   104 		// found namespace in default schema
   106 		if ( aDefaultSchema )
   105 		if ( aDefaultSchema )
   107 			{
   106 			{
   108 			CMdsNamespaceDef* namespaceDef = aDefaultSchema->GetNamespace( GetName() );
   107 			CMdsNamespaceDef* namespaceDef = aDefaultSchema->GetNamespace( GetName() );
   109 			if ( !namespaceDef )
   108 			if ( !namespaceDef )
   116 			{
   115 			{
   117 			User::Leave( KErrNotFound );
   116 			User::Leave( KErrNotFound );
   118 			}
   117 			}
   119 		}
   118 		}
   120 	CMdsObjectDef* object = CMdsObjectDef::NewLC( aObjectName, parent );
   119 	CMdsObjectDef* object = CMdsObjectDef::NewLC( aObjectName, parent );
   121 	iObjectDefs.AppendL( object );
   120 	User::LeaveIfError( iObjectDefs.InsertInOrderAllowRepeats(object, TLinearOrder<CMdsObjectDef>(CMdsNamespaceDef::CompareObjectDefId) ) );
   122 	CleanupStack::Pop( object );
   121 	CleanupStack::Pop( object );
   123 	return object;
   122 	return object;
   124 	}
   123 	}
   125 
   124 
   126 /**
   125 /**
   133 		{
   132 		{
   134 		User::Leave( KErrNotFound );
   133 		User::Leave( KErrNotFound );
   135 		}
   134 		}
   136 	CMdsObjectDef* object = CMdsObjectDef::NewLC( aName, parent );
   135 	CMdsObjectDef* object = CMdsObjectDef::NewLC( aName, parent );
   137 	object->SetFlags( (CMdsObjectDef::TObjectDefFlags)aFlags );
   136 	object->SetFlags( (CMdsObjectDef::TObjectDefFlags)aFlags );
   138 	iObjectDefs.AppendL( object );
       
   139 	object->SetId(aId);
   137 	object->SetId(aId);
       
   138 	User::LeaveIfError( iObjectDefs.InsertInOrderAllowRepeats(object, TLinearOrder<CMdsObjectDef>(CMdsNamespaceDef::CompareObjectDefId) ) );
   140 	object->SetStoredInDB();
   139 	object->SetStoredInDB();
   141 	CleanupStack::Pop( object );
   140 	CleanupStack::Pop( object );
   142 	}
   141 	}
   143 
   142 
   144 /**
   143 /**
   168 	if ( GetRelationDef( aRelationName ) )
   167 	if ( GetRelationDef( aRelationName ) )
   169 		{
   168 		{
   170 		User::Leave( KErrAlreadyExists );
   169 		User::Leave( KErrAlreadyExists );
   171 		}
   170 		}
   172 	CMdsRelationDef* relation = CMdsRelationDef::NewLC( aRelationName );
   171 	CMdsRelationDef* relation = CMdsRelationDef::NewLC( aRelationName );
   173 	iRelationDefs.AppendL( relation );
   172 	User::LeaveIfError( iRelationDefs.InsertInOrderAllowRepeats(relation, TLinearOrder<CMdsRelationDef>(CMdsNamespaceDef::CompareRelationDefId) ) );
   174 	CleanupStack::Pop( relation );
   173 	CleanupStack::Pop( relation );
   175 	}
   174 	}
   176 
   175 
   177 
   176 
   178 void CMdsNamespaceDef::AddRelationDefL( TDefId aId, const TDesC& aRelationName )
   177 void CMdsNamespaceDef::AddRelationDefL( TDefId aId, const TDesC& aRelationName )
   179 	{
   178 	{
   180 	CMdsRelationDef* relation = CMdsRelationDef::NewLC( aRelationName );
   179 	CMdsRelationDef* relation = CMdsRelationDef::NewLC( aRelationName );
   181 	relation->SetId(aId);
   180 	relation->SetId(aId);
   182 	iRelationDefs.AppendL( relation );
   181 	User::LeaveIfError( iRelationDefs.InsertInOrderAllowRepeats(relation, TLinearOrder<CMdsRelationDef>(CMdsNamespaceDef::CompareRelationDefId) ) );
   183 	relation->SetStoredInDB();
   182 	relation->SetStoredInDB();
   184 	CleanupStack::Pop( relation );
   183 	CleanupStack::Pop( relation );
   185 	}
   184 	}
   186 
   185 
   187 
   186 
   204 	if ( GetEventDef( aEventName ) )
   203 	if ( GetEventDef( aEventName ) )
   205 		{
   204 		{
   206 		User::Leave( KErrAlreadyExists );
   205 		User::Leave( KErrAlreadyExists );
   207 		}
   206 		}
   208 	CMdsEventDef* event = CMdsEventDef::NewLC( aEventName, aPriority );
   207 	CMdsEventDef* event = CMdsEventDef::NewLC( aEventName, aPriority );
   209 	iEventDefs.AppendL( event );
   208 	User::LeaveIfError( iEventDefs.InsertInOrderAllowRepeats(event, TLinearOrder<CMdsEventDef>(CMdsNamespaceDef::CompareEventDefId) ) );
   210 	CleanupStack::Pop( event );
   209 	CleanupStack::Pop( event );
   211 	}
   210 	}
   212 
   211 
   213 void CMdsNamespaceDef::AddEventDefL( TDefId aId, const TDesC& aEventName, TInt32 aPriority )
   212 void CMdsNamespaceDef::AddEventDefL( TDefId aId, const TDesC& aEventName, TInt32 aPriority )
   214 	{
   213 	{
   215 	CMdsEventDef* event = CMdsEventDef::NewLC( aEventName, aPriority );
   214 	CMdsEventDef* event = CMdsEventDef::NewLC( aEventName, aPriority );
   216 	event->SetId(aId);
   215 	event->SetId(aId);
   217 	iEventDefs.AppendL( event );
   216 	User::LeaveIfError( iEventDefs.InsertInOrderAllowRepeats(event, TLinearOrder<CMdsEventDef>(CMdsNamespaceDef::CompareEventDefId) ) );
   218 	event->SetStoredInDB();
   217 	event->SetStoredInDB();
   219 	CleanupStack::Pop( event );
   218 	CleanupStack::Pop( event );
   220 	}
   219 	}
   221 
   220 
   222 CMdsEventDef* CMdsNamespaceDef::GetEventDef( const TDesC& aEventName ) const
   221 CMdsEventDef* CMdsNamespaceDef::GetEventDef( const TDesC& aEventName ) const
   237 	{
   236 	{
   238 	if ( aId == KBaseObjectDefId ) // BaseObject (hardcoded)
   237 	if ( aId == KBaseObjectDefId ) // BaseObject (hardcoded)
   239 		{
   238 		{
   240 		return iBaseObject;
   239 		return iBaseObject;
   241 		}
   240 		}
   242 	
   241 
   243 	const TInt count = iObjectDefs.Count();
   242     TInt low( 0 );
   244 	
   243     TInt high( iObjectDefs.Count() );
   245 	for ( TInt i = 0; i < count; ++i )
   244     
   246 		{
   245     while( low < high )
   247 		if( iObjectDefs[i]->GetId() == aId )
   246         {
   248 			{
   247         TInt mid( (low+high)>>1 );
   249 			return iObjectDefs[i];
   248         
   250 			}
   249         const TInt compare( aId - iObjectDefs[mid]->GetId() );
   251 		}
   250         if( compare == 0 )
       
   251             {
       
   252             return iObjectDefs[mid];
       
   253             }
       
   254         else if( compare > 0 )
       
   255             {
       
   256             low = mid + 1;
       
   257             }
       
   258         else
       
   259             {
       
   260             high = mid;
       
   261             }
       
   262         }   
   252 	return NULL;
   263 	return NULL;
   253 	}
   264 	}
   254 
   265 
   255 const CMdsEventDef* CMdsNamespaceDef::GetEventByIdL( TDefId aId ) const
   266 const CMdsEventDef* CMdsNamespaceDef::GetEventByIdL( TDefId aId ) const
   256 	{
   267 	{
   257 	const TInt count = iEventDefs.Count();
   268     TInt low( 0 );
   258 	
   269     TInt high( iEventDefs.Count() );
   259 	for ( TInt i = 0; i < count; ++i )
   270     
   260 		{
   271     while( low < high )
   261 		if( iEventDefs[i]->GetId() == aId )
   272         {
   262 			{
   273         TInt mid( (low+high)>>1 );
   263 			return iEventDefs[i];
   274         
   264 			}
   275         const TInt compare( aId - iEventDefs[mid]->GetId() );
   265 		}
   276         if( compare == 0 )
       
   277             {
       
   278             return iEventDefs[mid];
       
   279             }
       
   280         else if( compare > 0 )
       
   281             {
       
   282             low = mid + 1;
       
   283             }
       
   284         else
       
   285             {
       
   286             high = mid;
       
   287             }
       
   288         }
   266 	return NULL;
   289 	return NULL;
   267 	}
   290 	}
   268 
   291 
   269 const CMdsRelationDef* CMdsNamespaceDef::GetRelationByIdL( TDefId aId ) const
   292 const CMdsRelationDef* CMdsNamespaceDef::GetRelationByIdL( TDefId aId ) const
   270 	{
   293 	{
   271 	const TInt count = iRelationDefs.Count();
   294     TInt low( 0 );
   272 	
   295     TInt high( iRelationDefs.Count() );
   273 	for ( TInt i = 0; i < count; ++i )
   296     
   274 		{
   297     while( low < high )
   275 		if( iRelationDefs[i]->GetId() == aId )
   298         {
   276 			{
   299         TInt mid( (low+high)>>1 );
   277 			return iRelationDefs[i];
   300         
   278 			}
   301         const TInt compare( aId - iRelationDefs[mid]->GetId() );
   279 		}
   302         if( compare == 0 )
       
   303             {
       
   304             return iRelationDefs[mid];
       
   305             }
       
   306         else if( compare > 0 )
       
   307             {
       
   308             low = mid + 1;
       
   309             }
       
   310         else
       
   311             {
       
   312             high = mid;
       
   313             }
       
   314         }
   280 	return NULL;
   315 	return NULL;
   281 	}
   316 	}
   282 
   317 
   283 void CMdsNamespaceDef::StoreToDBL( TBool aStoreOnlyNamespace )
   318 void CMdsNamespaceDef::StoreToDBL( TBool aStoreOnlyNamespace )
   284 	{
   319 	{
   310 	// add objectDef to DB
   345 	// add objectDef to DB
   311 	for( TInt i = 0; i < objectDefCount; ++i )
   346 	for( TInt i = 0; i < objectDefCount; ++i )
   312 		{
   347 		{
   313 		iObjectDefs[i]->StoreToDBL( GetId() );
   348 		iObjectDefs[i]->StoreToDBL( GetId() );
   314 		}
   349 		}
       
   350 	iObjectDefs.Sort( TLinearOrder<CMdsObjectDef>(CMdsNamespaceDef::CompareObjectDefId) );
   315 	
   351 	
   316 	const TInt eventDefCount = iEventDefs.Count();
   352 	const TInt eventDefCount = iEventDefs.Count();
   317 	
   353 	
   318 	// add relationDef to DB
   354 	// add relationDef to DB
   319 	for( TInt i = 0; i < eventDefCount; ++i )
   355 	for( TInt i = 0; i < eventDefCount; ++i )
   320 		{
   356 		{
   321 		iEventDefs[i]->StoreToDBL( GetId() );
   357 		iEventDefs[i]->StoreToDBL( GetId() );
   322 		}
   358 		}
       
   359 	iEventDefs.Sort( TLinearOrder<CMdsEventDef>(CMdsNamespaceDef::CompareEventDefId) );
   323 	
   360 	
   324 	const TInt relationDefCount = iRelationDefs.Count();
   361 	const TInt relationDefCount = iRelationDefs.Count();
   325 	
   362 	
   326 	// add eventDef to DB
   363 	// add eventDef to DB
   327 	for( TInt i = 0; i < relationDefCount; ++i )
   364 	for( TInt i = 0; i < relationDefCount; ++i )
   328 		{
   365 		{
   329 		iRelationDefs[i]->StoreToDBL( GetId() );
   366 		iRelationDefs[i]->StoreToDBL( GetId() );
   330 		}
   367 		}
       
   368 	iRelationDefs.Sort( TLinearOrder<CMdsRelationDef>(CMdsNamespaceDef::CompareRelationDefId) );
   331 
   369 
   332 	CleanupStack::PopAndDestroy( &rowData );
   370 	CleanupStack::PopAndDestroy( &rowData );
   333 	}
   371 	}
   334 	
   372 	
   335 
   373 
   344 			{
   382 			{
   345 			lObjectDef->MergeL( aNamespace->iObjectDefs[i], aDryRun );
   383 			lObjectDef->MergeL( aNamespace->iObjectDefs[i], aDryRun );
   346 			}
   384 			}
   347 		else if ( !aDryRun )
   385 		else if ( !aDryRun )
   348 			{
   386 			{
   349 			iObjectDefs.AppendL( aNamespace->iObjectDefs[i] );
   387 		    User::LeaveIfError( iObjectDefs.InsertInOrderAllowRepeats(aNamespace->iObjectDefs[i], 
       
   388 		                                  TLinearOrder<CMdsObjectDef>(CMdsNamespaceDef::CompareObjectDefId) ) );
   350 			aNamespace->iObjectDefs[i]->SetAllNotStoredInDB();
   389 			aNamespace->iObjectDefs[i]->SetAllNotStoredInDB();
   351 			aNamespace->iObjectDefs[i] = NULL;
   390 			aNamespace->iObjectDefs[i] = NULL;
   352 			}
   391 			}
   353 		}
   392 		}
   354 	}
   393 	}
   367 				User::Leave( KErrAlreadyExists );
   406 				User::Leave( KErrAlreadyExists );
   368 				}
   407 				}
   369 			}
   408 			}
   370 		else if ( !aDryRun )
   409 		else if ( !aDryRun )
   371 			{
   410 			{
   372 			iRelationDefs.AppendL( aNamespace->iRelationDefs[i] );
   411 		    User::LeaveIfError( iRelationDefs.InsertInOrderAllowRepeats(aNamespace->iRelationDefs[i], 
       
   412 		                                        TLinearOrder<CMdsRelationDef>(CMdsNamespaceDef::CompareRelationDefId) ) );
   373 			aNamespace->iRelationDefs[i]->SetAllNotStoredInDB();
   413 			aNamespace->iRelationDefs[i]->SetAllNotStoredInDB();
   374 			aNamespace->iRelationDefs[i] = NULL;
   414 			aNamespace->iRelationDefs[i] = NULL;
   375 			}
   415 			}
   376 		}
   416 		}
   377 	}
   417 	}
   390 				User::Leave( KErrAlreadyExists );
   430 				User::Leave( KErrAlreadyExists );
   391 				}
   431 				}
   392 			}
   432 			}
   393 		else if ( !aDryRun )
   433 		else if ( !aDryRun )
   394 			{
   434 			{
   395 			iEventDefs.AppendL( aNamespace->iEventDefs[i] );
   435 		    User::LeaveIfError( iEventDefs.InsertInOrderAllowRepeats(aNamespace->iEventDefs[i], TLinearOrder<CMdsEventDef>(CMdsNamespaceDef::CompareEventDefId) ) );
   396 			aNamespace->iEventDefs[i]->SetAllNotStoredInDB();
   436 			aNamespace->iEventDefs[i]->SetAllNotStoredInDB();
   397 			aNamespace->iEventDefs[i] = NULL;
   437 			aNamespace->iEventDefs[i] = NULL;
   398 			}
   438 			}
   399 		}
   439 		}
   400 	}
   440 	}
   478 	
   518 	
   479 	for ( TInt i = 0; i < count; ++i )
   519 	for ( TInt i = 0; i < count; ++i )
   480 		{
   520 		{
   481 		iObjectDefs[i]->ImportFromDBL();
   521 		iObjectDefs[i]->ImportFromDBL();
   482 		}
   522 		}
       
   523 	iObjectDefs.Sort( TLinearOrder<CMdsObjectDef>(CMdsNamespaceDef::CompareObjectDefId) );
   483 
   524 
   484 	// everything is ok, so set the flags
   525 	// everything is ok, so set the flags
   485 	SetStoredInDB();
   526 	SetStoredInDB();
   486 	SetTableStoredInDB();
   527 	SetTableStoredInDB();
   487 	}
   528 	}
   610 		}
   651 		}
   611 
   652 
   612 	return NULL;
   653 	return NULL;
   613 	}
   654 	}
   614 
   655 
       
   656 TInt CMdsNamespaceDef::CompareObjectDefId(const CMdsObjectDef& aFirst, const CMdsObjectDef& aSecond)
       
   657     {
       
   658     return aFirst.GetId() - aSecond.GetId();
       
   659     }
       
   660 
       
   661 TInt CMdsNamespaceDef::CompareEventDefId(const CMdsEventDef& aFirst, const CMdsEventDef& aSecond)
       
   662     {
       
   663     return aFirst.GetId() - aSecond.GetId();
       
   664     }
       
   665 
       
   666 TInt CMdsNamespaceDef::CompareRelationDefId(const CMdsRelationDef& aFirst, const CMdsRelationDef& aSecond)
       
   667     {
       
   668     return aFirst.GetId() - aSecond.GetId();
       
   669     }
       
   670 
   615 /**
   671 /**
   616  * Initialize static variables
   672  * Initialize static variables
   617  */
   673  */
   618 
   674 
   619 CMdsObjectDef* CMdsNamespaceDef::iBaseObject = NULL;
   675 CMdsObjectDef* CMdsNamespaceDef::iBaseObject = NULL;