/// <summary>
        /// Counts the specified references.
        /// </summary>
        /// <param name="entityType"></param>
        /// <param name="entityID"></param>
        /// <param name="propertyName"></param>
        /// <returns>The total number of references counted.</returns>
        public override int CountEntitiesWithReference(Type entityType, Guid entityID, string propertyName, Type referencedEntityType, string mirrorPropertyName)
        {
            int count = 0;

            using (LogGroup logGroup = LogGroup.StartDebug("Querying the data store based on the provided parameters."))
            {
                LogWriter.Debug("Entity type: " + entityType.FullName);
                LogWriter.Debug("Property name: " + propertyName);
                LogWriter.Debug("Entity ID: " + entityID);
                LogWriter.Debug("Mirror property name: " + mirrorPropertyName);
                LogWriter.Debug("Referenced entity type: " + referencedEntityType.FullName);

                Db4oDataStore store = (Db4oDataStore)GetDataStore(referencedEntityType);

                IObjectContainer container = store.ObjectContainer;

                Predicate matches = new MatchReferencePredicate(Provider, referencedEntityType, mirrorPropertyName, entityType, entityID, propertyName);

                IObjectSet os = store.ObjectContainer.Query(matches);

                count = os.Count;

                LogWriter.Debug("Total objects: " + count);
            }

            return(count);
        }
Example #2
0
        /// <summary>
        /// Retrieves the specified page of objects from the data store.
        /// </summary>
        /// <param name="propertyName">The name of the property to query for.</param>
        /// <param name="referenceID">The ID of the referenced entity.</param>
        /// <param name="location"></param>
        /// <param name="sortExpression">The sort expression to apply before retrieving the page.</param>
        /// <returns>An array of the objects retrieved.</returns>
        public override T[] GetPageOfEntitiesWithReference <T>(string propertyName, Type referencedEntityType, Guid referencedEntityID, PagingLocation location, string sortExpression)
        {
            Collection <T> page = new Collection <T>();

            //using (LogGroup logGroup = LogGroup.Start("Querying the data store based on the provided parameters.", NLog.LogLevel.Debug))
            //{
            //LogWriter.Debug("Property name: " + propertyName);
            //LogWriter.Debug("Referenced entity ID: " + referencedEntityID);

            if (location == null)
            {
                throw new ArgumentNullException("location");
            }

            Type type = typeof(T);


            string sortPropertyName = sortExpression.Replace("Ascending", "").Replace("Descending", "");

            Db4oDataStore store = (Db4oDataStore)GetDataStore(type);

            if (store == null)
            {
                throw new ArgumentException("Can't find data store for type '" + type.Name + "'.");
            }

            IObjectContainer container = store.ObjectContainer;

            if (container == null)
            {
                throw new Exception("No object container for store '" + store.Name + "'.");
            }

            Predicate matches = new MatchReferencePredicate(Provider, typeof(T), propertyName, referencedEntityType, referencedEntityID);

            IObjectSet os = store.ObjectContainer.Query(matches,
                                                        new DynamicComparer(
                                                            type,
                                                            sortExpression));

            page.AddRange(GetPage(os, location));

            return(Release((T[])page.ToArray()));
        }
Example #3
0
        /// <summary>
        /// Retrieves all the entities of the specified type with the specified reference.
        /// </summary>
        /// <param name="propertyName">The name of the property containing the reference.</param>
        /// <param name="referencedEntityType">The type of the referenced entity to match.</param>
        /// <param name="referencedEntityID">The ID of the referenced entity to match.</param>
        /// <returns>An array of the entities retrieved.</returns>
        public override IEntity[] GetEntitiesWithReference(Type entityType, string propertyName, Type referencedEntityType, Guid referencedEntityID)
        {
            List <IEntity> entities = new List <IEntity>();

            using (LogGroup logGroup = LogGroup.StartDebug("Querying the data store based on the provided parameters."))
            {
                LogWriter.Debug("Property name: " + propertyName);
                LogWriter.Debug("Referenced entity ID: " + referencedEntityID);

                if (referencedEntityType != null)
                {
                    LogWriter.Debug("Referenced entity type: " + referencedEntityType.ToString());
                }
                else
                {
                    LogWriter.Debug("Referenced entity type: [null]");
                }

                Db4oDataStore store = (Db4oDataStore)GetDataStore(entityType);

                // TODO: Check if performance can be improved by using SODA to load all references then
                // load all referenced entities

                Predicate matches = new MatchReferencePredicate(Provider, entityType, propertyName, referencedEntityType, referencedEntityID);

                IObjectSet os = store.ObjectContainer.Query(matches);

                while (os.HasNext())
                {
                    entities.Add((IEntity)os.Next());
                }

                LogWriter.Debug("Total objects: " + entities.Count);
            }

            return(Release(entities.ToArray()));
        }