public PocoComponentTuplizer(Mapping.Component component) : base(component) { componentClass = component.ComponentClass; var parentProperty = component.ParentProperty; if (parentProperty == null) { parentSetter = null; parentGetter = null; } else { parentSetter = parentProperty.GetSetter(componentClass); parentGetter = parentProperty.GetGetter(componentClass); } SetReflectionOptimizer(); // Fix for NH-3119 instantiator = BuildInstantiator(component); ClearOptimizerWhenUsingCustomAccessors(); }
public ComponentMetamodel(Mapping.Component component) { role = component.RoleName; isKey = component.IsKey; propertySpan = component.PropertySpan; properties = new StandardProperty[PropertySpan]; propertyIndexes = new Dictionary <string, int>(propertySpan); int i = 0; foreach (Mapping.Property property in component.PropertyIterator) { properties[i] = PropertyFactory.BuildStandardProperty(property, false); propertyIndexes[property.Name] = i; i++; } EntityMode = component.HasPocoRepresentation ? EntityMode.Poco : EntityMode.Map; var componentTuplizerFactory = new ComponentTuplizerFactory(); var tuplizerClassName = component.GetTuplizerImplClassName(EntityMode); ComponentTuplizer = tuplizerClassName == null ? componentTuplizerFactory.BuildDefaultComponentTuplizer(EntityMode, component) : componentTuplizerFactory.BuildComponentTuplizer(tuplizerClassName, component); }
public PocoComponentTuplizer(Mapping.Component component) : base(component) { componentClass = component.ComponentClass; var parentProperty = component.ParentProperty; if (parentProperty == null) { parentSetter = null; parentGetter = null; } else { parentSetter = parentProperty.GetSetter(componentClass); parentGetter = parentProperty.GetGetter(componentClass); } //todo ÐÞ¸ÄÔ´Âë //if (hasCustomAccessors || !Cfg.Environment.UseReflectionOptimizer) //{ // optimizer = null; //} //else //{ // optimizer = Cfg.Environment.BytecodeProvider.GetReflectionOptimizer(componentClass, getters, setters); //} }
public PocoComponentTuplizer(Mapping.Component component) : base(component) { componentClass = component.ComponentClass; string parentPropertyName = component.ParentProperty; if (parentPropertyName == null) { parentSetter = null; parentGetter = null; } else { IPropertyAccessor pa = PropertyAccessorFactory.GetPropertyAccessor(null); parentSetter = pa.GetSetter(componentClass, parentPropertyName); parentGetter = pa.GetGetter(componentClass, parentPropertyName); } if (hasCustomAccessors || !Cfg.Environment.UseReflectionOptimizer) { optimizer = null; } else { optimizer = Cfg.Environment.BytecodeProvider.GetReflectionOptimizer(componentClass, getters, setters); } }
/// <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; }
private void MapPropertyToIndex(Mapping.Property prop, int i) { propertyIndexes[prop.Name] = i; Mapping.Component comp = prop.Value as Mapping.Component; if (comp != null) { foreach (Mapping.Property subprop in comp.PropertyIterator) { propertyIndexes[prop.Name + '.' + subprop.Name] = i; } } }
private IComponentTuplizer BuildComponentTuplizer(string tuplizerImpl, Mapping.Component component) { try { System.Type implClass = ReflectHelper.ClassForName(tuplizerImpl); return((IComponentTuplizer)implClass.GetConstructor(componentTuplizerCTORSignature).Invoke(new object[] { component })); } catch (Exception t) { throw new HibernateException("Could not build tuplizer [" + tuplizerImpl + "]", t); } }
public ComponentMetamodel(Mapping.Component component) { role = component.RoleName; isKey = component.IsKey; propertySpan = component.PropertySpan; properties = new StandardProperty[PropertySpan]; propertyIndexes = new Dictionary <string, int>(propertySpan); int i = 0; foreach (Mapping.Property property in component.PropertyIterator) { properties[i] = PropertyFactory.BuildStandardProperty(property, false); propertyIndexes[property.Name] = i; i++; } tuplizerMapping = new ComponentEntityModeToTuplizerMapping(component); }
protected internal override IInstantiator BuildInstantiator(Mapping.Component component) { // TODO H3.2 not ported //if (component.IsEmbedded && ReflectHelper.IsAbstractClass(component.ComponentClass)) //{ // return new ProxiedInstantiator(component); //} if (optimizer == null) { return(new PocoInstantiator(component, null)); } else { return(new PocoInstantiator(component, optimizer.InstantiationOptimizer)); } }
private bool HasPartialUpdateComponentGeneration(Mapping.Component component) { foreach (Mapping.Property prop in component.PropertyIterator) { if (prop.Generation == PropertyGeneration.Always) { return true; } else if (prop.Value is Mapping.Component) { if (HasPartialUpdateComponentGeneration((Mapping.Component)prop.Value)) { return true; } } } return false; }
private bool HasPartialInsertComponentGeneration(Mapping.Component component) { foreach (Mapping.Property prop in component.PropertyIterator) { if (prop.Generation == PropertyGeneration.Always || prop.Generation == PropertyGeneration.Insert) { return(true); } else if (prop.Value is Mapping.Component) { if (HasPartialInsertComponentGeneration((Mapping.Component)prop.Value)) { return(true); } } } return(false); }
public PocoInstantiator(Mapping.Component component, IInstantiationOptimizer optimizer) { mappedClass = component.ComponentClass; this.optimizer = optimizer; proxyInterface = null; embeddedIdentifier = false; try { constructor = ReflectHelper.GetDefaultConstructor(mappedClass); } catch (PropertyNotFoundException) { log.Info("no default (no-argument) constructor for class: {0} (class must be instantiated by Interceptor)", mappedClass.FullName); constructor = null; } }
protected internal AbstractComponentTuplizer(Mapping.Component component) { propertySpan = component.PropertySpan; getters = new IGetter[propertySpan]; setters = new ISetter[propertySpan]; bool foundCustomAccessor = false; int i = 0; foreach (Mapping.Property prop in component.PropertyIterator) { getters[i] = BuildGetter(component, prop); setters[i] = BuildSetter(component, prop); if (!prop.IsBasicPropertyAccessor) { foundCustomAccessor = true; } i++; } if (log.IsDebugEnabled()) { log.Debug("{0} accessors found for component: {1}", foundCustomAccessor ? "Custom" : "No custom", component.ComponentClassName); } hasCustomAccessors = foundCustomAccessor; // Only to be secure that we can access to every things string[] getterNames = new string[propertySpan]; string[] setterNames = new string[propertySpan]; System.Type[] propTypes = new System.Type[propertySpan]; for (int j = 0; j < propertySpan; j++) { getterNames[j] = getters[j].PropertyName; setterNames[j] = setters[j].PropertyName; propTypes[j] = getters[j].ReturnType; } // Fix for NH-3119 //instantiator = BuildInstantiator(component); }
protected internal override IInstantiator BuildInstantiator(Mapping.Component component) { // TODO H3.2 not ported //if (component.IsEmbedded && ReflectHelper.IsAbstractClass(component.ComponentClass)) //{ // return new ProxiedInstantiator(component); //} //todo ÐÞ¸ÄÔ´Âë if (hasCustomAccessors || !Cfg.Environment.UseReflectionOptimizer) { optimizer = null; } else { optimizer = Cfg.Environment.BytecodeProvider.GetReflectionOptimizer(component.ComponentClass, getters, setters); } if (optimizer == null) { return(new PocoInstantiator(component, null)); } return(new PocoInstantiator(component, optimizer.InstantiationOptimizer)); }
protected internal abstract ISetter BuildSetter(Mapping.Component component, Mapping.Property prop);
protected internal abstract IInstantiator BuildInstantiator(Mapping.Component component);
protected internal override ISetter BuildSetter(Mapping.Component component, Mapping.Property prop) { return(BuildPropertyAccessor(prop).GetSetter(null, prop.Name)); }
protected internal override ISetter BuildSetter(Mapping.Component component, Mapping.Property prop) { return(prop.GetSetter(component.ComponentClass)); }
protected internal override IInstantiator BuildInstantiator(Mapping.Component component) { return(new DynamicMapInstantiator()); }
public ComponentEntityModeToTuplizerMapping(Mapping.Component component) { PersistentClass owner = component.Owner; // create our own copy of the user-supplied tuplizer impl map Dictionary <EntityMode, string> userSuppliedTuplizerImpls; if (component.TuplizerMap != null) { userSuppliedTuplizerImpls = new Dictionary <EntityMode, string>(component.TuplizerMap); } else { userSuppliedTuplizerImpls = new Dictionary <EntityMode, string>(); } // Build the dynamic-map tuplizer... ITuplizer dynamicMapTuplizer; string tuplizerImpl; if (!userSuppliedTuplizerImpls.TryGetValue(EntityMode.Map, out tuplizerImpl)) { dynamicMapTuplizer = new DynamicMapComponentTuplizer(component); } else { dynamicMapTuplizer = BuildComponentTuplizer(tuplizerImpl, component); 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 (owner.HasPocoRepresentation && component.HasPocoRepresentation) { if (tuplizerImpl == null) { pojoTuplizer = new PocoComponentTuplizer(component); } else { pojoTuplizer = BuildComponentTuplizer(tuplizerImpl, component); } } 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> entry in userSuppliedTuplizerImpls) { IComponentTuplizer tuplizer = BuildComponentTuplizer(entry.Value, component); AddTuplizer(entry.Key, tuplizer); } }
protected internal override ISetter BuildSetter(Mapping.Component component, Mapping.Property prop) => PropertyAccessorFactory.DynamicMapPropertyAccessor.GetSetter(null, prop.Name);
public IComponentTuplizer BuildDefaultComponentTuplizer(EntityMode entityMode, Mapping.Component component) { switch (entityMode) { case EntityMode.Poco: return(new PocoComponentTuplizer(component)); case EntityMode.Map: return(new DynamicMapComponentTuplizer(component)); default: throw new ArgumentOutOfRangeException(nameof(entityMode), entityMode, null); } }
public DynamicMapComponentTuplizer(Mapping.Component component) : base(component) { // Fix for NH-3119 instantiator = BuildInstantiator(component); }
protected internal override IInstantiator BuildInstantiator(Mapping.Component component) => new DynamicComponentInstantiator();
public DynamicMapComponentTuplizer(Mapping.Component component) : base(component) { }