Search in sources :

Example 1 with Author

use of io.micronaut.data.tck.entities.Author in project micronaut-data by micronaut-projects.

the class H2AuthorRepository method testReadDTO.

default Book testReadDTO(String title, int pages) {
    return customSearch(title, pages, (book, context) -> {
        AuthorDTO dto = context.readDTO("author_", Author.class, AuthorDTO.class);
        Author author = new Author();
        author.setName(dto.getName());
        book.setAuthor(author);
    });
}
Also used : AuthorDTO(io.micronaut.data.tck.entities.AuthorDTO) Author(io.micronaut.data.tck.entities.Author)

Example 2 with Author

use of io.micronaut.data.tck.entities.Author in project micronaut-data by micronaut-projects.

the class H2AuthorRepository method testReadSingleProperty.

default Book testReadSingleProperty(String title, int pages) {
    return customSearch(title, pages, (book, context) -> {
        Author author = new Author();
        author.setName(context.readString("author_name"));
        book.setAuthor(author);
    });
}
Also used : Author(io.micronaut.data.tck.entities.Author)

Example 3 with Author

use of io.micronaut.data.tck.entities.Author in project micronaut-data by micronaut-projects.

the class H2BookRepository method findByName.

@Transactional
public Author findByName(String name) {
    return jdbcOperations.prepareStatement("SELECT author_.id,author_.name,author_.nick_name,author_books_.id AS _books_id,author_books_.author_id AS _books_author_id,author_books_.title AS _books_title,author_books_.total_pages AS _books_total_pages,author_books_.publisher_id AS _books_publisher_id,author_books_.last_updated AS _books_last_updated FROM author AS author_ INNER JOIN book author_books_ ON author_.id=author_books_.author_id WHERE (author_.name = ?)", statement -> {
        statement.setString(1, name);
        ResultSet resultSet = statement.executeQuery();
        if (resultSet.next()) {
            Author author = jdbcOperations.readEntity(resultSet, Author.class);
            Set<Book> books = new HashSet<>();
            do {
                books.add(jdbcOperations.readEntity("_books_", resultSet, Book.class));
            } while (resultSet.next());
            author.setBooks(books);
            return author;
        }
        throw new EmptyResultException();
    });
}
Also used : EmptyResultException(io.micronaut.data.exceptions.EmptyResultException) Book(io.micronaut.data.tck.entities.Book) ResultSet(java.sql.ResultSet) Author(io.micronaut.data.tck.entities.Author) HashSet(java.util.HashSet) Transactional(javax.transaction.Transactional)

Example 4 with Author

use of io.micronaut.data.tck.entities.Author in project micronaut-data by micronaut-projects.

the class BookRepository method saveAuthorBooks.

public void saveAuthorBooks(List<AuthorBooksDto> authorBooksDtos) {
    List<Author> authors = new ArrayList<>();
    for (AuthorBooksDto dto : authorBooksDtos) {
        Author author = newAuthor(dto.getAuthorName());
        authors.add(author);
        for (BookDto book : dto.getBooks()) {
            newBook(author, book.getTitle(), book.getTotalPages());
        }
    }
    authorRepository.saveAll(authors);
}
Also used : BookDto(io.micronaut.data.tck.entities.BookDto) ArrayList(java.util.ArrayList) Author(io.micronaut.data.tck.entities.Author) AuthorBooksDto(io.micronaut.data.tck.entities.AuthorBooksDto)

Example 5 with Author

use of io.micronaut.data.tck.entities.Author in project micronaut-data by micronaut-projects.

the class BookRepository method newAuthor.

protected Author newAuthor(String name) {
    Author author = new Author();
    author.setName(name);
    return author;
}
Also used : Author(io.micronaut.data.tck.entities.Author)

Aggregations

Author (io.micronaut.data.tck.entities.Author)5 EmptyResultException (io.micronaut.data.exceptions.EmptyResultException)1 AuthorBooksDto (io.micronaut.data.tck.entities.AuthorBooksDto)1 AuthorDTO (io.micronaut.data.tck.entities.AuthorDTO)1 Book (io.micronaut.data.tck.entities.Book)1 BookDto (io.micronaut.data.tck.entities.BookDto)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Transactional (javax.transaction.Transactional)1