Former-commit-id: c89abea9e3cd78dab1795be28077793fc77cbf90
Former-commit-id: 2b1de036446dc361611a81db500b54199027eac2
TSXN
wanggang 5 years ago
parent d3d6e21c1d
commit 1f023e20e4

@ -17,6 +17,7 @@ repositories {
dependencies { dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.postgresql:postgresql' implementation 'org.postgresql:postgresql'
implementation 'org.jinq:jinq-jpa:1.8.30'
//compile group: 'org.postgresql', name: 'postgresql', version: '42.2.12' //compile group: 'org.postgresql', name: 'postgresql', version: '42.2.12'
testImplementation('org.springframework.boot:spring-boot-starter-test') { testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'

@ -1,12 +1,20 @@
package com.nabxp.demo.CockRoachDBJPATest; package com.nabxp.demo.CockRoachDBJPATest;
import org.jinq.jpa.JinqJPAStreamProvider;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.CommandLineRunner; import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;
@SpringBootApplication @SpringBootApplication
public class Application { public class Application {
private static final Logger log = LoggerFactory.getLogger(Application.class); private static final Logger log = LoggerFactory.getLogger(Application.class);
@ -15,13 +23,23 @@ public class Application {
SpringApplication.run(Application.class, args); SpringApplication.run(Application.class, args);
} }
@Autowired
private EntityManagerFactory entityManagerFactory;
@Bean @Bean
public CommandLineRunner commandLineRunner(CustomerRepository repository) { public CommandLineRunner commandLineRunner() {
return args -> { return args -> {
EntityManager em = entityManagerFactory.createEntityManager();
repository.save(new Customer("admin", "test")); em.getTransaction().begin();
log.info(String.valueOf(repository.count())); em.persist(new Customer("admin", "test"));
em.getTransaction().commit();
//repository.save(new Customer("admin", "test"));
//log.info(String.valueOf(repository.count()));
JinqJPAStreamProvider streams = new JinqJPAStreamProvider(entityManagerFactory);
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
streams.streamAll(em,Customer.class).forEach(o->System.out.println("@:"+o.getFirstName()));
//
em.close();
}; };
} }

@ -4,7 +4,7 @@
spring.jpa.hibernate.ddl-auto=create spring.jpa.hibernate.ddl-auto=create
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL94Dialect spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL94Dialect
#spring.datasource.url=jdbc:postgresql://localhost:26257/mytestj?sslmode=disable #spring.datasource.url=jdbc:postgresql://localhost:26257/mytestj?sslmode=disable
certs.path=C:/Users/wg/Desktop/ZHXY/labs/CockRoachDBTest/cockroach-v2.0.5.windows-6.2-amd64/certs/ certs.path=D:/1.0/ZHXY/labs/CockRoachDBTest/cockroach-v2.0.5.windows-6.2-amd64/certs/
spring.datasource.url=jdbc:postgresql://localhost:26257/mytestj?ssl=true\ spring.datasource.url=jdbc:postgresql://localhost:26257/mytestj?ssl=true\
&sslfactory=org.postgresql.ssl.jdbc4.LibPQFactory\ &sslfactory=org.postgresql.ssl.jdbc4.LibPQFactory\
&sslcert=${certs.path}client.root.crt\ &sslcert=${certs.path}client.root.crt\

Loading…
Cancel
Save