Java Code Examples for org.rapidoid.setup.My#entityManagerFactoryProvider()
The following examples show how to use
org.rapidoid.setup.My#entityManagerFactoryProvider() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JPACustomizationTest.java From rapidoid with Apache License 2.0 | 6 votes |
@Test public void testCustomEMFWithReq() { JPA.bootstrap(path()); On.post("/tx").transaction().json(() -> JPA.insert(new Book("posted"))); AtomicInteger n = new AtomicInteger(); My.entityManagerFactoryProvider(req -> { notNull(req); n.incrementAndGet(); return JPA.provideEmf(); }); for (int i = 0; i < total; i++) { int expectedId = i + 1; HTTP.post(localhost("/tx")) .expect() .entry("id", expectedId) .entry("title", "posted"); } eq(n.get(), total); }
Example 2
Source File: JPACustomizationTest.java From rapidoid with Apache License 2.0 | 6 votes |
@Test public void testCustomEMFWithoutReq() { JPA.bootstrap(path()); AtomicInteger n = new AtomicInteger(); My.entityManagerFactoryProvider(req -> { isNull(req); n.incrementAndGet(); return JPA.provideEmf(); }); for (int i = 0; i < total; i++) { JPA.transaction(() -> { Book book = JPA.insert(new Book("b")); notNull(book.getId()); }); } eq(n.get(), total); }
Example 3
Source File: Main.java From rapidoid with Apache License 2.0 | 3 votes |
public static void main(String[] args) { /* The EntityManagerFactory's should be properly initialized */ EntityManagerFactory emf1 = null; // FIXME EntityManagerFactory emf2 = null; // FIXME My.entityManagerFactoryProvider(req -> req.path().startsWith("/db1/") ? emf1 : emf2); }