BAEL-434 Spring Roo (#1589)
* Code for Dependency Injection Article. * Added Java based configuration. Downloaded formatter.xml and reformatted all changed files. Manually changed tab into 4 spaces in XML configuration files. * BAEL-434 - Spring Roo project files generated by Spring Roo. No formatting applied. Added POM, java and resources folders.
This commit is contained in:
+644
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,23 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* = RooApplication
|
||||
*
|
||||
* TODO Auto-generated class documentation
|
||||
*
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class RooApplication {
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(RooApplication.class, args);
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.baeldung.config;
|
||||
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryConfiguration;
|
||||
|
||||
/**
|
||||
* = SpringDataJpaDetachableRepositoryConfiguration
|
||||
TODO Auto-generated class documentation
|
||||
*
|
||||
*/
|
||||
@RooJpaRepositoryConfiguration
|
||||
public class SpringDataJpaDetachableRepositoryConfiguration {
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
|
||||
// You may push code into the target .java compilation unit if you wish to edit any member(s).
|
||||
|
||||
package com.baeldung.config;
|
||||
|
||||
import com.baeldung.RooApplication;
|
||||
import com.baeldung.config.SpringDataJpaDetachableRepositoryConfiguration;
|
||||
import io.springlets.data.jpa.repository.support.DetachableJpaRepositoryImpl;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
|
||||
privileged aspect SpringDataJpaDetachableRepositoryConfiguration_Roo_Jpa_Repository_Configuration {
|
||||
|
||||
declare @type: SpringDataJpaDetachableRepositoryConfiguration: @Configuration;
|
||||
|
||||
declare @type: SpringDataJpaDetachableRepositoryConfiguration: @EnableJpaRepositories(repositoryBaseClass = DetachableJpaRepositoryImpl.class, basePackageClasses = RooApplication.class);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.config;
|
||||
import org.springframework.roo.addon.web.mvc.controller.annotations.config.RooWebMvcConfiguration;
|
||||
import org.springframework.roo.addon.web.mvc.thymeleaf.annotations.RooWebMvcThymeleafUIConfiguration;
|
||||
|
||||
/**
|
||||
* = WebMvcConfiguration
|
||||
TODO Auto-generated class documentation
|
||||
*
|
||||
*/
|
||||
@RooWebMvcConfiguration(defaultLanguage = "en")
|
||||
@RooWebMvcThymeleafUIConfiguration
|
||||
public class WebMvcConfiguration {
|
||||
}
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
|
||||
// You may push code into the target .java compilation unit if you wish to edit any member(s).
|
||||
|
||||
package com.baeldung.config;
|
||||
|
||||
import com.baeldung.config.WebMvcConfiguration;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.thymeleaf.TemplateEngine;
|
||||
import org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver;
|
||||
import org.thymeleaf.spring4.view.ThymeleafViewResolver;
|
||||
import org.thymeleaf.templatemode.TemplateMode;
|
||||
|
||||
privileged aspect WebMvcConfiguration_Roo_ThymeleafUIConfiguration {
|
||||
|
||||
declare parents: WebMvcConfiguration implements ApplicationContextAware;
|
||||
|
||||
/**
|
||||
* TODO Auto-generated attribute documentation
|
||||
*
|
||||
*/
|
||||
@Autowired
|
||||
private ThymeleafProperties WebMvcConfiguration.thymeleafProperties;
|
||||
|
||||
/**
|
||||
* TODO Auto-generated attribute documentation
|
||||
*
|
||||
*/
|
||||
@Autowired
|
||||
private TemplateEngine WebMvcConfiguration.templateEngine;
|
||||
|
||||
/**
|
||||
* TODO Auto-generated attribute documentation
|
||||
*
|
||||
*/
|
||||
private ApplicationContext WebMvcConfiguration.applicationContext;
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return ThymeleafProperties
|
||||
*/
|
||||
public ThymeleafProperties WebMvcConfiguration.getThymeleafProperties() {
|
||||
return thymeleafProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return TemplateEngine
|
||||
*/
|
||||
public TemplateEngine WebMvcConfiguration.getTemplateEngine() {
|
||||
return templateEngine;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return ApplicationContext
|
||||
*/
|
||||
public ApplicationContext WebMvcConfiguration.getApplicationContext() {
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param applicationContext
|
||||
*/
|
||||
public void WebMvcConfiguration.setApplicationContext(ApplicationContext applicationContext) {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return ThymeleafViewResolver
|
||||
*/
|
||||
@Bean
|
||||
public ThymeleafViewResolver WebMvcConfiguration.javascriptThymeleafViewResolver() {
|
||||
ThymeleafViewResolver resolver = new ThymeleafViewResolver();
|
||||
resolver.setTemplateEngine(getTemplateEngine());
|
||||
resolver.setCharacterEncoding("UTF-8");
|
||||
resolver.setContentType("application/javascript");
|
||||
resolver.setViewNames(new String[] {"*.js"});
|
||||
resolver.setCache(getThymeleafProperties().isCache());
|
||||
return resolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return SpringResourceTemplateResolver
|
||||
*/
|
||||
@Bean
|
||||
public SpringResourceTemplateResolver WebMvcConfiguration.javascriptTemplateResolver() {
|
||||
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
|
||||
resolver.setApplicationContext(getApplicationContext());
|
||||
resolver.setPrefix("classpath:/templates/fragments/js/");
|
||||
resolver.setTemplateMode(TemplateMode.JAVASCRIPT);
|
||||
resolver.setCharacterEncoding("UTF-8");
|
||||
resolver.setCheckExistence(true);
|
||||
resolver.setCacheable(getThymeleafProperties().isCache());
|
||||
return resolver;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
|
||||
// You may push code into the target .java compilation unit if you wish to edit any member(s).
|
||||
|
||||
package com.baeldung.config;
|
||||
|
||||
import com.baeldung.config.WebMvcConfiguration;
|
||||
import io.tracee.binding.springmvc.TraceeInterceptor;
|
||||
import java.lang.Override;
|
||||
import java.util.Locale;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
|
||||
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
|
||||
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
|
||||
|
||||
privileged aspect WebMvcConfiguration_Roo_WebMvcConfiguration {
|
||||
|
||||
declare parents: WebMvcConfiguration extends WebMvcConfigurerAdapter;
|
||||
|
||||
declare @type: WebMvcConfiguration: @Configuration;
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return LocalValidatorFactoryBean
|
||||
*/
|
||||
@Primary
|
||||
@Bean
|
||||
public LocalValidatorFactoryBean WebMvcConfiguration.validator() {
|
||||
return new LocalValidatorFactoryBean();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return LocaleResolver
|
||||
*/
|
||||
@Bean
|
||||
public LocaleResolver WebMvcConfiguration.localeResolver() {
|
||||
SessionLocaleResolver localeResolver = new SessionLocaleResolver();
|
||||
localeResolver.setDefaultLocale(new Locale("en"));
|
||||
return localeResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return LocaleChangeInterceptor
|
||||
*/
|
||||
@Bean
|
||||
public LocaleChangeInterceptor WebMvcConfiguration.localeChangeInterceptor() {
|
||||
LocaleChangeInterceptor localeChangeInterceptor = new LocaleChangeInterceptor();
|
||||
localeChangeInterceptor.setParamName("lang");
|
||||
return localeChangeInterceptor;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param registry
|
||||
*/
|
||||
@Override
|
||||
public void WebMvcConfiguration.addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(localeChangeInterceptor());
|
||||
registry.addInterceptor(new TraceeInterceptor());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.baeldung.config.jackson;
|
||||
import org.springframework.roo.addon.web.mvc.controller.annotations.config.RooDomainModelModule;
|
||||
|
||||
/**
|
||||
* = DomainModelModule
|
||||
TODO Auto-generated class documentation
|
||||
*
|
||||
*/
|
||||
@RooDomainModelModule
|
||||
public class DomainModelModule {
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
|
||||
// You may push code into the target .java compilation unit if you wish to edit any member(s).
|
||||
|
||||
package com.baeldung.config.jackson;
|
||||
|
||||
import com.baeldung.config.jackson.DomainModelModule;
|
||||
import com.baeldung.domain.Book;
|
||||
import com.baeldung.web.BookJsonMixin;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import org.springframework.boot.jackson.JsonComponent;
|
||||
|
||||
privileged aspect DomainModelModule_Roo_DomainModelModule {
|
||||
|
||||
declare parents: DomainModelModule extends SimpleModule;
|
||||
|
||||
declare @type: DomainModelModule: @JsonComponent;
|
||||
|
||||
/**
|
||||
* TODO Auto-generated constructor documentation
|
||||
*
|
||||
*/
|
||||
public DomainModelModule.new() {
|
||||
// Mixin registration
|
||||
|
||||
setMixInAnnotation(Book.class, BookJsonMixin.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.baeldung.domain;
|
||||
import org.springframework.roo.addon.javabean.annotations.RooEquals;
|
||||
import org.springframework.roo.addon.javabean.annotations.RooJavaBean;
|
||||
import org.springframework.roo.addon.javabean.annotations.RooToString;
|
||||
import org.springframework.roo.addon.jpa.annotations.entity.RooJpaEntity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Version;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* = Book
|
||||
TODO Auto-generated class documentation
|
||||
*
|
||||
*/
|
||||
@RooJavaBean
|
||||
@RooToString
|
||||
@RooJpaEntity
|
||||
@RooEquals(isJpaEntity = true)
|
||||
public class Book {
|
||||
|
||||
/**
|
||||
* TODO Auto-generated attribute documentation
|
||||
*
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* TODO Auto-generated attribute documentation
|
||||
*
|
||||
*/
|
||||
@Version
|
||||
private Integer version;
|
||||
|
||||
/**
|
||||
* TODO Auto-generated attribute documentation
|
||||
*
|
||||
*/
|
||||
@NotNull
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* TODO Auto-generated attribute documentation
|
||||
*
|
||||
*/
|
||||
@NotNull
|
||||
private String author;
|
||||
|
||||
/**
|
||||
* TODO Auto-generated attribute documentation
|
||||
*
|
||||
*/
|
||||
@NotNull
|
||||
private String isbn;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
|
||||
// You may push code into the target .java compilation unit if you wish to edit any member(s).
|
||||
|
||||
package com.baeldung.domain;
|
||||
|
||||
import com.baeldung.domain.Book;
|
||||
import java.util.Objects;
|
||||
|
||||
privileged aspect Book_Roo_Equals {
|
||||
|
||||
/**
|
||||
* This `equals` implementation is specific for JPA entities and uses
|
||||
* the entity identifier for it, following the article in
|
||||
* https://vladmihalcea.com/2016/06/06/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
|
||||
*
|
||||
* @param obj
|
||||
* @return Boolean
|
||||
*/
|
||||
public boolean Book.equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
// instanceof is false if the instance is null
|
||||
if (!(obj instanceof Book)) {
|
||||
return false;
|
||||
}
|
||||
return getId() != null && Objects.equals(getId(), ((Book) obj).getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* This `hashCode` implementation is specific for JPA entities and uses a fixed `int` value to be able
|
||||
* to identify the entity in collections after a new id is assigned to the entity, following the article in
|
||||
* https://vladmihalcea.com/2016/06/06/how-to-implement-equals-and-hashcode-using-the-jpa-entity-identifier/
|
||||
*
|
||||
* @return Integer
|
||||
*/
|
||||
public int Book.hashCode() {
|
||||
return 31;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
|
||||
// You may push code into the target .java compilation unit if you wish to edit any member(s).
|
||||
|
||||
package com.baeldung.domain;
|
||||
|
||||
import com.baeldung.domain.Book;
|
||||
|
||||
privileged aspect Book_Roo_JavaBean {
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return Long
|
||||
*/
|
||||
public Long Book.getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void Book.setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return Integer
|
||||
*/
|
||||
public Integer Book.getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param version
|
||||
*/
|
||||
public void Book.setVersion(Integer version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String Book.getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param title
|
||||
*/
|
||||
public void Book.setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String Book.getAuthor() {
|
||||
return this.author;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param author
|
||||
*/
|
||||
public void Book.setAuthor(String author) {
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String Book.getIsbn() {
|
||||
return this.isbn;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param isbn
|
||||
*/
|
||||
public void Book.setIsbn(String isbn) {
|
||||
this.isbn = isbn;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
|
||||
// You may push code into the target .java compilation unit if you wish to edit any member(s).
|
||||
|
||||
package com.baeldung.domain;
|
||||
|
||||
import com.baeldung.domain.Book;
|
||||
import io.springlets.format.EntityFormat;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
privileged aspect Book_Roo_Jpa_Entity {
|
||||
|
||||
declare @type: Book: @Entity;
|
||||
|
||||
declare @type: Book: @EntityFormat;
|
||||
|
||||
/**
|
||||
* TODO Auto-generated attribute documentation
|
||||
*
|
||||
*/
|
||||
public static final String Book.ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE = "The given Iterable of items to add can't be null!";
|
||||
|
||||
/**
|
||||
* TODO Auto-generated attribute documentation
|
||||
*
|
||||
*/
|
||||
public static final String Book.ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE = "The given Iterable of items to add can't be null!";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
|
||||
// You may push code into the target .java compilation unit if you wish to edit any member(s).
|
||||
|
||||
package com.baeldung.domain;
|
||||
|
||||
import com.baeldung.domain.Book;
|
||||
|
||||
privileged aspect Book_Roo_ToString {
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public String Book.toString() {
|
||||
return "Book {" +
|
||||
"id='" + id + '\'' +
|
||||
", version='" + version + '\'' +
|
||||
", title='" + title + '\'' +
|
||||
", author='" + author + '\'' +
|
||||
", isbn='" + isbn + '\'' +
|
||||
", ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE='" + ITERABLE_TO_ADD_CANT_BE_NULL_MESSAGE + '\'' +
|
||||
", ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE='" + ITERABLE_TO_REMOVE_CANT_BE_NULL_MESSAGE + '\'' + "}" + super.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.repository;
|
||||
import com.baeldung.domain.Book;
|
||||
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepository;
|
||||
|
||||
/**
|
||||
* = BookRepository
|
||||
TODO Auto-generated class documentation
|
||||
*
|
||||
*/
|
||||
@RooJpaRepository(entity = Book.class)
|
||||
public interface BookRepository {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.repository;
|
||||
import com.baeldung.domain.Book;
|
||||
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustom;
|
||||
|
||||
/**
|
||||
* = BookRepositoryCustom
|
||||
TODO Auto-generated class documentation
|
||||
*
|
||||
*/
|
||||
@RooJpaRepositoryCustom(entity = Book.class)
|
||||
public interface BookRepositoryCustom {
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
|
||||
// You may push code into the target .java compilation unit if you wish to edit any member(s).
|
||||
|
||||
package com.baeldung.repository;
|
||||
|
||||
import com.baeldung.domain.Book;
|
||||
import com.baeldung.repository.BookRepositoryCustom;
|
||||
import io.springlets.data.domain.GlobalSearch;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
privileged aspect BookRepositoryCustom_Roo_Jpa_Repository_Custom {
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param globalSearch
|
||||
* @param pageable
|
||||
* @return Page
|
||||
*/
|
||||
public abstract Page<Book> BookRepositoryCustom.findAll(GlobalSearch globalSearch, Pageable pageable);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.repository;
|
||||
|
||||
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt;
|
||||
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepositoryCustomImpl;
|
||||
import com.baeldung.domain.Book;
|
||||
|
||||
/**
|
||||
* = BookRepositoryImpl
|
||||
*
|
||||
* TODO Auto-generated class documentation
|
||||
*
|
||||
*/
|
||||
@RooJpaRepositoryCustomImpl(repository = BookRepositoryCustom.class)
|
||||
public class BookRepositoryImpl extends QueryDslRepositorySupportExt<Book> {
|
||||
|
||||
/**
|
||||
* TODO Auto-generated constructor documentation
|
||||
*/
|
||||
BookRepositoryImpl() {
|
||||
super(Book.class);
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
|
||||
// You may push code into the target .java compilation unit if you wish to edit any member(s).
|
||||
|
||||
package com.baeldung.repository;
|
||||
|
||||
import com.baeldung.domain.Book;
|
||||
import com.baeldung.domain.QBook;
|
||||
import com.baeldung.repository.BookRepositoryCustom;
|
||||
import com.baeldung.repository.BookRepositoryImpl;
|
||||
import com.querydsl.core.types.Path;
|
||||
import com.querydsl.jpa.JPQLQuery;
|
||||
import io.springlets.data.domain.GlobalSearch;
|
||||
import io.springlets.data.jpa.repository.support.QueryDslRepositorySupportExt.AttributeMappingBuilder;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
privileged aspect BookRepositoryImpl_Roo_Jpa_Repository_Impl {
|
||||
|
||||
declare parents: BookRepositoryImpl implements BookRepositoryCustom;
|
||||
|
||||
declare @type: BookRepositoryImpl: @Transactional(readOnly = true);
|
||||
|
||||
/**
|
||||
* TODO Auto-generated attribute documentation
|
||||
*
|
||||
*/
|
||||
public static final String BookRepositoryImpl.TITLE = "title";
|
||||
|
||||
/**
|
||||
* TODO Auto-generated attribute documentation
|
||||
*
|
||||
*/
|
||||
public static final String BookRepositoryImpl.AUTHOR = "author";
|
||||
|
||||
/**
|
||||
* TODO Auto-generated attribute documentation
|
||||
*
|
||||
*/
|
||||
public static final String BookRepositoryImpl.ISBN = "isbn";
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param globalSearch
|
||||
* @param pageable
|
||||
* @return Page
|
||||
*/
|
||||
public Page<Book> BookRepositoryImpl.findAll(GlobalSearch globalSearch, Pageable pageable) {
|
||||
|
||||
QBook book = QBook.book;
|
||||
|
||||
JPQLQuery<Book> query = from(book);
|
||||
|
||||
Path<?>[] paths = new Path<?>[] {book.title,book.author,book.isbn};
|
||||
applyGlobalSearch(globalSearch, query, paths);
|
||||
|
||||
AttributeMappingBuilder mapping = buildMapper()
|
||||
.map(TITLE, book.title)
|
||||
.map(AUTHOR, book.author)
|
||||
.map(ISBN, book.isbn);
|
||||
|
||||
applyPagination(pageable, query, mapping);
|
||||
applyOrderById(query);
|
||||
|
||||
return loadPage(query, pageable, book);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
|
||||
// You may push code into the target .java compilation unit if you wish to edit any member(s).
|
||||
|
||||
package com.baeldung.repository;
|
||||
|
||||
import com.baeldung.domain.Book;
|
||||
import com.baeldung.repository.BookRepository;
|
||||
import com.baeldung.repository.BookRepositoryCustom;
|
||||
import io.springlets.data.jpa.repository.DetachableJpaRepository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
privileged aspect BookRepository_Roo_Jpa_Repository {
|
||||
|
||||
declare parents: BookRepository extends DetachableJpaRepository<Book, Long>;
|
||||
|
||||
declare parents: BookRepository extends BookRepositoryCustom;
|
||||
|
||||
declare @type: BookRepository: @Transactional(readOnly = true);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.service.api;
|
||||
import com.baeldung.domain.Book;
|
||||
import org.springframework.roo.addon.layers.service.annotations.RooService;
|
||||
|
||||
/**
|
||||
* = BookService
|
||||
TODO Auto-generated class documentation
|
||||
*
|
||||
*/
|
||||
@RooService(entity = Book.class)
|
||||
public interface BookService {
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
|
||||
// You may push code into the target .java compilation unit if you wish to edit any member(s).
|
||||
|
||||
package com.baeldung.service.api;
|
||||
|
||||
import com.baeldung.domain.Book;
|
||||
import com.baeldung.service.api.BookService;
|
||||
import io.springlets.data.domain.GlobalSearch;
|
||||
import io.springlets.format.EntityResolver;
|
||||
import java.util.List;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
privileged aspect BookService_Roo_Service {
|
||||
|
||||
declare parents: BookService extends EntityResolver<Book, Long>;
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param id
|
||||
* @return Book
|
||||
*/
|
||||
public abstract Book BookService.findOne(Long id);
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param book
|
||||
*/
|
||||
public abstract void BookService.delete(Book book);
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param entities
|
||||
* @return List
|
||||
*/
|
||||
public abstract List<Book> BookService.save(Iterable<Book> entities);
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param ids
|
||||
*/
|
||||
public abstract void BookService.delete(Iterable<Long> ids);
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param entity
|
||||
* @return Book
|
||||
*/
|
||||
public abstract Book BookService.save(Book entity);
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param id
|
||||
* @return Book
|
||||
*/
|
||||
public abstract Book BookService.findOneForUpdate(Long id);
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param ids
|
||||
* @return List
|
||||
*/
|
||||
public abstract List<Book> BookService.findAll(Iterable<Long> ids);
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
public abstract List<Book> BookService.findAll();
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return Long
|
||||
*/
|
||||
public abstract long BookService.count();
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param globalSearch
|
||||
* @param pageable
|
||||
* @return Page
|
||||
*/
|
||||
public abstract Page<Book> BookService.findAll(GlobalSearch globalSearch, Pageable pageable);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.service.impl;
|
||||
import com.baeldung.service.api.BookService;
|
||||
import org.springframework.roo.addon.layers.service.annotations.RooServiceImpl;
|
||||
|
||||
/**
|
||||
* = BookServiceImpl
|
||||
TODO Auto-generated class documentation
|
||||
*
|
||||
*/
|
||||
@RooServiceImpl(service = BookService.class)
|
||||
public class BookServiceImpl implements BookService {
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
|
||||
// You may push code into the target .java compilation unit if you wish to edit any member(s).
|
||||
|
||||
package com.baeldung.service.impl;
|
||||
|
||||
import com.baeldung.domain.Book;
|
||||
import com.baeldung.repository.BookRepository;
|
||||
import com.baeldung.service.impl.BookServiceImpl;
|
||||
import io.springlets.data.domain.GlobalSearch;
|
||||
import java.util.List;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
privileged aspect BookServiceImpl_Roo_Service_Impl {
|
||||
|
||||
declare @type: BookServiceImpl: @Service;
|
||||
|
||||
declare @type: BookServiceImpl: @Transactional(readOnly = true);
|
||||
|
||||
/**
|
||||
* TODO Auto-generated attribute documentation
|
||||
*
|
||||
*/
|
||||
private BookRepository BookServiceImpl.bookRepository;
|
||||
|
||||
/**
|
||||
* TODO Auto-generated constructor documentation
|
||||
*
|
||||
* @param bookRepository
|
||||
*/
|
||||
@Autowired
|
||||
public BookServiceImpl.new(BookRepository bookRepository) {
|
||||
setBookRepository(bookRepository);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return BookRepository
|
||||
*/
|
||||
public BookRepository BookServiceImpl.getBookRepository() {
|
||||
return bookRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param bookRepository
|
||||
*/
|
||||
public void BookServiceImpl.setBookRepository(BookRepository bookRepository) {
|
||||
this.bookRepository = bookRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param book
|
||||
*/
|
||||
@Transactional
|
||||
public void BookServiceImpl.delete(Book book) {
|
||||
getBookRepository().delete(book);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param entities
|
||||
* @return List
|
||||
*/
|
||||
@Transactional
|
||||
public List<Book> BookServiceImpl.save(Iterable<Book> entities) {
|
||||
return getBookRepository().save(entities);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param ids
|
||||
*/
|
||||
@Transactional
|
||||
public void BookServiceImpl.delete(Iterable<Long> ids) {
|
||||
List<Book> toDelete = getBookRepository().findAll(ids);
|
||||
getBookRepository().deleteInBatch(toDelete);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param entity
|
||||
* @return Book
|
||||
*/
|
||||
@Transactional
|
||||
public Book BookServiceImpl.save(Book entity) {
|
||||
return getBookRepository().save(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param id
|
||||
* @return Book
|
||||
*/
|
||||
public Book BookServiceImpl.findOne(Long id) {
|
||||
return getBookRepository().findOne(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param id
|
||||
* @return Book
|
||||
*/
|
||||
public Book BookServiceImpl.findOneForUpdate(Long id) {
|
||||
return getBookRepository().findOneDetached(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param ids
|
||||
* @return List
|
||||
*/
|
||||
public List<Book> BookServiceImpl.findAll(Iterable<Long> ids) {
|
||||
return getBookRepository().findAll(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return List
|
||||
*/
|
||||
public List<Book> BookServiceImpl.findAll() {
|
||||
return getBookRepository().findAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return Long
|
||||
*/
|
||||
public long BookServiceImpl.count() {
|
||||
return getBookRepository().count();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param globalSearch
|
||||
* @param pageable
|
||||
* @return Page
|
||||
*/
|
||||
public Page<Book> BookServiceImpl.findAll(GlobalSearch globalSearch, Pageable pageable) {
|
||||
return getBookRepository().findAll(globalSearch, pageable);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class<Book> BookServiceImpl.getEntityType() {
|
||||
return Book.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return Class
|
||||
*/
|
||||
public Class<Long> BookServiceImpl.getIdType() {
|
||||
return Long.class;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.baeldung.web;
|
||||
import com.baeldung.domain.Book;
|
||||
import com.baeldung.service.api.BookService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.jackson.JsonObjectDeserializer;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.roo.addon.web.mvc.controller.annotations.config.RooDeserializer;
|
||||
|
||||
/**
|
||||
* = BookDeserializer
|
||||
TODO Auto-generated class documentation
|
||||
*
|
||||
*/
|
||||
@RooDeserializer(entity = Book.class)
|
||||
public class BookDeserializer extends JsonObjectDeserializer<Book> {
|
||||
|
||||
/**
|
||||
* TODO Auto-generated attribute documentation
|
||||
*
|
||||
*/
|
||||
private BookService bookService;
|
||||
|
||||
/**
|
||||
* TODO Auto-generated attribute documentation
|
||||
*
|
||||
*/
|
||||
private ConversionService conversionService;
|
||||
|
||||
/**
|
||||
* TODO Auto-generated constructor documentation
|
||||
*
|
||||
* @param bookService
|
||||
* @param conversionService
|
||||
*/
|
||||
@Autowired
|
||||
public BookDeserializer(@Lazy BookService bookService, ConversionService conversionService) {
|
||||
this.bookService = bookService;
|
||||
this.conversionService = conversionService;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
|
||||
// You may push code into the target .java compilation unit if you wish to edit any member(s).
|
||||
|
||||
package com.baeldung.web;
|
||||
|
||||
import com.baeldung.domain.Book;
|
||||
import com.baeldung.service.api.BookService;
|
||||
import com.baeldung.web.BookDeserializer;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.ObjectCodec;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.springlets.web.NotFoundException;
|
||||
import java.io.IOException;
|
||||
import org.springframework.boot.jackson.JsonComponent;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
|
||||
privileged aspect BookDeserializer_Roo_EntityDeserializer {
|
||||
|
||||
declare @type: BookDeserializer: @JsonComponent;
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return BookService
|
||||
*/
|
||||
public BookService BookDeserializer.getBookService() {
|
||||
return bookService;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param bookService
|
||||
*/
|
||||
public void BookDeserializer.setBookService(BookService bookService) {
|
||||
this.bookService = bookService;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return ConversionService
|
||||
*/
|
||||
public ConversionService BookDeserializer.getConversionService() {
|
||||
return conversionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param conversionService
|
||||
*/
|
||||
public void BookDeserializer.setConversionService(ConversionService conversionService) {
|
||||
this.conversionService = conversionService;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param jsonParser
|
||||
* @param context
|
||||
* @param codec
|
||||
* @param tree
|
||||
* @return Book
|
||||
* @throws IOException
|
||||
*/
|
||||
public Book BookDeserializer.deserializeObject(JsonParser jsonParser, DeserializationContext context, ObjectCodec codec, JsonNode tree) throws IOException {
|
||||
String idText = tree.asText();
|
||||
Long id = conversionService.convert(idText, Long.class);
|
||||
Book book = bookService.findOne(id);
|
||||
if (book == null) {
|
||||
throw new NotFoundException("Book not found");
|
||||
}
|
||||
return book;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.web;
|
||||
import com.baeldung.domain.Book;
|
||||
import org.springframework.roo.addon.web.mvc.controller.annotations.config.RooJsonMixin;
|
||||
|
||||
/**
|
||||
* = BookJsonMixin
|
||||
TODO Auto-generated class documentation
|
||||
*
|
||||
*/
|
||||
@RooJsonMixin(entity = Book.class)
|
||||
public abstract class BookJsonMixin {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.baeldung.web;
|
||||
import com.baeldung.domain.Book;
|
||||
import org.springframework.roo.addon.web.mvc.controller.annotations.ControllerType;
|
||||
import org.springframework.roo.addon.web.mvc.controller.annotations.RooController;
|
||||
import org.springframework.roo.addon.web.mvc.thymeleaf.annotations.RooThymeleaf;
|
||||
|
||||
/**
|
||||
* = BooksCollectionThymeleafController
|
||||
TODO Auto-generated class documentation
|
||||
*
|
||||
*/
|
||||
@RooController(entity = Book.class, type = ControllerType.COLLECTION)
|
||||
@RooThymeleaf
|
||||
public class BooksCollectionThymeleafController {
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
// WARNING: DO NOT EDIT THIS FILE. THIS FILE IS MANAGED BY SPRING ROO.
|
||||
// You may push code into the target .java compilation unit if you wish to edit any member(s).
|
||||
|
||||
package com.baeldung.web;
|
||||
|
||||
import com.baeldung.service.api.BookService;
|
||||
import com.baeldung.web.BooksCollectionThymeleafController;
|
||||
|
||||
privileged aspect BooksCollectionThymeleafController_Roo_Controller {
|
||||
|
||||
/**
|
||||
* TODO Auto-generated attribute documentation
|
||||
*
|
||||
*/
|
||||
private BookService BooksCollectionThymeleafController.bookService;
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @return BookService
|
||||
*/
|
||||
public BookService BooksCollectionThymeleafController.getBookService() {
|
||||
return bookService;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Auto-generated method documentation
|
||||
*
|
||||
* @param bookService
|
||||
*/
|
||||
public void BooksCollectionThymeleafController.setBookService(BookService bookService) {
|
||||
this.bookService = bookService;
|
||||
}
|
||||
|
||||
}
|
||||
+470
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user