// Path: app/src/main/java/pl/droidsonroids/examplerealmmvp/model/Author.java
// public class Author extends RealmObject {
// 
//     @PrimaryKey
//     private int id;
// 
//     private String name;
//     private String lastname;
//     private RealmList<Book> books;
// 
//     public int getId() {
//         return id;
//     }
// 
//     public void setId(final int id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(final String name) {
//         this.name = name;
//     }
// 
//     public String getLastname() {
//         return lastname;
//     }
// 
//     public void setLastname(final String lastname) {
//         this.lastname = lastname;
//     }
// 
//     public RealmList<Book> getBooks() {
//         return books;
//     }
// 
//     public void setBooks(final RealmList<Book> books) {
//         this.books = books;
//     }
// }
// 
// Path: app/src/main/java/pl/droidsonroids/examplerealmmvp/model/Book.java
// public class Book extends RealmObject {
// 
//     @PrimaryKey
//     private int id;
// 
//     private String isbn;
//     private String title;
//     private Author author;
//     private Publisher publisher;
// 
//     public int getId() {
//         return id;
//     }
// 
//     public void setId(final int id) {
//         this.id = id;
//     }
// 
//     public String getIsbn() {
//         return isbn;
//     }
// 
//     public void setIsbn(final String isbn) {
//         this.isbn = isbn;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public void setTitle(final String title) {
//         this.title = title;
//     }
// 
//     public Author getAuthor() {
//         return author;
//     }
// 
//     public void setAuthor(final Author author) {
//         this.author = author;
//     }
// 
//     public Publisher getPublisher() {
//         return publisher;
//     }
// 
//     public void setPublisher(final Publisher publisher) {
//         this.publisher = publisher;
//     }
// 
//     public String getDetails() {
//         String details = "";
//         details += getAuthorFullName();
//         details += " | ";
//         details += getPublisher().getName();
//         return details;
//     }
// 
//     public String getAuthorFullName() {
//         return String.format("%s %s", getAuthor().getName(), getAuthor().getLastname());
//     }
// }
// 
// Path: app/src/main/java/pl/droidsonroids/examplerealmmvp/model/Publisher.java
// public class Publisher extends RealmObject {
// 
//     @PrimaryKey
//     private int id;
// 
//     private String name;
//     private RealmList<Book> books;
// 
//     public int getId() {
//         return id;
//     }
// 
//     public void setId(final int id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(final String name) {
//         this.name = name;
//     }
// 
//     public RealmList<Book> getBooks() {
//         return books;
//     }
// 
//     public void setBooks(final RealmList<Book> books) {
//         this.books = books;
//     }
// }


import io.realm.Realm;
import io.realm.RealmList;
import io.realm.RealmResults;
import pl.droidsonroids.examplerealmmvp.model.Author;
import pl.droidsonroids.examplerealmmvp.model.Book;
import pl.droidsonroids.examplerealmmvp.model.Publisher;
    }

    public RealmResults<Book> getAllBooks() {
        return mRealm.allObjects(Book.class);
    }

    public Book getBook(final int bookId) {
        return mRealm.where(Book.class).equalTo("id", bookId).findFirst();
    }

    public RealmList<Book> getPublisherBooks(final String publisher) {
        Publisher foundPublisher = getPublisher(publisher, mRealm);
        return foundPublisher == null ? new RealmList<Book>() : foundPublisher.getBooks();
    }

    public RealmList<Book> getAuthorBooks(final String author) {
        Author foundAuthor = getAuthor(splitAuthorName(author), mRealm);
        return foundAuthor == null ? new RealmList<Book>() : foundAuthor.getBooks();
    }

    public void addBookAsync(final String title, final String author, final String isbn, final String publisher,
            final OnTransactionCallback onTransactionCallback) {
        mRealm.executeTransaction(new Realm.Transaction() {
            @Override
            public void execute(final Realm realm) {
                Book book = realm.createObject(Book.class);
                book.setId(realm.allObjects(Book.class).size());
                book.setTitle(title);
                book.setAuthor(createOrGetAuthor(author, book, realm));
                book.setPublisher(createOrGetPublisher(publisher, book, realm));
// Path: app/src/main/java/pl/droidsonroids/examplerealmmvp/model/Author.java
// public class Author extends RealmObject {
// 
//     @PrimaryKey
//     private int id;
// 
//     private String name;
//     private String lastname;
//     private RealmList<Book> books;
// 
//     public int getId() {
//         return id;
//     }
// 
//     public void setId(final int id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(final String name) {
//         this.name = name;
//     }
// 
//     public String getLastname() {
//         return lastname;
//     }
// 
//     public void setLastname(final String lastname) {
//         this.lastname = lastname;
//     }
// 
//     public RealmList<Book> getBooks() {
//         return books;
//     }
// 
//     public void setBooks(final RealmList<Book> books) {
//         this.books = books;
//     }
// }
// 
// Path: app/src/main/java/pl/droidsonroids/examplerealmmvp/model/Book.java
// public class Book extends RealmObject {
// 
//     @PrimaryKey
//     private int id;
// 
//     private String isbn;
//     private String title;
//     private Author author;
//     private Publisher publisher;
// 
//     public int getId() {
//         return id;
//     }
// 
//     public void setId(final int id) {
//         this.id = id;
//     }
// 
//     public String getIsbn() {
//         return isbn;
//     }
// 
//     public void setIsbn(final String isbn) {
//         this.isbn = isbn;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public void setTitle(final String title) {
//         this.title = title;
//     }
// 
//     public Author getAuthor() {
//         return author;
//     }
// 
//     public void setAuthor(final Author author) {
//         this.author = author;
//     }
// 
//     public Publisher getPublisher() {
//         return publisher;
//     }
// 
//     public void setPublisher(final Publisher publisher) {
//         this.publisher = publisher;
//     }
// 
//     public String getDetails() {
//         String details = "";
//         details += getAuthorFullName();
//         details += " | ";
//         details += getPublisher().getName();
//         return details;
//     }
// 
//     public String getAuthorFullName() {
//         return String.format("%s %s", getAuthor().getName(), getAuthor().getLastname());
//     }
// }
// 
// Path: app/src/main/java/pl/droidsonroids/examplerealmmvp/model/Publisher.java
// public class Publisher extends RealmObject {
// 
//     @PrimaryKey
//     private int id;
// 
//     private String name;
//     private RealmList<Book> books;
// 
//     public int getId() {
//         return id;
//     }
// 
//     public void setId(final int id) {
//         this.id = id;
//     }
// 
//     public String getName() {
//         return name;
//     }
// 
//     public void setName(final String name) {
//         this.name = name;
//     }
// 
//     public RealmList<Book> getBooks() {
//         return books;
//     }
// 
//     public void setBooks(final RealmList<Book> books) {
//         this.books = books;
//     }
// }


// Path: app/src/main/java/pl/droidsonroids/examplerealmmvp/model/realm/RealmService.java
import io.realm.Realm;
import io.realm.RealmList;
import io.realm.RealmResults;
import pl.droidsonroids.examplerealmmvp.model.Author;
import pl.droidsonroids.examplerealmmvp.model.Book;
import pl.droidsonroids.examplerealmmvp.model.Publisher;

    }

    public RealmResults<Book> getAllBooks() {
        return mRealm.allObjects(Book.class);
    }

    public Book getBook(final int bookId) {
        return mRealm.where(Book.class).equalTo("id", bookId).findFirst();
    }

    public RealmList<Book> getPublisherBooks(final String publisher) {
        Publisher foundPublisher = getPublisher(publisher, mRealm);
        return foundPublisher == null ? new RealmList<Book>() : foundPublisher.getBooks();
    }

    public RealmList<Book> getAuthorBooks(final String author) {
        Author foundAuthor = getAuthor(splitAuthorName(author), mRealm);
        return foundAuthor == null ? new RealmList<Book>() : foundAuthor.getBooks();
    }

    public void addBookAsync(final String title, final String author, final String isbn, final String publisher,
            final OnTransactionCallback onTransactionCallback) {
        mRealm.executeTransaction(new Realm.Transaction() {
            @Override
            public void execute(final Realm realm) {
                Book book = realm.createObject(Book.class);
                book.setId(realm.allObjects(Book.class).size());
                book.setTitle(title);
                book.setAuthor(createOrGetAuthor(author, book, realm));
                book.setPublisher(createOrGetPublisher(publisher, book, realm));
                book.setIsbn(isbn);