Merge pull request #8125 from eugenp/revert-8119-BAEL-3275-2

Revert "BAEL-3275: Using blocking queue for pub-sub"
This commit is contained in:
Eric Martin
2019-10-31 20:43:47 -05:00
committed by GitHub
parent db85c8f275
commit 3225470df5
20543 changed files with 1642750 additions and 0 deletions
@@ -0,0 +1,13 @@
package com.baeldung;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class);
}
}
@@ -0,0 +1,108 @@
package com.baeldung.config;
import com.baeldung.data.BookRepository;
import com.baeldung.model.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import java.util.Random;
import java.util.stream.IntStream;
@Component
public class DBLoader implements ApplicationRunner {
private final BookRepository bookRepository;
@Autowired
DBLoader(BookRepository bookRepository){
this.bookRepository = bookRepository;
}
public void run(ApplicationArguments applicationArguments) throws Exception {
String[] templates = {
"Up and running with %s",
"%s Basics",
"%s for Beginners",
"%s for Neckbeards",
"Under the hood: %s",
"Discovering %s",
"A short guide to %s",
"%s with Baeldung"
};
String[] buzzWords = {
"Spring REST Data",
"Java 9",
"Scala",
"Groovy",
"Hibernate",
"Spring HATEOS",
"The HAL Browser",
"Spring webflux",
};
String[] authorFirstName = {
"John %s",
"Steve %s",
"Samantha %s",
"Gale %s",
"Tom %s"
};
String[] authorLastName = {
"Giles",
"Gill",
"Smith",
"Armstrong"
};
String[] blurbs = {
"It was getting dark when the %s %s" ,
"Scott was nearly there when he heard that a %s %s",
"Diana was a lovable Java coder until the %s %s",
"The gripping story of a small %s and the day it %s"
};
String[] blublMiddles = {
"distaster",
"dog",
"cat",
"turtle",
"hurricane"
};
String[] end = {
"hit the school",
"memorised pi to 100 decimal places!",
"became a world champion armwrestler",
"became a Java REST master!!"
};
Random random = new Random();
IntStream.range(0, 100)
.forEach(i -> {
String template = templates[i % templates.length];
String buzzword = buzzWords[i % buzzWords.length];
String blurbStart = blurbs[i % blurbs.length];
String middle = blublMiddles[i % blublMiddles.length];
String ending = end[i % end.length];
String blurb = String.format(blurbStart, middle, ending);
String firstName = authorFirstName[i % authorFirstName.length];
String lastname = authorLastName[i % authorLastName.length];
Book book = new Book(String.format(template, buzzword), String.format(firstName, lastname), blurb, random.nextInt(1000-200) + 200);
bookRepository.save(book);
System.out.println(book);
});
}
}
@@ -0,0 +1,23 @@
package com.baeldung.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.rest.core.event.ValidatingRepositoryEventListener;
import org.springframework.data.rest.webmvc.config.RepositoryRestConfigurerAdapter;
import org.springframework.validation.Validator;
@Configuration
public class RestConfig extends RepositoryRestConfigurerAdapter {
//access to global validator
@Autowired
@Lazy
private Validator validator;
@Override
public void configureValidatingRepositoryEventListener(ValidatingRepositoryEventListener validatingListener) {
validatingListener.addValidator("beforeCreate", validator );
validatingListener.addValidator("beforeSave", validator);
}
}
@@ -0,0 +1,21 @@
package com.baeldung.data;
import com.baeldung.model.Book;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RestResource;
import org.springframework.stereotype.Repository;
@Repository
public interface BookRepository extends PagingAndSortingRepository<Book, Long> {
@RestResource(rel = "title-contains", path="title-contains")
Page<Book> findByTitleContaining(@Param("query") String query, Pageable page);
@RestResource(rel = "author-contains", path="author-contains", exported = false)
Page<Book> findByAuthorContaining(@Param("query") String query, Pageable page);
}
@@ -0,0 +1,86 @@
package com.baeldung.model;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
@Entity
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@NotNull
@Column(columnDefinition = "VARCHAR", length = 100)
private String title;
@NotNull
@Column(columnDefinition = "VARCHAR", length = 100)
private String author;
@Column(columnDefinition = "VARCHAR", length = 1000)
private String blurb;
private int pages;
public Book() {
}
public Book(@NotNull String title, @NotNull String author, String blurb, int pages) {
this.title = title;
this.author = author;
this.blurb = blurb;
this.pages = pages;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public String getBlurb() {
return blurb;
}
public void setBlurb(String blurb) {
this.blurb = blurb;
}
public int getPages() {
return pages;
}
public void setPages(int pages) {
this.pages = pages;
}
@Override
public String toString() {
return "Book{" +
"id=" + id +
", title='" + title + '\'' +
", author='" + author + '\'' +
", blurb='" + blurb + '\'' +
", pages=" + pages +
'}';
}
}