public PocoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) : base(entityMetamodel, mappedEntity) { mappedClass = mappedEntity.MappedClass; proxyInterface = mappedEntity.ProxyInterface; islifecycleImplementor = typeof(ILifecycle).IsAssignableFrom(mappedClass); isValidatableImplementor = typeof(IValidatable).IsAssignableFrom(mappedClass); foreach (Mapping.Property property in mappedEntity.PropertyClosureIterator) { if (property.IsLazy) lazyPropertyNames.Add(property.Name); if (property.UnwrapProxy) unwrapProxyPropertyNames.Add(property.Name); } SetReflectionOptimizer(); Instantiator = BuildInstantiator(mappedEntity); if (hasCustomAccessors) { optimizer = null; } proxyValidator = Cfg.Environment.BytecodeProvider.ProxyFactoryFactory.ProxyValidator; }
public PocoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) : base(entityMetamodel, mappedEntity) { mappedClass = mappedEntity.MappedClass; proxyInterface = mappedEntity.ProxyInterface; islifecycleImplementor = typeof(ILifecycle).IsAssignableFrom(mappedClass); isValidatableImplementor = typeof(IValidatable).IsAssignableFrom(mappedClass); foreach (Mapping.Property property in mappedEntity.PropertyClosureIterator) { if (property.IsLazy) { lazyPropertyNames.Add(property.Name); } } SetReflectionOptimizer(); Instantiator = BuildInstantiator(mappedEntity); if (hasCustomAccessors) { optimizer = null; } proxyValidator = Cfg.Environment.BytecodeProvider.ProxyFactoryFactory.ProxyValidator; }
/// <summary> Constructs a new AbstractEntityTuplizer instance. </summary> /// <param name="entityMetamodel">The "interpreted" information relating to the mapped entity. </param> /// <param name="mappingInfo">The parsed "raw" mapping data relating to the given entity. </param> protected AbstractEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappingInfo) { this.entityMetamodel = entityMetamodel; if (!entityMetamodel.IdentifierProperty.IsVirtual) { idGetter = BuildPropertyGetter(mappingInfo.IdentifierProperty, mappingInfo); idSetter = BuildPropertySetter(mappingInfo.IdentifierProperty, mappingInfo); } else { idGetter = null; idSetter = null; } propertySpan = entityMetamodel.PropertySpan; getters = new IGetter[propertySpan]; setters = new ISetter[propertySpan]; bool foundCustomAccessor = false; int i = 0; foreach (Mapping.Property property in mappingInfo.PropertyClosureIterator) { getters[i] = BuildPropertyGetter(property, mappingInfo); setters[i] = BuildPropertySetter(property, mappingInfo); if (!property.IsBasicPropertyAccessor) { foundCustomAccessor = true; } i++; } if (log.IsDebugEnabled()) { log.Debug("{0} accessors found for entity: {1}", foundCustomAccessor ? "Custom" : "No custom", mappingInfo.EntityName); } hasCustomAccessors = foundCustomAccessor; //NH-1587 //instantiator = BuildInstantiator(mappingInfo); if (entityMetamodel.IsLazy) { proxyFactory = BuildProxyFactory(mappingInfo, idGetter, idSetter); if (proxyFactory == null) { entityMetamodel.IsLazy = false; } } else { proxyFactory = null; } Mapping.Component mapper = mappingInfo.IdentifierMapper; identifierMapperType = mapper == null ? null : (IAbstractComponentType)mapper.Type; }
/// <summary> Constructs a new AbstractEntityTuplizer instance. </summary> /// <param name="entityMetamodel">The "interpreted" information relating to the mapped entity. </param> /// <param name="mappingInfo">The parsed "raw" mapping data relating to the given entity. </param> protected AbstractEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappingInfo) { this.entityMetamodel = entityMetamodel; if (!entityMetamodel.IdentifierProperty.IsVirtual) { idGetter = BuildPropertyGetter(mappingInfo.IdentifierProperty, mappingInfo); idSetter = BuildPropertySetter(mappingInfo.IdentifierProperty, mappingInfo); } else { idGetter = null; idSetter = null; } propertySpan = entityMetamodel.PropertySpan; getters = new IGetter[propertySpan]; setters = new ISetter[propertySpan]; bool foundCustomAccessor = false; int i = 0; foreach (Mapping.Property property in mappingInfo.PropertyClosureIterator) { getters[i] = BuildPropertyGetter(property, mappingInfo); setters[i] = BuildPropertySetter(property, mappingInfo); if (!property.IsBasicPropertyAccessor) foundCustomAccessor = true; i++; } if (log.IsDebugEnabled) { log.DebugFormat("{0} accessors found for entity: {1}", foundCustomAccessor ? "Custom" : "No custom", mappingInfo.EntityName); } hasCustomAccessors = foundCustomAccessor; //NH-1587 //instantiator = BuildInstantiator(mappingInfo); if (entityMetamodel.IsLazy) { proxyFactory = BuildProxyFactory(mappingInfo, idGetter, idSetter); if (proxyFactory == null) { entityMetamodel.IsLazy = false; } } else { proxyFactory = null; } Mapping.Component mapper = mappingInfo.IdentifierMapper; identifierMapperType = mapper == null ? null : (IAbstractComponentType)mapper.Type; }
public IEntityTuplizer BuildEntityTuplizer(string className, EntityMetamodel em, PersistentClass pc) { try { System.Type implClass = ReflectHelper.ClassForName(className); return((IEntityTuplizer)implClass.GetConstructor(EntityTuplizerCtorSignature).Invoke(new object[] { em, pc })); } catch (Exception t) { throw new HibernateException("Could not build tuplizer [" + className + "]", t); } }
public IEntityTuplizer BuildDefaultEntityTuplizer(EntityMode entityMode, EntityMetamodel entityMetamodel, PersistentClass persistentClass) { switch (entityMode) { case EntityMode.Poco: return(new PocoEntityTuplizer(entityMetamodel, persistentClass)); case EntityMode.Map: return(new DynamicMapEntityTuplizer(entityMetamodel, persistentClass)); default: throw new ArgumentOutOfRangeException(nameof(entityMode), entityMode, null); } }
public PocoEntityInstantiator( EntityMetamodel entityMetamodel, PersistentClass persistentClass, IInstantiationOptimizer optimizer, IProxyFactory proxyFactory) : base( persistentClass.MappedClass, optimizer, persistentClass.HasEmbeddedIdentifier) { _entityMetamodel = entityMetamodel; _proxyInterface = persistentClass.ProxyInterface; _enhancedForLazyLoading = entityMetamodel.BytecodeEnhancementMetadata.EnhancedForLazyLoading; _proxyFactory = proxyFactory; }
public PocoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) : base(entityMetamodel, mappedEntity) { mappedClass = mappedEntity.MappedClass; proxyInterface = mappedEntity.ProxyInterface; islifecycleImplementor = typeof(ILifecycle).IsAssignableFrom(mappedClass); isValidatableImplementor = typeof(IValidatable).IsAssignableFrom(mappedClass); SetReflectionOptimizer(); Instantiator = BuildInstantiator(mappedEntity); ClearOptimizerWhenUsingCustomAccessors(); proxyValidator = Cfg.Environment.BytecodeProvider.ProxyFactoryFactory.ProxyValidator; }
public PocoEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) : base(entityMetamodel, mappedEntity) { mappedClass = mappedEntity.MappedClass; proxyInterface = mappedEntity.ProxyInterface; islifecycleImplementor = typeof(ILifecycle).IsAssignableFrom(mappedClass); isValidatableImplementor = typeof(IValidatable).IsAssignableFrom(mappedClass); foreach (Mapping.Property property in mappedEntity.PropertyClosureIterator) { if (property.IsLazy) lazyPropertyNames.Add(property.Name); } if (hasCustomAccessors || !Cfg.Environment.UseReflectionOptimizer) { optimizer = null; } else { optimizer = Cfg.Environment.BytecodeProvider.GetReflectionOptimizer(mappedClass, getters, setters); } }
/// <summary> /// Instantiates a EntityEntityModeToTuplizerMapping based on the given /// entity mapping and metamodel definitions. /// </summary> /// <param name="mappedEntity">The entity mapping definition. </param> /// <param name="em">The entity metamodel definition. </param> public EntityEntityModeToTuplizerMapping(PersistentClass mappedEntity, EntityMetamodel em) { // create our own copy of the user-supplied tuplizer impl map Dictionary<EntityMode, System.Type> userSuppliedTuplizerImpls; if (mappedEntity.TuplizerMap != null) { userSuppliedTuplizerImpls = new Dictionary<EntityMode, System.Type>(mappedEntity.TuplizerMap); } else { userSuppliedTuplizerImpls = new Dictionary<EntityMode, System.Type>(); } // Build the dynamic-map tuplizer... ITuplizer dynamicMapTuplizer; System.Type tuplizerImpl; if (!userSuppliedTuplizerImpls.TryGetValue(EntityMode.Map, out tuplizerImpl)) { dynamicMapTuplizer = new DynamicMapEntityTuplizer(em, mappedEntity); } else { dynamicMapTuplizer = BuildEntityTuplizer(tuplizerImpl, mappedEntity, em); userSuppliedTuplizerImpls.Remove(EntityMode.Map); } // then the pojo tuplizer, using the dynamic-map tuplizer if no pojo representation is available ITuplizer pojoTuplizer; System.Type tempObject2; userSuppliedTuplizerImpls.TryGetValue(EntityMode.Poco, out tempObject2); userSuppliedTuplizerImpls.Remove(EntityMode.Poco); tuplizerImpl = tempObject2; if (mappedEntity.HasPocoRepresentation) { if (tuplizerImpl == null) { pojoTuplizer = new PocoEntityTuplizer(em, mappedEntity); } else { pojoTuplizer = BuildEntityTuplizer(tuplizerImpl, mappedEntity, em); } } else { pojoTuplizer = dynamicMapTuplizer; } // put the "standard" tuplizers into the tuplizer map first if (pojoTuplizer != null) { AddTuplizer(EntityMode.Poco, pojoTuplizer); } if (dynamicMapTuplizer != null) { AddTuplizer(EntityMode.Map, dynamicMapTuplizer); } // then handle any user-defined entity modes... foreach (KeyValuePair<EntityMode, System.Type> pair in userSuppliedTuplizerImpls) { IEntityTuplizer tuplizer = BuildEntityTuplizer(pair.Value, mappedEntity, em); AddTuplizer(pair.Key, tuplizer); } }
private static IEntityTuplizer BuildEntityTuplizer(System.Type implClass, PersistentClass pc, EntityMetamodel em) { try { return (IEntityTuplizer)implClass.GetConstructor(entityTuplizerCTORSignature).Invoke(new object[] { em, pc }); } catch (Exception t) { throw new HibernateException("Could not build tuplizer [" + implClass.FullName + "]", t); } }
public NullableTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappedEntity) : base(entityMetamodel, mappedEntity) { }
/// <summary> Constructs a new AbstractEntityTuplizer instance. </summary> /// <param name="entityMetamodel">The "interpreted" information relating to the mapped entity. </param> /// <param name="mappingInfo">The parsed "raw" mapping data relating to the given entity. </param> public AbstractEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappingInfo) { this.entityMetamodel = entityMetamodel; if (!entityMetamodel.IdentifierProperty.IsVirtual) { idGetter = BuildPropertyGetter(mappingInfo.IdentifierProperty, mappingInfo); idSetter = BuildPropertySetter(mappingInfo.IdentifierProperty, mappingInfo); } else { idGetter = null; idSetter = null; } propertySpan = entityMetamodel.PropertySpan; getters = new IGetter[propertySpan]; setters = new ISetter[propertySpan]; bool foundCustomAccessor = false; int i = 0; foreach (Mapping.Property property in mappingInfo.PropertyClosureIterator) { getters[i] = BuildPropertyGetter(property, mappingInfo); setters[i] = BuildPropertySetter(property, mappingInfo); if (!property.IsBasicPropertyAccessor) foundCustomAccessor = true; i++; } if (log.IsDebugEnabled) { log.DebugFormat("{0} accessors found for entity: {1}", foundCustomAccessor ? "Custom" : "No custom", mappingInfo.EntityName); } hasCustomAccessors = foundCustomAccessor; instantiator = BuildInstantiator(mappingInfo); if (entityMetamodel.IsLazy) { /* NH Different implementation * When we are using an interface we need to use the interface itself to have * the getter and setter of the identifier to prevent proxy initialization. * The BasicLazyInitializer use method.Equals to recognize the the identifier setter. */ IGetter pidGetter = idGetter; ISetter pidSetter = idSetter; if (mappingInfo.HasIdentifierProperty && mappingInfo.ProxyInterface != null) { pidGetter = mappingInfo.IdentifierProperty.GetGetter(mappingInfo.ProxyInterface); pidSetter = mappingInfo.IdentifierProperty.GetSetter(mappingInfo.ProxyInterface); } proxyFactory = BuildProxyFactory(mappingInfo, pidGetter, pidSetter); /*******************************************************************************/ if (proxyFactory == null) { entityMetamodel.IsLazy = false; } } else { proxyFactory = null; } Mapping.Component mapper = mappingInfo.IdentifierMapper; identifierMapperType = mapper == null ? null : (IAbstractComponentType)mapper.Type; }
/// <summary> /// Instantiates a EntityEntityModeToTuplizerMapping based on the given /// entity mapping and metamodel definitions. /// </summary> /// <param name="mappedEntity">The entity mapping definition. </param> /// <param name="em">The entity metamodel definition. </param> public EntityEntityModeToTuplizerMapping(PersistentClass mappedEntity, EntityMetamodel em) { // create our own copy of the user-supplied tuplizer impl map Dictionary <EntityMode, string> userSuppliedTuplizerImpls = mappedEntity.TuplizerMap != null ? new Dictionary <EntityMode, string>( mappedEntity.TuplizerMap) : new Dictionary <EntityMode, string>(); // Build the dynamic-map tuplizer... ITuplizer dynamicMapTuplizer; string tuplizerImpl; if (!userSuppliedTuplizerImpls.TryGetValue(EntityMode.Map, out tuplizerImpl)) { dynamicMapTuplizer = new DynamicMapEntityTuplizer(em, mappedEntity); } else { dynamicMapTuplizer = BuildEntityTuplizer(tuplizerImpl, mappedEntity, em); userSuppliedTuplizerImpls.Remove(EntityMode.Map); } // then the pojo tuplizer, using the dynamic-map tuplizer if no pojo representation is available ITuplizer pojoTuplizer; string tempObject2; userSuppliedTuplizerImpls.TryGetValue(EntityMode.Poco, out tempObject2); userSuppliedTuplizerImpls.Remove(EntityMode.Poco); tuplizerImpl = tempObject2; if (mappedEntity.HasPocoRepresentation) { if (tuplizerImpl == null) { pojoTuplizer = new PocoEntityTuplizer(em, mappedEntity); } else { pojoTuplizer = BuildEntityTuplizer(tuplizerImpl, mappedEntity, em); } } else { pojoTuplizer = dynamicMapTuplizer; } // put the "standard" tuplizers into the tuplizer map first if (pojoTuplizer != null) { AddTuplizer(EntityMode.Poco, pojoTuplizer); } if (dynamicMapTuplizer != null) { AddTuplizer(EntityMode.Map, dynamicMapTuplizer); } // then handle any user-defined entity modes... foreach (KeyValuePair <EntityMode, string> pair in userSuppliedTuplizerImpls) { IEntityTuplizer tuplizer = BuildEntityTuplizer(pair.Value, mappedEntity, em); AddTuplizer(pair.Key, tuplizer); } }
internal DynamicMapEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappingInfo) : base(entityMetamodel, mappingInfo) { }
internal DynamicMapEntityTuplizer(EntityMetamodel entityMetamodel, PersistentClass mappingInfo) : base(entityMetamodel, mappingInfo) { // NH different behavior fo NH-1587 Instantiator = BuildInstantiator(mappingInfo); }
private static IEntityTuplizer BuildEntityTuplizer(string className, PersistentClass pc, EntityMetamodel em) { try { System.Type implClass = ReflectHelper.ClassForName(className); return (IEntityTuplizer)implClass.GetConstructor(entityTuplizerCTORSignature).Invoke(new object[] { em, pc }); } catch (Exception t) { throw new HibernateException("Could not build tuplizer [" + className + "]", t); } }