Examples of EntityManager


Examples of javax.persistence.EntityManager

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

Examples of javax.persistence.EntityManager

    @Transactional
    @Override public final void remove(DomainEntity entity) {
        Assert.notNull(entity);
        Assert.notNull(entity.getId());
        EntityManager em = getEntityManager();
        try {
            em.remove(entity);
        } catch (IllegalArgumentException ie) {
            logger.debug("Error removing entity from DB: " + ie.getMessage() + ". Trying to reattach and then remove the entity");
            remove(entity.getClass(), entity.getId());
        }
    }
View Full Code Here

Examples of javax.persistence.EntityManager

     * Gets the current entity manager (or create one) for the given transaction
     * if there is one.
     * @return an entitymanager
     */
    public synchronized EntityManager getCurrent() {
        EntityManager current = null;

        // Get current transaction (if any)
        Transaction currentTx = null;
        try {
            currentTx = JTransactionManager.getTransactionManager().getTransaction();
View Full Code Here

Examples of javax.persistence.EntityManager

     * Builds a new Entity manager for the given transaction.
     * @param tx transaction on which associate the entity manager
     * @return built entity manager.
     */
    private EntityManager buildNewTxEntityManager(final Transaction tx) {
        EntityManager entityManager = this.entityManagerFactory.createEntityManager();

        /**
         * The persistence context is created and then associated with the
         * current JTA transaction. The persistence context ends when the
         * associated JTA transaction commits or rolls back,
View Full Code Here

Examples of javax.persistence.EntityManager

            EZBPersistenceUnitManager persistenceUnitManager = this.injectionHolder.getPersistenceUnitManager();
            for (IENCBinding<IJavaxPersistenceContext> binding : this.encBindingHolder.getPersistenceContextBindings()) {
                String encName = binding.getName();
                String unitName = binding.getValue().getUnitName();
                PersistenceContextType type = binding.getValue().getType();
                EntityManager em = persistenceUnitManager.getEntityManager(unitName, type);

                try {
                    createSubcontexts(envCtx, encName);
                    envCtx.rebind(encName, em);
                    if (this.logger.isDebugEnabled()) {
View Full Code Here

Examples of javax.persistence.EntityManager

     * @param entityId the identifier of the entity that the listenr methdos was
     *        called.
     */
    public void insertCallbackLogger(final String className, final CallbackType callbackEvent,
            final String callbackClassName, final int entityId) {
        EntityManager entityManager = entityManagerFactory.createEntityManager();

        ListenerLogger logger = new ListenerLogger();
        logger.setCallbackClassName(callbackClassName);
        logger.setCallbackEvent(callbackEvent);
        logger.setClassName(className);
        logger.setInsertionDate(getTime());
        logger.setEntityId(entityId);
        entityManager.persist(logger);
        entityManager.flush();
    }
View Full Code Here

Examples of javax.persistence.EntityManager

     * @param entityId the the entity for which the listener was called.
     * @return the list of results.
     */
    public List findLifecycleEventByEntity(final String className, final CallbackType callbackEvent,
            final int entityId) {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Query query = entityManager.createQuery("SELECT e FROM ListenerManager "
                + "e WHERE e.className = :className AND e.callbackEvent= :event AND e.entityId = :entityId");
        query.setParameter("className", className);
        query.setParameter("event", callbackEvent);
        query.setParameter("entityId", new Integer(entityId));
        return query.getResultList();
View Full Code Here

Examples of javax.persistence.EntityManager

     * @param operationType the operation type.
     * @param description the operation description.
     */
    public void insertOperationLogger(final String className, final CallbackType event, final String eventClassName,
            final OperationType operationType, final String description) {
        EntityManager entityManager = entityManagerFactory.createEntityManager();

        OperationLogger logger = new OperationLogger();
        logger.setCallbackClassName(eventClassName);
        logger.setCallbackEvent(event);
        logger.setClassName(className);
        logger.setInsertionDate(getTime());
        logger.setOperationType(operationType);
        logger.setDescription(description);
        entityManager.persist(logger);
        entityManager.flush();
    }
View Full Code Here

Examples of javax.persistence.EntityManager

        // Checks if the size of descriptions is the same as eventClassNames.
        assertTrue(descriptions.length == eventClassNames.length,
                "The length of descriptions and event class names must be equal.");

        EntityManager entityManager = entityManagerFactory.createEntityManager();
        Query query = entityManager.createQuery("SELECT e FROM OperationLogger "
                + "e WHERE e.className = :className AND e.callbackEvent= :event AND e.operationType = :operationType");
        query.setParameter("className", className);
        query.setParameter("event", event);
        query.setParameter("operationType", operationType);
        List callbackList = query.getResultList();
View Full Code Here

Examples of javax.persistence.EntityManager

   /**
     * Deletes a callback event from the database.
     * @param id the callback identifier.
     */
    public void deleteCallbackEvent(final int id) {
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        CallbackLogger callbackLogger = entityManager.find(CallbackLogger.class, new Integer(id));
        if (callbackLogger != null) {
            entityManager.remove(callbackLogger);
        }
    }
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.