/aws-android-sdk-s3/src/main/java/com/amazonaws/mobileconnectors/s3/transferutility/TransferTable.java

https://gitlab.com/github-cloud-corp/aws-sdk-android · Java · 303 lines · 113 code · 45 blank · 145 comment · 6 complexity · 43af0f115b78e6dff61bd085833d53dc MD5 · raw file

  1. /**
  2. * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  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. * A copy of the License is located at
  7. *
  8. * http://aws.amazon.com/apache2.0
  9. *
  10. * or in the "license" file accompanying this file. This file is distributed
  11. * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  12. * express or implied. See the License for the specific language governing
  13. * permissions and limitations under the License.
  14. */
  15. package com.amazonaws.mobileconnectors.s3.transferutility;
  16. import android.database.sqlite.SQLiteDatabase;
  17. class TransferTable {
  18. /**
  19. * Database table name
  20. */
  21. public static final String TABLE_TRANSFER = "awstransfer";
  22. /**
  23. * A unique id of the transfer record
  24. */
  25. public static final String COLUMN_ID = "_id";
  26. /**
  27. * For upload part record only, the transfer id of the main record of the
  28. * part record.
  29. */
  30. public static final String COLUMN_MAIN_UPLOAD_ID = "main_upload_id";
  31. /**
  32. * Transfer type, can be whether "upload" or "download"
  33. */
  34. public static final String COLUMN_TYPE = "type";
  35. /**
  36. * The current state of the transfer, values of all states are in
  37. * <code>TransferConstants</code>.
  38. */
  39. public static final String COLUMN_STATE = "state";
  40. /**
  41. * The name of the bucket.
  42. */
  43. public static final String COLUMN_BUCKET_NAME = "bucket_name";
  44. /**
  45. * A key in the bucket.
  46. */
  47. public static final String COLUMN_KEY = "key";
  48. /**
  49. * The total bytes to transfer.
  50. */
  51. public static final String COLUMN_BYTES_TOTAL = "bytes_total";
  52. /**
  53. * The bytes currently transferred.
  54. */
  55. public static final String COLUMN_BYTES_CURRENT = "bytes_current";
  56. /**
  57. * The path of the file to transfer.
  58. */
  59. public static final String COLUMN_FILE = "file";
  60. /**
  61. * The bytes offset of the file.
  62. */
  63. public static final String COLUMN_FILE_OFFSET = "file_offset";
  64. /**
  65. * Whether the transfer is a multi-part transfer.
  66. */
  67. public static final String COLUMN_IS_MULTIPART = "is_multipart";
  68. /**
  69. * Whether the part is the last part of the file.
  70. */
  71. public static final String COLUMN_IS_LAST_PART = "is_last_part";
  72. /**
  73. * The number of the part in the transfer.
  74. */
  75. public static final String COLUMN_PART_NUM = "part_num";
  76. /**
  77. * The multipart upload id.
  78. */
  79. public static final String COLUMN_MULTIPART_ID = "multipart_id";
  80. /**
  81. * The Etag of the transfer
  82. */
  83. public static final String COLUMN_ETAG = "etag";
  84. /**
  85. * The range's start index in the file.
  86. */
  87. public static final String COLUMN_DATA_RANGE_START = "range_start";
  88. /**
  89. * The range's end index in the file.
  90. */
  91. public static final String COLUMN_DATA_RANGE_LAST = "range_last";
  92. /**
  93. * Whether the transfer is encrypted.
  94. */
  95. public static final String COLUMN_IS_ENCRYPTED = "is_encrypted";
  96. /*
  97. * the following columns are not used yet
  98. */
  99. public static final String COLUMN_SPEED = "speed";
  100. public static final String COLUMN_VERSION_ID = "version_id";
  101. public static final String COLUMN_HEADER_EXPIRE = "header_expire";
  102. /**
  103. * If the object requires the requester to pay
  104. */
  105. public static final String COLUMN_IS_REQUESTER_PAYS = "is_requester_pays";
  106. /**
  107. * User specified content Type
  108. */
  109. public static final String COLUMN_HEADER_CONTENT_TYPE = "header_content_type";
  110. /**
  111. * User specified content language
  112. */
  113. public static final String COLUMN_HEADER_CONTENT_LANGUAGE = "header_content_language";
  114. /**
  115. * User specified content disposition
  116. */
  117. public static final String COLUMN_HEADER_CONTENT_DISPOSITION = "header_content_disposition";
  118. /**
  119. * User specified content encoding
  120. */
  121. public static final String COLUMN_HEADER_CONTENT_ENCODING = "header_content_encoding";
  122. /**
  123. * User specified cache control
  124. */
  125. public static final String COLUMN_HEADER_CACHE_CONTROL = "header_cache_control";
  126. /**
  127. * ============ Below added in 2.2.6 for support for metadata ============
  128. */
  129. /**
  130. * User specified lifecycle configuration expiration time rule id
  131. */
  132. public static final String COLUMN_EXPIRATION_TIME_RULE_ID = "expiration_time_rule_id";
  133. /**
  134. * User specified lifecycle configuration expiration time rule id
  135. */
  136. public static final String COLUMN_HTTP_EXPIRES_DATE = "http_expires_date";
  137. /**
  138. * User specified server side encryption algorithm
  139. */
  140. public static final String COLUMN_SSE_ALGORITHM = "sse_algorithm";
  141. /**
  142. * User specified content MD5
  143. */
  144. public static final String COLUMN_CONTENT_MD5 = "content_md5";
  145. /**
  146. * Json serialization of user metadata to store with the Object
  147. */
  148. public static final String COLUMN_USER_METADATA = "user_metadata";
  149. /**
  150. * ============ Below added in 2.2.11 for support for KMS ============
  151. */
  152. /**
  153. * User specified KMS key for server side encryption
  154. */
  155. public static final String COLUMN_SSE_KMS_KEY = "kms_key";
  156. /**
  157. * Canned ACL of this upload.
  158. */
  159. public static final String COLUMN_CANNED_ACL = "canned_acl";
  160. /*
  161. * Database creation SQL statement
  162. */
  163. private static final String DATABASE_CREATE = "create table "
  164. + TABLE_TRANSFER
  165. + "("
  166. + COLUMN_ID + " integer primary key autoincrement, "
  167. + COLUMN_MAIN_UPLOAD_ID + " integer, "
  168. + COLUMN_TYPE + " text not null, "
  169. + COLUMN_STATE + " text not null, "
  170. + COLUMN_BUCKET_NAME + " text not null, "
  171. + COLUMN_KEY + " text not null, "
  172. + COLUMN_VERSION_ID + " text, "
  173. + COLUMN_BYTES_TOTAL + " bigint, "
  174. + COLUMN_BYTES_CURRENT + " bigint, "
  175. + COLUMN_SPEED + " bigint, "
  176. + COLUMN_IS_REQUESTER_PAYS + " integer, "
  177. + COLUMN_IS_ENCRYPTED + " integer, "
  178. + COLUMN_FILE + " text not null, "
  179. + COLUMN_FILE_OFFSET + " bigint, "
  180. + COLUMN_IS_MULTIPART + " int, "
  181. + COLUMN_PART_NUM + " int not null, "
  182. + COLUMN_IS_LAST_PART + " integer, "
  183. + COLUMN_MULTIPART_ID + " text, "
  184. + COLUMN_ETAG + " text, "
  185. + COLUMN_DATA_RANGE_START + " bigint, "
  186. + COLUMN_DATA_RANGE_LAST + " bigint, "
  187. + COLUMN_HEADER_CONTENT_TYPE + " text, "
  188. + COLUMN_HEADER_CONTENT_LANGUAGE + " text, "
  189. + COLUMN_HEADER_CONTENT_DISPOSITION + " text, "
  190. + COLUMN_HEADER_CONTENT_ENCODING + " text, "
  191. + COLUMN_HEADER_CACHE_CONTROL + " text, "
  192. + COLUMN_HEADER_EXPIRE + " text"
  193. + ");";
  194. /**
  195. * Creates the database.
  196. *
  197. * @param database An SQLiteDatabase instance.
  198. */
  199. public static void onCreate(SQLiteDatabase database, int version) {
  200. database.execSQL(DATABASE_CREATE);
  201. onUpgrade(database, 1, version);
  202. }
  203. /**
  204. * Upgrades the database.
  205. *
  206. * @param database An SQLiteDatabase instance.
  207. * @param oldVersion The old version of the database.
  208. * @param newVersion The new version of the database.
  209. */
  210. public static void onUpgrade(SQLiteDatabase database, int oldVersion,
  211. int newVersion) {
  212. if (oldVersion < 2 && newVersion >= 2) {
  213. addVersion2Columns(database);
  214. }
  215. if (oldVersion < 3 && newVersion >= 3) {
  216. addVersion3Columns(database);
  217. }
  218. if (oldVersion < 4 && newVersion >= 4) {
  219. addVersion4Columns(database);
  220. }
  221. }
  222. /**
  223. * Adds columns that were introduced in version 2 to the database
  224. */
  225. private static void addVersion2Columns(SQLiteDatabase database) {
  226. String addUserMetadata = "ALTER TABLE " + TABLE_TRANSFER +
  227. " ADD COLUMN " + COLUMN_USER_METADATA + " text;";
  228. String addExpirationTimeRuleId = "ALTER TABLE " + TABLE_TRANSFER +
  229. " ADD COLUMN " + COLUMN_EXPIRATION_TIME_RULE_ID + " text;";
  230. String addHttpExpires = "ALTER TABLE " + TABLE_TRANSFER +
  231. " ADD COLUMN " + COLUMN_HTTP_EXPIRES_DATE + " text;";
  232. String addSSEAlgorithm = "ALTER TABLE " + TABLE_TRANSFER +
  233. " ADD COLUMN " + COLUMN_SSE_ALGORITHM + " text;";
  234. String addContentMD5 = "ALTER TABLE " + TABLE_TRANSFER +
  235. " ADD COLUMN " + COLUMN_CONTENT_MD5 + " text;";
  236. database.execSQL(addUserMetadata);
  237. database.execSQL(addExpirationTimeRuleId);
  238. database.execSQL(addHttpExpires);
  239. database.execSQL(addSSEAlgorithm);
  240. database.execSQL(addContentMD5);
  241. }
  242. /**
  243. * Adds columns that were introduced in version 3 to the database
  244. */
  245. private static void addVersion3Columns(SQLiteDatabase database) {
  246. String addKMSKey = "ALTER TABLE " + TABLE_TRANSFER +
  247. " ADD COLUMN " + COLUMN_SSE_KMS_KEY + " text;";
  248. database.execSQL(addKMSKey);
  249. }
  250. /**
  251. * Adds columns that were introduced in version 3 to the database
  252. */
  253. private static void addVersion4Columns(SQLiteDatabase database) {
  254. String addCannedAcl = "ALTER TABLE " + TABLE_TRANSFER +
  255. " ADD COLUMN " + COLUMN_CANNED_ACL + " text;";
  256. database.execSQL(addCannedAcl);
  257. }
  258. }