Пример #1
0
        protected override void NullSafeMapToEntityFromMap(AuditConfiguration verCfg, object obj, IDictionary data, object primaryKey, IAuditReaderImplementor versionsReader, long revision)
        {
            var    entityId = _delegat.MapToIdFromMap(data);
            object value    = null;

            if (entityId != null)
            {
                if (!versionsReader.FirstLevelCache.TryGetValue(_referencedEntityName, revision, entityId, out value))
                {
                    var referencedEntity = GetEntityInfo(verCfg, _referencedEntityName);
                    var ignoreNotFound   = false;
                    if (!referencedEntity.IsAudited)
                    {
                        var referencingEntityName = verCfg.EntCfg.GetEntityNameForVersionsEntityName((string)data["$type$"]);
                        var relation = verCfg.EntCfg.GetRelationDescription(referencingEntityName, PropertyData.Name);
                        ignoreNotFound = relation != null && relation.IsIgnoreNotFound;
                    }
                    var removed = RevisionType.Deleted.Equals(data[verCfg.AuditEntCfg.RevisionTypePropName]);

                    value = ignoreNotFound ?
                            ToOneEntityLoader.LoadImmediate(versionsReader, _referencedEntityName, entityId, revision, removed, verCfg) :
                            ToOneEntityLoader.CreateProxyOrLoadImmediate(versionsReader, _referencedEntityName, entityId, revision, removed, verCfg);
                }
            }
            SetPropertyValue(obj, value);
        }
Пример #2
0
        public void MapToEntityFromMap(AuditConfiguration verCfg, Object obj, IDictionary <String, Object> data, Object primaryKey,
                                       IAuditReaderImplementor versionsReader, long revision)
        {
            if (obj == null)
            {
                return;
            }

            Object entityId = delegat.MapToIdFromMap(DictionaryWrapper <String, Object> .Wrap((IDictionary)data[propertyData.Name]));
            Object value;

            if (entityId == null)
            {
                value = null;
            }
            else
            {
                if (versionsReader.FirstLevelCache.Contains(referencedEntityName, revision, entityId))
                {
                    value = versionsReader.FirstLevelCache[referencedEntityName, revision, entityId];
                }
                else
                {
                    //java: Class<?> entityClass = ReflectionTools.loadClass(referencedEntityName);
                    value = versionsReader.SessionImplementor.Factory.GetEntityPersister(referencedEntityName).CreateProxy(
                        entityId, new ToOneDelegateSessionImplementor(versionsReader, Toolz.ResolveDotnetType(referencedEntityName), entityId, revision, verCfg));
                }
            }
            PropertyInfo propInfo = obj.GetType().GetProperty(propertyData.Name);

            propInfo.SetValue(obj, value, null);
        }
Пример #3
0
 public object MapToObjectFromFullMap(EntityInstantiator entityInstantiator,
                                      IDictionary data,
                                      object dataObject,
                                      long revision)
 {
     return(_relatedIdMapper.MapToIdFromMap((IDictionary)data[_verEntCfg.OriginalIdPropName]));
 }
Пример #4
0
        /**
         * Creates an entity instance based on an entry from the versions table.
         * @param entityName Name of the entity, which instances should be read
         * @param versionsEntity An entry in the versions table, from which data should be mapped.
         * @param revision Revision at which this entity was read.
         * @return An entity instance, with versioned properties set as in the versionsEntity map, and proxies
         * created for collections.
         */
        public Object CreateInstanceFromVersionsEntity(String entityName, IDictionary <string, object> versionsEntity, long revision)
        {
            if (versionsEntity == null)
            {
                return(null);
            }

            // The $type$ property holds the name of the (versions) entity
            String name = verCfg.EntCfg.GetEntityNameForVersionsEntityName(((String)versionsEntity["$type$"]));

            if (name != null)
            {
                entityName = name;
            }

            // First mapping the primary key
            IIdMapper idMapper = verCfg.EntCfg[entityName].GetIdMapper();
            IDictionary <string, object> originalId = DictionaryWrapper <string, object> .Wrap((IDictionary)versionsEntity[verCfg.AuditEntCfg.OriginalIdPropName]);

            Object primaryKey = idMapper.MapToIdFromMap(originalId);

            // Checking if the entity is in cache
            if (versionsReader.FirstLevelCache.Contains(entityName, revision, primaryKey))
            {
                return(versionsReader.FirstLevelCache[entityName, revision, primaryKey]);
            }

            // If it is not in the cache, creating a new entity instance
            Object ret;

            try {
                //System.Type cls = ReflectionTools.loadClass(entityName);
                //ret = ReflectHelper.GetDefaultConstructor(cls).newInstance();
                ret = Activator.CreateInstance(Toolz.ResolveDotnetType(entityName));
            } catch (Exception e) {
                throw new AuditException(e);
            }

            // Putting the newly created entity instance into the first level cache, in case a one-to-one bidirectional
            // relation is present (which is eagerly loaded).
            versionsReader.FirstLevelCache.Add(entityName, revision, primaryKey, ret);

            verCfg.EntCfg[entityName].PropertyMapper.MapToEntityFromMap(verCfg, ret, versionsEntity, primaryKey,
                                                                        versionsReader, revision);
            idMapper.MapToEntityFromMap(ret, originalId);

            return(ret);
        }
 public Object MapToObjectFromFullMap(EntityInstantiator entityInstantiator, IDictionary <String, Object> data,
                                      Object dataObject, long revision)
 {
     return(relatedIdMapper.MapToIdFromMap((IDictionary <String, Object>)data[verEntCfg.OriginalIdPropName]));
 }