Add column 'Remote_Id' to the local files db. Create upgrade for 'Permissions' and 'Remote_id' db changes.

This commit is contained in:
jabarros 2014-06-23 14:49:52 +02:00 committed by David A. Velasco
parent 80f6250604
commit 8a1e3f743e
6 changed files with 47 additions and 6 deletions

View file

@ -187,6 +187,7 @@ public class FileDataStorageManager {
cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, file.isShareByLink() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
boolean sameRemotePath = fileExists(file.getRemotePath());
if (sameRemotePath ||
@ -287,6 +288,7 @@ public class FileDataStorageManager {
cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, file.isShareByLink() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
boolean existsByPath = fileExists(file.getRemotePath());
if (existsByPath || fileExists(file.getFileId())) {
@ -345,6 +347,7 @@ public class FileDataStorageManager {
cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, folder.isShareByLink() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, folder.getPublicLink());
cv.put(ProviderTableMeta.FILE_PERMISSIONS, folder.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, folder.getRemoteId());
operations.add(ContentProviderOperation.newUpdate(ProviderTableMeta.CONTENT_URI).
withValues(cv).
@ -754,6 +757,7 @@ public class FileDataStorageManager {
c.getColumnIndex(ProviderTableMeta.FILE_SHARE_BY_LINK)) == 1 ? true : false);
file.setPublicLink(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PUBLIC_LINK)));
file.setPermissions(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_PERMISSIONS)));
file.setRemoteId(c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID)));
}
return file;
@ -1097,6 +1101,7 @@ public class FileDataStorageManager {
cv.put(ProviderTableMeta.FILE_SHARE_BY_LINK, file.isShareByLink() ? 1 : 0);
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, file.getPublicLink());
cv.put(ProviderTableMeta.FILE_PERMISSIONS, file.getPermissions());
cv.put(ProviderTableMeta.FILE_REMOTE_ID, file.getRemoteId());
boolean existsByPath = fileExists(file.getRemotePath());
if (existsByPath || fileExists(file.getFileId())) {

View file

@ -66,6 +66,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
private String mPublicLink;
private String mPermissions;
private String mRemoteId;
/**
@ -107,6 +108,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
mShareByLink = source.readInt() == 1;
mPublicLink = source.readString();
mPermissions = source.readString();
mRemoteId = source.readString();
}
@Override
@ -128,6 +130,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
dest.writeInt(mShareByLink ? 1 : 0);
dest.writeString(mPublicLink);
dest.writeString(mPermissions);
dest.writeString(mRemoteId);
}
/**
@ -339,6 +342,7 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
mShareByLink = false;
mPublicLink = null;
mPermissions = null;
mRemoteId = null;
}
/**
@ -531,4 +535,12 @@ public class OCFile implements Parcelable, Comparable<OCFile> {
this.mPermissions = permissions;
}
public String getRemoteId() {
return mRemoteId;
}
public void setRemoteId(String remoteId) {
this.mRemoteId = remoteId;
}
}

View file

@ -69,6 +69,7 @@ public class ProviderMeta {
public static final String FILE_SHARE_BY_LINK = "share_by_link";
public static final String FILE_PUBLIC_LINK = "public_link";
public static final String FILE_PERMISSIONS = "permissions";
public static final String FILE_REMOTE_ID = "remote_id";
public static final String FILE_DEFAULT_SORT_ORDER = FILE_NAME
+ " collate nocase asc";

View file

@ -417,6 +417,7 @@ public class SynchronizeFolderOperation extends RemoteOperation {
file.setModificationTimestamp(remote.getModifiedTimestamp());
file.setEtag(remote.getEtag());
file.setPermissions(remote.getPermissions());
file.setRemoteId(remote.getRemoteId());
return file;
}

View file

@ -95,6 +95,8 @@ public class FileContentProvider extends ContentProvider {
ProviderTableMeta.FILE_PUBLIC_LINK);
mFileProjectionMap.put(ProviderTableMeta.FILE_PERMISSIONS,
ProviderTableMeta.FILE_PERMISSIONS);
mFileProjectionMap.put(ProviderTableMeta.FILE_REMOTE_ID,
ProviderTableMeta.FILE_REMOTE_ID);
}
private static final int SINGLE_FILE = 1;
@ -557,7 +559,8 @@ public class FileContentProvider extends ContentProvider {
+ ProviderTableMeta.FILE_ETAG + " TEXT, "
+ ProviderTableMeta.FILE_SHARE_BY_LINK + " INTEGER, "
+ ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT, "
+ ProviderTableMeta.FILE_PERMISSIONS + " TEXT null);"
+ ProviderTableMeta.FILE_PERMISSIONS + " TEXT null,"
+ ProviderTableMeta.FILE_REMOTE_ID + " TEXT null);"
);
// Create table ocshares
@ -646,7 +649,7 @@ public class FileContentProvider extends ContentProvider {
}
if (!upgraded)
Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion);
if (oldVersion < 6 && newVersion >= 6) {
Log_OC.i("SQL", "Entering in the #5 ADD in onUpgrade");
db.beginTransaction();
@ -658,10 +661,6 @@ public class FileContentProvider extends ContentProvider {
db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
" ADD COLUMN " + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT " +
" DEFAULT NULL");
db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
" ADD COLUMN " + ProviderTableMeta.FILE_PERMISSIONS + " TEXT " +
" DEFAULT NULL");
// Create table ocshares
db.execSQL("CREATE TABLE " + ProviderTableMeta.OCSHARES_TABLE_NAME + "("
@ -680,6 +679,27 @@ public class FileContentProvider extends ContentProvider {
+ ProviderTableMeta.OCSHARES_USER_ID + " INTEGER, "
+ ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + " INTEGER,"
+ ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " TEXT );" );
upgraded = true;
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
if (!upgraded)
Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion);
if (oldVersion < 7 && newVersion >= 7) {
Log_OC.i("SQL", "Entering in the #6 ADD in onUpgrade");
db.beginTransaction();
try {
db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_TABLE_NAME +
" ADD COLUMN " + ProviderTableMeta.FILE_PERMISSIONS + " TEXT " +
" DEFAULT NULL");
db .execSQL("ALTER TABLE " + ProviderTableMeta.FILE_REMOTE_ID +
" ADD COLUMN " + ProviderTableMeta.FILE_REMOTE_ID + " TEXT " +
" DEFAULT NULL");
upgraded = true;
db.setTransactionSuccessful();

View file

@ -98,6 +98,7 @@ public class FileStorageUtils {
file.setModificationTimestamp(remote.getModifiedTimestamp());
file.setEtag(remote.getEtag());
file.setPermissions(remote.getPermissions());
file.setRemoteId(remote.getRemoteId());
return file;
}
@ -115,6 +116,7 @@ public class FileStorageUtils {
file.setModifiedTimestamp(ocFile.getModificationTimestamp());
file.setEtag(ocFile.getEtag());
file.setPermissions(ocFile.getPermissions());
file.setRemoteId(ocFile.getRemoteId());
return file;
}