|
@@ -56,46 +56,81 @@ public class FileContentProvider extends ContentProvider {
|
|
|
|
|
|
private DataBaseHelper mDbHelper;
|
|
|
|
|
|
- private static HashMap<String, String> mProjectionMap;
|
|
|
+ // Projection for filelist table
|
|
|
+ private static HashMap<String, String> mFileProjectionMap;
|
|
|
static {
|
|
|
- mProjectionMap = new HashMap<String, String>();
|
|
|
- mProjectionMap.put(ProviderTableMeta._ID, ProviderTableMeta._ID);
|
|
|
- mProjectionMap.put(ProviderTableMeta.FILE_PARENT,
|
|
|
+ mFileProjectionMap = new HashMap<String, String>();
|
|
|
+ mFileProjectionMap.put(ProviderTableMeta._ID, ProviderTableMeta._ID);
|
|
|
+ mFileProjectionMap.put(ProviderTableMeta.FILE_PARENT,
|
|
|
ProviderTableMeta.FILE_PARENT);
|
|
|
- mProjectionMap.put(ProviderTableMeta.FILE_PATH,
|
|
|
+ mFileProjectionMap.put(ProviderTableMeta.FILE_PATH,
|
|
|
ProviderTableMeta.FILE_PATH);
|
|
|
- mProjectionMap.put(ProviderTableMeta.FILE_NAME,
|
|
|
+ mFileProjectionMap.put(ProviderTableMeta.FILE_NAME,
|
|
|
ProviderTableMeta.FILE_NAME);
|
|
|
- mProjectionMap.put(ProviderTableMeta.FILE_CREATION,
|
|
|
+ mFileProjectionMap.put(ProviderTableMeta.FILE_CREATION,
|
|
|
ProviderTableMeta.FILE_CREATION);
|
|
|
- mProjectionMap.put(ProviderTableMeta.FILE_MODIFIED,
|
|
|
+ mFileProjectionMap.put(ProviderTableMeta.FILE_MODIFIED,
|
|
|
ProviderTableMeta.FILE_MODIFIED);
|
|
|
- mProjectionMap.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
|
|
|
+ mFileProjectionMap.put(ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA,
|
|
|
ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA);
|
|
|
- mProjectionMap.put(ProviderTableMeta.FILE_CONTENT_LENGTH,
|
|
|
+ mFileProjectionMap.put(ProviderTableMeta.FILE_CONTENT_LENGTH,
|
|
|
ProviderTableMeta.FILE_CONTENT_LENGTH);
|
|
|
- mProjectionMap.put(ProviderTableMeta.FILE_CONTENT_TYPE,
|
|
|
+ mFileProjectionMap.put(ProviderTableMeta.FILE_CONTENT_TYPE,
|
|
|
ProviderTableMeta.FILE_CONTENT_TYPE);
|
|
|
- mProjectionMap.put(ProviderTableMeta.FILE_STORAGE_PATH,
|
|
|
+ mFileProjectionMap.put(ProviderTableMeta.FILE_STORAGE_PATH,
|
|
|
ProviderTableMeta.FILE_STORAGE_PATH);
|
|
|
- mProjectionMap.put(ProviderTableMeta.FILE_LAST_SYNC_DATE,
|
|
|
+ mFileProjectionMap.put(ProviderTableMeta.FILE_LAST_SYNC_DATE,
|
|
|
ProviderTableMeta.FILE_LAST_SYNC_DATE);
|
|
|
- mProjectionMap.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA,
|
|
|
+ mFileProjectionMap.put(ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA,
|
|
|
ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA);
|
|
|
- mProjectionMap.put(ProviderTableMeta.FILE_KEEP_IN_SYNC,
|
|
|
+ mFileProjectionMap.put(ProviderTableMeta.FILE_KEEP_IN_SYNC,
|
|
|
ProviderTableMeta.FILE_KEEP_IN_SYNC);
|
|
|
- mProjectionMap.put(ProviderTableMeta.FILE_ACCOUNT_OWNER,
|
|
|
+ mFileProjectionMap.put(ProviderTableMeta.FILE_ACCOUNT_OWNER,
|
|
|
ProviderTableMeta.FILE_ACCOUNT_OWNER);
|
|
|
- mProjectionMap.put(ProviderTableMeta.FILE_ETAG,
|
|
|
+ mFileProjectionMap.put(ProviderTableMeta.FILE_ETAG,
|
|
|
ProviderTableMeta.FILE_ETAG);
|
|
|
- mProjectionMap.put(ProviderTableMeta.FILE_SHARE_BY_LINK,
|
|
|
+ mFileProjectionMap.put(ProviderTableMeta.FILE_SHARE_BY_LINK,
|
|
|
ProviderTableMeta.FILE_PUBLIC_LINK);
|
|
|
}
|
|
|
|
|
|
private static final int SINGLE_FILE = 1;
|
|
|
private static final int DIRECTORY = 2;
|
|
|
private static final int ROOT_DIRECTORY = 3;
|
|
|
-
|
|
|
+ private static final int SHARES = 4;
|
|
|
+
|
|
|
+ // Projection for ocshares table
|
|
|
+ private static HashMap<String, String> mOCSharesProjectionMap;
|
|
|
+ static {
|
|
|
+ mOCSharesProjectionMap = new HashMap<String, String>();
|
|
|
+ mOCSharesProjectionMap.put(ProviderTableMeta._ID, ProviderTableMeta._ID);
|
|
|
+ mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_FILE_SOURCE,
|
|
|
+ ProviderTableMeta.OCSHARES_FILE_SOURCE);
|
|
|
+ mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_ITEM_SOURCE,
|
|
|
+ ProviderTableMeta.OCSHARES_ITEM_SOURCE);
|
|
|
+ mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_SHARE_TYPE,
|
|
|
+ ProviderTableMeta.OCSHARES_SHARE_TYPE);
|
|
|
+ mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_SHARE_WITH,
|
|
|
+ ProviderTableMeta.OCSHARES_SHARE_WITH);
|
|
|
+ mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_PATH,
|
|
|
+ ProviderTableMeta.OCSHARES_PATH);
|
|
|
+ mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_PERMISSIONS,
|
|
|
+ ProviderTableMeta.OCSHARES_PERMISSIONS);
|
|
|
+ mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_SHARED_DATE,
|
|
|
+ ProviderTableMeta.OCSHARES_SHARED_DATE);
|
|
|
+ mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_EXPIRATION_DATE,
|
|
|
+ ProviderTableMeta.OCSHARES_EXPIRATION_DATE);
|
|
|
+ mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_TOKEN,
|
|
|
+ ProviderTableMeta.OCSHARES_TOKEN);
|
|
|
+ mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME,
|
|
|
+ ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME);
|
|
|
+ mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_IS_DIRECTORY,
|
|
|
+ ProviderTableMeta.OCSHARES_IS_DIRECTORY);
|
|
|
+ mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_USER_ID,
|
|
|
+ ProviderTableMeta.OCSHARES_USER_ID);
|
|
|
+ mOCSharesProjectionMap.put(ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED,
|
|
|
+ ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED);
|
|
|
+ }
|
|
|
+
|
|
|
private UriMatcher mUriMatcher;
|
|
|
|
|
|
@Override
|
|
@@ -114,7 +149,7 @@ public class FileContentProvider extends ContentProvider {
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ // TODO: switch(uri)
|
|
|
private int delete(SQLiteDatabase db, Uri uri, String where, String[] whereArgs) {
|
|
|
int count = 0;
|
|
|
switch (mUriMatcher.match(uri)) {
|
|
@@ -126,7 +161,7 @@ public class FileContentProvider extends ContentProvider {
|
|
|
}
|
|
|
Log_OC.d(TAG, "Removing FILE " + remotePath);
|
|
|
*/
|
|
|
- count = db.delete(ProviderTableMeta.DB_NAME,
|
|
|
+ count = db.delete(ProviderTableMeta.FILE_TABLE_NAME,
|
|
|
ProviderTableMeta._ID
|
|
|
+ "="
|
|
|
+ uri.getPathSegments().get(1)
|
|
@@ -170,7 +205,7 @@ public class FileContentProvider extends ContentProvider {
|
|
|
}
|
|
|
Log_OC.d(TAG, "Removing DIRECTORY " + folderName + " (or maybe not) ");
|
|
|
*/
|
|
|
- count += db.delete(ProviderTableMeta.DB_NAME,
|
|
|
+ count += db.delete(ProviderTableMeta.FILE_TABLE_NAME,
|
|
|
ProviderTableMeta._ID
|
|
|
+ "="
|
|
|
+ uri.getPathSegments().get(1)
|
|
@@ -183,7 +218,7 @@ public class FileContentProvider extends ContentProvider {
|
|
|
break;
|
|
|
case ROOT_DIRECTORY:
|
|
|
//Log_OC.d(TAG, "Removing ROOT!");
|
|
|
- count = db.delete(ProviderTableMeta.DB_NAME, where, whereArgs);
|
|
|
+ count = db.delete(ProviderTableMeta.FILE_TABLE_NAME, where, whereArgs);
|
|
|
break;
|
|
|
default:
|
|
|
//Log_OC.e(TAG, "Unknown uri " + uri);
|
|
@@ -193,6 +228,7 @@ public class FileContentProvider extends ContentProvider {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ // TODO: switch(uri)
|
|
|
@Override
|
|
|
public String getType(Uri uri) {
|
|
|
switch (mUriMatcher.match(uri)) {
|
|
@@ -222,6 +258,7 @@ public class FileContentProvider extends ContentProvider {
|
|
|
return newUri;
|
|
|
}
|
|
|
|
|
|
+ // TODO: switch(uri)
|
|
|
private Uri insert(SQLiteDatabase db, Uri uri, ContentValues values) {
|
|
|
if (mUriMatcher.match(uri) != SINGLE_FILE &&
|
|
|
mUriMatcher.match(uri) != ROOT_DIRECTORY) {
|
|
@@ -236,7 +273,7 @@ public class FileContentProvider extends ContentProvider {
|
|
|
String[] whereArgs = new String[] {remotePath, accountName};
|
|
|
Cursor doubleCheck = query(db, uri, projection, where, whereArgs, null);
|
|
|
if (doubleCheck == null || !doubleCheck.moveToFirst()) { // ugly patch; serious refactorization is needed to reduce work in FileDataStorageManager and bring it to FileContentProvider
|
|
|
- long rowId = db.insert(ProviderTableMeta.DB_NAME, null, values);
|
|
|
+ long rowId = db.insert(ProviderTableMeta.FILE_TABLE_NAME, null, values);
|
|
|
if (rowId > 0) {
|
|
|
Uri insertedFileUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId);
|
|
|
//Log_OC.d(TAG, "Inserted " + values.getAsString(ProviderTableMeta.FILE_PATH) + " at provider " + this);
|
|
@@ -265,6 +302,8 @@ public class FileContentProvider extends ContentProvider {
|
|
|
mUriMatcher.addURI(authority, "file/#", SINGLE_FILE);
|
|
|
mUriMatcher.addURI(authority, "dir/", DIRECTORY);
|
|
|
mUriMatcher.addURI(authority, "dir/#", DIRECTORY);
|
|
|
+ mUriMatcher.addURI(authority, "shares/", SHARES);
|
|
|
+ mUriMatcher.addURI(authority, "shares/#", SHARES);
|
|
|
|
|
|
return true;
|
|
|
}
|
|
@@ -287,8 +326,8 @@ public class FileContentProvider extends ContentProvider {
|
|
|
private Cursor query(SQLiteDatabase db, Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
|
|
|
SQLiteQueryBuilder sqlQuery = new SQLiteQueryBuilder();
|
|
|
|
|
|
- sqlQuery.setTables(ProviderTableMeta.DB_NAME);
|
|
|
- sqlQuery.setProjectionMap(mProjectionMap);
|
|
|
+ sqlQuery.setTables(ProviderTableMeta.FILE_TABLE_NAME);
|
|
|
+ sqlQuery.setProjectionMap(mFileProjectionMap);
|
|
|
|
|
|
switch (mUriMatcher.match(uri)) {
|
|
|
case ROOT_DIRECTORY:
|
|
@@ -304,13 +343,15 @@ public class FileContentProvider extends ContentProvider {
|
|
|
+ uri.getPathSegments().get(1));
|
|
|
}
|
|
|
break;
|
|
|
+ case SHARES: //TODO
|
|
|
+ break;
|
|
|
default:
|
|
|
throw new IllegalArgumentException("Unknown uri id: " + uri);
|
|
|
}
|
|
|
|
|
|
String order;
|
|
|
if (TextUtils.isEmpty(sortOrder)) {
|
|
|
- order = ProviderTableMeta.DEFAULT_SORT_ORDER;
|
|
|
+ order = ProviderTableMeta.FILE_DEFAULT_SORT_ORDER;
|
|
|
} else {
|
|
|
order = sortOrder;
|
|
|
}
|
|
@@ -322,6 +363,7 @@ public class FileContentProvider extends ContentProvider {
|
|
|
return c;
|
|
|
}
|
|
|
|
|
|
+ // TODO: switch(uri)
|
|
|
@Override
|
|
|
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
|
|
|
|
@@ -340,12 +382,13 @@ public class FileContentProvider extends ContentProvider {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ // TODO: switch(uri)
|
|
|
private int update(SQLiteDatabase db, Uri uri, ContentValues values, String selection, String[] selectionArgs) {
|
|
|
switch (mUriMatcher.match(uri)) {
|
|
|
case DIRECTORY:
|
|
|
return updateFolderSize(db, selectionArgs[0]);
|
|
|
default:
|
|
|
- return db.update(ProviderTableMeta.DB_NAME, values, selection, selectionArgs);
|
|
|
+ return db.update(ProviderTableMeta.FILE_TABLE_NAME, values, selection, selectionArgs);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -386,7 +429,7 @@ public class FileContentProvider extends ContentProvider {
|
|
|
Log_OC.d("FileContentProvider", "Updating " + folderSize + " to " + childrenSize);
|
|
|
ContentValues cv = new ContentValues();
|
|
|
cv.put(ProviderTableMeta.FILE_CONTENT_LENGTH, childrenSize);
|
|
|
- count = db.update(ProviderTableMeta.DB_NAME, cv, folderWhere, whereArgs);
|
|
|
+ count = db.update(ProviderTableMeta.FILE_TABLE_NAME, cv, folderWhere, whereArgs);
|
|
|
|
|
|
// propagate update until root
|
|
|
if (folderParentId > FileDataStorageManager.ROOT_PARENT_ID) {
|
|
@@ -435,7 +478,7 @@ public class FileContentProvider extends ContentProvider {
|
|
|
public void onCreate(SQLiteDatabase db) {
|
|
|
// files table
|
|
|
Log_OC.i("SQL", "Entering in onCreate");
|
|
|
- db.execSQL("CREATE TABLE " + ProviderTableMeta.DB_NAME + "("
|
|
|
+ db.execSQL("CREATE TABLE " + ProviderTableMeta.FILE_TABLE_NAME + "("
|
|
|
+ ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
|
|
|
+ ProviderTableMeta.FILE_NAME + " TEXT, "
|
|
|
+ ProviderTableMeta.FILE_PATH + " TEXT, "
|
|
@@ -462,7 +505,7 @@ public class FileContentProvider extends ContentProvider {
|
|
|
boolean upgraded = false;
|
|
|
if (oldVersion == 1 && newVersion >= 2) {
|
|
|
Log_OC.i("SQL", "Entering in the #1 ADD in onUpgrade");
|
|
|
- db.execSQL("ALTER TABLE " + ProviderTableMeta.DB_NAME +
|
|
|
+ db.execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
|
|
|
" ADD COLUMN " + ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER " +
|
|
|
" DEFAULT 0");
|
|
|
upgraded = true;
|
|
@@ -471,12 +514,12 @@ public class FileContentProvider extends ContentProvider {
|
|
|
Log_OC.i("SQL", "Entering in the #2 ADD in onUpgrade");
|
|
|
db.beginTransaction();
|
|
|
try {
|
|
|
- db.execSQL("ALTER TABLE " + ProviderTableMeta.DB_NAME +
|
|
|
+ db.execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
|
|
|
" ADD COLUMN " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " INTEGER " +
|
|
|
" DEFAULT 0");
|
|
|
|
|
|
// assume there are not local changes pending to upload
|
|
|
- db.execSQL("UPDATE " + ProviderTableMeta.DB_NAME +
|
|
|
+ db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME +
|
|
|
" SET " + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " = " + System.currentTimeMillis() +
|
|
|
" WHERE " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL");
|
|
|
|
|
@@ -490,11 +533,11 @@ public class FileContentProvider extends ContentProvider {
|
|
|
Log_OC.i("SQL", "Entering in the #3 ADD in onUpgrade");
|
|
|
db.beginTransaction();
|
|
|
try {
|
|
|
- db .execSQL("ALTER TABLE " + ProviderTableMeta.DB_NAME +
|
|
|
+ db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
|
|
|
" ADD COLUMN " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " INTEGER " +
|
|
|
" DEFAULT 0");
|
|
|
|
|
|
- db.execSQL("UPDATE " + ProviderTableMeta.DB_NAME +
|
|
|
+ db.execSQL("UPDATE " + ProviderTableMeta.FILE_TABLE_NAME +
|
|
|
" SET " + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " = " + ProviderTableMeta.FILE_MODIFIED +
|
|
|
" WHERE " + ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL");
|
|
|
|
|
@@ -511,7 +554,7 @@ public class FileContentProvider extends ContentProvider {
|
|
|
Log_OC.i("SQL", "Entering in the #4 ADD in onUpgrade");
|
|
|
db.beginTransaction();
|
|
|
try {
|
|
|
- db .execSQL("ALTER TABLE " + ProviderTableMeta.DB_NAME +
|
|
|
+ db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
|
|
|
" ADD COLUMN " + ProviderTableMeta.FILE_ETAG + " TEXT " +
|
|
|
" DEFAULT NULL");
|
|
|
|
|
@@ -528,14 +571,32 @@ public class FileContentProvider extends ContentProvider {
|
|
|
Log_OC.i("SQL", "Entering in the #5 ADD in onUpgrade");
|
|
|
db.beginTransaction();
|
|
|
try {
|
|
|
- db .execSQL("ALTER TABLE " + ProviderTableMeta.DB_NAME +
|
|
|
+ db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
|
|
|
" ADD COLUMN " + ProviderTableMeta.FILE_SHARE_BY_LINK + " INTEGER " +
|
|
|
" DEFAULT 0");
|
|
|
|
|
|
- db .execSQL("ALTER TABLE " + ProviderTableMeta.DB_NAME +
|
|
|
+ db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
|
|
|
" ADD COLUMN " + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT " +
|
|
|
" DEFAULT NULL");
|
|
|
|
|
|
+ // Create table ocshares
|
|
|
+ db.execSQL("CREATE TABLE " + ProviderTableMeta.OCSHARES_TABLE_NAME + "("
|
|
|
+ + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, "
|
|
|
+ + ProviderTableMeta.OCSHARES_FILE_SOURCE + " INTEGER, "
|
|
|
+ + ProviderTableMeta.OCSHARES_ITEM_SOURCE + " INTEGER, "
|
|
|
+ + ProviderTableMeta.OCSHARES_SHARE_TYPE + " INTEGER, "
|
|
|
+ + ProviderTableMeta.OCSHARES_SHARE_WITH + " TEXT, "
|
|
|
+ + ProviderTableMeta.OCSHARES_PATH + " TEXT, "
|
|
|
+ + ProviderTableMeta.OCSHARES_PERMISSIONS+ " INTEGER, "
|
|
|
+ + ProviderTableMeta.OCSHARES_SHARED_DATE + " INTEGER, "
|
|
|
+ + ProviderTableMeta.OCSHARES_EXPIRATION_DATE + " INTEGER, "
|
|
|
+ + ProviderTableMeta.OCSHARES_TOKEN + " TEXT, "
|
|
|
+ + ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME + " TEXT, "
|
|
|
+ + ProviderTableMeta.OCSHARES_IS_DIRECTORY + " INTEGER, " // boolean
|
|
|
+ + ProviderTableMeta.OCSHARES_USER_ID + " INTEGER, "
|
|
|
+ + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + " INTEGER );"
|
|
|
+ );
|
|
|
+
|
|
|
upgraded = true;
|
|
|
db.setTransactionSuccessful();
|
|
|
} finally {
|