|
14 | 14 | */ |
15 | 15 | package com.owncloud.android.datamodel; |
16 | 16 |
|
17 | | -import android.content.ContentProviderOperation; |
18 | | -import android.content.ContentProviderResult; |
19 | 17 | import android.content.ContentResolver; |
20 | 18 | import android.content.ContentValues; |
21 | | -import android.content.OperationApplicationException; |
22 | 19 | import android.database.Cursor; |
23 | | -import android.net.Uri; |
24 | | -import android.os.RemoteException; |
25 | 20 |
|
26 | 21 | import com.nextcloud.client.account.CurrentAccountProvider; |
27 | 22 | import com.nextcloud.client.account.User; |
@@ -94,97 +89,6 @@ private void initOCCapability() { |
94 | 89 | } |
95 | 90 | } |
96 | 91 |
|
97 | | - /** |
98 | | - * Stores an upload object in DB. |
99 | | - * |
100 | | - * @param ocUpload Upload object to store |
101 | | - * @return upload id, -1 if the insert process fails. |
102 | | - */ |
103 | | - public long storeUpload(OCUpload ocUpload) { |
104 | | - OCUpload existingUpload = getPendingCurrentOrFailedUpload(ocUpload); |
105 | | - if (existingUpload != null) { |
106 | | - Log_OC.v(TAG, "Will update upload in db since " + ocUpload.getLocalPath() + " already exists as " + |
107 | | - "pending, current or failed upload"); |
108 | | - long existingId = existingUpload.getUploadId(); |
109 | | - ocUpload.setUploadId(existingId); |
110 | | - updateUpload(ocUpload); |
111 | | - return existingId; |
112 | | - } |
113 | | - |
114 | | - |
115 | | - Log_OC.v(TAG, "Inserting " + ocUpload.getLocalPath() + " with status=" + ocUpload.getUploadStatus()); |
116 | | - |
117 | | - ContentValues cv = getContentValues(ocUpload); |
118 | | - Uri result = getDB().insert(ProviderTableMeta.CONTENT_URI_UPLOADS, cv); |
119 | | - |
120 | | - Log_OC.d(TAG, "storeUpload returns with: " + result + " for file: " + ocUpload.getLocalPath()); |
121 | | - if (result == null) { |
122 | | - Log_OC.e(TAG, "Failed to insert item " + ocUpload.getLocalPath() + " into upload db."); |
123 | | - return -1; |
124 | | - } else { |
125 | | - long new_id = Long.parseLong(result.getPathSegments().get(1)); |
126 | | - ocUpload.setUploadId(new_id); |
127 | | - notifyObserversNow(); |
128 | | - |
129 | | - return new_id; |
130 | | - } |
131 | | - |
132 | | - } |
133 | | - |
134 | | - public void storeUploads(final List<OCUpload> ocUploads) { |
135 | | - Log_OC.v(TAG, "Inserting " + ocUploads.size() + " uploads"); |
136 | | - ArrayList<ContentProviderOperation> operations = new ArrayList<>(ocUploads.size()); |
137 | | - for (OCUpload ocUpload : ocUploads) { |
138 | | - |
139 | | - OCUpload existingUpload = getPendingCurrentOrFailedUpload(ocUpload); |
140 | | - if (existingUpload != null) { |
141 | | - Log_OC.v(TAG, "Will update upload in db since " + ocUpload.getLocalPath() + " already exists as" + |
142 | | - " pending, current or failed upload"); |
143 | | - ocUpload.setUploadId(existingUpload.getUploadId()); |
144 | | - updateUpload(ocUpload); |
145 | | - continue; |
146 | | - } |
147 | | - |
148 | | - final ContentProviderOperation operation = ContentProviderOperation |
149 | | - .newInsert(ProviderTableMeta.CONTENT_URI_UPLOADS) |
150 | | - .withValues(getContentValues(ocUpload)) |
151 | | - .build(); |
152 | | - operations.add(operation); |
153 | | - } |
154 | | - |
155 | | - try { |
156 | | - final ContentProviderResult[] contentProviderResults = getDB().applyBatch(MainApp.getAuthority(), operations); |
157 | | - for (int i = 0; i < contentProviderResults.length; i++) { |
158 | | - final ContentProviderResult result = contentProviderResults[i]; |
159 | | - final long new_id = Long.parseLong(result.uri.getPathSegments().get(1)); |
160 | | - ocUploads.get(i).setUploadId(new_id); |
161 | | - } |
162 | | - notifyObserversNow(); |
163 | | - } catch (OperationApplicationException | RemoteException e) { |
164 | | - Log_OC.e(TAG, "Error inserting uploads", e); |
165 | | - } |
166 | | - } |
167 | | - |
168 | | - @NonNull |
169 | | - private ContentValues getContentValues(OCUpload ocUpload) { |
170 | | - ContentValues cv = new ContentValues(); |
171 | | - cv.put(ProviderTableMeta.UPLOADS_LOCAL_PATH, ocUpload.getLocalPath()); |
172 | | - cv.put(ProviderTableMeta.UPLOADS_REMOTE_PATH, ocUpload.getRemotePath()); |
173 | | - cv.put(ProviderTableMeta.UPLOADS_ACCOUNT_NAME, ocUpload.getAccountName()); |
174 | | - cv.put(ProviderTableMeta.UPLOADS_FILE_SIZE, ocUpload.getFileSize()); |
175 | | - cv.put(ProviderTableMeta.UPLOADS_STATUS, ocUpload.getUploadStatus().value); |
176 | | - cv.put(ProviderTableMeta.UPLOADS_LOCAL_BEHAVIOUR, ocUpload.getLocalAction()); |
177 | | - cv.put(ProviderTableMeta.UPLOADS_NAME_COLLISION_POLICY, ocUpload.getNameCollisionPolicy().serialize()); |
178 | | - cv.put(ProviderTableMeta.UPLOADS_IS_CREATE_REMOTE_FOLDER, ocUpload.isCreateRemoteFolder() ? 1 : 0); |
179 | | - cv.put(ProviderTableMeta.UPLOADS_LAST_RESULT, ocUpload.getLastResult().getValue()); |
180 | | - cv.put(ProviderTableMeta.UPLOADS_CREATED_BY, ocUpload.getCreatedBy()); |
181 | | - cv.put(ProviderTableMeta.UPLOADS_IS_WHILE_CHARGING_ONLY, ocUpload.isWhileChargingOnly() ? 1 : 0); |
182 | | - cv.put(ProviderTableMeta.UPLOADS_IS_WIFI_ONLY, ocUpload.isUseWifiOnly() ? 1 : 0); |
183 | | - cv.put(ProviderTableMeta.UPLOADS_FOLDER_UNLOCK_TOKEN, ocUpload.getFolderUnlockToken()); |
184 | | - return cv; |
185 | | - } |
186 | | - |
187 | | - |
188 | 92 | /** |
189 | 93 | * Update an upload object in DB. |
190 | 94 | * |
@@ -414,26 +318,6 @@ public OCUpload getPendingCurrentOrFailedUpload(OCUpload upload) { |
414 | 318 | return null; |
415 | 319 | } |
416 | 320 |
|
417 | | - @Nullable |
418 | | - public OCUpload getUploadByRemotePath(String remotePath) { |
419 | | - OCUpload result = null; |
420 | | - try (Cursor cursor = getDB().query( |
421 | | - ProviderTableMeta.CONTENT_URI_UPLOADS, |
422 | | - null, |
423 | | - ProviderTableMeta.UPLOADS_REMOTE_PATH + "=?", |
424 | | - new String[]{remotePath}, |
425 | | - ProviderTableMeta.UPLOADS_REMOTE_PATH + " ASC")) { |
426 | | - |
427 | | - if (cursor != null) { |
428 | | - if (cursor.moveToFirst()) { |
429 | | - result = createOCUploadFromCursor(cursor); |
430 | | - } |
431 | | - } |
432 | | - } |
433 | | - Log_OC.d(TAG, "Retrieve job " + result + " for remote path " + remotePath); |
434 | | - return result; |
435 | | - } |
436 | | - |
437 | 321 | public @Nullable |
438 | 322 | OCUpload getUploadById(long id) { |
439 | 323 | OCUpload result = null; |
|
0 commit comments