// 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();
}
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;
}
}
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, ...);
}
}
- // TODO 共通
- public SQLiteDatabase getSQLiteDatabase() {
- DatabaseHelper helper = DatabaseHelper.getInstance();
- SQLiteDatabase db = helper.getWritableDatabase();
- return db;
- }
-
public List<Book> search() {
return search(null, null, null);
}
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 {
}
public long add(Book book) {
- return add(getSQLiteDatabase(), book);
+ return add(DatabaseHelper.getInstance().getSQLiteDatabase(), book);
}
private long add(SQLiteDatabase db, Book 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) {
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);
}
return id;
}
-
+
public long deleteNT(long did) {
long id = -1; // TODO
int i = 1;
-
+
SQLiteStatement stmt = deleteIdStmt;
stmt.bindLong(i++, did);
stmt.execute();
}
+ public SQLiteDatabase getSQLiteDatabase() {
+ DatabaseHelper helper = DatabaseHelper.getInstance();
+ SQLiteDatabase db = helper.getWritableDatabase();
+ return db;
+ }
}
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 + " = ?");
// 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" };
}
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) };
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 {
}
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) {
}
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) {
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;
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;
// 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);
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) {
}
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) {