private void addNote() { String noteText = editText.getText().toString(); editText.setText(""); final DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); String comment = "Added on " + df.format(new Date()); Note note = new Note(0, noteText, comment, new Date()); noteDao.insert(note); Log.d(App.TAG, "Inserted new note, ID: " + note.getId()); updateNotes(); }
private void addNote() { String noteText = editText.getText().toString(); editText.setText(""); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); String comment = "Added on " + df.format(new Date()); Note note = new Note(); note.setText(noteText); note.setComment(comment); note.setDate(new Date()); notesBox.put(note); Log.d(App.TAG, "Inserted new note, ID: " + note.getId()); }
private void addNote() { String noteText = editText.getText().toString(); editText.setText(""); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); String comment = "Added on " + df.format(new Date()); Note note = new Note(); note.setText(noteText); note.setComment(comment); note.setDate(new Date()); notesBox.put(note); Log.d(App.TAG, "Inserted new note, ID: " + note.getId()); }
private void addNote() { String noteText = editText.getText().toString(); editText.setText(""); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); String comment = "Added on " + df.format(new Date()); Note note = new Note(); note.setText(noteText); note.setComment(comment); note.setDate(new Date()); notesBox.put(note); Log.d(App.TAG, "Inserted new note, ID: " + note.getId()); }
private void addNote() { String noteText = editText.getText().toString(); editText.setText(""); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); String comment = "Added on " + df.format(new Date()); Note note = new Note(); note.setText(noteText); note.setComment(comment); note.setDate(new Date()); notesBox.put(note); Log.d(App.TAG, "Inserted new note, ID: " + note.getId()); updateNotes(); }
public static void main(String[] args) { BoxStore store = MyObjectBox.builder().name("objectbox-notes-db").build(); Box<Note> box = store.boxFor(Note.class); String text = args.length > 0 ? String.join(" ", args) : "No text given"; box.put(new Note(text)); System.out.println(box.count() + " notes in ObjectBox database:"); for (Note note : box.getAll()) { System.out.println(note); } store.close(); } }
@Test public void testPutAndGet() { Box<Note> box = store.boxFor(Note.class); Note note = new Note(); note.setText("Hello Desktop"); note.setDate(new Date()); long id = box.put(note); Note noteFromBox = box.get(id); assertEquals("Hello Desktop", noteFromBox.getText()); }
@Test public void testParentAndChildren() { Box<Note> box = store.boxFor(Note.class); Note parent = new Note(); parent.setText("Parent"); Note note = new Note(); note.setText("Child"); note.setParent(parent); long childId = box.put(note); long parentId = note.getParent().getId(); assertTrue(parentId > 0); Note noteFromBox = box.get(childId); assertEquals("Child", noteFromBox.getText()); assertEquals("Parent", noteFromBox.getParent().getText()); Note parentNoteFromBox = box.get(parentId); assertEquals(1, parentNoteFromBox.getChildren().size()); assertEquals(childId, parentNoteFromBox.getChildren().get(0).getId()); } }