|
|
|
@ -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();
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|