summaryrefslogtreecommitdiff
path: root/tests/unit/SQLMap/maps/MySql/Category.xml
blob: ec81449b002a902a272715e7a1f97e83ca40077a (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
<?xml version="1.0" encoding="utf-8"?>
<sqlMap namespace="Category" >
	
	<alias>
		<typeAlias alias="Category" type="IBatisNet.DataMapper.Test.Domain.Category, IBatisNet.DataMapper.Test"/>
	</alias>
	
	
		<select id="GetCategory" parameterClass="Integer" resultClass="Category">
			select
			Category_ID as Id,
			Category_Name as Name,
			Category_Guid as GuidString
			from Categories  
			where Category_ID = #value# 
		</select>
		
		<select id="GetCategoryGuid" parameterClass="Integer" resultClass="guid">
			select
			Category_Guid as value
			from Categories  
			where Category_ID = #value# 
		</select>
		
		<!-- Test for statement as insert -->
		<!-- Needs to be <insert> vs <statement> for MySql due to selectKey -->
		<insert id="InsertCategory" parameterClass="Category">
			<selectKey property="Id" type="post" resultClass="int">
				select LAST_INSERT_ID() as value
            </selectKey>			
  			insert into Categories  
				(Category_Name, Category_Guid) 
			values 
				(#Name#, #GuidString:Varchar#);
		</insert>
		
		<!--  -->
		<insert id="InsertCategoryViaInsertStatement" parameterClass="Category" >
			<selectKey property="Id" type="post" resultClass="int">
				select LAST_INSERT_ID() as value
            </selectKey>			
            insert into Categories  
				(Category_Name, Category_Guid) 
			values 
				(#Name#, #GuidString:Varchar#)
		</insert>

		<!-- Needs to be <insert> vs <statement> for MySql due to selectKey -->		
		<insert id="InsertCategoryViaParameterMap" parameterMap="InsertParam">
			<selectKey property="Id" type="post" resultClass="int">
				select LAST_INSERT_ID() as value
            </selectKey>
			insert into Categories  
				(Category_Name, Category_Guid)
			values 
				(?,?);
		</insert>

		<!-- Needs to be <insert> vs <statement> for MySql due to selectKey -->		
		<insert id="InsertCategoryNull" parameterMap="insert-null-params">
			<selectKey property="Id" type="post" resultClass="int">
				select LAST_INSERT_ID() as value
            </selectKey>
			insert into Categories  
				(Category_Name, Category_Guid)
			values 
				(?,?);
		</insert>
		
		<update id="UpdateCategoryViaParameterMap" parameterMap="UpdateParam">
			update Categories set
			Category_Name =?,
			Category_Guid = ?
			where
			Category_Id = ?
		</update>

		<procedure id="InsertCategoryViaStoreProcedure" parameterMap="category-insert-params">
			ps_InsertCategorie
		</procedure>
		
		<insert id="InsertCategoryGenerate" parameterMap="insert-generate-params">
			<selectKey property="Id" type="post" resultClass="int">
				select LAST_INSERT_ID() as value
            </selectKey>
            <generate table="Categories" />
		</insert>
		
		<update id="UpdateCategoryGenerate" parameterMap="update-generate-params">
			<generate table="Categories" by="Category_Id"/>
		</update>
		
		<delete id="DeleteCategoryGenerate" parameterMap="delete-generate-params">
			<generate table="Categories" by="Category_Id, Category_Name"/>
		</delete>
		
		<select id="SelectByPKCategoryGenerate" resultClass="Category" parameterClass="Category" parameterMap="select-generate-params">
			<generate table="Categories" by="Category_Id"/> 
		</select>
		
		<select id="SelectAllCategoryGenerate" resultClass="Category" parameterMap="select-generate-params">
			<generate table="Categories" /> 
		</select>
		
		<statement id="DynamicGuid" 
			resultClass="Category" 
			parameterClass="Category">
			select
			Category_ID as Id,
			Category_Name as Name,
			Category_Guid as Guid
			from Categories  
			<dynamic prepend="where">
				<isNotEqual prepend="and" property="Guid" compareProperty="EmptyGuid">
					Category_Guid=#GuidString:Varchar#
				</isNotEqual>
			</dynamic>
		</statement>
		<parameterMap id="category-insert-params">
			<parameter property="Id" column="Category_Id" dbType="Int32" />
			<parameter property="Name" column="Category_Name"/>
			<parameter property="GuidString" column="Category_Guid" dbType="Varchar"/>
		</parameterMap>
		
		<parameterMap id="InsertParam">
			<parameter property="Name" column="Category_Name"/>
			<parameter property="GuidString" column="Category_Guid" dbType="Varchar"/>
		</parameterMap>
		
		<parameterMap id="insert-null-params">
			<parameter property="Name" column="Category_Name"/>
			<parameter property="GuidString" column="Category_Guid" nullValue="00000000-0000-0000-0000-000000000000" dbType="Varchar"/>
		</parameterMap>
		
		<parameterMap id="UpdateParam" extends="InsertParam">
			<parameter property="Id" column="Category_Id" />
		</parameterMap>
		
		<!-- Used by generated statement -->
		
		<parameterMap id="insert-generate-params">
			<parameter property="Name" column="Category_Name"/>
			<parameter property="GuidString" column="Category_Guid" dbType="Varchar"/>
		</parameterMap>
		
		<parameterMap id="update-generate-params" extends="insert-generate-params">
			<parameter property="Id" column="Category_Id" />
		</parameterMap>
		
		<parameterMap id="delete-generate-params">
			<parameter property="Id" column="Category_Id" />
			<parameter property="Name" column="Category_Name"/>
		</parameterMap>
		
		<parameterMap id="select-generate-params">
			<parameter property="Id" column="Category_Id" />
			<parameter property="Name" column="Category_Name"/>
			<parameter property="GuidString" column="Category_Guid" dbType="Varchar"/>
		</parameterMap>
		
	
</sqlMap>