summaryrefslogtreecommitdiffstats
path: root/tests/com/iciql/test/models/EnumModels.java
blob: e5f6f39ee5a9741ddf9dc4ef6030f5c5ac69a8c8 (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
/*
 * Copyright 2011 James Moger.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.iciql.test.models;

import java.util.Arrays;
import java.util.List;

import com.iciql.Iciql.EnumId;
import com.iciql.Iciql.EnumType;
import com.iciql.Iciql.IQColumn;
import com.iciql.Iciql.IQEnum;
import com.iciql.Iciql.IQTable;

public abstract class EnumModels {

	/**
	 * Test of @IQEnum annotated enumeration. This strategy is the default
	 * strategy for all fields of the Tree enum.
	 * 
	 * Individual Tree field declarations can override this strategy by
	 * specifying a different @IQEnum annotation.
	 * 
	 * Here ORDINAL specifies that this enum will be mapped to an INT column.
	 */
	@IQEnum(EnumType.ENUMID)
	public enum Tree implements EnumId {
		PINE(10), OAK(20), BIRCH(30), WALNUT(40), MAPLE(50);

		private int enumid;

		Tree(int id) {
			this.enumid = id;
		}

		@Override
		public int enumId() {
			return enumid;
		}
	}

	@IQColumn(primaryKey = true)
	public Integer id;
	
	public abstract Tree tree();

	/**
	 * Test model for enum-as-enumid.
	 */
	@IQTable(inheritColumns = true)
	public static class EnumIdModel extends EnumModels {

		// no need to specify ENUMID type as the enumeration definition
		// specifies it.
		@IQColumn
		private Tree tree;

		public EnumIdModel() {
		}

		public EnumIdModel(int id, Tree tree) {
			this.id = id;
			this.tree = tree;
		}

		@Override
		public Tree tree() {
			return tree;
		}

		public static List<EnumIdModel> createList() {
			return Arrays.asList(new EnumIdModel(400, Tree.WALNUT), new EnumIdModel(200, Tree.OAK),
					new EnumIdModel(500, Tree.MAPLE), new EnumIdModel(300, Tree.BIRCH), new EnumIdModel(100,
							Tree.PINE));
		}
	}

	/**
	 * Test model for enum-as-ordinal.
	 */
	@IQTable(inheritColumns = true)
	public static class EnumOrdinalModel extends EnumModels {

		// override the enumtype to ordinal
		@IQEnum(EnumType.ORDINAL)
		@IQColumn
		private Tree tree;

		public EnumOrdinalModel() {
		}

		public EnumOrdinalModel(int id, Tree tree) {
			this.id = id;
			this.tree = tree;
		}
		
		@Override
		public Tree tree() {
			return tree;
		}

		public static List<EnumOrdinalModel> createList() {
			return Arrays.asList(new EnumOrdinalModel(400, Tree.WALNUT), new EnumOrdinalModel(200, Tree.OAK),
					new EnumOrdinalModel(500, Tree.MAPLE), new EnumOrdinalModel(300, Tree.BIRCH),
					new EnumOrdinalModel(100, Tree.PINE));
		}
	}

	/**
	 * Test model for enum-as-string.
	 */
	@IQTable(inheritColumns = true)
	public static class EnumStringModel extends EnumModels {

		// override the enumtype to string
		// ensure that we specify a length so that the column is VARCHAR
		@IQEnum(EnumType.NAME)
		@IQColumn(length = 25)
		private Tree tree;

		public EnumStringModel() {
		}

		public EnumStringModel(int id, Tree tree) {
			this.id = id;
			this.tree = tree;
		}

		@Override
		public Tree tree() {
			return tree;
		}
		
		public static List<EnumStringModel> createList() {
			return Arrays.asList(new EnumStringModel(400, Tree.WALNUT), new EnumStringModel(200, Tree.OAK),
					new EnumStringModel(500, Tree.MAPLE), new EnumStringModel(300, Tree.BIRCH),
					new EnumStringModel(100, Tree.PINE));
		}
	}
}