public ResultSetMappingSecondPass(XmlNode element, String path, Mappings mappings, XmlNamespaceManager nsmgr)
			: base(nsmgr)
		{
			this.element = element;
			this.path = path;
			this.mappings = mappings;
		}
		public NamedSQLQuerySecondPass(XmlNode queryElem, string path, Mappings mappings, XmlNamespaceManager nsmgr)
			: base(nsmgr)
		{
			this.queryElem = queryElem;
			this.path = path;
			this.mappings = mappings;
		}
Exemplo n.º 3
0
 private static void SetDefaultMappingsProperties(Mappings mappings) {
     mappings.SchemaName = null;
     mappings.DefaultCascade = "none";
     mappings.DefaultAccess = "property";
     mappings.DefaultLazy = true;
     mappings.IsAutoImport = true;
     mappings.DefaultNamespace = null;
     mappings.DefaultAssembly = null;
 }
Exemplo n.º 4
0
		/// <summary>
		/// Converts a partial class name into a fully qualified one
		/// </summary>
		/// <param name="className"></param>
		/// <param name="mapping"></param>
		/// <returns></returns>
		public static string FullClassName(string className, Mappings mapping)
		{
			if (className == null)
			{
				return null;
			}

			return TypeNameParser.Parse(className, mapping.DefaultNamespace, mapping.DefaultAssembly)
				.ToString();
		}
Exemplo n.º 5
0
        private void AddAuditing(Mappings mappings)
        {
            var auditObjects = new List<IAuxiliaryDatabaseObject>();
              foreach (var table in mappings.IterateTables.ToArray())
              {
            var auditTable = new AuditTable(
              table, _namingStrategy, _columnSource);
            mappings.AddAuxiliaryDatabaseObject(auditTable);

            var insertTrigger = new AuditTrigger(table,
              auditTable, _namingStrategy, TriggerActions.INSERT);
            mappings.AddAuxiliaryDatabaseObject(insertTrigger);

            var updateTrigger = new AuditTrigger(table,
              auditTable, _namingStrategy, TriggerActions.UPDATE);
            mappings.AddAuxiliaryDatabaseObject(updateTrigger);

            var deleteTrigger = new AuditTrigger(table,
              auditTable, _namingStrategy, TriggerActions.DELETE);
            mappings.AddAuxiliaryDatabaseObject(deleteTrigger);
              }
        }
Exemplo n.º 6
0
		/// <summary>
		/// Converts a partial class name into a fully qualified one
		/// </summary>
		/// <param name="className"></param>
		/// <param name="mapping"></param>
		/// <returns></returns>
		public static string FullClassName( string className, Mappings mapping )
		{
			if( className == null )
			{
				return null;
			}
			int commaPosn = className.IndexOf( ',' );
			int dotPosn = className.IndexOf( '.' );

			// Check for namespace; ok to have a dot after the comma as it's part of the assembly name
			bool needNamespace = ( dotPosn == -1 || ( commaPosn > -1 && dotPosn > commaPosn ) ) && mapping.DefaultNamespace != null;
			// Add if we don't have any commas and a default exists
			bool needAssembly = commaPosn == -1 && mapping.DefaultAssembly != null;

			if( needNamespace == false && needAssembly == false )
			{
				return className;
			}
			else
			{
				StringBuilder sb = new StringBuilder();

				if( needNamespace )
				{
					sb.Append( mapping.DefaultNamespace );
					sb.Append( "." );
				}

				sb.Append( className );

				if( needAssembly )
				{
					sb.Append( ", " );
					sb.Append( mapping.DefaultAssembly );
				}
				return sb.ToString();
			}
		}
Exemplo n.º 7
0
		public static void BindIntegerValue( XmlNode node, IntegerValue model, string defaultColumnName, bool isNullable, Mappings mappings )
		{
			BindSimpleValue( node, model, isNullable, defaultColumnName, mappings );

			if( model.ColumnCollection.Count > 1 )
			{
				log.Error( "This shouldn't happen, check BindIntegerValue" );
			}
			foreach( Column col in model.ColumnCollection )
			{
				col.Type = NHibernateUtil.Int32;
				col.TypeIndex = 0;
				break;
			}
		}
Exemplo n.º 8
0
		public static void BindColumns( XmlNode node, SimpleValue model, bool isNullable, bool autoColumn, string propertyPath, Mappings mappings )
		{
			//COLUMN(S)
			XmlAttribute columnAttribute = node.Attributes[ "column" ];
			if( columnAttribute == null )
			{
				int count = 0;
				Table table = model.Table;

				foreach( XmlNode columnElement in node.SelectNodes( nsColumn, nsmgr ) )
				{
					Column col = new Column( model.Type, count++ );
					BindColumn( columnElement, col, isNullable );

					string name = columnElement.Attributes[ "name" ].Value;
					col.Name = mappings.NamingStrategy.ColumnName( name );
					if( table != null )
					{
						table.AddColumn( col );
					}
					//table=null -> an association, fill it in later
					model.AddColumn( col );
					
					//column index
					XmlAttribute indexNode = columnElement.Attributes[ "index" ];
					if( indexNode != null && table != null )
					{
						table.GetIndex( indexNode.Value ).AddColumn( col );
					}

					//column group index (although it can serve as a separate column index)
					XmlAttribute parentElementIndexAttr = node.Attributes[ "index" ];
					if( parentElementIndexAttr != null && table != null )
					{
						table.GetIndex( parentElementIndexAttr.Value ).AddColumn( col );
					}
					XmlAttribute uniqueNode = columnElement.Attributes[ "unique-key" ];
					if( uniqueNode != null && table != null )
					{
						table.GetUniqueKey( uniqueNode.Value ).AddColumn( col );
					}
				}
			}
			else
			{
				Column col = new Column( model.Type, 0 );
				BindColumn( node, col, isNullable );
				col.Name = mappings.NamingStrategy.ColumnName( columnAttribute.Value );
				Table table = model.Table;
				if( table != null )
				{
					table.AddColumn( col );
				} //table=null -> an association - fill it in later
				model.AddColumn( col );
				//column group index (although can serve as a separate column index)
				XmlAttribute indexAttr = node.Attributes[ "index" ];
				if( indexAttr != null && table != null )
				{
					table.GetIndex( indexAttr.Value ).AddColumn( col );
				}
			}

			if( autoColumn && model.ColumnSpan == 0 )
			{
				Column col = new Column( model.Type, 0 );
				BindColumn( node, col, isNullable );
				col.Name = mappings.NamingStrategy.PropertyToColumnName( propertyPath );
				model.Table.AddColumn( col );
				model.AddColumn( col );
			}
		}
Exemplo n.º 9
0
		//automatically makes a column with the default name if none is specifed by XML
		public static void BindSimpleValue( XmlNode node, SimpleValue model, bool isNullable, string path, Mappings mappings )
		{
			model.Type = GetTypeFromXML( node );

			XmlAttribute formulaNode = node.Attributes[ "formula" ];
			if( formulaNode != null )
			{
				Formula f = new Formula();
				f.FormulaString = formulaNode.InnerText;
				model.Formula = f;
			}
			else
			{
				BindColumns( node, model, isNullable, true, path, mappings );
			}

			XmlAttribute fkNode = node.Attributes[ "foreign-key" ];
			if( fkNode != null )
			{
				model.ForeignKeyName = fkNode.Value;
			}
		}
Exemplo n.º 10
0
				public override Mapping.Collection Create( XmlNode node, string prefix, string path, PersistentClass owner, Mappings mappings )
				{
					Map map = new Map( owner );
					Binder.BindCollection( node, map, prefix, path, mappings );
					return map;
				}
Exemplo n.º 11
0
		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 );
		}
Exemplo n.º 12
0
		public static void BindOneToMany( XmlNode node, OneToMany model, Mappings mappings )
		{
			model.Type = ( EntityType ) NHibernateUtil.Entity(
				ClassForNameChecked( node.Attributes[ "class" ].Value, mappings,
				                     "associated class not found: {0}" ) );
		}
Exemplo n.º 13
0
		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;
		}
Exemplo n.º 14
0
		/// <remarks>
		/// Called for all collections
		/// </remarks>
		public static void BindCollection( XmlNode node, Mapping.Collection model, string className, string path, Mappings mappings )
		{
			//ROLENAME
			model.Role = StringHelper.Qualify( className, path );

			XmlAttribute inverseNode = node.Attributes[ "inverse" ];
			if( inverseNode != null )
			{
				model.IsInverse = StringHelper.BooleanValue( inverseNode.Value );
			}

			XmlAttribute orderNode = node.Attributes[ "order-by" ];
			if( orderNode != null )
			{
				model.OrderBy = orderNode.Value;
			}
			XmlAttribute whereNode = node.Attributes[ "where" ];
			if( whereNode != null )
			{
				model.Where = whereNode.Value;
			}
			XmlAttribute batchNode = node.Attributes[ "batch-size" ];
			if( batchNode != null )
			{
				model.BatchSize = Int32.Parse( batchNode.Value );
			}

			//PERSISTER
			XmlAttribute persisterNode = node.Attributes[ "persister" ];
			if( persisterNode == null )
			{
				//persister = CollectionPersisterImpl.class;
			}
			else
			{
				model.CollectionPersisterClass = ClassForNameChecked(
					persisterNode.Value, mappings,
					"could not instantiate collection persister class: {0}" );
			}

			InitOuterJoinFetchSetting( node, model );

			XmlNode oneToManyNode = node.SelectSingleNode( nsOneToMany, nsmgr );
			if( oneToManyNode != null )
			{
				OneToMany oneToMany = new OneToMany( model.Owner );
				model.Element = oneToMany;
				BindOneToMany( oneToManyNode, oneToMany, mappings );
				//we have to set up the table later!! yuck
			}
			else
			{
				//TABLE
				XmlAttribute tableNode = node.Attributes[ "table" ];
				string tableName;
				if( tableNode != null )
				{
					tableName = mappings.NamingStrategy.TableName( tableNode.Value );
				}
				else
				{
					tableName = mappings.NamingStrategy.PropertyToTableName( className, path );
				}
				XmlAttribute schemaNode = node.Attributes[ "schema" ];
				string schema = schemaNode == null ? mappings.SchemaName : schemaNode.Value;
				model.CollectionTable = mappings.AddTable( schema, tableName );

				log.Info( "Mapping collection: " + model.Role + " -> " + model.CollectionTable.Name );
			}

			//LAZINESS
			XmlAttribute lazyNode = node.Attributes[ "lazy" ];
			if( lazyNode != null )
			{
				model.IsLazy = StringHelper.BooleanValue( lazyNode.Value );
			}

			//SORT
			XmlAttribute sortedAtt = node.Attributes[ "sort" ];
			// unsorted, natural, comparator.class.name
			if( sortedAtt == null || sortedAtt.Value.Equals( "unsorted" ) )
			{
				model.IsSorted = false;
			}
			else
			{
				model.IsSorted = true;
				string comparatorClassName = FullClassName( sortedAtt.Value, mappings );
				if( !comparatorClassName.Equals( "natural" ) )
				{
					try
					{
						model.Comparer = ( IComparer ) Activator.CreateInstance( ReflectHelper.ClassForName( comparatorClassName ) );
					}
					catch
					{
						throw new MappingException( "could not instantiate comparer class: " + comparatorClassName );
					}
				}
			}

			//ORPHAN DELETE (used for programmer error detection)
			XmlAttribute cascadeAtt = node.Attributes[ "cascade" ];
			if( cascadeAtt != null && cascadeAtt.Value.Equals( "all-delete-orphan" ) )
			{
				model.OrphanDelete = true;
			}

			//set up second pass
			if( model is List )
			{
				mappings.AddSecondPass( new ListSecondPass( node, mappings, ( List ) model ) );
			}
			else if( model is Map )
			{
				mappings.AddSecondPass( new MapSecondPass( node, mappings, ( Map ) model ) );
			}
			else if( model is Set )
			{
				mappings.AddSecondPass( new SetSecondPass( node, mappings, ( Set ) model ) );
			}
			else if( model is IdentifierCollection )
			{
				mappings.AddSecondPass( new IdentifierCollectionSecondPass( node, mappings, ( IdentifierCollection ) model ) );
			}
			else
			{
				mappings.AddSecondPass( new CollectionSecondPass( node, mappings, model ) );
			}
		}
Exemplo n.º 15
0
		public static void BindAny( XmlNode node, Any model, bool isNullable, Mappings mappings )
		{
			model.IdentifierType = GetTypeFromXML( node );

			XmlAttribute metaAttribute = node.Attributes[ "meta-type" ];
			if( metaAttribute != null )
			{
				IType metaType = TypeFactory.HeuristicType( metaAttribute.Value );
				if( metaType == null )
				{
					throw new MappingException( "could not interpret meta-type" );
				}
				model.MetaType = metaType;

				Hashtable values = new Hashtable();
				foreach( XmlNode metaValue in node.SelectNodes( nsMetaValue, nsmgr ) )
				{
					try
					{
						object value = ((IDiscriminatorType) model.MetaType).FromString( metaValue.Attributes["value"].Value );
						System.Type clazz = ReflectHelper.ClassForName( FullClassName( metaValue.Attributes["class"].Value, mappings ) );
						values[ value ] = clazz;
					}
					catch( InvalidCastException )
					{
						throw new MappingException( "meta-type was not an IDiscriminatorType: " + metaType.Name );
					}
					catch( HibernateException he )
					{
						throw new MappingException( "could not interpret meta-value", he );
					}
					catch( TypeLoadException cnfe )
					{
						throw new MappingException( "meta-value class not found", cnfe );
					}
				}

				if( values.Count > 0 )
				{
					model.MetaType = new MetaType( values, model.MetaType );
				}
			}

			BindColumns( node, model, isNullable, false, null, mappings );
		}
Exemplo n.º 16
0
		private static string PropertyAccess( XmlNode node, Mappings mappings )
		{
			XmlAttribute accessNode = node.Attributes[ "access" ];
			return accessNode != null ? accessNode.Value : mappings.DefaultAccess;
		}
Exemplo n.º 17
0
				public override Mapping.Collection Create( XmlNode node, string prefix, string path, PersistentClass owner, Mappings mappings )
				{
					PrimitiveArray array = new PrimitiveArray( owner );
					Binder.BindArray( node, array, prefix, path, mappings );
					return array;
				}
Exemplo n.º 18
0
				public override Mapping.Collection Create( XmlNode node, string prefix, string path, PersistentClass owner, Mappings mappings )
				{
					IdentifierBag bag = new IdentifierBag( owner );
					Binder.BindCollection( node, bag, prefix, path, mappings );
					return bag;
				}
Exemplo n.º 19
0
				public override Mapping.Collection Create( XmlNode node, string prefix, string path, PersistentClass owner, Mappings mappings )
				{
					List list = new List( owner );
					Binder.BindCollection( node, list, prefix, path, mappings );
					return list;
				}
Exemplo n.º 20
0
				public override Mapping.Collection Create( XmlNode node, string prefix, string path, PersistentClass owner, Mappings mappings )
				{
					Set setCollection = new Set( owner );
					Binder.BindCollection( node, setCollection, prefix, path, mappings );
					return setCollection;
				}
Exemplo n.º 21
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="node"></param>
		/// <param name="model"></param>
		/// <param name="mappings"></param>
		public static void BindProperty( XmlNode node, Mapping.Property model, Mappings mappings )
		{
			model.Name = GetPropertyName( node );
			IType type = model.Value.Type;
			if( type == null )
			{
				throw new MappingException( "could not determine a property type for: " + model.Name );
			}

			model.PropertyAccessorName = PropertyAccess( node, mappings );

			XmlAttribute cascadeNode = node.Attributes[ "cascade" ];
			model.Cascade = ( cascadeNode == null ) ? mappings.DefaultCascade : cascadeNode.Value;

			XmlAttribute updateNode = node.Attributes[ "update" ];
			model.IsUpdateable = ( updateNode == null ) ? true : "true".Equals( updateNode.Value );

			XmlAttribute insertNode = node.Attributes[ "insert" ];
			model.IsInsertable = ( insertNode == null ) ? true : "true".Equals( insertNode.Value );

			if( log.IsDebugEnabled )
			{
				string msg = "Mapped property: " + model.Name;
				string columns = Columns( model.Value );
				if( columns.Length > 0 )
				{
					msg += " -> " + columns;
				}
				if( model.Type != null )
				{
					msg += ", type: " + model.Type.Name;
				}
				log.Debug( msg );
			}

			model.MetaAttributes = GetMetas( node );
		}
Exemplo n.º 22
0
		private static System.Type GetPropertyType( XmlNode definingNode, Mappings mappings,
			System.Type containingType, string propertyName )
		{
			if( definingNode.Attributes[ "class" ] != null )
			{
				return ClassForNameChecked( definingNode.Attributes[ "class" ].Value, mappings,
					"could not find class: {0}" );
			}
			else if( containingType == null )
			{
				return null;
			}

			string access = PropertyAccess( definingNode, mappings );

			return ReflectHelper.ReflectedPropertyClass( containingType, propertyName, access );
		}
Exemplo n.º 23
0
		public static void BindManyToOne( XmlNode node, ManyToOne model, string defaultColumnName, bool isNullable, Mappings mappings )
		{
			BindColumns( node, model, isNullable, true, defaultColumnName, mappings );
			InitOuterJoinFetchSetting( node, model );

			XmlAttribute ukName = node.Attributes[ "property-ref" ];
			if( ukName != null )
			{
				model.ReferencedPropertyName = ukName.Value;
			}

			XmlAttribute typeNode = node.Attributes[ "class" ];

			if( typeNode != null )
			{
				model.Type = TypeFactory.ManyToOne(
					ClassForNameChecked( typeNode.Value, mappings,
					                     "could not find class: {0}" ),
					model.ReferencedPropertyName );
			}

			XmlAttribute fkNode = node.Attributes[ "foreign-key" ];
			if( fkNode != null )
			{
				model.ForeignKeyName = fkNode.Value;
			}
		}
Exemplo n.º 24
0
		public static void BindSetSecondPass( XmlNode node, Set model, IDictionary persistentClasses, Mappings mappings )
		{
			BindCollectionSecondPass( node, model, persistentClasses, mappings );

			if( !model.IsOneToMany )
			{
				model.CreatePrimaryKey();
			}
		}
Exemplo n.º 25
0
		public static void BindOneToOne( XmlNode node, OneToOne model, bool isNullable, Mappings mappings )
		{
			//BindColumns( node, model, isNullable, false, null, mappings );
			InitOuterJoinFetchSetting( node, model );

			XmlAttribute constrNode = node.Attributes[ "constrained" ];
			bool constrained = constrNode != null && constrNode.Value.Equals( "true" );
			model.IsConstrained = constrained;

			model.ForeignKeyType = ( constrained ? ForeignKeyType.ForeignKeyFromParent : ForeignKeyType.ForeignKeyToParent );

			XmlAttribute fkNode = node.Attributes[ "foreign-key" ];
			if( fkNode != null )
			{
				model.ForeignKeyName = fkNode.Value;
			}

			XmlAttribute ukName = node.Attributes[ "property-ref" ];
			if( ukName != null )
			{
				model.ReferencedPropertyName = ukName.Value;
			}

			XmlAttribute classNode = node.Attributes[ "class" ];
			if( classNode != null )
			{
				model.Type = TypeFactory.OneToOne(
					ClassForNameChecked( classNode.Value, mappings, "could not find class: {0}" ),
					model.ForeignKeyType, model.ReferencedPropertyName );
			}
		}
Exemplo n.º 26
0
		public static void BindSubclass( XmlNode node, Subclass model, Mappings mappings )
		{
			BindClass( node, model, mappings );

			if( model.ClassPersisterClass == null )
			{
				model.RootClazz.ClassPersisterClass = typeof( EntityPersister );
			}

			model.Table = model.Superclass.Table;

			log.Info( "Mapping subclass: " + model.Name + " -> " + model.Table.Name );

			// properties
			PropertiesFromXML( node, model, mappings );
		}
Exemplo n.º 27
0
		/// <remarks>
		/// Called for arrays and primitive arrays
		/// </remarks>
		public static void BindArray( XmlNode node, Array model, string prefix, string path, Mappings mappings )
		{
			BindCollection( node, model, prefix, path, mappings );

			XmlAttribute att = node.Attributes[ "element-class" ];

			if( att != null )
			{
				model.ElementClass = ClassForNameChecked( att.Value, mappings,
				                                          "could not find element class: {0}" );
			}
			else
			{
				foreach( XmlNode subnode in node.ChildNodes )
				{
					string name = subnode.LocalName; //.Name;

					//I am only concerned with elements that are from the nhibernate namespace
					if( subnode.NamespaceURI != Configuration.MappingSchemaXMLNS )
					{
						continue;
					}

					switch( name )
					{
					case "element":
						IType type = GetTypeFromXML( subnode );

						model.ElementClass = type.ReturnedClass;

						break;

					case "one-to-many":
					case "many-to-many":
					case "composite-element":
						model.ElementClass = ClassForNameChecked(
							subnode.Attributes[ "class" ].Value, mappings,
							"element class not found: {0}" );
						break;
					}
				}
			}
		}
Exemplo n.º 28
0
		private static string GetClassTableName( PersistentClass model, XmlNode node, Mappings mappings )
		{
			XmlAttribute tableNameNode = node.Attributes[ "table" ];
			if( tableNameNode == null )
			{
				return mappings.NamingStrategy.ClassToTableName( model.Name );
			}
			else
			{
				return mappings.NamingStrategy.TableName( tableNameNode.Value );
			}
		}
Exemplo n.º 29
0
 public EntityMapper(Mappings mappings, Dialect.Dialect dialect)
 {
     this.mappings = mappings;
     this.dialect = dialect;
 }
Exemplo n.º 30
0
		public static void BindJoinedSubclass( XmlNode node, Subclass model, Mappings mappings )
		{
			BindClass( node, model, mappings );

			// joined subclass
			if( model.ClassPersisterClass == null )
			{
				model.RootClazz.ClassPersisterClass = typeof( NormalizedEntityPersister );
			}

			//table + schema names
			XmlAttribute schemaNode = node.Attributes[ "schema" ];
			string schema = schemaNode == null ? mappings.SchemaName : schemaNode.Value;
			Table mytable = mappings.AddTable( schema, GetClassTableName( model, node, mappings ) );
			model.Table = mytable;

			log.Info( "Mapping joined-subclass: " + model.Name + " -> " + model.Table.Name );

			XmlNode keyNode = node.SelectSingleNode( nsKey, nsmgr );
			SimpleValue key = new SimpleValue( mytable );
			model.Key = key;
			BindSimpleValue( keyNode, key, false, model.Name, mappings );

			model.Key.Type = model.Identifier.Type;
			model.CreatePrimaryKey( dialect );
			model.CreateForeignKey();

			// CHECK
			XmlAttribute chNode = node.Attributes[ "check" ];
			if( chNode != null )
			{
				mytable.AddCheckConstraint( chNode.Value );
			}

			// properties
			PropertiesFromXML( node, model, mappings );
		}