Search in sources :

Example 76 with EntityManagerFactory

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();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) Query(javax.persistence.Query) EntityManagerFactory(javax.persistence.EntityManagerFactory) ConnectionParam(org.simpleflatmapper.db.ConnectionParam)

Example 77 with EntityManagerFactory

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);
}
Also used : IAnswer(org.easymock.IAnswer) PersistenceEnv(org.opencastproject.util.persistence.PersistenceEnv) WorkflowService(org.opencastproject.workflow.api.WorkflowService) EntityManagerFactory(javax.persistence.EntityManagerFactory) Incidents(org.opencastproject.serviceregistry.api.Incidents) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) Before(org.junit.Before)

Example 78 with EntityManagerFactory

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();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) EntityManagerFactory(javax.persistence.EntityManagerFactory) HibernateEntityManagerFactory(org.hibernate.ejb.HibernateEntityManagerFactory) PersistFilter(com.google.inject.persist.PersistFilter) AfterClass(org.junit.AfterClass)

Example 79 with EntityManagerFactory

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());
}
Also used : BeanValidationEventListener(org.hibernate.cfg.beanvalidation.BeanValidationEventListener) HibernateEntityManagerFactory(org.hibernate.jpa.HibernateEntityManagerFactory) EntityManagerFactory(javax.persistence.EntityManagerFactory) HibernateEntityManagerFactory(org.hibernate.jpa.HibernateEntityManagerFactory) SessionFactoryImpl(org.hibernate.internal.SessionFactoryImpl) EventListenerRegistry(org.hibernate.event.service.spi.EventListenerRegistry)

Example 80 with EntityManagerFactory

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);
}
Also used : EntityManagerFactory(javax.persistence.EntityManagerFactory) Test(org.junit.Test)

Aggregations

EntityManagerFactory (javax.persistence.EntityManagerFactory)302 EntityManager (javax.persistence.EntityManager)103 Test (org.junit.Test)90 HashMap (java.util.HashMap)48 EntityTransaction (javax.persistence.EntityTransaction)30 EJBException (javax.ejb.EJBException)22 Map (java.util.Map)17 AssertionFailedError (junit.framework.AssertionFailedError)17 TestFailureException (org.apache.openejb.test.TestFailureException)17 ArrayList (java.util.ArrayList)15 JMSException (javax.jms.JMSException)15 KieSession (org.kie.api.runtime.KieSession)14 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)14 Properties (java.util.Properties)13 InitialContext (javax.naming.InitialContext)13 List (java.util.List)12 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)12 RemoteException (java.rmi.RemoteException)11 Query (javax.persistence.Query)11 PrintWriter (java.io.PrintWriter)10