Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7aca4495 authored by Vincent Bourgmayer's avatar Vincent Bourgmayer
Browse files

Improve SyncedFolderDAO

Remove useless access  modifier (public | private)
Rewrite getSyncedFolderByLocalPath(String) to avoid usage of escaped double quotes
parent ada1d3a7
Loading
Loading
Loading
Loading
Loading
+15 −14
Original line number Diff line number Diff line
@@ -35,13 +35,12 @@ import com.owncloud.android.lib.resources.files.FileUtils;

/**
 * @author Vincent Bourgmayer
 * //todo put consistency in method's visibility
 * Source: https://vogella.developpez.com/tutoriels/android/utilisation-base-donnees-sqlite/
 */
class SyncedFolderDAO {
/* package */ class SyncedFolderDAO {
    private SQLiteDatabase mDB;
    private final DbHelper mHelper;
    private final String[] allColumns = { SyncedFolderContract._ID,
    private static final String[] allColumns = { SyncedFolderContract._ID,
        CATEGORIE_LABEL,
        LOCAL_PATH,
        REMOTE_PATH,
@@ -53,7 +52,7 @@ class SyncedFolderDAO {
        IS_MEDIA_TYPE
    };

    SyncedFolderDAO(Context context){
    /* package */ SyncedFolderDAO(Context context){
        Timber.tag(SyncedFolderDAO.class.getSimpleName());
        this.mHelper = new DbHelper(context);
    }
@@ -63,14 +62,14 @@ class SyncedFolderDAO {
     * @param writeMod Connexion mod. If set to true, database is open in writable mod, else it is opened in read mod.
     * @throws SQLException SqlException
     */
    void open(Boolean writeMod) throws SQLException {
    /* package */ void open(Boolean writeMod) throws SQLException {
        mDB = (writeMod)? mHelper.getWritableDatabase() : mHelper.getReadableDatabase();
    }

    /**
     * Close Database connexion
     */
    void close() {
    /* package */ void close() {
        mHelper.close();
    }

@@ -98,7 +97,7 @@ class SyncedFolderDAO {
    * @param syncedFolder element to register
    * @return Id of the last inserted value
    */
    long insert(SyncedFolder syncedFolder){
    /* package */ long insert(SyncedFolder syncedFolder){
        return mDB.insertWithOnConflict(TABLE_NAME,
                null,
                toContentValues(syncedFolder), SQLiteDatabase.CONFLICT_IGNORE);
@@ -108,7 +107,7 @@ class SyncedFolderDAO {
     * Delete all syncedFolder with the same categorie's label
     * @param id syncedFolder's id
     */
    public int delete(long id) {
    /* package */ int delete(long id) {
        return mDB.delete(TABLE_NAME, SyncedFolderContract._ID
                + " = " + id, null);
    }
@@ -118,7 +117,7 @@ class SyncedFolderDAO {
     * @param syncedFolder syncedFolder to update
     * @return Number of row affected
     */
    public int update(SyncedFolder syncedFolder){
    /* package */ int update(SyncedFolder syncedFolder){
       return mDB.update(TABLE_NAME,
                toContentValues(syncedFolder),
                SyncedFolderContract._ID+" = "+ syncedFolder.getId(),
@@ -131,8 +130,8 @@ class SyncedFolderDAO {
    * todo rewrite this method and at least its description because it's not clear...
    * @return List of all syncedFolder
    */
    List<SyncedFolder> getSyncedFolderList(String selection, String[] args) {
        final List<SyncedFolder> syncedFolders = new ArrayList<SyncedFolder>();
    /* package */ List<SyncedFolder> getSyncedFolderList(String selection, String[] args) {
        final List<SyncedFolder> syncedFolders = new ArrayList<>();
        final Cursor cursor = mDB.query(TABLE_NAME, allColumns, selection,args, null, null,
                null);

@@ -157,7 +156,7 @@ class SyncedFolderDAO {
     * @param syncFolderID id of the synced folder to update
     * @return number of row affected
     */
    int reduceLastModifiedValue(int syncFolderID) {
    /* package */ int reduceLastModifiedValue(int syncFolderID) {
        final ContentValues values = new ContentValues();
        values.put( LOCAL_LAST_MODIFIED, 1 );

@@ -166,8 +165,10 @@ class SyncedFolderDAO {
                    null);
    }

    SyncedFolder getSyncedFolderByLocalPath(String localPath){
        final Cursor cursor = mDB.query(TABLE_NAME, allColumns, LOCAL_PATH + " like \"" + localPath + FileUtils.PATH_SEPARATOR + "\"", new String[0], null, null, null);
    /* package */ SyncedFolder getSyncedFolderByLocalPath(String localPath){
        final String whereClause = LOCAL_PATH + " LIKE ?";
        final String[] whereValue = new String[] { localPath + FileUtils.PATH_SEPARATOR };
        final Cursor cursor = mDB.query(TABLE_NAME, allColumns, whereClause, whereValue, null, null, null);
        cursor.moveToFirst();
        SyncedFolder result = null;
        if (!cursor.isAfterLast()) {