1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.room; 18 19 import androidx.annotation.IntDef; 20 import androidx.annotation.RequiresApi; 21 22 import java.lang.annotation.ElementType; 23 import java.lang.annotation.Retention; 24 import java.lang.annotation.RetentionPolicy; 25 import java.lang.annotation.Target; 26 27 /** 28 * Allows specific customization about the column associated with this field. 29 * <p> 30 * For example, you can specify a column name for the field or change the column's type affinity. 31 */ 32 @Target(ElementType.FIELD) 33 @Retention(RetentionPolicy.CLASS) 34 public @interface ColumnInfo { 35 /** 36 * Name of the column in the database. Defaults to the field name if not set. 37 * 38 * @return Name of the column in the database. 39 */ name()40 String name() default INHERIT_FIELD_NAME; 41 42 /** 43 * The type affinity for the column, which will be used when constructing the database. 44 * <p> 45 * If it is not specified, the value defaults to {@link #UNDEFINED} and Room resolves it based 46 * on the field's type and available TypeConverters. 47 * <p> 48 * See <a href="https://www.sqlite.org/datatype3.html">SQLite types documentation</a> for 49 * details. 50 * 51 * @return The type affinity of the column. This is either {@link #UNDEFINED}, {@link #TEXT}, 52 * {@link #INTEGER}, {@link #REAL}, or {@link #BLOB}. 53 */ typeAffinity()54 @SuppressWarnings("unused") @SQLiteTypeAffinity int typeAffinity() default UNDEFINED; 55 56 /** 57 * Convenience method to index the field. 58 * <p> 59 * If you would like to create a composite index instead, see: {@link Index}. 60 * 61 * @return True if this field should be indexed, false otherwise. Defaults to false. 62 */ index()63 boolean index() default false; 64 65 /** 66 * The collation sequence for the column, which will be used when constructing the database. 67 * <p> 68 * The default value is {@link #UNSPECIFIED}. In that case, Room does not add any 69 * collation sequence to the column, and SQLite treats it like {@link #BINARY}. 70 * 71 * @return The collation sequence of the column. This is either {@link #UNSPECIFIED}, 72 * {@link #BINARY}, {@link #NOCASE}, {@link #RTRIM}, {@link #LOCALIZED} or {@link #UNICODE}. 73 */ collate()74 @Collate int collate() default UNSPECIFIED; 75 76 /** 77 * Constant to let Room inherit the field name as the column name. If used, Room will use the 78 * field name as the column name. 79 */ 80 String INHERIT_FIELD_NAME = "[field-name]"; 81 82 /** 83 * Undefined type affinity. Will be resolved based on the type. 84 * 85 * @see #typeAffinity() 86 */ 87 int UNDEFINED = 1; 88 /** 89 * Column affinity constant for strings. 90 * 91 * @see #typeAffinity() 92 */ 93 int TEXT = 2; 94 /** 95 * Column affinity constant for integers or booleans. 96 * 97 * @see #typeAffinity() 98 */ 99 int INTEGER = 3; 100 /** 101 * Column affinity constant for floats or doubles. 102 * 103 * @see #typeAffinity() 104 */ 105 int REAL = 4; 106 /** 107 * Column affinity constant for binary data. 108 * 109 * @see #typeAffinity() 110 */ 111 int BLOB = 5; 112 113 /** 114 * The SQLite column type constants that can be used in {@link #typeAffinity()} 115 */ 116 @IntDef({UNDEFINED, TEXT, INTEGER, REAL, BLOB}) 117 @interface SQLiteTypeAffinity { 118 } 119 120 /** 121 * Collation sequence is not specified. The match will behave like {@link #BINARY}. 122 * 123 * @see #collate() 124 */ 125 int UNSPECIFIED = 1; 126 /** 127 * Collation sequence for case-sensitive match. 128 * 129 * @see #collate() 130 */ 131 int BINARY = 2; 132 /** 133 * Collation sequence for case-insensitive match. 134 * 135 * @see #collate() 136 */ 137 int NOCASE = 3; 138 /** 139 * Collation sequence for case-sensitive match except that trailing space characters are 140 * ignored. 141 * 142 * @see #collate() 143 */ 144 int RTRIM = 4; 145 /** 146 * Collation sequence that uses system's current locale. 147 * 148 * @see #collate() 149 */ 150 @RequiresApi(21) 151 int LOCALIZED = 5; 152 /** 153 * Collation sequence that uses Unicode Collation Algorithm. 154 * 155 * @see #collate() 156 */ 157 @RequiresApi(21) 158 int UNICODE = 6; 159 160 @IntDef({UNSPECIFIED, BINARY, NOCASE, RTRIM, LOCALIZED, UNICODE}) 161 @interface Collate { 162 } 163 } 164