From: Yuji Konishi Date: Sat, 28 Jul 2012 09:07:19 +0000 (+0900) Subject: T29084 X-Git-Url: http://git.sourceforge.jp/view?a=commitdiff_plain;h=80e79630e07d6b436491af6fdc33b1b7e291d241;p=everfolder%2Fsource.git T29084 --- diff --git a/source/workspace/EverFolder/src/com/yuji/ef/EverFolderActivity.java b/source/workspace/EverFolder/src/com/yuji/ef/EverFolderActivity.java index 5ffd700..3ee2e68 100644 --- a/source/workspace/EverFolder/src/com/yuji/ef/EverFolderActivity.java +++ b/source/workspace/EverFolder/src/com/yuji/ef/EverFolderActivity.java @@ -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(); } diff --git a/source/workspace/EverFolder/src/com/yuji/ef/Initialize.java b/source/workspace/EverFolder/src/com/yuji/ef/Initialize.java index bb80e3d..7271349 100644 --- a/source/workspace/EverFolder/src/com/yuji/ef/Initialize.java +++ b/source/workspace/EverFolder/src/com/yuji/ef/Initialize.java @@ -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; } } diff --git a/source/workspace/EverFolder/src/com/yuji/ef/dao/BookDao.java b/source/workspace/EverFolder/src/com/yuji/ef/dao/BookDao.java index 59b111a..067c502 100644 --- a/source/workspace/EverFolder/src/com/yuji/ef/dao/BookDao.java +++ b/source/workspace/EverFolder/src/com/yuji/ef/dao/BookDao.java @@ -33,7 +33,7 @@ public class BookDao implements IDao { 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 { } - // TODO 共通 - public SQLiteDatabase getSQLiteDatabase() { - DatabaseHelper helper = DatabaseHelper.getInstance(); - SQLiteDatabase db = helper.getWritableDatabase(); - return db; - } - public List search() { return search(null, null, null); } @@ -90,11 +83,12 @@ public class BookDao implements IDao { private List search(String selection, String[] selectionArgs, String orderBy) { - return search(getSQLiteDatabase(), selection, selectionArgs, orderBy); + return search(DatabaseHelper.getInstance().getSQLiteDatabase(), + selection, selectionArgs, orderBy); } - - private List search(SQLiteDatabase db, String selection, String[] selectionArgs, - String orderBy) { + + private List search(SQLiteDatabase db, String selection, + String[] selectionArgs, String orderBy) { List list = new ArrayList(); Cursor cursor = null; try { @@ -130,7 +124,7 @@ public class BookDao implements IDao { } 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 { 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 { 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 { } return id; } - + public long deleteNT(long did) { long id = -1; // TODO int i = 1; - + SQLiteStatement stmt = deleteIdStmt; stmt.bindLong(i++, did); stmt.execute(); diff --git a/source/workspace/EverFolder/src/com/yuji/ef/dao/DatabaseHelper.java b/source/workspace/EverFolder/src/com/yuji/ef/dao/DatabaseHelper.java index 725e2d7..12bd949 100644 --- a/source/workspace/EverFolder/src/com/yuji/ef/dao/DatabaseHelper.java +++ b/source/workspace/EverFolder/src/com/yuji/ef/dao/DatabaseHelper.java @@ -65,4 +65,9 @@ public class DatabaseHelper extends SQLiteOpenHelper { } + public SQLiteDatabase getSQLiteDatabase() { + DatabaseHelper helper = DatabaseHelper.getInstance(); + SQLiteDatabase db = helper.getWritableDatabase(); + return db; + } } diff --git a/source/workspace/EverFolder/src/com/yuji/ef/dao/NodeDao.java b/source/workspace/EverFolder/src/com/yuji/ef/dao/NodeDao.java index e987701..eef316f 100644 --- a/source/workspace/EverFolder/src/com/yuji/ef/dao/NodeDao.java +++ b/source/workspace/EverFolder/src/com/yuji/ef/dao/NodeDao.java @@ -51,9 +51,8 @@ public class NodeDao implements IDao { 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 { // top.add(node.getId()); } - public SQLiteDatabase getSQLiteDatabase() { - DatabaseHelper helper = DatabaseHelper.getInstance(); - SQLiteDatabase db = helper.getWritableDatabase(); - return db; - } - public List 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 { } 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 { return list.get(0); } - private List search(SQLiteDatabase db, String selection, String[] selectionArgs, - String orderBy) { + private List search(SQLiteDatabase db, String selection, + String[] selectionArgs, String orderBy) { List list = new ArrayList(); Cursor cursor = null; try { @@ -344,7 +338,8 @@ public class NodeDao implements IDao { } 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 { } 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 { 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; diff --git a/source/workspace/EverFolder/src/com/yuji/ef/utility/FolderUtil.java b/source/workspace/EverFolder/src/com/yuji/ef/utility/FolderUtil.java index e38582d..163901b 100644 --- a/source/workspace/EverFolder/src/com/yuji/ef/utility/FolderUtil.java +++ b/source/workspace/EverFolder/src/com/yuji/ef/utility/FolderUtil.java @@ -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 noteBookList = bookDao.search(db); - HashMap map = new HashMap(); - for (Book noteBook : noteBookList) { - guid = noteBook.getGuid(); - DirNode dirNode = (DirNode) nodeDao.searchById(db, - noteBook.getNId()); - if (dirNode == null) { - // TODO - } - map.put(guid, dirNode); - } - - List noteListList = util.getNoteList(); - for (NoteList noteList : noteListList) { - List 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 noteBookList = bookDao.search(db); +// HashMap map = new HashMap(); +// for (Book noteBook : noteBookList) { +// guid = noteBook.getGuid(); +// DirNode dirNode = (DirNode) nodeDao.searchById(db, +// noteBook.getNId()); +// if (dirNode == null) { +// // TODO +// } +// map.put(guid, dirNode); +// } +// +// List noteListList = util.getNoteList(); +// for (NoteList noteList : noteListList) { +// List 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) {