summaryrefslogtreecommitdiff
path: root/tests/unit/Data/SqlMap/maps/sqlite/Account.xml
blob: aa175459e48b72121bebe99fca70b8ad2eb87a5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
<?xml version="1.0" encoding="UTF-8" ?>
<sqlMap namespace="Account" >

	<!-- =============================================
                <resultMap
					name="name"
					class="name"
					extend="resultMapId"
				>
				<result
					property="name"
					column="name"
					columnIndex="name"
					nullValue="value"
					select="name"
					resultMap="name"
					lazyLoad="true/false"
					dbType=""
				/>
				<procedure
					name="name"
					parameterMap="name"
				>
				<statement
						name="name"
						parameterClass="name"
						parameterMap="name"
						resultClass="name"
						resultMap="name"
						listClass="name"
				>
				<parameterMap
						name="name"
						class=""
				>
				<parameter
						property="name"
						dbType=""
						output="true/false"
						type=""
						nullValue=""
						extend="parameterMapId"
				/>

       ============================================= -->

		<cacheModel id="account-cache" implementation="LRU" >
			<flushInterval hours="24"/>
			<flushOnExecute  statement="UpdateAccountViaInlineParameters"/>
			<flushOnExecute  statement="UpdateAccountViaParameterMap"/>
			<property name="size" value="10"/>
		</cacheModel>

		<!--
		<cacheModel name="account-cache" implementation="LRU" >
			<flushInterval hours="24"/>
			<flushOnExecute statement="UpdateAccountViaInlineParameters"/>
			<flushOnExecute statement="UpdateAccountViaParameterMap"/>
			<property name="CacheSize" value="50"/>
		</cacheModel>
		-->


	<alias>
		<typeAlias alias="HundredsBool" type="IBatisNet.DataMapper.Test.Domain.HundredsTypeHandlerCallback, IBatisNet.DataMapper.Test"/>
	</alias>

		<resultMap id="account-result"  class="Account" >
			<result property="Id"           column="Account_Id"/>
			<result property="FirstName"    column="Account_FirstName"/>
			<result property="LastName"     column="Account_LastName"/>
			<result property="EmailAddress" column="Account_Email" nullValue="no_email@provided.com"/>
			<result property="BannerOptions" column="Account_Banner_Option" typeHandler="OuiNonBool"/>
			<result property="CartOptions"	column="Account_Cart_Option" typeHandler="HundredsBool"/>
		</resultMap>
		<resultMap id="indexed-account-result" class="Account">
			<result property="Id"           column="Account_Id"			columnIndex="0"/>
			<result property="FirstName"    column="Account_FirstName"	columnIndex="1"/>
			<result property="LastName"     column="Account_LastName"	columnIndex="2"/>
			<result property="EmailAddress" column="Account_Email"		columnIndex="3"	nullValue="no_email@provided.com"/>
		</resultMap>
		<resultMap id="account-result-nullable-email" class="Account">
			<result property="Id"           column="Account_Id"/>
			<result property="FirstName"    column="Account_FirstName"/>
			<result property="LastName"     column="Account_LastName"/>
			<result property="EmailAddress" column="Account_Email"/>
		</resultMap>

		<resultMap id="email-result" class="string">
			<result property="value" column="Account_Email"/>
		</resultMap>

		<resultMap id="account-hashtable-result" class="array">
			<result property="Id"           column="Account_Id"/>
			<result property="FirstName"    column="Account_FirstName"/>
			<result property="LastName"     column="Account_LastName"/>
			<result property="EmailAddress" column="Account_Email"/>
		</resultMap>


	<!-- =============================================
        MAPPED STATEMENTS - w/Inline Parameters
    =============================================
    -->

		<select id="GetAllAccountsAsArrayListViaResultClass"
						resultClass="TList">
			select
			Account_Id as Id,
			Account_FirstName as FirstName,
			Account_LastName as LastName,
			Account_Email as EmailAddress
			from Accounts
			order by Account_Id
		</select>

		<select id="GetAccountsDynamic" resultMap="account-result" parameterClass="Hashtable" >
			select * from Accounts
			<dynamic prepend="where">
					<isParameterPresent>
					<isNotEmpty prepend="and" property="FirstName" >
							Account_FirstName LIKE '%$FirstName$%'
					</isNotEmpty>
					<isNotEmpty prepend="and" property="LastName" >
							Account_LastName LIKE '%$LastName$%'
					</isNotEmpty>
					<isNotEmpty prepend="and" property="EmailAddress"  >
							Account_Email LIKE '%$EmailAddress$%'
					</isNotEmpty>
					</isParameterPresent>
				</dynamic>
				order by Account_LastName
				limit 0, $MaximumAllowed$
		</select>

  		<select id="SelectWithProperty"
					resultMap="account-result">
			select *
			from Accounts
			where Account_FirstName = ${accountName}
		</select>

		<select id="GetCachedAccountsViaResultMap"
					resultMap="account-result"
					cacheModel="account-cache" >
			select *
			from Accounts
			order by Account_Id
		</select>

    	<select id="GetNoAccountWithCache"
						parameterClass="Integer"
						resultMap="account-hashtable-result"
						cacheModel="account-cache">
			select *
			from Accounts
			where Account_Id = #value#
		</select>

		<select id="GetAccountAsHashtable"
						parameterClass="Integer"
						resultMap="account-hashtable-result">
			select *
			from Accounts
			where Account_Id = #value#
		</select>

		<select id="GetAllAccountsAsHashMapViaResultMap"
						resultMap="account-hashtable-result">
			select *
			from Accounts
			order by Account_Id
		</select>

		<select id="GetAccountAsHashtableResultClass"
						parameterClass="int"
						resultClass="array">
			select
			Account_Id as Id,
			Account_FirstName as FirstName,
			Account_LastName as LastName,
			Account_Email as EmailAddress
			from Accounts
			where Account_Id = #value#
		</select>

		<select id="GetAllAccountsAsHashtableViaResultClass"
						resultClass="array">
			select
			Account_Id as Id,
			Account_FirstName as FirstName,
			Account_LastName as LastName,
			Account_Email as EmailAddress
			from Accounts
			order by Account_Id
		</select>

		<select id="GetAccountViaColumnName"
				parameterClass="int"
				resultMap="account-result">
			select
			Account_Id,
			Account_FirstName,
			Account_LastName,
			Account_Email,
			Account_Banner_Option,
			Account_Cart_Option
			from Accounts
			where Account_Id = #value#
		</select>

		<select id="GetAccountViaColumnIndex"
				parameterClass="int"
				resultMap="indexed-account-result">
			select
			Account_Id,
			Account_FirstName,
			Account_LastName,
			Account_Email
			from Accounts
			where Account_Id = #value#
		</select>

		<select id="GetAllAccountsViaResultMap"
					resultMap="account-result">
			select * from Accounts
			order by Account_Id
		</select>

		<select id="GetAllAccountsViaResultClass"
			resultClass="Account">
			select
			Account_Id as Id,
			Account_FirstName as FirstName,
			Account_LastName as LastName,
			Account_Email as EmailAddress
			from Accounts
			order by Account_Id
		</select>

		<select id="GetFewAccountsViaResultMap"
			resultMap="account-result">
			<![CDATA[
			select * from Accounts
			where Account_Id < 2
			order by Account_Id
			]]>
		</select>

		<select id="GetNoAccountsViaResultMap"
					resultMap="account-result">
			select * from Accounts
			where Account_Id > 1000
			order by Account_Id
		</select>


		<select id="GetAccountNullableEmail"
			resultMap="account-result-nullable-email">
			select
			Account_Id,
			Account_FirstName,
			Account_LastName,
			Account_Email
			from Accounts
			where Account_Id = #value#
		</select>

		<select id="GetAccountViaResultClass"
			resultClass="Account">
			<![CDATA[
					select
					Account_Id as Id,
					Account_FirstName as FirstName,
					Account_LastName as LastName,
					Account_Email as EmailAddress
					from Accounts
					where Account_Id = #value#
			]]>
		</select>

		<select id="GetAccountViaInlineParameters"
				resultMap="indexed-account-result">
			select
			Account_Id,
			Account_FirstName,
			Account_LastName,
			Account_Email
			from Accounts
			where Account_Id = #Id# and Account_Id = #Id#
		</select>

		 <select id="GetEmailAddressViaResultClass" resultClass="string">
			select Account_Email as value
			from Accounts
			where Account_Id = #value#
		</select>

		<select id="GetEmailAddressViaResultMap"
						parameterClass="int"
						resultMap="email-result">
			select Account_Email
			from Accounts
			where Account_Id = #value#
		</select>

		<select id="GetAllEmailAddressesViaResultClass"
							resultClass="string">
			select Account_Email
			from Accounts
			order by Account_Id
		</select>

		 <select id="GetAllEmailAddressesViaResultMap"
                    resultMap="email-result">
			select Account_Email
			from Accounts
			order by Account_Id
		</select>

		 <insert id="InsertAccountViaParameterMap"
                    parameterMap="account-insert-params">
			insert into Accounts
				(Account_Id, Account_FirstName, Account_LastName, Account_Email, Account_Banner_Option, Account_Cart_Option)
			values
				(?, ?, ?, ?, ?, ?)
		</insert>

		 <update id="UpdateAccountViaParameterMap"
                    parameterMap="update-params">
			update Accounts set
			Account_FirstName = ?,
			Account_LastName = ?,
			Account_Email = ?
			where
			Account_Id = ?
		</update>

		<update id="UpdateAccountViaParameterMap2"
                    parameterMap="update-params2">
			update Accounts set
			Account_Id = ?,
			Account_FirstName = ?,
			Account_LastName = ?,
			Account_Email = ?
			where
			Account_Id = ?
		</update>

		<delete id="DeleteAccountViaInlineParameters">
			delete from Accounts
			where
			Account_Id = #Id#
		</delete>

		<select id="GetAccountComplexMapping"
					resultMap="indexed-account-result"
                    parameterClass="array">
			select *
			from Accounts
			where
			Account_FirstName = #Account.FirstName#
			And Account_LastName = #Order.City#
		</select>

		<select id="GetDynamicOrderedEmailAddressesViaResultMap"
                    resultMap="email-result">
			select Account_Email
			from Accounts
			order by $value$
		</select>

		<!-- Dynamic statements -->
		<select id="GetAllAccountsViaResultMapWithDynamicElement"
				resultMap="account-result">
			select * from Accounts
			where Account_Email $value$ '%@%'
			order by Account_Id
		</select>

		<select id="SimpleDynamicSubstitution"
             parameterClass="Hashtable"
             resultClass="Account">
			$statement$
		</select>

		<!-- Public Fields -->
		<insert id="InsertAccountViaPublicFields">
			insert into Accounts
				(Account_Id, Account_FirstName, Account_LastName, Account_Email)
			values
				(#Id#, #FirstName#, #LastName#, #EmailAddress#
			)
		</insert>


		<!-- Inline Parameters -->
		<update id="UpdateAccountViaInlineParameters"
			parameterClass="Account">
			update Accounts set
			Account_FirstName = #FirstName#,
			Account_LastName = #LastName#,
			Account_Email = #EmailAddress, dbType=VarChar, nullValue=no_email@provided.com#
			where
			Account_Id = #Id#
		</update>

		<insert id="InsertAccountViaInlineParameters"
			parameterClass="Account" >
			insert into Accounts
				(Account_Id, Account_FirstName, Account_LastName, Account_Email)
			values
				(#Id#, #FirstName#, #LastName#, #EmailAddress, dbType=VarChar, nullValue=no_email@provided.com#
			)
		</insert>

		<insert id="InsertAccountNullableEmail"
			parameterClass="Account" >
			insert into Accounts
				(Account_Id, Account_FirstName, Account_LastName, Account_Email)
			values
				( #Id#, #FirstName#, #LastName#, #EmailAddress, dbType=VarChar# )
		</insert>

		<insert id="InsertAccountUknownParameterClass">
			insert into Accounts
				(Account_Id, Account_FirstName, Account_LastName, Account_Email)
			values
				( #Id#, #FirstName#, #LastName#, #EmailAddress, dbType=VarChar# )
		</insert>

		<delete id="DeleteAccount"
			parameterClass="Account">
			delete from Accounts
			where Account_Id = #Id#
			and Account_Id = #Id#
		</delete>

		<!-- Extends statement -->
		<select id="GetAllAccounts"
					resultMap="indexed-account-result">
			select
			Account_Id,
			Account_FirstName,
			Account_LastName,
			Account_Email
			from Accounts
		</select>

		<select id="GetAllAccountsOrderByName"
			extends="GetAllAccounts"
			resultMap="indexed-account-result">
			order by Account_FirstName
		</select>

		<select id="GetOneAccount"
			extends="GetAllAccounts"
			resultMap="indexed-account-result">
			where Account_Id = #value#
		</select>

		<select id="GetSomeAccount"
			extends="GetAllAccounts"
			parameterClass="Hashtable"
			resultMap="indexed-account-result">
			where Account_Id between #lowID# and #hightID#
		</select>

		<select id="SelectAccountJIRA29" parameterClass="map" resultClass="Account">
			select
				Account_Id as Id,
				Account_FirstName as FirstName,
				Account_LastName as LastName,
				Account_Email as EmailAddress
			from Accounts
			where Account_FirstName = '##$AccountName$##'
		</select>

		<select id="SelectAccountJIRA29-2"
				parameterClass="Hashtable"
				resultClass="Account">
			select
				Account_Id as Id,
				Account_FirstName as FirstName,
				Account_LastName as LastName,
				Account_Email as EmailAddress
			from Accounts
			where 1=1
			<isNotEmpty prepend="AND" property="Foo">
				(Account_FirstName = '##$Foo$##')
			</isNotEmpty>
		</select>

		<select id="GetAccountWithRepeatingProperty"
						parameterClass="Account"
						resultMap="indexed-account-result">
			select
					Account_Id,
					Account_FirstName,
					Account_LastName,
					Account_Email
			from Accounts
			where Account_Id = #Id# and
					Account_Id = #Id# and
					Account_FirstName = #FirstName# and
					Account_LastName = #LastName# and
					Account_Id = #Id#
		</select>

		<select id="GetAllAccountsViaCustomTypeHandler"
			resultMap="account-result">
			select * from Accounts
			order by Account_Id
		</select>

		<!-- JIRA-110 -->
		<select id="GetManyAccound" resultClass="Account">
			SELECT
				Account_Id as Id,
				Account_FirstName as FirstName,
				Account_LastName as LastName,
				Account_Email as EmailAddress
			FROM Accounts
		</select>

		<select id="Get1Account" extends="GetManyAccound" resultClass="Account">WHERE Account_Id=1</select>

		<statement id="GetAccounts" resultMap="account-result">
			SELECT *
			FROM
			Accounts
		</statement>
		<!-- JIRA-110 -->

		<insert id="InsertAccountDynamic" parameterClass="Account">
			INSERT INTO Accounts
			(Account_Id, Account_FirstName, Account_LastName, Account_Email)
			VALUES(#Id#, #FirstName#, #LastName#
			<dynamic prepend=",">
				<isNotNull prepend="," property="EmailAddress">
					#EmailAddress#
				</isNotNull>
				<isNull prepend="," property="EmailAddress">
						null
				</isNull>
			</dynamic>
			)
        </insert>


		<!-- accounts and orders -->

		<select id="getAccountWithOrders" resultMap="Account-with-Orders">
			SELECT
				Accounts.Account_Id as Account_Id,
				Accounts.Account_FirstName as Account_FirstName,
				Accounts.Account_LastName as Account_LastName,
				Accounts.Account_Email as Account_Email,
				Accounts.Account_Banner_Option as Account_Banner_Option,
				Accounts.Account_Cart_Option as Account_Cart_Option,
				Orders.Order_Id as Order_Id,
				Orders.Order_Date as Order_Date,
				Orders.Order_CardType as Order_CardType,
				Orders.Order_CardNumber as Order_CardNumber,
				Orders.Order_CardExpiry as Order_CardExpiry,
				Orders.Order_Street as Order_Street,
				Orders.Order_City as Order_City,
				Orders.Order_Province as Order_Province,
				Orders.Order_PostalCode as Order_PostalCode,
				Orders.Order_FavouriteLineItem as Order_FavouriteLineItem
				FROM accounts
				LEFT JOIN orders ON
					accounts.account_id = orders.account_id
		</select>

		<resultMap id="Account-with-Orders" class="AccountWithOrders" groupBy="Account_Id">
			<result property="Id"           column="Account_Id"/>
			<result property="FirstName"    column="Account_FirstName"/>
			<result property="LastName"     column="Account_LastName"/>
			<result property="EmailAddress" column="Account_Email" />
			<result property="Orders" resultMapping="account-orders" />
		</resultMap>

		<resultMap id="account-orders" 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>


		<!-- For procedure, the parameters of the parameterMap must in the same order
		as for the procedure paramaters-->
		<procedure id="InsertAccountViaStoreProcedure" parameterMap="account-insert-params">
			ps_InsertAccount
		</procedure>

		<procedure id="SwapEmailAddresses" parameterMap="swap-params">
			ps_swap_email_address
		</procedure>

	<!-- =============================================
            OPTIONAL EXPLICIT PARAMETER MAP
    ============================================= -->

		<parameterMap id="swap-params">
			<parameter property="email1" column="First_Email" />
			<parameter property="email2" column="Second_Email" />
		</parameterMap>

		<parameterMap id="account-insert-params">
			<parameter property="Id" />
			<parameter property="FirstName" />
			<parameter property="LastName" />
			<parameter property="EmailAddress" nullValue="no_email@provided.com"/>
			<parameter property="BannerOptions"  dbType="Varchar" type="bool"/>
			<parameter property="CartOptions"	column="Account_Cart_Option" typeHandler="HundredsBool"/>
		</parameterMap>

		<parameterMap id="update-params">
			<parameter property="FirstName" />
			<parameter property="LastName" />
			<parameter property="EmailAddress" nullValue="no_email@provided.com"/>
			<parameter property="Id" />
		</parameterMap>

		<parameterMap id="update-params2">
			<parameter property="Id" />
			<parameter property="FirstName" />
			<parameter property="LastName" />
			<parameter property="EmailAddress" nullValue="no_email@provided.com"/>
			<parameter property="Id" />
		</parameterMap>


</sqlMap>