+ private static final Logger LOGGER = Logger.getLogger(JpaBuilder.class
+ .getName());
+
+ /**
+ * Callback interface to execute some JPA code within a transaction with the
+ * entitymanager to use provided as input.
+ */
+ public static interface JpaUnitOfWork<T> {
+ /**
+ * Executes the unit of work. A transaction has been started.
+ *
+ * @param aEm
+ * Entity manager.
+ * @return Result of the execute method. If you don't want to return
+ * anything use <code>Void</code> for the return type and return
+ * null from the implementation.
+ */
+ T execute(EntityManager aEm) throws Exception;
+ }
+
+ private PersistenceUnitDescription persistenceUnit;
+ private DataSource dataSource;
+ private EntityManagerFactory factory;
+
+ /**
+ * Constructs the builder.
+ *
+ * @param aDataSource
+ * Datasource of database.
+ * @param aPersistenceUnit
+ * Persistence unit.
+ */
+ public JpaBuilder(DataSource aDataSource,
+ PersistenceUnitDescription aPersistenceUnit) {
+ persistenceUnit = aPersistenceUnit;
+ dataSource = aDataSource;
+ StubInitialContextFactory.register();
+ }