@POST @Consumes(MediaType.APPLICATION_JSON) public Response createBook(@Valid @NoId(idField = "id") Book book) { book.setId(1); return Response.created(URI.create("http://blah.com/books/1")) .entity(book).build(); }
Book book = new Book(); book.setId(1L); bookRepository.save(book);
public List<Book> getBooks() { List<Book> bookList = new ArrayList(); SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor= db.rawQuery( "select * from "+TABLE_NAME, null); if (cursor.moveToFirst()) { do { Book book = new Book(); book.setId(cursor.getString(cursor.getColumnIndex("id"))); book.setTitle(cursor.getString(cursor.getColumnIndex("title"))); book.setDescription(cursor.getString(cursor.getColumnIndex("description"))); bookList.add(book); } while (cursor.moveToNext()); } return bookList; }
public List<Book> getBooks() { List<Book> bookList = new ArrayList<Book>(); SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor= db.rawQuery( "select * from tblbooks", null ); if (cursor.moveToFirst()) { // change here do { Book book = new Book(); // need to add here book.setId(cursor.getString(cursor.getColumnIndex("id"))); book.setTitle(cursor.getString(cursor.getColumnIndex("title"))); book.setDescription(cursor.getString(cursor.getColumnIndex("description"))); bookList.add(book); } while (cursor.moveToNext()); cursor.close(); } } return bookList; }
Book book = new Book(); book.setId(bookRecord.getId()); book.setFirstname(bookRecord.getFirstname());
public class BookService { @Inject private NumberGenerator numberGenerator; private Date instanciationDate; @PostConstruct private void setInstanciationDate() { instanciationDate = new Date(); } public Book createBook(String title, String description, double price) { Book book = new Book(title, description, price); book.setId(numberGenerator.generateNumber()); book.setDate(instanciationDate); return book; } }
book.setId(Integer.parseInt(cursor.getString(0))); book.setTitle(cursor.getString(1)); book.setAuthor(cursor.getString(2));
if (cursor.moveToFirst()) { do { Book book = new Book();//here book.setId(cursor.getString(cursor.getColumnIndex("id"))); book.setTitle(cursor.getString(cursor.getColumnIndex("title"))); book.setDescription(cursor.getString(cursor.getColumnIndex("description"))); bookList.add(book); } while (cursor.moveToNext()); }
@GET public Collection<Book> getBooks() { List<Book> outBooks = new ArrayList<>(); for (Book book : bookRepo.getBooks()) { Book outBook = new Book(); outBook.setId(book.getId()); outBook.setTitle(book.getTitle()); outBook.setCreator(book.getCreator()); outBooks.add(outBook); } return outBooks; }
book.setId(id);
public Book parse(Document doc) throws XPathExpressionException, URISyntaxException { Book book = new Book(); String id = xpath.evaluate("//pgterms:ebook/@rdf:about", doc); book.setId(id); book.setTitle(xpath.evaluate("//dcterms:title/text()", doc)); book.setCreator(xpath.evaluate("//dcterms:creator//pgterms:name/text()", doc)); NodeList files = (NodeList)xpath.evaluate("//pgterms:file", doc, XPathConstants.NODESET); //NodeList subjects = (NodeList)xpath.evaluate("//dcterms:subject/rdf:Description/rdf:value", doc, XPathConstants.NODESET); for (int c = 0; c < files.getLength(); c++) { Format format = parseFormat((Element)files.item(c)); if (format.getMediaType().startsWith("image")) { book.setCover(format.getFile()); } book.getFormats().add(format); } /* for (int c = 0; c < subjects.getLength(); c++) { Element subjectEl = (Element)subjects.item(c); book.getSubjects().add(new Subject(subjectEl.getTextContent())); } */ return book; }
public void createBook() { Book book = new Book(); book.setId(1); book.setDescription("Mastering the Behavior Driven Development with " + "Ruby on Rails");
public void execute(Realm realm) { Book book = new Book(); book.setId(1); book.setAuthor("Reto Meier"); book.setTitle("Android 4 Application Development"); realm.insertOrUpdate(book); book.setId(2); book.setAuthor("Itzik Ben-Gan"); book.setTitle("Microsoft SQL Server 2012 T-SQL Fundamentals"); realm.insertOrUpdate(book); book.setId(3); book.setAuthor("Magnus Lie Hetland"); book.setTitle("Beginning Python: From Novice To Professional Paperback"); realm.insertOrUpdate(book); book.setId(4); book.setAuthor("Chad Fowler"); book.setTitle("The Passionate Programmer: Creating a Remarkable Career in Software Development"); book.setId(5); book.setAuthor("Yashavant Kanetkar"); book.setTitle("Written Test Questions In C Programming");