OSDN Git Service

T29084
authorYuji Konishi <yuji.k64613@gmail.com>
Sat, 28 Jul 2012 09:07:19 +0000 (18:07 +0900)
committerYuji Konishi <yuji.k64613@gmail.com>
Sat, 28 Jul 2012 09:07:19 +0000 (18:07 +0900)
source/workspace/EverFolder/src/com/yuji/ef/EverFolderActivity.java
source/workspace/EverFolder/src/com/yuji/ef/Initialize.java
source/workspace/EverFolder/src/com/yuji/ef/dao/BookDao.java
source/workspace/EverFolder/src/com/yuji/ef/dao/DatabaseHelper.java
source/workspace/EverFolder/src/com/yuji/ef/dao/NodeDao.java
source/workspace/EverFolder/src/com/yuji/ef/utility/FolderUtil.java

index 5ffd700..3ee2e68 100644 (file)
@@ -337,14 +337,24 @@ public class EverFolderActivity extends BaseActivity {
 
                // TODO DBへのアクセス
                // sp.remove(src.getId());
-               dao.remoteChildrenId(sp, src.getId());
-               if (dst instanceof DirNode) {
-                       // dst.add(src.getId());
-                       dao.addChildrenId(dst, src.getId());
-               } else if (dst instanceof FileNode) {
-                       // dp.add(src.getId());
-                       dao.addChildrenId(dp, src.getId());
-               }
+               SQLiteDatabase db = DatabaseHelper.getInstance().getSQLiteDatabase();
+               db.beginTransaction();
+               try {
+                       dao.remoteChildrenIdNT(sp, src.getId());
+                       if (dst instanceof DirNode) {
+                               // dst.add(src.getId());
+                               dao.updateParentNT(src, dst.getId());
+                               dao.addChildrenIdNT(dst, src.getId());
+                       } else if (dst instanceof FileNode) {
+                               // dp.add(src.getId());
+                               dao.updateParentNT(src, dst.getId());
+                               dao.addChildrenIdNT(dp, src.getId());
+                       }
+
+                       db.setTransactionSuccessful();
+               } finally {
+                       db.endTransaction();
+               }               
 
                updateList();
        }
index bb80e3d..7271349 100644 (file)
@@ -12,11 +12,15 @@ public class Initialize {
                if (!isInit) {
                        return;
                }
-               
-               EvernoteUtil util = EvernoteUtil.getInstance();
-               util.setConfig("yuji-k64613", "TODO");
-               DatabaseHelper.init(context);
-               
+
+               try {
+                       EvernoteUtil util = EvernoteUtil.getInstance();
+                       util.setConfig("yuji-k64613", "TODO");
+                       DatabaseHelper.init(context);
+               } catch (Exception e) {
+                       // TODO
+                       e.printStackTrace();
+               }
                isInit = false;
        }
 }
index 59b111a..067c502 100644 (file)
@@ -33,7 +33,7 @@ public class BookDao implements IDao<Book> {
                db.execSQL("CREATE TABLE BOOK (" + android.provider.BaseColumns._ID
                                + " INTEGER PRIMARY KEY AUTOINCREMENT," + "TYPE INTEGER,"
                                + "GUID TEXT," + "NID INTEGER," + "NAME TEXT" + ");");
-               
+
                // TODO
                // CREATE INDEX インデックス名 ON テーブル名(カラム名1, カラム名2, ...);
        }
@@ -51,13 +51,6 @@ public class BookDao implements IDao<Book> {
 
        }
 
-       // TODO 共通
-       public SQLiteDatabase getSQLiteDatabase() {
-               DatabaseHelper helper = DatabaseHelper.getInstance();
-               SQLiteDatabase db = helper.getWritableDatabase();
-               return db;
-       }
-
        public List<Book> search() {
                return search(null, null, null);
        }
@@ -90,11 +83,12 @@ public class BookDao implements IDao<Book> {
 
        private List<Book> search(String selection, String[] selectionArgs,
                        String orderBy) {
-               return search(getSQLiteDatabase(), selection, selectionArgs, orderBy);
+               return search(DatabaseHelper.getInstance().getSQLiteDatabase(),
+                               selection, selectionArgs, orderBy);
        }
-       
-       private List<Book> search(SQLiteDatabase db, String selection, String[] selectionArgs,
-                       String orderBy) {
+
+       private List<Book> search(SQLiteDatabase db, String selection,
+                       String[] selectionArgs, String orderBy) {
                List<Book> list = new ArrayList<Book>();
                Cursor cursor = null;
                try {
@@ -130,7 +124,7 @@ public class BookDao implements IDao<Book> {
        }
 
        public long add(Book book) {
-               return add(getSQLiteDatabase(), book);
+               return add(DatabaseHelper.getInstance().getSQLiteDatabase(), book);
        }
 
        private long add(SQLiteDatabase db, Book book) {
@@ -156,12 +150,13 @@ public class BookDao implements IDao<Book> {
                return id;
        }
 
-       public long delete(long id){
-               return delete(getSQLiteDatabase(), id);         
+       public long delete(long id) {
+               return delete(DatabaseHelper.getInstance().getSQLiteDatabase(), id);
        }
 
        public long updateName(Book book, String name) {
-               return updateName(getSQLiteDatabase(), book, name);
+               return updateName(DatabaseHelper.getInstance().getSQLiteDatabase(),
+                               book, name);
        }
 
        public long updateName(SQLiteDatabase db, Book book, String name) {
@@ -188,10 +183,9 @@ public class BookDao implements IDao<Book> {
                return id;
        }
 
-
-       public long delete(SQLiteDatabase db, long did){
+       public long delete(SQLiteDatabase db, long did) {
                long id = -1;
-               
+
                db.beginTransaction();
                try {
                        id = deleteNT(did);
@@ -201,11 +195,11 @@ public class BookDao implements IDao<Book> {
                }
                return id;
        }
-       
+
        public long deleteNT(long did) {
                long id = -1; // TODO
                int i = 1;
-               
+
                SQLiteStatement stmt = deleteIdStmt;
                stmt.bindLong(i++, did);
                stmt.execute();
index 725e2d7..12bd949 100644 (file)
@@ -65,4 +65,9 @@ public class DatabaseHelper extends SQLiteOpenHelper {
 
        }
 
+       public SQLiteDatabase getSQLiteDatabase() {
+               DatabaseHelper helper = DatabaseHelper.getInstance();
+               SQLiteDatabase db = helper.getWritableDatabase();
+               return db;
+       }       
 }
index e987701..eef316f 100644 (file)
@@ -51,9 +51,8 @@ public class NodeDao implements IDao<Node> {
                updateStatusStmt = db
                                .compileStatement("UPDATE Node SET STATUS = ? WHERE "
                                                + android.provider.BaseColumns._ID + " = ?");
-               updateNameStmt = db
-                               .compileStatement("UPDATE Node SET NAME = ? WHERE "
-                                               + android.provider.BaseColumns._ID + " = ?");
+               updateNameStmt = db.compileStatement("UPDATE Node SET NAME = ? WHERE "
+                               + android.provider.BaseColumns._ID + " = ?");
                updateParentStmt = db
                                .compileStatement("UPDATE Node SET PARENT = ? WHERE "
                                                + android.provider.BaseColumns._ID + " = ?");
@@ -146,20 +145,15 @@ public class NodeDao implements IDao<Node> {
                // top.add(node.getId());
        }
 
-       public SQLiteDatabase getSQLiteDatabase() {
-               DatabaseHelper helper = DatabaseHelper.getInstance();
-               SQLiteDatabase db = helper.getWritableDatabase();
-               return db;
-       }
-
        public List<Node> search() {
-               return search(getSQLiteDatabase(), null, null, null);
+               return search(DatabaseHelper.getInstance().getSQLiteDatabase(), null,
+                               null, null);
        }
 
        public Node searchRoot() {
-               return searchRoot(getSQLiteDatabase());
+               return searchRoot(DatabaseHelper.getInstance().getSQLiteDatabase());
        }
-       
+
        public Node searchRoot(SQLiteDatabase db) {
                String selection = "TYPE = ?";
                String[] selectionArgs = { "0" };
@@ -172,9 +166,9 @@ public class NodeDao implements IDao<Node> {
        }
 
        public Node searchById(long id) {
-               return searchById(getSQLiteDatabase(), id);
+               return searchById(DatabaseHelper.getInstance().getSQLiteDatabase(), id);
        }
-       
+
        public Node searchById(SQLiteDatabase db, long id) {
                String selection = android.provider.BaseColumns._ID + " = ?";
                String[] selectionArgs = { String.valueOf(id) };
@@ -197,8 +191,8 @@ public class NodeDao implements IDao<Node> {
                return list.get(0);
        }
 
-       private List<Node> search(SQLiteDatabase db, String selection, String[] selectionArgs,
-                       String orderBy) {
+       private List<Node> search(SQLiteDatabase db, String selection,
+                       String[] selectionArgs, String orderBy) {
                List<Node> list = new ArrayList<Node>();
                Cursor cursor = null;
                try {
@@ -344,7 +338,8 @@ public class NodeDao implements IDao<Node> {
        }
 
        public long updateStatus(Node node, Node.Status status) {
-               return updateStatus(getSQLiteDatabase(), node, status);
+               return updateStatus(DatabaseHelper.getInstance().getSQLiteDatabase(),
+                               node, status);
        }
 
        public long updateStatus(SQLiteDatabase db, Node node, Node.Status status) {
@@ -373,7 +368,8 @@ public class NodeDao implements IDao<Node> {
        }
 
        public long updateName(Node node, String name) {
-               return updateName(getSQLiteDatabase(), node, name);
+               return updateName(DatabaseHelper.getInstance().getSQLiteDatabase(),
+                               node, name);
        }
 
        public long updateName(SQLiteDatabase db, Node node, String name) {
@@ -400,6 +396,24 @@ public class NodeDao implements IDao<Node> {
                return id;
        }
 
+       public long updateParent(Node node, long parent) {
+               return updateParent(DatabaseHelper.getInstance().getSQLiteDatabase(),
+                               node, parent);
+       }
+
+       public long updateParent(SQLiteDatabase db, Node node, long parent) {
+               long id = -1;
+
+               db.beginTransaction();
+               try {
+                       id = updateParentNT(node, parent);
+                       db.setTransactionSuccessful();
+               } finally {
+                       db.endTransaction();
+               }
+               return id;
+       }
+
        public long updateParentNT(Node node, long parent) {
                long id = -1;
                int i = 1;
index e38582d..163901b 100644 (file)
@@ -8,6 +8,7 @@ import android.database.sqlite.SQLiteDatabase;
 import com.evernote.edam.notestore.NoteList;
 import com.evernote.edam.type.Note;
 import com.evernote.edam.type.Notebook;
+import com.yuji.ef.common.CommonUtil;
 import com.yuji.ef.dao.Book;
 import com.yuji.ef.dao.BookDao;
 import com.yuji.ef.dao.DatabaseHelper;
@@ -42,10 +43,10 @@ public class FolderUtil {
                // nodeDao.delete(db);
 
                // ROOT
-               Node node;
-               Node n;
+//             Node node;
+//             Node n;
+//             String guid;
                long id;
-               String guid;
 
                Node top = new RootNode("", null);
                id = nodeDao.addNT(top);
@@ -54,35 +55,34 @@ public class FolderUtil {
                updateNotebook(db);
 
                // TODO
-               // updateNote(db); に変更
-               
-               List<Book> noteBookList = bookDao.search(db);
-               HashMap<String, Node> map = new HashMap<String, Node>();
-               for (Book noteBook : noteBookList) {
-                       guid = noteBook.getGuid();
-                       DirNode dirNode = (DirNode) nodeDao.searchById(db,
-                                       noteBook.getNId());
-                       if (dirNode == null) {
-                               // TODO
-                       }
-                       map.put(guid, dirNode);
-               }
-
-               List<NoteList> noteListList = util.getNoteList();
-               for (NoteList noteList : noteListList) {
-                       List<Note> notes = noteList.getNotes();
-                       for (Note note : notes) {
-                               String name = note.getTitle();
-                               guid = note.getNotebookGuid();
-
-                               node = map.get(guid);
-                               if (node != null) {
-                                       n = new FileNode(name, null);
-                                       n.setGuid(note.getGuid());
-                                       addFileNodeNT(node, n);
-                               }
-                       }
-               }
+               updateNote(db);
+//             List<Book> noteBookList = bookDao.search(db);
+//             HashMap<String, Node> map = new HashMap<String, Node>();
+//             for (Book noteBook : noteBookList) {
+//                     guid = noteBook.getGuid();
+//                     DirNode dirNode = (DirNode) nodeDao.searchById(db,
+//                                     noteBook.getNId());
+//                     if (dirNode == null) {
+//                             // TODO
+//                     }
+//                     map.put(guid, dirNode);
+//             }
+//
+//             List<NoteList> noteListList = util.getNoteList();
+//             for (NoteList noteList : noteListList) {
+//                     List<Note> notes = noteList.getNotes();
+//                     for (Note note : notes) {
+//                             String name = note.getTitle();
+//                             guid = note.getNotebookGuid();
+//
+//                             node = map.get(guid);
+//                             if (node != null) {
+//                                     n = new FileNode(name, null);
+//                                     n.setGuid(note.getGuid());
+//                                     addFileNodeNT(node, n);
+//                             }
+//                     }
+//             }
        }
 
        public void updateNotebook(SQLiteDatabase db) {
@@ -155,7 +155,7 @@ public class FolderUtil {
                                        }
 
                                        String pGuid = oldParent.getGuid();
-                                       if (!pGuid.equals(nbGuid)) {
+                                       if (!CommonUtil.isNull(pGuid) && !pGuid.equals(nbGuid)) {
                                                // 親が異なる
                                                DirNode parent = (DirNode)nodeDao.searchByGuid(db, nbGuid);
                                                if (parent == null) {