diff --git a/labs/CockRoachDBTest/CockRoachDBJPATest/build.gradle b/labs/CockRoachDBTest/CockRoachDBJPATest/build.gradle index 281dd68b..f55a0c1e 100644 --- a/labs/CockRoachDBTest/CockRoachDBJPATest/build.gradle +++ b/labs/CockRoachDBTest/CockRoachDBJPATest/build.gradle @@ -17,6 +17,7 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.postgresql:postgresql' + implementation 'org.jinq:jinq-jpa:1.8.30' //compile group: 'org.postgresql', name: 'postgresql', version: '42.2.12' testImplementation('org.springframework.boot:spring-boot-starter-test') { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' diff --git a/labs/CockRoachDBTest/CockRoachDBJPATest/src/main/java/com/nabxp/demo/CockRoachDBJPATest/Application.java b/labs/CockRoachDBTest/CockRoachDBJPATest/src/main/java/com/nabxp/demo/CockRoachDBJPATest/Application.java index 23552fac..76e7ccf7 100644 --- a/labs/CockRoachDBTest/CockRoachDBJPATest/src/main/java/com/nabxp/demo/CockRoachDBJPATest/Application.java +++ b/labs/CockRoachDBTest/CockRoachDBJPATest/src/main/java/com/nabxp/demo/CockRoachDBJPATest/Application.java @@ -1,12 +1,20 @@ package com.nabxp.demo.CockRoachDBJPATest; +import org.jinq.jpa.JinqJPAStreamProvider; import org.slf4j.Logger; 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.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import javax.persistence.PersistenceContext; + @SpringBootApplication public class Application { private static final Logger log = LoggerFactory.getLogger(Application.class); @@ -15,13 +23,23 @@ public class Application { SpringApplication.run(Application.class, args); } + @Autowired + private EntityManagerFactory entityManagerFactory; + @Bean - public CommandLineRunner commandLineRunner(CustomerRepository repository) { + public CommandLineRunner commandLineRunner() { return args -> { - - repository.save(new Customer("admin", "test")); - log.info(String.valueOf(repository.count())); - + EntityManager em = entityManagerFactory.createEntityManager(); + em.getTransaction().begin(); + 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(); }; } diff --git a/labs/CockRoachDBTest/CockRoachDBJPATest/src/main/resources/application.properties b/labs/CockRoachDBTest/CockRoachDBJPATest/src/main/resources/application.properties index 43d5f937..a4e47994 100644 --- a/labs/CockRoachDBTest/CockRoachDBJPATest/src/main/resources/application.properties +++ b/labs/CockRoachDBTest/CockRoachDBJPATest/src/main/resources/application.properties @@ -4,7 +4,7 @@ spring.jpa.hibernate.ddl-auto=create spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL94Dialect #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\ &sslfactory=org.postgresql.ssl.jdbc4.LibPQFactory\ &sslcert=${certs.path}client.root.crt\