-
Notifications
You must be signed in to change notification settings - Fork 48
/
Column.java
190 lines (164 loc) · 6.49 KB
/
Column.java
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
/*
* Copyright (c) 2015 FUJI Goro (gfx).
*
* 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.github.gfx.android.orma.annotation;
import androidx.annotation.LongDef;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.CLASS)
public @interface Column {
/**
* @return The column name in SQLite tables. It is case-insensitive.
*/
String value() default "";
/**
* @return Create an index for the column.
*/
boolean indexed() default false;
/**
* Specifies {@code UNIQUE} constraint. Shortcut of {@code uniqueOnConflict = OnConflict.ABORT}.
*
* @return True if the column value is unique in the table.
*/
boolean unique() default false;
/**
* Specifies {@code UNIQUE} constraint with an {@code ON CONFLICT} clause.
*
* @return One of {@code OnConflict.ABORT}, {@code FAIL}, {@code IGNORE},
* {@code REPLACE}, or {@code ROLLBACK}
*/
@OnConflict int uniqueOnConflict() default OnConflict.NONE;
ForeignKeyAction onDelete() default ForeignKeyAction.CASCADE;
ForeignKeyAction onUpdate() default ForeignKeyAction.CASCADE;
/**
* The {@code DEFAULT} expression for the column. Currently it is only used in migration.
*
* @return An SQLite expression. For example. {@code "''"} for an empty string, and {@code "0"} for a literal zero,
*/
String defaultExpr() default "";
/**
* Specifies how the column is compared.
*
* @return One of {@code Column.Collate.BINARY} (the default), {@code NOCASE} or {@code RTRIM}
*/
Collate collate() default Collate.BINARY;
/**
* Specifies a storage type for the column to suppress automatic migration for existing tables.
* <strong>Not recommended</strong>. Will become deprecated in a future.
*
* @return An SQLite data type. e.g. {@code "TEXT"}, {@code "FLOAT"}, {@code "INTEGER"}, or {@code "BLOB"}
*/
String storageType() default "";
/**
* @return Flags that control which helpers to generate
*/
@Helpers long helpers() default Helpers.AUTO;
/**
* SQLite's {@code COLLATE} algorithms.
*
* @see <a href="https://www.sqlite.org/datatype3.html#collation">https://www.sqlite.org/datatype3.html#collation</a>
*/
enum Collate {
/**
* <blockquote cite="https://www.sqlite.org/datatype3.html#collation">Compares string data using memcmp(), regardless
* of text encoding.</blockquote>
*/
BINARY,
/**
* <blockquote cite="https://www.sqlite.org/datatype3.html#collation">The same as binary, except the 26 upper
* case characters of ASCII are folded to their lower case equivalents before the comparison is performed. Note that
* only ASCII characters are case folded. SQLite does not attempt to do full UTF case folding due to the size of the
* tables required.</blockquote>
*/
NOCASE,
/**
* <blockquote cite="https://www.sqlite.org/datatype3.html#collation">The same as binary, except that trailing space
* characters are ignored.</blockquote>
*/
RTRIM
}
/**
* SQLite's <code>ON DELETE</code> and <code>ON UPDATE</code> actions.
*
* @see <a href="https://www.sqlite.org/foreignkeys.html">SQLite Foreign Key Support</a>
*/
enum ForeignKeyAction {
NO_ACTION,
RESTRICT,
SET_NULL,
SET_DEFAULT,
CASCADE,
}
@Target({ElementType.FIELD, ElementType.LOCAL_VARIABLE, ElementType.PARAMETER, ElementType.METHOD})
@Retention(RetentionPolicy.CLASS)
@LongDef(flag = true, value = {
Helpers.NONE,
Helpers.AUTO,
Helpers.CONDITION_EQ,
Helpers.CONDITION_NOT_EQ,
Helpers.CONDITION_IS_NULL,
Helpers.CONDITION_IS_NOT_NULL,
Helpers.CONDITION_IN,
Helpers.CONDITION_NOT_IN,
Helpers.CONDITION_LT,
Helpers.CONDITION_LE,
Helpers.CONDITION_GT,
Helpers.CONDITION_GE,
Helpers.CONDITION_BETWEEN,
Helpers.ORDER_IN_ASC,
Helpers.ORDER_IN_DESC,
Helpers.PLUCK,
Helpers.MIN,
Helpers.MAX,
Helpers.SUM,
Helpers.AVG,
})
@interface Helpers {
long NONE = 0;
long AUTO = 1;
long CONDITION_EQ = AUTO << 1;
long CONDITION_NOT_EQ = CONDITION_EQ << 1;
long CONDITION_IS_NULL = CONDITION_NOT_EQ << 1;
long CONDITION_IS_NOT_NULL = CONDITION_IS_NULL << 1;
long CONDITION_IN = CONDITION_IS_NOT_NULL << 1;
long CONDITION_NOT_IN = CONDITION_IN << 1;
long CONDITION_GLOB = CONDITION_NOT_IN << 1;
long CONDITION_NOT_GLOB = CONDITION_GLOB << 1;
long CONDITION_LIKE = CONDITION_NOT_GLOB << 1;
long CONDITION_NOT_LIKE = CONDITION_LIKE << 1;
long CONDITION_LT = CONDITION_NOT_LIKE << 1;
long CONDITION_LE = CONDITION_LT << 1;
long CONDITION_GT = CONDITION_LE << 1;
long CONDITION_GE = CONDITION_GT << 1;
long CONDITION_BETWEEN = CONDITION_GE << 1;
long CONDITIONS = CONDITION_EQ | CONDITION_NOT_EQ | CONDITION_IS_NULL | CONDITION_IS_NOT_NULL
| CONDITION_IN | CONDITION_NOT_IN
| CONDITION_GLOB | CONDITION_NOT_GLOB | CONDITION_LIKE | CONDITION_NOT_LIKE
| CONDITION_LT | CONDITION_LE | CONDITION_GT | CONDITION_GE | CONDITION_BETWEEN;
long ORDER_IN_ASC = CONDITION_BETWEEN << 1;
long ORDER_IN_DESC = ORDER_IN_ASC << 1;
long ORDERS = ORDER_IN_ASC | ORDER_IN_DESC;
long PLUCK = ORDER_IN_DESC << 1;
long MIN = PLUCK << 1;
long MAX = MIN << 1;
long SUM = MAX << 1;
long AVG = SUM << 1;
long AGGREGATORS = MIN | MAX | SUM | AVG;
long ALL = CONDITIONS | ORDERS | PLUCK | AGGREGATORS;
}
}