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,14 @@
package com.baeldung.h2db.auto.configuration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
public class AutoConfigurationDemo {
public static void main(String[] args) {
SpringApplication.run(AutoConfigurationDemo.class, args);
}
}
@@ -0,0 +1,53 @@
package com.baeldung.h2db.demo.client;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.PropertySource;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
@SpringBootApplication
@ComponentScan("com.baeldung.h2db.demo.client")
public class ClientSpringBootApp {
@Autowired
private JdbcTemplate jdbcTemplate;
public static void main(String[] args) {
System.setProperty("spring.datasource.url","jdbc:h2:tcp://localhost:9091/mem:mydb");
SpringApplication.run(ClientSpringBootApp.class, args);
}
@PostConstruct
private void initDb() {
System.out.println("****** Inserting more sample data in the table: Employees ******");
String sqlStatements[] = {
"insert into employees(first_name, last_name) values('Donald','Trump')",
"insert into employees(first_name, last_name) values('Barack','Obama')"
};
Arrays.asList(sqlStatements).stream().forEach(sql -> {
System.out.println(sql);
jdbcTemplate.execute(sql);
});
System.out.println(String.format("****** Fetching from table: %s ******", "Employees"));
jdbcTemplate.query("select id,first_name,last_name from employees",
new RowMapper<Object>() {
@Override
public Object mapRow(ResultSet rs, int i) throws SQLException {
System.out.println(String.format("id:%s,first_name:%s,last_name:%s",
rs.getString("id"),
rs.getString("first_name"),
rs.getString("last_name")));
return null;
}
});
}
}
@@ -0,0 +1,61 @@
package com.baeldung.h2db.demo.server;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import javax.annotation.PostConstruct;
import org.h2.tools.Server;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
@SpringBootApplication
@ComponentScan("com.baeldung.h2db.demo.server")
public class SpringBootApp {
@Autowired
private JdbcTemplate jdbcTemplate;
public static void main(String[] args) {
SpringApplication.run(SpringBootApp.class, args);
}
@PostConstruct
private void initDb() {
System.out.println(String.format("****** Creating table: %s, and Inserting test data ******", "Employees"));
String sqlStatements[] = {
"drop table employees if exists",
"create table employees(id serial,first_name varchar(255),last_name varchar(255))",
"insert into employees(first_name, last_name) values('Eugen','Paraschiv')",
"insert into employees(first_name, last_name) values('Scott','Tiger')"
};
Arrays.asList(sqlStatements).stream().forEach(sql -> {
System.out.println(sql);
jdbcTemplate.execute(sql);
});
System.out.println(String.format("****** Fetching from table: %s ******", "Employees"));
jdbcTemplate.query("select id,first_name,last_name from employees",
new RowMapper<Object>() {
@Override
public Object mapRow(ResultSet rs, int i) throws SQLException {
System.out.println(String.format("id:%s,first_name:%s,last_name:%s",
rs.getString("id"),
rs.getString("first_name"),
rs.getString("last_name")));
return null;
}
});
}
@Bean(initMethod = "start", destroyMethod = "stop")
public Server inMemoryH2DatabaseServer() throws SQLException {
return Server.createTcpServer("-tcp", "-tcpAllowOthers", "-tcpPort", "9091");
}
}
@@ -0,0 +1,12 @@
package com.baeldung.h2db.springboot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringBootH2Application {
public static void main(String... args) {
SpringApplication.run(SpringBootH2Application.class, args);
}
}
@@ -0,0 +1,10 @@
package com.baeldung.h2db.springboot.daos;
import com.baeldung.h2db.springboot.models.User;
import org.springframework.data.repository.CrudRepository;
public interface UserRepository extends CrudRepository<User, Integer> {
}
@@ -0,0 +1,54 @@
package com.baeldung.h2db.springboot.models;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Table(name = "users")
@Entity
public class User {
@Id
@GeneratedValue
private int id;
private String firstName;
private String lastName;
public User() { }
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
'}';
}
}