OSDN Git Service

T29015
authorYuji Konishi <yuji.k64613@gmail.com>
Mon, 16 Jul 2012 08:54:03 +0000 (17:54 +0900)
committerYuji Konishi <yuji.k64613@gmail.com>
Mon, 16 Jul 2012 08:54:03 +0000 (17:54 +0900)
source/workspace/EverFolder/.classpath
source/workspace/EverFolder/gen/com/yuji/ef/BuildConfig.java [deleted file]
source/workspace/EverFolder/src/com/yuji/ef/EverFolderActivity.java
source/workspace/EverFolder/src/com/yuji/ef/dao/Book.java [new file with mode: 0644]
source/workspace/EverFolder/src/com/yuji/ef/dao/BookDao.java [new file with mode: 0644]
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 6aed2eb..e9e83f6 100644 (file)
@@ -4,5 +4,10 @@
        <classpathentry kind="src" path="gen"/>
        <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
        <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+       <classpathentry kind="lib" path="libs/evernote-api-1.21.jar"/>
+       <classpathentry kind="lib" path="libs/evernote-client-android.jar"/>
+       <classpathentry kind="lib" path="libs/libthrift.jar"/>
+       <classpathentry kind="lib" path="libs/scribe-1.3.0.jar"/>
+       <classpathentry kind="lib" path="libs/slf4j-android-1.5.8.jar"/>
        <classpathentry kind="output" path="bin/classes"/>
 </classpath>
diff --git a/source/workspace/EverFolder/gen/com/yuji/ef/BuildConfig.java b/source/workspace/EverFolder/gen/com/yuji/ef/BuildConfig.java
deleted file mode 100644 (file)
index 3ff9469..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-/** Automatically generated file. DO NOT MODIFY */
-package com.yuji.ef;
-
-public final class BuildConfig {
-    public final static boolean DEBUG = true;
-}
\ No newline at end of file
index 14de4e2..ad4d440 100644 (file)
@@ -4,6 +4,7 @@ import java.util.List;
 
 import android.content.Intent;
 import android.content.res.Resources;
+import android.database.sqlite.SQLiteDatabase;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.graphics.PixelFormat;
@@ -16,8 +17,10 @@ import android.view.View.OnClickListener;
 import android.view.WindowManager;
 import android.widget.Button;
 
+import com.yuji.ef.dao.DatabaseHelper;
 import com.yuji.ef.dao.DirNode;
 import com.yuji.ef.dao.FileNode;
+import com.yuji.ef.dao.IDao;
 import com.yuji.ef.dao.Node;
 import com.yuji.ef.dao.Node.Status;
 import com.yuji.ef.dao.NodeDao;
@@ -101,6 +104,7 @@ public class EverFolderActivity extends BaseActivity {
                try {
                        switch (item.getItemId()) {
                        case Menu.FIRST:
+                               dummy();
                                break;
                        case Menu.FIRST + 1:
                                intent = new Intent(this, (Class<?>) SettingActivity.class);
@@ -115,6 +119,29 @@ public class EverFolderActivity extends BaseActivity {
                return super.onOptionsItemSelected(item);
        }
 
+       private void dummy(){
+               try {
+                       FolderUtil util = FolderUtil.getInstance();
+                       
+                       DatabaseHelper helper = DatabaseHelper.getInstance();
+                       SQLiteDatabase db = helper.getWritableDatabase();
+                       
+                       db.beginTransaction();
+                       try {
+                               util.updateNotebook(db);
+                               
+                               db.setTransactionSuccessful();
+                       } finally {
+                               db.endTransaction();
+                       }                       
+                       updateList();
+                       setStatus();
+               }
+               catch (Exception e){
+                       e.printStackTrace();
+               }
+       }
+       
        private void updateList() {
                NodeDao dao = (NodeDao) NodeDao.getInstance();
                top = dao.searchRoot();
diff --git a/source/workspace/EverFolder/src/com/yuji/ef/dao/Book.java b/source/workspace/EverFolder/src/com/yuji/ef/dao/Book.java
new file mode 100644 (file)
index 0000000..4885852
--- /dev/null
@@ -0,0 +1,35 @@
+package com.yuji.ef.dao;
+
+public class Book {
+       private long id;
+       private long nid;
+       private String guid;
+       private String name;
+       
+       public Book(long id, String guid, long nid, String name){
+               this.id = id;
+               this.guid = guid;
+               this.nid = nid;
+               this.name = name;
+       }
+       
+       public String getName() {
+               return name;
+       }
+
+       public void setName(String name) {
+               this.name = name;
+       }
+       
+       public long getId() {
+               return id;
+       }
+       
+       public String getGuid() {
+               return guid;
+       }
+
+       public long getNId() {
+               return nid;
+       }
+}
diff --git a/source/workspace/EverFolder/src/com/yuji/ef/dao/BookDao.java b/source/workspace/EverFolder/src/com/yuji/ef/dao/BookDao.java
new file mode 100644 (file)
index 0000000..59b111a
--- /dev/null
@@ -0,0 +1,214 @@
+package com.yuji.ef.dao;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.database.Cursor;
+import android.database.SQLException;
+import android.database.sqlite.SQLiteDatabase;
+import android.database.sqlite.SQLiteStatement;
+
+import com.yuji.ef.common.CommonUtil;
+import com.yuji.ef.utility.Debug;
+import com.yuji.ef.utility.FolderUtil;
+
+public class BookDao implements IDao<Book> {
+       private static IDao<Book> instance = null;
+       private SQLiteStatement insertStmt = null;
+       private SQLiteStatement updateStmt = null;
+       private SQLiteStatement deleteIdStmt = null;
+
+       public static IDao<Book> getInstance() {
+               if (instance == null) {
+                       instance = new BookDao();
+               }
+               return instance;
+       }
+
+       private BookDao() {
+
+       }
+
+       public void onCreate(SQLiteDatabase db) {
+               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, ...);
+       }
+
+       public void init(SQLiteDatabase db) {
+               insertStmt = db.compileStatement("INSERT INTO BOOK (" + "GUID,"
+                               + "NID," + "NAME" + ") VALUES (" + "?,?,?" + ");");
+               updateStmt = db.compileStatement("UPDATE BOOK SET NAME = ? WHERE "
+                               + android.provider.BaseColumns._ID + " = ?");
+               deleteIdStmt = db.compileStatement("DELETE FROM BOOK WHERE "
+                               + android.provider.BaseColumns._ID + " = ?");
+       }
+
+       public void start(SQLiteDatabase db) {
+
+       }
+
+       // TODO 共通
+       public SQLiteDatabase getSQLiteDatabase() {
+               DatabaseHelper helper = DatabaseHelper.getInstance();
+               SQLiteDatabase db = helper.getWritableDatabase();
+               return db;
+       }
+
+       public List<Book> search() {
+               return search(null, null, null);
+       }
+
+       public List<Book> search(SQLiteDatabase db) {
+               return search(db, null, null, null);
+       }
+
+       public Book searchById(long id) {
+               String selection = android.provider.BaseColumns._ID + " = ?";
+               String[] selectionArgs = { String.valueOf(id) };
+               String orderBy = null;
+               List<Book> list = search(selection, selectionArgs, orderBy);
+               if (list.size() <= 0) {
+                       return null;
+               }
+               return list.get(0);
+       }
+
+       public Book searchByGuid(SQLiteDatabase db, String guid) {
+               String selection = "GUID" + " = ?";
+               String[] selectionArgs = { guid };
+               String orderBy = null;
+               List<Book> list = search(db, selection, selectionArgs, orderBy);
+               if (list.size() <= 0) {
+                       return null;
+               }
+               return list.get(0);
+       }
+
+       private List<Book> search(String selection, String[] selectionArgs,
+                       String orderBy) {
+               return search(getSQLiteDatabase(), selection, selectionArgs, orderBy);
+       }
+       
+       private List<Book> search(SQLiteDatabase db, String selection, String[] selectionArgs,
+                       String orderBy) {
+               List<Book> list = new ArrayList<Book>();
+               Cursor cursor = null;
+               try {
+                       cursor = db.query("BOOK", new String[] {
+                                       android.provider.BaseColumns._ID, "GUID", "NID", "NAME" },
+                                       selection, selectionArgs, null, null, orderBy);
+                       cursor.moveToFirst();
+                       int size = cursor.getCount();
+                       for (int i = 0; i < size; i++) {
+                               Book book = new Book(cursor.getLong(0), cursor.getString(1),
+                                               cursor.getLong(2), cursor.getString(3));
+                               list.add(book);
+                               cursor.moveToNext();
+                       }
+               } catch (SQLException e) {
+                       Debug.d(this, null, e);
+                       list = null;
+               } catch (Exception e) {
+                       Debug.d(this, null, e);
+                       list = null;
+               } finally {
+                       if (cursor != null) {
+                               cursor.close();
+                               cursor = null;
+                       }
+               }
+               return list;
+       }
+
+       public boolean isEmpty() {
+               List<Book> list = search();
+               return list == null || list.size() <= 0;
+       }
+
+       public long add(Book book) {
+               return add(getSQLiteDatabase(), book);
+       }
+
+       private long add(SQLiteDatabase db, Book book) {
+               long id = -1;
+               db.beginTransaction();
+               try {
+                       id = addNT(book);
+                       db.setTransactionSuccessful();
+               } finally {
+                       db.endTransaction();
+               }
+               return id;
+       }
+
+       public long addNT(Book book) {
+               long id = -1;
+               int i = 1;
+               SQLiteStatement stmt = insertStmt;
+               stmt.bindString(i++, book.getGuid());
+               stmt.bindLong(i++, book.getNId());
+               stmt.bindString(i++, book.getName());
+               id = stmt.executeInsert();
+               return id;
+       }
+
+       public long delete(long id){
+               return delete(getSQLiteDatabase(), id);         
+       }
+
+       public long updateName(Book book, String name) {
+               return updateName(getSQLiteDatabase(), book, name);
+       }
+
+       public long updateName(SQLiteDatabase db, Book book, String name) {
+               long id = -1;
+
+               db.beginTransaction();
+               try {
+                       id = updateNameNT(book, name);
+                       db.setTransactionSuccessful();
+               } finally {
+                       db.endTransaction();
+               }
+               return id;
+       }
+
+       public long updateNameNT(Book book, String name) {
+               long id = -1;
+               int i = 1;
+
+               SQLiteStatement stmt = updateStmt;
+               stmt.bindString(i++, name);
+               stmt.bindLong(i++, book.getId());
+               id = stmt.executeInsert();
+               return id;
+       }
+
+
+       public long delete(SQLiteDatabase db, long did){
+               long id = -1;
+               
+               db.beginTransaction();
+               try {
+                       id = deleteNT(did);
+                       db.setTransactionSuccessful();
+               } finally {
+                       db.endTransaction();
+               }
+               return id;
+       }
+       
+       public long deleteNT(long did) {
+               long id = -1; // TODO
+               int i = 1;
+               
+               SQLiteStatement stmt = deleteIdStmt;
+               stmt.bindLong(i++, did);
+               stmt.execute();
+               return id;
+       }
+}
\ No newline at end of file
index 37f31e0..725e2d7 100644 (file)
@@ -23,6 +23,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
                }
                daoList = new ArrayList<IDao<?>>();
                daoList.add(NodeDao.getInstance());
+               daoList.add(BookDao.getInstance());
 
                DatabaseHelper helper = new DatabaseHelper(context);
                SQLiteDatabase db = helper.getWritableDatabase();
index 558731d..be18f95 100644 (file)
@@ -9,7 +9,6 @@ import android.database.sqlite.SQLiteDatabase;
 import android.database.sqlite.SQLiteStatement;
 
 import com.yuji.ef.common.CommonUtil;
-import com.yuji.ef.dao.Node.Status;
 import com.yuji.ef.utility.Debug;
 import com.yuji.ef.utility.FolderUtil;
 
@@ -19,6 +18,7 @@ public class NodeDao implements IDao<Node> {
        private SQLiteStatement insertStmt = null;
        private SQLiteStatement updateChildrenStmt = null;
        private SQLiteStatement updateStatusStmt = null;
+       private SQLiteStatement updateNameStmt = null;
        private SQLiteStatement deleteStmt = null;
        private SQLiteStatement deleteIdStmt = null;
 
@@ -42,21 +42,27 @@ public class NodeDao implements IDao<Node> {
 
        public void init(SQLiteDatabase db) {
                insertStmt = db.compileStatement("INSERT INTO Node (" + "TYPE,"
-                               + "GUID," + "PARENT," + "NAME," + "CHILDREN," + "STATUS" + ") VALUES ("
-                               + "?,?,?,?,?,?" + ");");
-               updateChildrenStmt = db.compileStatement("UPDATE Node SET CHILDREN = ? WHERE "
-                               + android.provider.BaseColumns._ID + " = ?");
-               updateStatusStmt = db.compileStatement("UPDATE Node SET STATUS = ? WHERE "
-                               + android.provider.BaseColumns._ID + " = ?");
+                               + "GUID," + "PARENT," + "NAME," + "CHILDREN," + "STATUS"
+                               + ") VALUES (" + "?,?,?,?,?,?" + ");");
+               updateChildrenStmt = db
+                               .compileStatement("UPDATE Node SET CHILDREN = ? WHERE "
+                                               + android.provider.BaseColumns._ID + " = ?");
+               updateStatusStmt = db
+                               .compileStatement("UPDATE Node SET STATUS = ? WHERE "
+                                               + android.provider.BaseColumns._ID + " = ?");
+               updateNameStmt = db
+                               .compileStatement("UPDATE Node SET NAME = ? WHERE "
+                                               + android.provider.BaseColumns._ID + " = ?");
                deleteStmt = db.compileStatement("DELETE FROM Node");
-               deleteIdStmt = db.compileStatement("DELETE FROM Node WHERE " + android.provider.BaseColumns._ID + " = ?");
+               deleteIdStmt = db.compileStatement("DELETE FROM Node WHERE "
+                               + android.provider.BaseColumns._ID + " = ?");
        }
 
        public void start(SQLiteDatabase db) {
                FolderUtil util = FolderUtil.getInstance();
                util.init(db);
        }
-       
+
        public void start2(SQLiteDatabase db) {
                // top = new DirNode(null, null);
                // top.setStatus(Node.Status.OPEN);
@@ -90,67 +96,71 @@ public class NodeDao implements IDao<Node> {
                id = addNT(node);
                node.setId(id);
                addChildrenIdNT(top, node.getId());
-               //top.add(node.getId());
+               // top.add(node.getId());
 
                // SUB
                n = new FileNode("ファイルaaa", null);
                n.setParent(node.getId());
                id = addNT(n);
                addChildrenIdNT(node, id);
-               //node.add(n.getId());
+               // node.add(n.getId());
                n = new FileNode("ファイルbb", null);
                n.setParent(node.getId());
                id = addNT(n);
                addChildrenIdNT(node, id);
-               //node.add(n.getId());
+               // node.add(n.getId());
                n = new FileNode("ファイルc", null);
                n.setParent(node.getId());
                id = addNT(n);
                addChildrenIdNT(node, id);
-               //node.add(n.getId());
+               // node.add(n.getId());
 
                // NODE
                node = new DirNode("ディレクトリAAA", null);
                node.setParent(top.getId());
                id = addNT(node);
                addChildrenIdNT(top, id);
-               //top.add(node.getId());
+               // top.add(node.getId());
 
                // SUB
                n = new DirNode("ディレクトリ", null);
                n.setParent(node.getId());
                id = addNT(n);
                addChildrenIdNT(node, id);
-               //node.add(n.getId());
+               // node.add(n.getId());
                n = new FileNode("yyyファイル", null);
                n.setParent(node.getId());
                id = addNT(n);
                addChildrenIdNT(node, id);
-               //node.add(n.getId());
+               // node.add(n.getId());
 
                // NODE
                node = new FileNode("ファイルあいうえお", null);
                node.setParent(top.getId());
                id = addNT(node);
                addChildrenIdNT(top, id);
-               //top.add(node.getId());
+               // top.add(node.getId());
        }
 
-       public SQLiteDatabase getSQLiteDatabase(){
+       public SQLiteDatabase getSQLiteDatabase() {
                DatabaseHelper helper = DatabaseHelper.getInstance();
                SQLiteDatabase db = helper.getWritableDatabase();
-               return db;      
+               return db;
        }
-       
+
        public List<Node> search() {
-               return search(null, null, null);
+               return search(getSQLiteDatabase(), null, null, null);
        }
 
        public Node searchRoot() {
+               return searchRoot(getSQLiteDatabase());
+       }
+       
+       public Node searchRoot(SQLiteDatabase db) {
                String selection = "TYPE = ?";
                String[] selectionArgs = { "0" };
                String orderBy = null;
-               List<Node> list = search(selection, selectionArgs, orderBy);
+               List<Node> list = search(db, selection, selectionArgs, orderBy);
                if (list.size() <= 0) {
                        return null;
                }
@@ -158,30 +168,31 @@ public class NodeDao implements IDao<Node> {
        }
 
        public Node searchById(long id) {
+               return searchById(getSQLiteDatabase(), id);
+       }
+       
+       public Node searchById(SQLiteDatabase db, long id) {
                String selection = android.provider.BaseColumns._ID + " = ?";
                String[] selectionArgs = { String.valueOf(id) };
                String orderBy = null;
-               List<Node> list = search(selection, selectionArgs, orderBy);
+               List<Node> list = search(db, selection, selectionArgs, orderBy);
                if (list.size() <= 0) {
                        return null;
                }
                return list.get(0);
        }
 
-       private List<Node> search(String selection, String[] selectionArgs,
+       private List<Node> search(SQLiteDatabase db, String selection, String[] selectionArgs,
                        String orderBy) {
                List<Node> list = new ArrayList<Node>();
                Cursor cursor = null;
                try {
-                       DatabaseHelper helper = DatabaseHelper.getInstance();
-                       SQLiteDatabase db = helper.getReadableDatabase();
-
                        NodeFactory factory = NodeFactory.getInstance();
 
                        cursor = db.query("Node", new String[] {
                                        android.provider.BaseColumns._ID, "TYPE", "GUID", "PARENT",
-                                       "NAME", "CHILDREN", "STATUS" }, selection, selectionArgs, null, null,
-                                       orderBy);
+                                       "NAME", "CHILDREN", "STATUS" }, selection, selectionArgs,
+                                       null, null, orderBy);
                        cursor.moveToFirst();
                        int size = cursor.getCount();
                        for (int i = 0; i < size; i++) {
@@ -194,7 +205,8 @@ public class NodeDao implements IDao<Node> {
                                // cursor.getLong(4));
                                Node node = factory.create(cursor.getLong(0), cursor.getInt(1),
                                                cursor.getString(2), cursor.getLong(3),
-                                               cursor.getString(4), cursor.getString(5), cursor.getInt(6));
+                                               cursor.getString(4), cursor.getString(5),
+                                               cursor.getInt(6));
                                list.add(node);
                                cursor.moveToNext();
                        }
@@ -217,7 +229,7 @@ public class NodeDao implements IDao<Node> {
                List<Node> list = search();
                return list == null || list.size() <= 0;
        }
-       
+
        public long add(Node node) {
                DatabaseHelper helper = DatabaseHelper.getInstance();
                SQLiteDatabase db = helper.getWritableDatabase();
@@ -315,16 +327,14 @@ public class NodeDao implements IDao<Node> {
                // node.add(id);
                return updateChildrenNT(node, Node.concatChildren(l));
        }
-       
-       public long updateStatus(Node node, Node.Status status){
-               DatabaseHelper helper = DatabaseHelper.getInstance();
-               SQLiteDatabase db = helper.getWritableDatabase();
-               return updateStatus(db, node, status);          
+
+       public long updateStatus(Node node, Node.Status status) {
+               return updateStatus(getSQLiteDatabase(), node, status);
        }
-       
-       public long updateStatus(SQLiteDatabase db, Node node, Node.Status status){
+
+       public long updateStatus(SQLiteDatabase db, Node node, Node.Status status) {
                long id = -1;
-               
+
                db.beginTransaction();
                try {
                        id = updateStatusNT(node, status);
@@ -334,12 +344,12 @@ public class NodeDao implements IDao<Node> {
                }
                return id;
        }
-       
+
        public long updateStatusNT(Node node, Node.Status status) {
                long id = -1;
                int i = 1;
                int code = Node.getStatusCode(status);
-               
+
                SQLiteStatement stmt = updateStatusStmt;
                stmt.bindLong(i++, code);
                stmt.bindLong(i++, node.getId());
@@ -347,6 +357,34 @@ public class NodeDao implements IDao<Node> {
                return id;
        }
 
+       public long updateName(Node node, String name) {
+               return updateName(getSQLiteDatabase(), node, name);
+       }
+
+       public long updateName(SQLiteDatabase db, Node node, String name) {
+               long id = -1;
+
+               db.beginTransaction();
+               try {
+                       id = updateNameNT(node, name);
+                       db.setTransactionSuccessful();
+               } finally {
+                       db.endTransaction();
+               }
+               return id;
+       }
+
+       public long updateNameNT(Node node, String name) {
+               long id = -1;
+               int i = 1;
+
+               SQLiteStatement stmt = updateNameStmt;
+               stmt.bindString(i++, name);
+               stmt.bindLong(i++, node.getId());
+               id = stmt.executeInsert();
+               return id;
+       }
+
        public long updateChildren(Node node, String children) {
                DatabaseHelper helper = DatabaseHelper.getInstance();
                SQLiteDatabase db = helper.getWritableDatabase();
@@ -365,15 +403,15 @@ public class NodeDao implements IDao<Node> {
                return id;
        }
 
-       public long delete(long id){
+       public long delete(long id) {
                DatabaseHelper helper = DatabaseHelper.getInstance();
                SQLiteDatabase db = helper.getWritableDatabase();
-               return delete(db, id);          
+               return delete(db, id);
        }
-       
-       public long delete(SQLiteDatabase db, long did){
+
+       public long delete(SQLiteDatabase db, long did) {
                long id = -1;
-               
+
                db.beginTransaction();
                try {
                        id = deleteNT(did);
@@ -383,26 +421,26 @@ public class NodeDao implements IDao<Node> {
                }
                return id;
        }
-       
+
        public long deleteNT(long did) {
                long id = -1; // TODO
                int i = 1;
-               
+
                SQLiteStatement stmt = deleteIdStmt;
                stmt.bindLong(i++, did);
                stmt.execute();
                return id;
        }
 
-       public long delete(){
+       public long delete() {
                DatabaseHelper helper = DatabaseHelper.getInstance();
                SQLiteDatabase db = helper.getWritableDatabase();
-               return delete(db);              
+               return delete(db);
        }
-       
-       public long delete(SQLiteDatabase db){
+
+       public long delete(SQLiteDatabase db) {
                long id = -1;
-               
+
                db.beginTransaction();
                try {
                        deleteNT();
@@ -412,7 +450,7 @@ public class NodeDao implements IDao<Node> {
                }
                return id;
        }
-       
+
        public void deleteNT() {
                SQLiteStatement stmt = deleteStmt;
                stmt.execute();
index ad0606c..42a4008 100644 (file)
@@ -8,7 +8,8 @@ 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.evernote.edam.type.Tag;
+import com.yuji.ef.dao.Book;
+import com.yuji.ef.dao.BookDao;
 import com.yuji.ef.dao.DatabaseHelper;
 import com.yuji.ef.dao.DirNode;
 import com.yuji.ef.dao.FileNode;
@@ -18,7 +19,8 @@ import com.yuji.ef.dao.RootNode;
 
 public class FolderUtil {
        private EvernoteUtil util = EvernoteUtil.getInstance();
-       private NodeDao dao = (NodeDao) NodeDao.getInstance();
+       private NodeDao nodeDao = (NodeDao) NodeDao.getInstance();
+       private BookDao bookDao = (BookDao) BookDao.getInstance();
 
        public static FolderUtil getInstance() {
                if (instance == null) {
@@ -34,10 +36,10 @@ public class FolderUtil {
        }
 
        public void init(SQLiteDatabase db) {
-               List<Notebook> noteBookList = util.getNoteBookList();
-               List<Tag> tagList = util.getTagList();
+               // List<Notebook> noteBookList = util.getNoteBookList();
+               // List<Tag> tagList = util.getTagList();
 
-               dao.delete(db);
+               // nodeDao.delete(db);
 
                // ROOT
                Node node;
@@ -45,34 +47,22 @@ public class FolderUtil {
                long id;
                String guid;
 
-               HashMap<String, Node> map = new HashMap<String, Node>();
-
                Node top = new RootNode("", null);
-               id = dao.addNT(top);
+               id = nodeDao.addNT(top);
                top.setId(id);
 
-               for (Notebook noteBook : noteBookList) {
-                       String name = noteBook.getName();
+               updateNotebook(db);
 
-                       // NODE
-                       node = new DirNode(name, null);
-                       addDirNodeNT(top, node);
-
-                       DirNode dirNode = (DirNode) node;
+               List<Book> noteBookList = bookDao.search(db);
+               HashMap<String, Node> map = new HashMap<String, Node>();
+               for (Book noteBook : noteBookList) {
                        guid = noteBook.getGuid();
-                       dirNode.setNotebookGuid(guid);
-
+                       DirNode dirNode = (DirNode) nodeDao.searchById(db,
+                                       noteBook.getNId());
+                       if (dirNode == null){
+                               // TODO
+                       }
                        map.put(guid, dirNode);
-
-                       // SUB
-                       // for (Tag tag : tagList) {
-                       // name = tag.getName();
-                       //
-                       // n = new DirNode(name, null);
-                       // n.setParent(node.getId());
-                       // id = dao.addNT(n);
-                       // dao.addChildrenIdNT(node, id);
-                       // }
                }
 
                List<NoteList> noteListList = util.getNoteList();
@@ -91,6 +81,39 @@ public class FolderUtil {
                }
        }
 
+       public void updateNotebook(SQLiteDatabase db) {
+               List<Notebook> noteBookList = util.getNoteBookList();
+
+               long id;
+               Node top = nodeDao.searchRoot(db);
+
+               for (Notebook notebook : noteBookList) {
+                       String guid = notebook.getGuid();
+                       String name = notebook.getName();
+
+                       Book oldBook = bookDao.searchByGuid(db, guid);
+                       if (oldBook == null) {
+                               DirNode dirNode = new DirNode(name, null);
+                               guid = notebook.getGuid();
+                               dirNode.setNotebookGuid(guid);
+
+                               id = addDirNodeNT(top, dirNode);
+
+                               Book book = new Book(-1, guid, id, name);
+                               bookDao.addNT(book);
+                       } else {
+                               String oldName = oldBook.getName();
+                               if (!name.equals(oldName)) {
+                                       bookDao.updateNameNT(oldBook, name);
+                                       
+                                       // TODO #29015
+                                       Node node = nodeDao.searchById(db, oldBook.getNId());
+                                       nodeDao.updateNameNT(node, name);
+                               }
+                       }
+               }
+       }
+
        public long addFileNode(Node parent, Node node) {
                DatabaseHelper helper = DatabaseHelper.getInstance();
                SQLiteDatabase db = helper.getWritableDatabase();
@@ -113,8 +136,8 @@ public class FolderUtil {
        private long addFileNodeNT(Node parent, Node node) {
                long id;
                node.setParent(parent.getId());
-               id = dao.addNT(node);
-               dao.addChildrenIdNT(parent, id);
+               id = nodeDao.addNT(node);
+               nodeDao.addChildrenIdNT(parent, id);
                return id;
        }
 
@@ -140,9 +163,9 @@ public class FolderUtil {
        private long addDirNodeNT(Node parent, Node node) {
                long id;
                node.setParent(parent.getId());
-               id = dao.addNT(node);
+               id = nodeDao.addNT(node);
                node.setId(id);
-               dao.addChildrenIdNT(parent, node.getId());
+               nodeDao.addChildrenIdNT(parent, node.getId());
                return id;
        }
 
@@ -167,30 +190,28 @@ public class FolderUtil {
 
        private long deleteNodeNT(Node node) {
                long id;
-               
-               if (node instanceof DirNode){
-                       DirNode dirNode = (DirNode)node;
+
+               if (node instanceof DirNode) {
+                       DirNode dirNode = (DirNode) node;
                        List<Long> list = dirNode.getChildren();
-                       for (Long l : list){
+                       for (Long l : list) {
                                id = l.longValue();
-                               Node n = dao.searchById(id);
-                               if (n != null){
+                               Node n = nodeDao.searchById(id);
+                               if (n != null) {
                                        deleteNodeNT(n);
                                }
                        }
                }
-               
+
                id = node.getParent();
-               if (id >= 0){
-                       Node p = dao.searchById(id);
-                       if (p != null){
-                               dao.remoteChildrenIdNT(p, node.getId());
+               if (id >= 0) {
+                       Node p = nodeDao.searchById(id);
+                       if (p != null) {
+                               nodeDao.remoteChildrenIdNT(p, node.getId());
                        }
                }
-               dao.deleteNT(node.getId());
-               
-               
-               
+               nodeDao.deleteNT(node.getId());
+
                return 0;
        }
 }