Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package trabfinal;
- /**
- *
- * @author pablo
- */
- public class TrabFinal {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- Database db = new Database();
- // Book b1 = new Book("Pablo", "Java", "987598759", "Vol. 1", "2B", "O'Reilly");
- // db.insertBook(b1);
- db.printAll();
- db.closeDatabase();
- }
- }
- //////////////////////////////////////////////////////////////////////////////////
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package trabfinal;
- /**
- *
- * @author pablo
- */
- public class Book {
- String author;
- String title;
- String ISBN;
- String box;
- String area;
- String publisher;
- public Book(String author, String title, String ISBN, String box, String area, String publisher) {
- this.author = author;
- this.title = title;
- this.ISBN = ISBN;
- this.box = box;
- this.area = area;
- this.publisher = publisher;
- }
- public String getAuthor() {
- return author;
- }
- public String getTitle() {
- return title;
- }
- public String getISBN() {
- return ISBN;
- }
- public String getBox() {
- return box;
- }
- public String getArea() {
- return area;
- }
- public String getPublisher() {
- return publisher;
- }
- @Override
- public String toString() {
- return "Author: " + author + "\nTitle: " + title + "\nISBN: " + ISBN + "\nBox: " + box + "\nArea: " + area + "\nPublisher: " + publisher;
- }
- }
- ////////////////////////////////////////////////////////////////////////
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package trabfinal;
- import com.db4o.Db4oEmbedded;
- import com.db4o.ObjectContainer;
- import com.db4o.ObjectSet;
- /**
- *
- * @author pablo
- */
- public class Database {
- public static ObjectContainer db;
- public Database() {
- db = Db4oEmbedded.openFile("database4.db");
- }
- public void insertBook(Book b) {
- db.store(b); //store data
- db.commit(); //update database
- }
- public void removeBook(Book b) {
- db.delete(b); //remove data
- db.commit(); //remove database
- }
- public ObjectSet searchBook(Object dado) {
- return db.queryByExample(dado);
- }
- public void printAll(){
- ObjectSet<Book> query = db.query(Book.class);
- for(Book b : query){
- System.out.println(b);
- }
- }
- public void closeDatabase(){
- db.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment