use of javax.persistence.EntityManagerFactory in project mapping-benchmark by arnaudroger.
the class HibernateBenchmark method main.
public static void main(String[] args) throws Exception {
ConnectionParam connParam = new ConnectionParam();
connParam.db = DbTarget.HSQLDB;
connParam.init();
EntityManagerFactory sf = Persistence.createEntityManagerFactory("jpa");
EntityManager session = sf.createEntityManager();
try {
Query query = session.createQuery("select s from MappedObject4 s");
query.setMaxResults(2);
List<?> sr = query.getResultList();
for (Object o : sr) {
System.out.println(o.toString());
}
} finally {
session.close();
}
}
use of javax.persistence.EntityManagerFactory in project opencast by opencast.
the class OsgiIncidentServiceTest method setUp.
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
final EntityManagerFactory emf = PersistenceUtil.newTestEntityManagerFactory(AbstractIncidentService.PERSISTENCE_UNIT_NAME);
penv = PersistenceEnvs.persistenceEnvironment(emf);
// Mock up a job
Job job = createNiceMock(Job.class);
expect(job.getProcessingHost()).andStubReturn(PROCESSING_HOST);
expect(job.getJobType()).andStubReturn(JOB_TYPE);
expect(job.getCreator()).andStubReturn("creator");
expect(job.getOrganization()).andStubReturn("organization");
replay(job);
// Mock up a service registry
final ServiceRegistry serviceRegistry = createNiceMock(ServiceRegistry.class);
expect(serviceRegistry.getJob(EasyMock.anyLong())).andAnswer(new IAnswer<Job>() {
@Override
public Job answer() throws Throwable {
final Long jobId = (Long) EasyMock.getCurrentArguments()[0];
return jobs.get(jobId);
}
}).anyTimes();
replay(serviceRegistry);
// Mock up a workflow service
final WorkflowService workflowService = createNiceMock(WorkflowService.class);
replay(workflowService);
incidentService = new AbstractIncidentService() {
@Override
protected ServiceRegistry getServiceRegistry() {
return serviceRegistry;
}
@Override
protected WorkflowService getWorkflowService() {
return workflowService;
}
@Override
protected PersistenceEnv getPenv() {
return PersistenceEnvs.persistenceEnvironment(emf);
}
};
incidents = new Incidents(serviceRegistry, incidentService);
}
use of javax.persistence.EntityManagerFactory in project candlepin by candlepin.
the class DatabaseTestFixture method destroy.
@AfterClass
public static void destroy() {
parentInjector.getInstance(PersistFilter.class).destroy();
EntityManager manager = parentInjector.getInstance(EntityManager.class);
if (manager.isOpen()) {
manager.close();
}
EntityManagerFactory emf = parentInjector.getInstance(EntityManagerFactory.class);
if (emf.isOpen()) {
emf.close();
}
}
use of javax.persistence.EntityManagerFactory in project candlepin by candlepin.
the class CandlepinContextListener method insertValidationEventListeners.
/**
* There's no way to really get Guice to perform injections on stuff that
* the JpaPersistModule is creating, so we resort to grabbing the EntityManagerFactory
* after the fact and adding the Validation EventListener ourselves.
* @param injector
*/
private void insertValidationEventListeners(Injector injector) {
javax.inject.Provider<EntityManagerFactory> emfProvider = injector.getProvider(EntityManagerFactory.class);
HibernateEntityManagerFactory hibernateEntityManagerFactory = (HibernateEntityManagerFactory) emfProvider.get();
SessionFactoryImpl sessionFactoryImpl = (SessionFactoryImpl) hibernateEntityManagerFactory.getSessionFactory();
EventListenerRegistry registry = sessionFactoryImpl.getServiceRegistry().getService(EventListenerRegistry.class);
javax.inject.Provider<BeanValidationEventListener> listenerProvider = injector.getProvider(BeanValidationEventListener.class);
registry.getEventListenerGroup(EventType.PRE_INSERT).appendListener(listenerProvider.get());
registry.getEventListenerGroup(EventType.PRE_UPDATE).appendListener(listenerProvider.get());
registry.getEventListenerGroup(EventType.PRE_DELETE).appendListener(listenerProvider.get());
}
use of javax.persistence.EntityManagerFactory in project opencast by opencast.
the class UserSettingsServiceTest method findUserSettingsInputNoSettingsNoSignaturesExpectsEmptyUserSettings.
@Test
public void findUserSettingsInputNoSettingsNoSignaturesExpectsEmptyUserSettings() throws UserSettingsServiceException {
int offset = 0;
int limit = 10;
EntityManagerFactory emf = setupEntityManagerFactory(0, 0, limit, limit, offset, limit);
UserSettingsService userSettingsService = setupUserSettingsService(emf);
userSettingsService.findUserSettings(limit, offset);
}
Aggregations