<?xml version="1.0" encoding="UTF-8" ?>

<sqlMap namespace="Order" >


	<resultMap id="credit-card-result" class="string">
		<result property="value" column="Order_CardNumber"/>
	</resultMap>

	<resultMap id="order-with-lines-result" class="Order" 
							extends="lite-order-result-by-name" >
		<result property="LineItemsList" lazyLoad="true" column="Order_ID" select="GetLineItemsForOrder" />
	</resultMap>
	
	<resultMap id="order-with-lines-result-statement-namespaces" class="Order" 
							extends="lite-order-result-by-name" >
		<result property="LineItemsList" lazyLoad="true" column="Order_ID" select="LineItem.GetLineItemsForOrder" />
	</resultMap>		
	
	<resultMap id="order-with-lines-collection" class="Order"
							extends="lite-order-result-by-name" >
		<result property="LineItems" column="Order_ID"  select="GetLineItemsForOrderWithListClass" />
	</resultMap>
	
	<resultMap id="order-with-lines-array" class="Order"
							extends="lite-order-result-by-name">
		<result property="LineItemsArray" column="Order_ID" select="GetLineItemsForOrder"/>
	</resultMap>

	<resultMap id="lite-order-map-result" class="array">
		<result property="Id"         type="Int" column="Order_ID"/>
		<result property="Date"       type="date" column="Order_Date"/>
		<result property="CardExpiry" type="string" column="Order_CardExpiry"/>
		<result property="CardType"   type="string" column="Order_CardType"/>
		<result property="CardNumber" type="string" column="Order_CardNumber"/>
		<result property="Street"     type="string" column="Order_Street"/>
		<result property="City"       type="string" column="Order_City"/>
		<result property="Province"   type="string" column="Order_Province"/>
		<result property="PostalCode" type="string" column="Order_PostalCode"/>
	</resultMap>

	<resultMap id="lite-order-result-by-name" class="Order">
		<result property="Id"         column="Order_ID"/>
		<result property="Date"       type="date" column="Order_Date" nullValue="0001-01-01 00:00:00"/>
		<result property="CardExpiry" column="Order_CardExpiry"/>
		<result property="CardType"   column="Order_CardType"/>
		<result property="CardNumber" column="Order_CardNumber"/>
		<result property="Street"     column="Order_Street"/>
		<result property="City"       column="Order_City"/>
		<result property="Province"   column="Order_Province"/>
		<result property="PostalCode" column="Order_PostalCode"/>
	</resultMap>
	
	<resultMap id="order-with-types-result" class="Order">
		<result property="Id"         column="Order_ID"			dbType="Int"/><!-- Int for SqlClient, Obdc; Integer for Oledb -->
		<result property="Date"       type="date" column="Order_Date"		dbType="DateTime "/>
		<result property="CardExpiry" column="Order_CardExpiry" dbType="VarChar"/>
		<result property="CardType"   column="Order_CardType"	dbType="VarChar"/>
		<result property="CardNumber" column="Order_CardNumber" dbType="VarChar"/>
		<result property="Street"     column="Order_Street"		dbType="VarChar"/>
		<result property="City"       column="Order_City"		dbType="VarChar"/>
		<result property="Province"   column="Order_Province"	dbType="VarChar"/>
		<result property="PostalCode" column="Order_PostalCode" dbType="VarChar"/>
	</resultMap>
	
	<resultMap id="lite-order-result-by-index" class="Order">
		<result property="Id"         column="Order_ID"			columnIndex="0"/>
		<result property="Date"       type="date" column="Order_Date"		columnIndex="1" />
		<result property="CardExpiry" column="Order_CardExpiry" columnIndex="2"/>
		<result property="CardType"   column="Order_CardType"	columnIndex="3" />
		<result property="CardNumber" column="Order_CardNumber" columnIndex="4" />
		<result property="Street"     column="Order_Street"		columnIndex="5" />
		<result property="City"       column="Order_City"		columnIndex="6" />
		<result property="Province"   column="Order_Province"	columnIndex="7"/>
		<result property="PostalCode" column="Order_PostalCode" columnIndex="8" />
	</resultMap>
	
	<resultMap id="order-with-account-result" class="Order">
		<result property="Id"         column="Order_ID"/>
		<result property="Date"       type="date"  column="Order_Date"/>
		<result property="CardExpiry" column="Order_CardExpiry"/>
		<result property="CardType"   column="Order_CardType"/>
		<result property="CardNumber" column="Order_CardNumber"/>
		<result property="Street"     column="Order_Street"/>
		<result property="City"       column="Order_City"/>
		<result property="Province"   column="Order_Province"/>
		<result property="PostalCode" column="Order_PostalCode"/>
		<result property="Account"    column="Account_ID" select="GetAccountViaColumnName" />
	</resultMap>

	<resultMap id="order-with-sp-account-result" class="Order">
		<result property="Id"         column="Order_ID"/>
		<result property="Date"       type="date" column="Order_Date"/>
		<result property="CardExpiry" column="Order_CardExpiry"/>
		<result property="CardType"   column="Order_CardType"/>
		<result property="CardNumber" column="Order_CardNumber"/>
		<result property="Street"     column="Order_Street"/>
		<result property="City"       column="Order_City"/>
		<result property="Province"   column="Order_Province"/>
		<result property="PostalCode" column="Order_PostalCode"/>
		<result property="Account"    column="Account_ID=Account_ID" select="GetAccountViaSP" />
	</resultMap>
			
	<resultMap id="order-with-collection-result" class="Order">
		<result property="Id"				column="Order_ID"/>
		<result property="Date"				type="date" column="Order_Date"/>
		<result property="CardExpiry"		column="Order_CardExpiry"/>
		<result property="CardType"			column="Order_CardType"/>
		<result property="CardNumber"		column="Order_CardNumber"/>
		<result property="Street"			column="Order_Street"/>
		<result property="City"				column="Order_City"/>
		<result property="Province"			column="Order_Province"/>
		<result property="PostalCode"		column="Order_PostalCode"/>
		<result property="LineItemsList"	column="Order_ID" select="GetLineItemsForOrder" />	
		<result property="LineItems"		column="Order_ID" select="GetLineItemsForOrder" lazyLoad="false" />
	</resultMap>
	
	<resultMap id="order-with-favourite-line-item" class="Order">
		<result property="Id"					column="Order_ID"/>
		<result property="Date"					type="date"  column="Order_Date"/>
		<result property="CardExpiry"			column="Order_CardExpiry"/>
		<result property="CardType"				column="Order_CardType"/>
		<result property="CardNumber"			column="Order_CardNumber"/>
		<result property="Street"				column="Order_Street"/>
		<result property="City"					column="Order_City"/>
		<result property="Province"				column="Order_Province"/>
		<result property="PostalCode"			column="Order_PostalCode"/>
		<result property="FavouriteLineItem"	column="Order_ID=Order_ID,LineItem_ID=Order_FavouriteLineItem" select="GetSpecificLineItem" />
	</resultMap>
	
	<resultMap id="order-with-dyn-favourite-line-item" class="Order">
		<result property="Id"					column="Order_ID"/>
		<result property="Date"					type="date" column="Order_Date"/>
		<result property="CardExpiry"			column="Order_CardExpiry"/>
		<result property="CardType"				column="Order_CardType"/>
		<result property="CardNumber"			column="Order_CardNumber"/>
		<result property="Street"				column="Order_Street"/>
		<result property="City"					column="Order_City"/>
		<result property="Province"				column="Order_Province"/>
		<result property="PostalCode"			column="Order_PostalCode"/>
		<result property="FavouriteLineItem"	
					column="Order_ID=Order_ID,LineItem_ID=Order_FavouriteLineItem" 
					select="GetDynSpecificLineItem" />
	</resultMap>
	<resultMap id="order-joined-favourite" class="Order">
		<result property="Id"					column="Order_ID"/>
		<result property="Date"					type="date" column="Order_Date"/>
		<result property="CardExpiry"			column="Order_CardExpiry"/>
		<result property="CardType"				column="Order_CardType"/>
		<result property="CardNumber"			column="Order_CardNumber"/>
		<result property="Street"				column="Order_Street"/>
		<result property="City"					column="Order_City"/>
		<result property="Province"				column="Order_Province"/>
		<result property="PostalCode"			column="Order_PostalCode"/>
		<result property="FavouriteLineItem"	resultMapping="LineItem" />
	</resultMap>
	
	<resultMap id="order-joined-favourite2" class="Order">
		<result property="Id"					column="Order_ID"/>
		<result property="Date"					type="date" column="Order_Date"/>
		<result property="CardExpiry"			column="Order_CardExpiry"/>
		<result property="CardType"				column="Order_CardType"/>
		<result property="CardNumber"			column="Order_CardNumber"/>
		<result property="Street"				column="Order_Street"/>
		<result property="City"					column="Order_City"/>
		<result property="Province"				column="Order_Province"/>
		<result property="PostalCode"			column="Order_PostalCode"/>
		<result property="FavouriteLineItem.Id" column="LineItem_ID"/>
		<result property="FavouriteLineItem.Code" column="LineItem_Code"/>
		<result property="FavouriteLineItem.Quantity" column="LineItem_Quantity"/>
		<result property="FavouriteLineItem.Price" column="LineItem_Price"/>			
	</resultMap>

	<resultMap id="order-joined-with-account" class="Order">
		<result property="Id"         column="Order_ID"/>
		<result property="Date"       type="date" column="Order_Date" nullValue="0001-01-01 00:00:00"/>
		<result property="CardExpiry" column="Order_CardExpiry"/>
		<result property="CardType"   column="Order_CardType"/>
		<result property="CardNumber" column="Order_CardNumber"/>
		<result property="Street"     column="Order_Street"/>
		<result property="City"       column="Order_City"/>
		<result property="Province"   column="Order_Province"/>
		<result property="PostalCode" column="Order_PostalCode"/>
		<result property="Account"	resultMapping="account-result-nullable-email" />
	</resultMap>	
	
	<resultMap id="order-hash" class="array">
		<result property="Date"       column="Order_Date" nullValue="0001-01-01 00:00:00"/>
	</resultMap>	

	<statement id="GetOrderByHashTable"
				parameterClass="Int"
				resultMap="order-hash" >
		select Order_Date from Orders where Order_ID = #value#
	</statement>
		
	<statement id="GetOrderLiteByColumnName"
				parameterClass="Int"
				resultMap="lite-order-result-by-name" >
		select * from Orders where Order_ID = #value#
	</statement>
	
	<statement id="GetOrderLiteByColumnIndex"
				parameterClass="Int"
				resultMap="lite-order-result-by-index" >
		select
		Order_ID,
		Order_Date,
		Order_CardExpiry,
		Order_CardType,
		Order_CardNumber,
		Order_Street,
		Order_City,
		Order_Province,
		Order_PostalCode
		from Orders where Order_ID = #value#
	</statement>
	
	<statement id="GetOrderWithTypes"
				parameterClass="Int"
				resultMap="order-with-types-result" >
		select * from Orders where Order_ID = #value#
	</statement>
	
	<statement id="GetOrderWithLineItems"
				parameterClass="Integer"
				resultMap="order-with-lines-result" >
		select * from Orders where Order_ID = #value#
	</statement>
	
	<statement id="GetOrderWithLineItemsUsingStatementNamespaces"
				parameterClass="Integer"
				resultMap="order-with-lines-result-statement-namespaces" >
		select * from Orders where Order_ID = #value#
	</statement>		

	<statement id="GetAllOrderWithLineItems"
				parameterClass="Integer"
				resultMap="order-with-lines-result" >
		select * from Orders
	</statement>
	
	<statement id="GetOrderCardExpiryViaResultClass"
				parameterClass="int"
				resultClass="date">
		select
		Order_Date as datetime
		from Orders where Order_ID = #value#
	</statement>
	
	<statement id="GetOrderWithAccount"
				parameterClass="int"
				resultMap="order-with-account-result" >
		select * from Orders where Order_ID = #value#
	</statement>
	
	<statement id="GetOrderWithAccountViaSP"
				parameterClass="int"
				resultMap="order-with-sp-account-result" >
		select * from Orders where Order_ID = #value#
	</statement>
	
	<statement id="GetOrderWithLineItemsCollection"
				parameterClass="Integer"
				resultMap="order-with-collection-result" >
		select * from Orders where Order_ID = #value#
	</statement>
	
	 <statement id="GetOrderJoinedFavourite"
				parameterClass="Integer"
				resultMap="order-joined-favourite" >
		select * from Orders, LineItems
		where Orders.Order_ID = LineItems.Order_ID
		and Order_FavouriteLineItem = LineItems.LineItem_ID
		and Orders.Order_ID = #value#
	</statement>
	
	<statement id="GetOrderJoinedFavourite2"
				parameterClass="Integer"
				resultMap="order-joined-favourite2" >
		select * from Orders, LineItems
		where Orders.Order_ID = LineItems.Order_ID
		and Order_FavouriteLineItem = LineItems.LineItem_ID
		and Orders.Order_ID = #value#
	</statement>

	<statement id="GetOrderJoinedFavourite3"
				parameterClass="Integer"
				resultClass="Order" >
		select 
			Orders.Order_ID as Id,
			Order_Date as Date,
			Order_CardExpiry as CardExpiry,
			Order_CardType as CardType,
			Order_CardNumber as CardNumber,
			Order_Street as Street,
			Order_City as City,
			Order_Province as Province,
			Order_PostalCode as PostalCode,
			LineItem_ID as "FavouriteLineItem.Id",
			LineItem_Code as "FavouriteLineItem.Code",
			LineItem_Quantity as "FavouriteLineItem.Quantity",
			LineItem_Price as "FavouriteLineItem.Price"
		from Orders, LineItems
		where Orders.Order_ID = LineItems.Order_ID
		and Order_FavouriteLineItem = LineItems.LineItem_ID
		and Orders.Order_ID = #value#
	</statement>
	
	<statement id="GetOrderWithFavouriteLineItem"
				parameterClass="int"
				resultMap="order-with-favourite-line-item" >
		select * from Orders where Order_ID = #value#
	</statement>
	
	<statement id="GetOrderWithLineItemCollection"
				parameterClass="int"
				resultMap="order-with-lines-collection" >
		select * from Orders where Order_ID = #value#
	</statement>
	
	<statement id="GetOrderAsHastable"
				parameterClass="Integer"
				resultMap="lite-order-map-result" >
		select * from Orders where Order_ID = #value#
	</statement>
	
	<statement id="GetOrderWithLineItemArray"
			parameterClass="int"
			resultMap="order-with-lines-array">
			select * from Orders where Order_ID = #value#
	</statement>
	
	<statement id="GetAllCreditCardNumbersFromOrders"
			resultMap="credit-card-result" >
		select distinct Order_CardNumber from Orders
		order by Order_CardNumber
	</statement>
	
	<statement id="InsertOrderViaParameterMap"
				parameterMap="order-insert-params" >
		insert into Orders  
			(Order_ID, Account_ID, Order_Date, Order_CardExpiry, Order_CardType, 
				Order_CardNumber, Order_Street, Order_City, Order_Province, Order_PostalCode ) 
		values 
			(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
	</statement>		
	
	<statement id="InsertOrderViaExtendParameterMap"
				parameterMap="insert-extend" >
		insert into Orders  
			(Order_ID, Account_ID, Order_Date, Order_CardExpiry, Order_CardType, 
				Order_CardNumber, Order_Street, Order_City, Order_Province, Order_PostalCode ) 
		values 
			(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
	</statement>
	
	<statement id="InsertOrderViaPublicFields">
		insert into Orders  
			(Order_ID, Account_ID, Order_Date, Order_CardExpiry, Order_CardType, 
				Order_CardNumber, Order_Street, Order_City, Order_Province, Order_PostalCode ) 
		values 
			(#Id#, #Account.Id#, #Date#, #CardExpiry#, #CardType#, #CardNumber#, #Street#, #City#, #Province#, #PostalCode#)
	</statement>		
			
	<select id="GetOrderWithDynFavouriteLineItem"
			parameterClass="Integer"
			resultMap="order-with-dyn-favourite-line-item">
		select * from Orders where Order_ID = #value#
	</select>			
	
	<select id="SelectOrderByDate"
			parameterClass="array"
			resultMap="lite-order-result-by-name">
		select * from Orders where Order_Date = #Foo#
	</select>	
	
	<select id="SelectOrderByDateDynamic"
			parameterClass="array"
			resultMap="lite-order-result-by-name">
		select * from Orders
		where 1=1
		<isNotEmpty prepend="AND" property="Foo"> 
			(Order_Date = '$Foo$') 
		</isNotEmpty> 
	</select>
			
	<select id="GetAccountJIRA45"
			parameterClass="int"
			resultMap="indexed-account-result">
		select
		Account_ID,
		Account_FirstName,
		Account_LastName,
		Account_Email
		from Accounts
		where Account_ID = #value#
	</select>

	<select id="GetOrderJoinWithAccount"
			parameterClass="Integer"
			resultMap="order-joined-with-account">
		select 
			Order_ID, 
			Order_Date, 
			Order_CardExpiry, 
			Order_CardType,
			Order_CardNumber, 
			Order_Street, 
			Order_City, 
			Order_Province, 
			Order_PostalCode,
			acc.Account_ID,
			acc.Account_FirstName,
			acc.Account_LastName,
			acc.Account_Email 
		from Orders as ord
		LEFT OUTER JOIN Accounts as acc on acc.Account_ID = ord.Account_ID
		where Order_ID = #value#
	</select>	
			
	
	<parameterMap id="order-insert-params">
		<parameter property="Id" dbType="Int"/>	<!-- Int for SqlClient, Obdc; Integer for Oledb -->
		<parameter property="Account.Id" type="integer"/>
		<parameter property="Date" type="date" nullValue="0001-01-01 00:00:00" />
		<parameter property="CardExpiry" />
		<parameter property="CardType" />			
		<parameter property="CardNumber" />
		<parameter property="Street" />
		<parameter property="City" />			
		<parameter property="Province" />
		<parameter property="PostalCode" />
	</parameterMap>

	<parameterMap id="params-parent"> <!-- 1043181 support request -->
		<parameter property="Id" dbType="Int"/>	
		<parameter property="Account.Id"/>
		<parameter property="Date" type="date" nullValue="0001-01-01 00:00:00" />
		<parameter property="CardExpiry" />
		<parameter property="CardType" />			
		<parameter property="CardNumber" />
		<parameter property="Street" />
		<parameter property="City" />			
		<parameter property="Province" />
		<parameter property="PostalCode" />		
	</parameterMap>
	
	<parameterMap id="insert-extend" extends="params-parent">
	</parameterMap>
			
	<statement id="GetOrderWithLineItemsNoLazyLoad"
				parameterClass="Integer"
				resultMap="order-with-lines-result-no-lazy-load" >
		select * from Orders where Order_ID = #value#
	</statement>

	<resultMap id="order-with-lines-result-no-lazy-load" class="Order" 
							extends="lite-order-result-by-name" >
		<result property="LineItemsList" type="TList" column="Order_ID" select="GetLineItemsForOrder" />
	</resultMap>

		<statement id="GetOrderWithLineItemCollectionNoLazy"
				parameterClass="int"
				resultMap="order-with-lines-collection-no-lazy-load" >
		select * from Orders where Order_ID = #value#
	</statement>

	<resultMap id="order-with-lines-collection-no-lazy-load" class="Order"
							extends="lite-order-result-by-name" >
		<result property="LineItems" column="Order_ID" 
			select="GetLineItemsForOrderWithListClass" />
	</resultMap>

</sqlMap>