Examples of EntityManager


Examples of javax.persistence.EntityManager

        Reader reader = new InputStreamReader( TaskServiceEscalationBaseTest.class.getResourceAsStream( "../QueryData_UnescalatedDeadlines.mvel" ) );
        List<Task> tasks = (List<Task>) eval( reader,
                                              vars );
        long now = ((Date)vars.get( "now" )).getTime();
       
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        for ( Task task : tasks ) {
            // for this one we put the task in directly;
            em.persist( task );
        }
        em.getTransaction().commit();

        // now create a new service, to see if it initiates from the DB correctly
        MockEscalatedDeadlineHandler handler = new MockEscalatedDeadlineHandler();
        TaskService local = new TaskService(emf, SystemEventListenerFactory.getSystemEventListener(), handler);     
               
View Full Code Here

Examples of javax.persistence.EntityManager

    public void testPersistenceVariables() throws NamingException, NotSupportedException, SystemException, RollbackException, HeuristicMixedException, HeuristicRollbackException {
        MyEntity myEntity = new MyEntity("This is a test Entity with annotation in fields");
        MyEntityMethods myEntityMethods = new MyEntityMethods("This is a test Entity with annotations in methods");
        MyEntityOnlyFields myEntityOnlyFields = new MyEntityOnlyFields("This is a test Entity with annotations in fields and without accesors methods");
        MyVariableSerializable myVariableSerializable = new MyVariableSerializable("This is a test SerializableObject");
        EntityManager em = emf.createEntityManager();
        UserTransaction utx = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" );
        utx.begin();
        em.joinTransaction();
        em.persist(myEntity);
        em.persist(myEntityMethods);
        em.persist(myEntityOnlyFields);
        utx.commit();
        em.close();
        Environment env =  createEnvironment();
        KnowledgeBase kbase = createKnowledgeBase( "VariablePersistenceStrategyProcess.rf" );
        StatefulKnowledgeSession ksession = createSession( kbase, env );

      
View Full Code Here

Examples of javax.persistence.EntityManager

    public void testPersistenceVariablesWithTypeChange() throws NamingException, NotSupportedException, SystemException, RollbackException, HeuristicMixedException, HeuristicRollbackException {
        MyEntity myEntity = new MyEntity("This is a test Entity with annotation in fields");
        MyEntityMethods myEntityMethods = new MyEntityMethods("This is a test Entity with annotations in methods");
        MyEntityOnlyFields myEntityOnlyFields = new MyEntityOnlyFields("This is a test Entity with annotations in fields and without accesors methods");
        MyVariableSerializable myVariableSerializable = new MyVariableSerializable("This is a test SerializableObject");
        EntityManager em = emf.createEntityManager();
        UserTransaction utx = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" );
        utx.begin();
        em.joinTransaction();
        em.persist(myEntity);
        em.persist(myEntityMethods);
        em.persist(myEntityOnlyFields);
        utx.commit();
        em.close();
        Environment env = createEnvironment();
        KnowledgeBase kbase = createKnowledgeBase( "VariablePersistenceStrategyProcessTypeChange.rf" );
        StatefulKnowledgeSession ksession = createSession( kbase, env );
       
       
View Full Code Here

Examples of javax.persistence.EntityManager

       
        MyEntity myEntity = new MyEntity("This is a test Entity with annotation in fields");
        MyEntityMethods myEntityMethods = new MyEntityMethods("This is a test Entity with annotations in methods");
        MyEntityOnlyFields myEntityOnlyFields = new MyEntityOnlyFields("This is a test Entity with annotations in fields and without accesors methods");
        MyVariableSerializable myVariableSerializable = new MyVariableSerializable("This is a test SerializableObject");
        EntityManager em = emf.createEntityManager();
        UserTransaction utx = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" );
        utx.begin();
        em.joinTransaction();
        em.persist(myEntity);
        em.persist(myEntityMethods);
        em.persist(myEntityOnlyFields);
        utx.commit();
        em.close();
        Environment env = createEnvironment();
        KnowledgeBase kbase = createKnowledgeBase( "VariablePersistenceStrategySubProcess.rf" );
        StatefulKnowledgeSession ksession = createSession( kbase, env );
      
       
View Full Code Here

Examples of javax.persistence.EntityManager

   
    @Test
    public void testWorkItemWithVariablePersistence() throws Exception{
        MyEntity myEntity = new MyEntity("This is a test Entity");
        MyVariableSerializable myVariableSerializable = new MyVariableSerializable("This is a test SerializableObject");
        EntityManager em = emf.createEntityManager();
        UserTransaction utx = (UserTransaction) new InitialContext().lookup( "java:comp/UserTransaction" );
        utx.begin();
       
        em.joinTransaction();
        em.persist(myEntity);
        utx.commit();
        em.close();
        Environment env = createEnvironment();
        KnowledgeBase kbase = createKnowledgeBase( "VPSProcessWithWorkItems.rf" );
        StatefulKnowledgeSession ksession = createSession( kbase , env);
       
       
View Full Code Here

Examples of javax.persistence.EntityManager

  @Override
  public Object execute(Object[] parameters) {
    if (parameters.length == 0)
      return null;
    EntityManager em = getContext().getEntityManager();
    if (parameters[0].getClass().isArray()) {
      for (Object entity : (Object[]) parameters[0]) {
        em.persist(entity);
      }
    } else {
      em.persist(parameters[0]);
    }
    return null;
  }
View Full Code Here

Examples of javax.persistence.EntityManager

  @Override
  public Object execute(Object[] parameters) {
    if (parameters.length == 0)
      return null;
    EntityManager em = getContext().getEntityManager();
    if (parameters[0].getClass().isArray()) {
      for (Object entity : (Object[]) parameters[0]) {
        em.remove(entity);
      }
    } else {
      em.remove(parameters[0]);
    }
    return null;
  }
View Full Code Here

Examples of javax.persistence.EntityManager

   * 获取属性查询方式的返回结果
   * @param parameters 参数
   * @return
   */
  private Object propertyResult(Object[] parameters) {
    EntityManager em = getContext().getEntityManager();
    Annotation[][] annos = method.getParameterAnnotations();
    Named named = null;
    for (Annotation a : annos[0]) {
      final Class<? extends Annotation> clazz = a.annotationType();
      if (clazz.equals(Named.class)) {
        named = (Named) a;
      }
    }
    if (named == null)
      return em.find(getMethodReturnType(), parameters[0]);
    else {
      String ejbql = "from " + getMethodReturnType().getSimpleName() + " entity where entity." + named.value()
              + "=?";
      Query query = em.createQuery(ejbql);
      query.setParameter(1, parameters[0]);
      return query.getSingleResult();
    }
  }
View Full Code Here

Examples of javax.persistence.EntityManager

    }
  }
 
  private Query getQuery() {
    Retrieve retrieve = getAnnotation();
    EntityManager em = getContext().getEntityManager();
    if (StringUtils.isNotBlank(retrieve.namedQuery()))
      return em.createNamedQuery(retrieve.namedQuery());
    if (retrieve.nativeQuery()) {
      if (retrieve.resultClass().equals(void.class))
        return em.createNativeQuery(retrieve.query());
      else
        return em.createNativeQuery(retrieve.query(), retrieve.resultClass());
    } else
      return em.createQuery(retrieve.query());
  }
View Full Code Here

Examples of javax.persistence.EntityManager

  @Override
  public Object execute(Object[] parameters) {
    if (parameters.length == 0)
      return null;
    EntityManager em = getContext().getEntityManager();
    if (parameters[0].getClass().isArray()) {
      for (Object entity : (Object[]) parameters[0]) {
        entity = em.merge(entity);
      }
    } else {
      parameters[0] = em.merge(parameters[0]);
    }
    return null;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.