/// <summary> /// Constructs StandardProperty instances. /// </summary> /// <param name="name">The name by which the property can be referenced within /// its owner.</param> /// <param name="node">The node name to use for XML-based representation of this /// property.</param> /// <param name="type">The Hibernate Type of this property.</param> /// <param name="lazy">Should this property be handled lazily?</param> /// <param name="insertable">Is this property an insertable value?</param> /// <param name="updateable">Is this property an updateable value?</param> /// <param name="insertGenerated">Is this property generated in the database on insert?</param> /// <param name="updateGenerated">Is this property generated in the database on update?</param> /// <param name="nullable">Is this property a nullable value?</param> /// <param name="checkable">Is this property a checkable value?</param> /// <param name="versionable">Is this property a versionable value?</param> /// <param name="cascadeStyle">The cascade style for this property's value.</param> public StandardProperty( String name, String node, IType type, bool lazy, bool insertable, bool updateable, bool insertGenerated, bool updateGenerated, bool nullable, bool checkable, bool versionable, Cascades.CascadeStyle cascadeStyle) : base(name, node, type) { this.lazy = lazy; this.insertable = insertable; this.updateable = updateable; this.insertGenerated = insertGenerated; this.updateGenerated = updateGenerated; this.nullable = nullable; this.dirtyCheckable = checkable; this.versionable = versionable; this.cascadeStyle = cascadeStyle; }
public static void BindComponent( XmlNode node, Component model, System.Type reflectedClass, string className, string path, bool isNullable, Mappings mappings ) { XmlAttribute classNode = node.Attributes[ "class" ]; if( "dynamic-component".Equals( node.Name ) ) { model.IsEmbedded = false; model.IsDynamic = true; } else if( classNode != null ) { model.ComponentClass = ClassForNameChecked( classNode.Value, mappings, "component class not found: {0}" ); model.IsEmbedded = false; } else if( reflectedClass != null ) { model.ComponentClass = reflectedClass; model.IsEmbedded = false; } else { // an "embedded" component (ids only) model.ComponentClass = model.Owner.MappedClass; model.IsEmbedded = true; } foreach( XmlNode subnode in node.ChildNodes ) { //I am only concerned with elements that are from the nhibernate namespace if( subnode.NamespaceURI != Configuration.MappingSchemaXMLNS ) { continue; } string name = subnode.LocalName; //.Name; string propertyName = GetPropertyName( subnode ); string subpath = propertyName == null ? null : StringHelper.Qualify( path, propertyName ); CollectionType collectType = CollectionType.CollectionTypeFromString( name ); IValue value = null; if( collectType != null ) { Mapping.Collection collection = collectType.Create( subnode, className, subpath, model.Owner, mappings ); mappings.AddCollection( collection ); value = collection; } else if( "many-to-one".Equals( name ) || "key-many-to-one".Equals( name ) ) { value = new ManyToOne( model.Table ); BindManyToOne( subnode, ( ManyToOne ) value, subpath, isNullable, mappings ); } else if( "one-to-one".Equals( name ) ) { value = new OneToOne( model.Table, model.Owner.Identifier ); BindOneToOne( subnode, ( OneToOne ) value, isNullable, mappings ); } else if( "any".Equals( name ) ) { value = new Any( model.Table ); BindAny( subnode, ( Any ) value, isNullable, mappings ); } else if( "property".Equals( name ) || "key-property".Equals( name ) ) { value = new SimpleValue( model.Table ); BindSimpleValue( subnode, ( SimpleValue ) value, isNullable, subpath, mappings ); } else if( "component".Equals( name ) || "dynamic-component".Equals( name ) || "nested-composite-element".Equals( name ) ) { System.Type subreflectedClass = model.ComponentClass == null ? null : GetPropertyType( subnode, mappings, model.ComponentClass, propertyName ); value = ( model.Owner != null ) ? new Component( model.Owner ) : // a class component new Component( model.Table ); // a composite element BindComponent( subnode, ( Component ) value, subreflectedClass, className, subpath, isNullable, mappings ); } else if( "parent".Equals( name ) ) { model.ParentProperty = propertyName; } if( value != null ) { model.AddProperty( CreateProperty( value, propertyName, model.ComponentClass, subnode, mappings ) ); } } int span = model.PropertySpan; string[ ] names = new string[span]; IType[ ] types = new IType[span]; Cascades.CascadeStyle[ ] cascade = new Cascades.CascadeStyle[span]; OuterJoinFetchStrategy[ ] joinedFetch = new OuterJoinFetchStrategy[span]; int i = 0; foreach( Mapping.Property prop in model.PropertyCollection ) { if( prop.IsFormula ) { throw new MappingException( "properties of components may not be formulas: " + prop.Name ); } if( !prop.IsInsertable || !prop.IsUpdateable ) { throw new MappingException( "insert=\"false\", update=\"false\" not supported for properties of components: " + prop.Name ); } names[ i ] = prop.Name; types[ i ] = prop.Type; cascade[ i ] = prop.CascadeStyle; joinedFetch[ i ] = prop.Value.OuterJoinFetchSetting; i++; } IType componentType; if( model.IsDynamic ) { componentType = new DynamicComponentType( names, types, joinedFetch, cascade ); } else { IGetter[ ] getters = new IGetter[span]; ISetter[ ] setters = new ISetter[span]; bool foundCustomAccessor = false; i = 0; foreach( Mapping.Property prop in model.PropertyCollection ) { setters[ i ] = prop.GetSetter( model.ComponentClass ); getters[ i ] = prop.GetGetter( model.ComponentClass ); if( !prop.IsBasicPropertyAccessor ) { foundCustomAccessor = true; } i++; } componentType = new ComponentType( model.ComponentClass, names, getters, setters, foundCustomAccessor, types, joinedFetch, cascade, model.ParentProperty ); } model.Type = componentType; }