/// <summary> /// Generates a VersionProperty representation for an entity mapping given its /// version mapping Property. /// </summary> /// <param name="property">The version mapping Property.</param> /// <param name="lazyAvailable">Is property lazy loading currently available.</param> /// <returns>The appropriate VersionProperty definition.</returns> public static VersionProperty BuildVersionProperty(Mapping.Property property, bool lazyAvailable) { String mappedUnsavedValue = ((IKeyValue)property.Value).NullValue; VersionValue unsavedValue = UnsavedValueFactory.GetUnsavedVersionValue( mappedUnsavedValue, GetGetter(property), (IVersionType)property.Type, GetConstructor(property.PersistentClass) ); bool lazy = lazyAvailable && property.IsLazy; return(new VersionProperty( property.Name, property.NodeName, property.Value.Type, lazy, property.IsInsertable, property.IsUpdateable, property.Generation == PropertyGeneration.Insert || property.Generation == PropertyGeneration.Always, property.Generation == PropertyGeneration.Always, property.IsOptional, property.IsUpdateable && !lazy, property.IsOptimisticLocked, property.CascadeStyle, unsavedValue )); }
/// <summary> /// Generate a "standard" (i.e., non-identifier and non-version) based on the given /// mapped property. /// </summary> /// <param name="property">The mapped property.</param> /// <param name="lazyAvailable">Is property lazy loading currently available.</param> /// <returns>The appropriate StandardProperty definition.</returns> public static StandardProperty BuildStandardProperty(Mapping.Property property, bool lazyAvailable) { IType type = property.Value.Type; // we need to dirty check collections, since they can cause an owner // version number increment // we need to dirty check many-to-ones with not-found="ignore" in order // to update the cache (not the database), since in this case a null // entity reference can lose information bool alwaysDirtyCheck = type.IsAssociationType && ((IAssociationType)type).IsAlwaysDirtyChecked; return(new StandardProperty( property.Name, property.NodeName, type, lazyAvailable && property.IsLazy, property.IsInsertable, property.IsUpdateable, property.Generation == PropertyGeneration.Insert || property.Generation == PropertyGeneration.Always, property.Generation == PropertyGeneration.Always, property.IsOptional, alwaysDirtyCheck || property.IsUpdateable, property.IsOptimisticLocked, property.CascadeStyle, property.Value.FetchMode )); }
private void CreateIdentifierProperty(HbmId idSchema, PersistentClass rootClass, SimpleValue id) { if (idSchema.name != null) { string access = idSchema.access ?? mappings.DefaultAccess; id.SetTypeUsingReflection(rootClass.MappedClass.AssemblyQualifiedName, idSchema.name, access); Mapping.Property property = new Mapping.Property(id); property.Name = idSchema.name; if (property.Value.Type == null) throw new MappingException("could not determine a property type for: " + property.Name); property.PropertyAccessorName = idSchema.access ?? mappings.DefaultAccess; property.Cascade = mappings.DefaultCascade; property.IsUpdateable = true; property.IsInsertable = true; property.IsOptimisticLocked = true; property.Generation = PropertyGeneration.Never; property.MetaAttributes = GetMetas(idSchema); rootClass.IdentifierProperty = property; LogMappedProperty(property); } }
private void BindTimestamp(HbmTimestamp timestampSchema, PersistentClass rootClass, Table table) { if (timestampSchema == null) return; string propertyName = timestampSchema.name; SimpleValue simpleValue = new SimpleValue(table); BindColumns(timestampSchema, simpleValue, propertyName); if (!simpleValue.IsTypeSpecified) simpleValue.TypeName = NHibernateUtil.Timestamp.Name; Mapping.Property property = new Mapping.Property(simpleValue); BindProperty(timestampSchema, property); // for version properties marked as being generated, make sure they are "always" // generated; "insert" is invalid. This is dis-allowed by the schema, but just to make // sure... if (property.Generation == PropertyGeneration.Insert) throw new MappingException("'generated' attribute cannot be 'insert' for versioning property"); simpleValue.NullValue = timestampSchema.unsavedvalue; rootClass.Version = property; rootClass.AddProperty(property); }
public static UnwrapProxyPropertyDescriptor From( Mapping.Property property, int propertyIndex) { return(new UnwrapProxyPropertyDescriptor( propertyIndex, property.Name, property.Type )); }
private static IGetter GetGetter(Mapping.Property mappingProperty) { if (mappingProperty == null || !mappingProperty.PersistentClass.HasPocoRepresentation) { return(null); } IPropertyAccessor pa = PropertyAccessorFactory.GetPropertyAccessor(mappingProperty, EntityMode.Poco); return(pa.GetGetter(mappingProperty.PersistentClass.MappedClass, mappingProperty.Name)); }
public void BindCompositeId(HbmCompositeId idSchema, PersistentClass rootClass) { if (idSchema == null) { return; } compositeId = new Component(rootClass); rootClass.Identifier = compositeId; if (idSchema.name == null) { BindComponent(null, "id", idSchema); rootClass.HasEmbeddedIdentifier = compositeId.IsEmbedded; } else { System.Type reflectedClass = GetPropertyType(rootClass.MappedClass, idSchema.name, idSchema); BindComponent(reflectedClass, idSchema.name, idSchema); Mapping.Property prop = new Mapping.Property(compositeId); BindProperty(prop, idSchema); rootClass.IdentifierProperty = prop; } compositeId.Table.SetIdentifierValue(compositeId); compositeId.NullValue = GetXmlEnumAttribute(idSchema.unsavedvalue); System.Type compIdClass = compositeId.ComponentClass; //<Simon date='26.04.2010'> if (compositeId.IsDynamic) { return; } //</Simon> if (!ReflectHelper.OverridesEquals(compIdClass)) { throw new MappingException( "composite-id class must override Equals(): " + compIdClass.FullName ); } if (!ReflectHelper.OverridesGetHashCode(compIdClass)) { throw new MappingException( "composite-id class must override GetHashCode(): " + compIdClass.FullName ); } // Serializability check not ported }
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; } } }
/// <summary> /// Called when [translate to SQL type string]. /// </summary> /// <param name="fromType">From type.</param> /// <returns></returns> protected override string OnTranslateToSqlTypeString(Mapping.Property fromType) { var sqlSb = new StringBuilder(); sqlSb.Append(Escape(fromType.ColumnName)); string to = null; var fType = fromType.SqlType.ToLower(); if (!string.IsNullOrWhiteSpace(fType)) { translationTypeMap.TryGetValue(fType, out to); if ((fromType.Length > 0) && !fType.Equals("text") && !fType.Equals("ntext") && !fType.Equals("image")) { if (!string.IsNullOrWhiteSpace(to) && !to.ToUpper().Equals("NTEXT")) { to = $"{to}({fromType.Length})"; } } } var sType = to ?? fromType.SqlType; sqlSb.AppendFormat(" {0}", sType); //if (fromType.IsIdentity) //{ // //sqlSb.AppendFormat(" autoincrement"); //} //if (fromType.IsPrimaryKey) //{ // sqlSb.AppendFormat(" {0}", PrimarykeySql().ToUpper()); //} if (!string.IsNullOrWhiteSpace(fromType.DefaultValue)) { string dVal = fromType.DefaultValue.Replace("N'", "'"); var sfunc = GetFunction(fromType.DefaultValue); if (sfunc != null) { dVal = sfunc.ToString(); } sqlSb.AppendFormat(" DEFAULT({0})", dVal); } if (!fromType.IsNullable) { sqlSb.Append(" NOT NULL"); } return(sqlSb.ToString()); }
public static LazyPropertyDescriptor From( Mapping.Property property, int propertyIndex, int lazyIndex) { // TODO: port lazy fetch groups return(new LazyPropertyDescriptor( propertyIndex, lazyIndex, property.Name, property.Type )); }
private ValueInclusion DetermineInsertValueGenerationType(Mapping.Property mappingProperty, StandardProperty runtimeProperty) { if (runtimeProperty.IsInsertGenerated) { return(ValueInclusion.Full); } else if (mappingProperty.Value is Mapping.Component) { if (HasPartialInsertComponentGeneration((Mapping.Component)mappingProperty.Value)) { return(ValueInclusion.Partial); } } return(ValueInclusion.None); }
private ValueInclusion DetermineUpdateValueGenerationType(Mapping.Property mappingProperty, StandardProperty runtimeProperty) { if (runtimeProperty.IsUpdateGenerated) { return ValueInclusion.Full; } else if (mappingProperty.Value is Mapping.Component) { if (HasPartialUpdateComponentGeneration((Mapping.Component)mappingProperty.Value)) { return ValueInclusion.Partial; } } return ValueInclusion.None; }
private void MapPropertyToIndex(string path, Mapping.Property prop, int i) { var propPath = !string.IsNullOrEmpty(path) ? $"{path}.{prop.Name}" : prop.Name; propertyIndexes[propPath] = i; _propertyTypes[propPath] = prop.Type; if (!(prop.Value is Mapping.Component comp)) { return; } foreach (var subprop in comp.PropertyIterator) { MapPropertyToIndex(propPath, subprop, i); } }
public static void LogMapped(this Mapping.Property property, IInternalLogger log) { if (log.IsDebugEnabled) { string msg = "Mapped property: " + property.Name; string columns = string.Join(",", property.Value.ColumnIterator.Select(c => c.Text).ToArray()); if (columns.Length > 0) { msg += " -> " + columns; } if (property.Type != null) { msg += ", type: " + property.Type.Name; } log.Debug(msg); } }
public static LazyPropertyDescriptor From( Mapping.Property property, int propertyIndex, int lazyIndex) { var fetchGroupName = string.IsNullOrEmpty(property.LazyGroup) ? "DEFAULT" : property.LazyGroup; return(new LazyPropertyDescriptor( propertyIndex, lazyIndex, property.Name, property.Type, fetchGroupName )); }
//TODO: ideally we need the construction of PropertyAccessor to take the following: // 1) EntityMode // 2) EntityMode-specific data (i.e., the classname for pojo entities) // 3) Property-specific data based on the EntityMode (i.e., property-name or dom4j-node-name) // The easiest way, with the introduction of the new runtime-metamodel classes, would be the // the following predicates: // 1) PropertyAccessorFactory.getPropertyAccessor() takes references to both a // org.hibernate.metadata.EntityModeMetadata and org.hibernate.metadata.Property // 2) What is now termed a "PropertyAccessor" stores any values needed from those two // pieces of information // 3) Code can then simply call PropertyAccess.getGetter() with no parameters; likewise with // PropertyAccessor.getSetter() /// <summary> Retrieves a PropertyAccessor instance based on the given property definition and entity mode. </summary> /// <param name="property">The property for which to retrieve an accessor. </param> /// <param name="mode">The mode for the resulting entity. </param> /// <returns> An appropriate accessor. </returns> public static IPropertyAccessor GetPropertyAccessor(Mapping.Property property, EntityMode?mode) { //TODO: this is temporary in that the end result will probably not take a Property reference per-se. EntityMode modeToUse = mode ?? EntityMode.Poco; switch (modeToUse) { case EntityMode.Poco: return(GetPocoPropertyAccessor(property.PropertyAccessorName)); case EntityMode.Map: return(DynamicMapPropertyAccessor); default: throw new MappingException("Unknown entity mode [" + mode + "]"); } }
public void BindCompositeId(HbmCompositeId idSchema, PersistentClass rootClass) { if (idSchema == null) return; compositeId = new Component(rootClass); rootClass.Identifier = compositeId; if (idSchema.name == null) { BindComponent(null, "id", idSchema); rootClass.HasEmbeddedIdentifier = compositeId.IsEmbedded; } else { System.Type reflectedClass = GetPropertyType(rootClass.MappedClass, idSchema.name, idSchema); BindComponent(reflectedClass, idSchema.name, idSchema); Mapping.Property prop = new Mapping.Property(compositeId); BindProperty(prop, idSchema); rootClass.IdentifierProperty = prop; } compositeId.Table.SetIdentifierValue(compositeId); compositeId.NullValue = GetXmlEnumAttribute(idSchema.unsavedvalue); System.Type compIdClass = compositeId.ComponentClass; //<Simon date='26.04.2010'> if(compositeId.IsDynamic) return; //</Simon> if (!ReflectHelper.OverridesEquals(compIdClass)) throw new MappingException( "composite-id class must override Equals(): " + compIdClass.FullName ); if (!ReflectHelper.OverridesGetHashCode(compIdClass)) throw new MappingException( "composite-id class must override GetHashCode(): " + compIdClass.FullName ); // Serializability check not ported }
private void BindProperty(Mapping.Property property, HbmCompositeId idSchema) { property.Name = idSchema.name; if (property.Value.Type == null) { throw new MappingException("could not determine a property type for: " + property.Name); } property.PropertyAccessorName = idSchema.access ?? mappings.DefaultAccess; property.Cascade = mappings.DefaultCascade; property.IsUpdateable = true; property.IsInsertable = true; property.IsOptimisticLocked = true; property.Generation = PropertyGeneration.Never; property.MetaAttributes = new Dictionary <string, MetaAttribute>(); LogMappedProperty(property); }
/// <summary> /// Generates an IdentifierProperty representation of the for a given entity mapping. /// </summary> /// <param name="mappedEntity">The mapping definition of the entity.</param> /// <param name="generator">The identifier value generator to use for this identifier.</param> /// <returns>The appropriate IdentifierProperty definition.</returns> public static IdentifierProperty BuildIdentifierProperty(PersistentClass mappedEntity, IIdentifierGenerator generator) { string mappedUnsavedValue = mappedEntity.Identifier.NullValue; IType type = mappedEntity.Identifier.Type; Mapping.Property property = mappedEntity.IdentifierProperty; IdentifierValue unsavedValue = UnsavedValueFactory.GetUnsavedIdentifierValue(mappedUnsavedValue, GetGetter(property), type, GetConstructor(mappedEntity)); if (property == null) { // this is a virtual id property... return(new IdentifierProperty(type, mappedEntity.HasEmbeddedIdentifier, mappedEntity.HasIdentifierMapper, unsavedValue, generator)); } else { return(new IdentifierProperty(property.Name, property.NodeName, type, mappedEntity.HasEmbeddedIdentifier, unsavedValue, generator)); } }
protected override ISetter BuildPropertySetter(Mapping.Property mappedProperty, PersistentClass mappedEntity) { return(mappedProperty.GetSetter(mappedEntity.MappedClass)); }
private void BindComponent(System.Type reflectedClass, string path, HbmCompositeId idSchema) { if (idSchema.@class != null) { compositeId.ComponentClass = ClassForNameChecked(idSchema.@class, mappings, "component class not found: {0}"); compositeId.IsEmbedded = false; } else if (reflectedClass != null) { compositeId.ComponentClass = reflectedClass; compositeId.IsEmbedded = false; } else { //<Simon date='26.04.2010'> if (compositeId.Owner.HasPocoRepresentation) { //</Simon> // an "embedded" component (ids only) compositeId.ComponentClass = compositeId.Owner.MappedClass; compositeId.IsEmbedded = true; //<Simon date='26.04.2010'> } else { compositeId.IsDynamic = true; } //</Simon> } foreach (object item in idSchema.Items ?? new object[0]) { HbmKeyManyToOne keyManyToOneSchema = item as HbmKeyManyToOne; HbmKeyProperty keyPropertySchema = item as HbmKeyProperty; if (keyManyToOneSchema != null) { ManyToOne manyToOne = new ManyToOne(compositeId.Table); string propertyName = keyManyToOneSchema.name == null ? null : StringHelper.Qualify(path, keyManyToOneSchema.name); BindManyToOne(keyManyToOneSchema, manyToOne, propertyName, false); Mapping.Property property = CreateProperty(manyToOne, keyManyToOneSchema.name, compositeId.ComponentClass, keyManyToOneSchema); compositeId.AddProperty(property); } else if (keyPropertySchema != null) { SimpleValue value = new SimpleValue(compositeId.Table); string propertyName = keyPropertySchema.name == null ? null : StringHelper.Qualify(path, keyPropertySchema.name); BindSimpleValue(keyPropertySchema, value, false, propertyName); Mapping.Property property = CreateProperty(value, keyPropertySchema.name, compositeId.ComponentClass, keyPropertySchema); compositeId.AddProperty(property); } } }
private Mapping.Property CreateProperty(SimpleValue value, string propertyName, System.Type parentClass, HbmKeyProperty keyPropertySchema) { if (parentClass != null && value.IsSimpleValue) value.SetTypeUsingReflection(parentClass.AssemblyQualifiedName, propertyName, keyPropertySchema.access ?? mappings.DefaultAccess); // This is done here 'cos we might only know the type here (ugly!) if (value is ToOne) { ToOne toOne = (ToOne) value; string propertyRef = toOne.ReferencedPropertyName; if (propertyRef != null) mappings.AddUniquePropertyReference(toOne.ReferencedEntityName, propertyRef); } value.CreateForeignKey(); Mapping.Property prop = new Mapping.Property(); prop.Value = value; BindProperty(keyPropertySchema, prop); return prop; }
/// <summary> /// Called when [translate to SQL type string]. /// </summary> /// <param name="fromType">From type.</param> /// <returns></returns> protected override string OnTranslateToSqlTypeString(Mapping.Property fromType) { if (fromType == null) { throw new ArgumentNullException(nameof(fromType)); } if (fromType.IsMappingComplexType()) { return(string.Empty); } StringBuilder sqlSb = new StringBuilder(); try { sqlSb.Append(Escape(fromType.ColumnName)); string to = null; string fType = fromType.SqlType.ToLower(); if (!string.IsNullOrWhiteSpace(fType)) { translationTypeMap.TryGetValue(fType, out to); if ((fromType.Length > 0) && !fType.Equals("text") && !fType.Equals("ntext") && !fType.Equals("image")) { if (!string.IsNullOrWhiteSpace(to) && !to.ToUpper().Equals("NTEXT")) { to = string.Format("{0}({1})", to, fromType.Length); } } } var sType = to ?? fromType.SqlType; sqlSb.AppendFormat(" {0}", sType); if (fromType.IsIdentity) { sqlSb.AppendFormat(" IDENTITY(1,1)"); } //if (fromType.IsPrimaryKey) //{ // sqlSb.AppendFormat(" {0}", PrimarykeySql().ToUpper()); //} if (!string.IsNullOrWhiteSpace(fromType.DefaultValue)) { string dVal = fromType.DefaultValue; var sfunc = GetFunction(fromType.DefaultValue); if (sfunc != null) { dVal = sfunc.ToString(); } sqlSb.AppendFormat(" DEFAULT({0})", dVal); } if (!fromType.IsNullable) { sqlSb.Append(" NOT NULL"); } return(sqlSb.ToString()); } catch (Exception exception) { throw new GoliathDataException($"Could no get sql type for property {fromType.PropertyName} - {fromType.ColumnName}", exception); } }
public static void BindRootClass( XmlNode node, RootClass model, Mappings mappings ) { BindClass( node, model, mappings ); //TABLENAME XmlAttribute schemaNode = node.Attributes[ "schema" ]; string schema = schemaNode == null ? mappings.SchemaName : schemaNode.Value; Table table = mappings.AddTable( schema, GetClassTableName( model, node, mappings ) ); model.Table = table; log.Info( "Mapping class: " + model.Name + " -> " + model.Table.Name ); //MUTABLE XmlAttribute mutableNode = node.Attributes[ "mutable" ]; model.IsMutable = ( mutableNode == null ) || mutableNode.Value.Equals( "true" ); //WHERE XmlAttribute whereNode = node.Attributes[ "where" ]; if( whereNode != null ) { model.Where = whereNode.Value; } //CHECK XmlAttribute checkNode = node.Attributes[ "check" ]; if( checkNode != null ) { table.AddCheckConstraint( checkNode.Value ); } //POLYMORPHISM XmlAttribute polyNode = node.Attributes[ "polymorphism" ]; model.IsExplicitPolymorphism = ( polyNode != null ) && polyNode.Value.Equals( "explicit" ); foreach( XmlNode subnode in node.ChildNodes ) { string name = subnode.LocalName; //Name; string propertyName = GetPropertyName( subnode ); //I am only concerned with elements that are from the nhibernate namespace if( subnode.NamespaceURI != Configuration.MappingSchemaXMLNS ) { continue; } switch( name ) { case "id": SimpleValue id = new SimpleValue( table ); model.Identifier = id; if( propertyName == null ) { BindSimpleValue( subnode, id, false, RootClass.DefaultIdentifierColumnName, mappings ); if( id.Type == null ) { throw new MappingException( "must specify an identifier type: " + model.MappedClass.Name ); } model.IdentifierProperty = null; } else { BindSimpleValue( subnode, id, false, propertyName, mappings ); id.SetTypeByReflection( model.MappedClass, propertyName, PropertyAccess( subnode, mappings ) ); Mapping.Property prop = new Mapping.Property( id ); BindProperty( subnode, prop, mappings ); model.IdentifierProperty = prop; } if( id.Type.ReturnedClass.IsArray ) { throw new MappingException( "illegal use of an array as an identifier (arrays don't reimplement equals)" ); } MakeIdentifier( subnode, id, mappings ); break; case "composite-id": Component compId = new Component( model ); model.Identifier = compId; if( propertyName == null ) { BindComponent( subnode, compId, null, model.Name, "id", false, mappings ); model.HasEmbeddedIdentifier = compId.IsEmbedded; model.IdentifierProperty = null; } else { System.Type reflectedClass = GetPropertyType( subnode, mappings, model.MappedClass, propertyName ); BindComponent( subnode, compId, reflectedClass, model.Name, propertyName, false, mappings ); Mapping.Property prop = new Mapping.Property( compId ); BindProperty( subnode, prop, mappings ); model.IdentifierProperty = prop; } MakeIdentifier( subnode, compId, mappings ); System.Type compIdClass = compId.ComponentClass; if( !ReflectHelper.OverridesEquals( compIdClass ) ) { throw new MappingException( "composite-id class must override Equals(): " + compIdClass.FullName ); } if( !ReflectHelper.OverridesGetHashCode( compIdClass ) ) { throw new MappingException( "composite-id class must override GetHashCode(): " + compIdClass.FullName ); } // Serializability check not ported break; case "version": case "timestamp": //VERSION SimpleValue val = new SimpleValue( table ); BindSimpleValue( subnode, val, false, propertyName, mappings ); if( val.Type == null ) { val.Type = ( ( "version".Equals( name ) ) ? NHibernateUtil.Int32 : NHibernateUtil.Timestamp ); } Mapping.Property timestampProp = new Mapping.Property( val ); BindProperty( subnode, timestampProp, mappings ); MakeVersion( subnode, val ); model.Version = timestampProp; model.AddNewProperty( timestampProp ); break; case "discriminator": //DISCRIMINATOR SimpleValue discrim = new SimpleValue( table ); model.Discriminator = discrim; BindSimpleValue( subnode, discrim, false, RootClass.DefaultDiscriminatorColumnName, mappings ); if( discrim.Type == null ) { discrim.Type = NHibernateUtil.String; foreach( Column col in discrim.ColumnCollection ) { col.Type = NHibernateUtil.String; break; } } model.IsPolymorphic = true; if( subnode.Attributes[ "force" ] != null && "true".Equals( subnode.Attributes[ "force" ].Value ) ) { model.IsForceDiscriminator = true; } if( subnode.Attributes[ "insert" ] != null && "false".Equals( subnode.Attributes[ "insert" ].Value ) ) { model.IsDiscriminatorInsertable = false; } break; case "jcs-cache": case "cache": string className = model.MappedClass.FullName; ICacheConcurrencyStrategy cache = CacheFactory.CreateCache( subnode, className, model.IsMutable ); mappings.AddCache( className, cache ); model.Cache = cache; break; } } model.CreatePrimaryKey( dialect ); PropertiesFromXML( node, model, mappings ); }
private static Mapping.Property CreateProperty( IValue value, string propertyName, System.Type parentClass, XmlNode subnode, Mappings mappings ) { if( parentClass != null && value.IsSimpleValue ) { ( ( SimpleValue ) value ).SetTypeByReflection( parentClass, propertyName, PropertyAccess( subnode, mappings ) ); } // This is done here 'cos we might only know the type here (ugly!) if( value is ToOne ) { string propertyRef = ( ( ToOne ) value ).ReferencedPropertyName; if( propertyRef != null ) { mappings.AddUniquePropertyReference( ( ( EntityType ) value.Type ).AssociatedClass, propertyRef ); } } value.CreateForeignKey(); Mapping.Property prop = new Mapping.Property(); prop.Value = value; BindProperty( subnode, prop, mappings ); return prop; }
protected Mapping.Property CreateProperty(IValue value, string propertyName, System.Type parentClass, XmlNode subnode) { if (parentClass != null && value.IsSimpleValue) value.SetTypeUsingReflection(parentClass.AssemblyQualifiedName, propertyName, PropertyAccess(subnode)); // This is done here 'cos we might only know the type here (ugly!) if (value is ToOne) { ToOne toOne = (ToOne) value; string propertyRef = toOne.ReferencedPropertyName; if (propertyRef != null) mappings.AddUniquePropertyReference(toOne.ReferencedEntityName, propertyRef); } value.CreateForeignKey(); Mapping.Property prop = new Mapping.Property(); prop.Value = value; BindProperty(subnode, prop); return prop; }
protected internal override ISetter BuildSetter(Mapping.Component component, Mapping.Property prop) => PropertyAccessorFactory.DynamicMapPropertyAccessor.GetSetter(null, prop.Name);
public void Apply(Mapping.Property property) { throw new Exception("Any kind of exception"); }
private IPropertyAccessor BuildPropertyAccessor(Mapping.Property property) { return(PropertyAccessorFactory.DynamicMapPropertyAccessor); }
protected internal abstract ISetter BuildSetter(Mapping.Component component, Mapping.Property prop);
protected internal override ISetter BuildSetter(Mapping.Component component, Mapping.Property prop) { return(prop.GetSetter(component.ComponentClass)); }
private Mapping.Property CreateProperty(ToOne value, string propertyName, System.Type parentClass, HbmKeyManyToOne keyManyToOneSchema) { if (parentClass != null && value.IsSimpleValue) value.SetTypeUsingReflection(parentClass.AssemblyQualifiedName, propertyName, keyManyToOneSchema.access ?? mappings.DefaultAccess); string propertyRef = value.ReferencedPropertyName; if (propertyRef != null) mappings.AddUniquePropertyReference(value.ReferencedEntityName, propertyRef); value.CreateForeignKey(); Mapping.Property prop = new Mapping.Property(); prop.Value = value; BindProperty(keyManyToOneSchema, prop); return prop; }
private void MapPropertyToIndex(Mapping.Property prop, int i) { MapPropertyToIndex(null, prop, i); }
/// <summary> Build an appropriate Setter for the given property. </summary> /// <param name="mappedProperty">The property to be accessed via the built Setter. </param> /// <param name="mappedEntity">The entity information regarding the mapped entity owning this property. </param> /// <returns> An appropriate Setter instance. </returns> protected abstract ISetter BuildPropertySetter(Mapping.Property mappedProperty, PersistentClass mappedEntity);
protected internal override ISetter BuildSetter(Mapping.Component component, Mapping.Property prop) { return(BuildPropertyAccessor(prop).GetSetter(null, prop.Name)); }
protected override ISetter BuildPropertySetter(Mapping.Property mappedProperty, PersistentClass mappedEntity) { return(BuildPropertyAccessor(mappedProperty).GetSetter(null, mappedProperty.Name)); }
private static void BindVersioningProperty(Table table, XmlNode subnode, Mappings mappings, string name, RootClass entity) { string propertyName = subnode.Attributes["name"].Value; SimpleValue val = new SimpleValue(table); BindSimpleValue(subnode, val, false, propertyName, mappings); if (val.Type == null) { val.Type = (("version".Equals(name)) ? NHibernateUtil.Int32 : NHibernateUtil.Timestamp); } Mapping.Property prop = new Mapping.Property(val); BindProperty(subnode, prop, mappings); // for version properties marked as being generated, make sure they are "always" // generated; "insert" is invalid. This is dis-allowed by the schema, but just to make // sure... if (prop.Generation == PropertyGeneration.Insert) { throw new MappingException("'generated' attribute cannot be 'insert' for versioning property"); } MakeVersion(subnode, val); entity.Version = prop; entity.AddProperty(prop); }