Class JpaEndpoint

  • All Implemented Interfaces:
    AutoCloseable, org.apache.camel.CamelContextAware, org.apache.camel.Endpoint, org.apache.camel.IsSingleton, org.apache.camel.Service, org.apache.camel.ShutdownableService, org.apache.camel.spi.HasId, org.apache.camel.StatefulService, org.apache.camel.SuspendableService

    @UriEndpoint(firstVersion="1.0.0",
                 scheme="jpa",
                 title="JPA",
                 syntax="jpa:entityType",
                 category={DATABASE,SQL})
    public class JpaEndpoint
    extends org.apache.camel.support.ScheduledPollEndpoint
    Store and retrieve Java objects from databases using Java Persistence API (JPA).
    • Field Summary

      • Fields inherited from class org.apache.camel.support.service.BaseService

        BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void configureProperties​(Map<String,​Object> options)  
      org.apache.camel.Consumer createConsumer​(org.apache.camel.Processor processor)  
      protected String createEndpointUri()  
      protected javax.persistence.EntityManager createEntityManager()
      Deprecated.
      use getEntityManagerFactory() to get hold of factory and create an entity manager using the factory.
      protected javax.persistence.EntityManagerFactory createEntityManagerFactory()  
      org.apache.camel.PollingConsumer createPollingConsumer()  
      org.apache.camel.Producer createProducer()  
      protected org.apache.camel.Expression createProducerExpression()  
      protected org.springframework.transaction.PlatformTransactionManager createTransactionManager()  
      protected org.springframework.transaction.support.TransactionTemplate createTransactionTemplate()  
      protected void doInit()  
      JpaComponent getComponent()  
      DeleteHandler<Object> getDeleteHandler()  
      javax.persistence.EntityManagerFactory getEntityManagerFactory()  
      Map<String,​Object> getEntityManagerProperties()
      Additional properties for the entity manager to use.
      Class<?> getEntityType()  
      javax.persistence.LockModeType getLockModeType()  
      int getMaximumResults()  
      int getMaxMessagesPerPoll()  
      String getNamedQuery()  
      String getNativeQuery()  
      Map<String,​Object> getParameters()  
      String getPersistenceUnit()  
      DeleteHandler<Object> getPreDeleteHandler()  
      org.apache.camel.Expression getProducerExpression()  
      String getQuery()  
      Class<?> getResultClass()  
      org.springframework.transaction.PlatformTransactionManager getTransactionManager()  
      Boolean getUseExecuteUpdate()  
      boolean isConsumeDelete()  
      boolean isConsumeLockEntity()  
      boolean isFindEntity()  
      boolean isFlushOnSend()  
      boolean isJoinTransaction()  
      boolean isRemove()  
      boolean isSharedEntityManager()  
      boolean isSkipLockedEntity()  
      boolean isTransacted()  
      boolean isUsePassedInEntityManager()  
      boolean isUsePersist()  
      void setConsumeDelete​(boolean consumeDelete)
      If true, the entity is deleted after it is consumed; if false, the entity is not deleted.
      void setConsumeLockEntity​(boolean consumeLockEntity)
      Specifies whether or not to set an exclusive lock on each entity bean while processing the results from polling.
      void setDeleteHandler​(DeleteHandler<Object> deleteHandler)
      To use a custom DeleteHandler to delete the row after the consumer is done processing the exchange
      void setEntityManagerFactory​(javax.persistence.EntityManagerFactory entityManagerFactory)
      The EntityManagerFactory to use.
      void setEntityManagerProperties​(Map<String,​Object> entityManagerProperties)  
      void setEntityType​(Class<?> entityType)
      The JPA annotated class to use as entity.
      void setFindEntity​(boolean findEntity)
      If enabled then the producer will find a single entity by using the message body as key and entityType as the class type.
      void setFlushOnSend​(boolean flushOnSend)
      Flushes the EntityManager after the entity bean has been persisted.
      void setJoinTransaction​(boolean joinTransaction)
      The camel-jpa component will join transaction by default.
      void setLockModeType​(javax.persistence.LockModeType lockModeType)
      To configure the lock mode on the consumer.
      void setMaximumResults​(int maximumResults)
      Set the maximum number of results to retrieve on the Query.
      void setMaxMessagesPerPoll​(int maxMessagesPerPoll)
      An integer value to define the maximum number of messages to gather per poll.
      void setNamedQuery​(String namedQuery)
      To use a named query.
      void setNativeQuery​(String nativeQuery)
      To use a custom native query.
      void setParameters​(Map<String,​Object> parameters)
      This key/value mapping is used for building the query parameters.
      void setPersistenceUnit​(String persistenceUnit)
      The JPA persistence unit used by default.
      void setPreDeleteHandler​(DeleteHandler<Object> preDeleteHandler)
      To use a custom Pre-DeleteHandler to delete the row after the consumer has read the entity.
      void setProducerExpression​(org.apache.camel.Expression producerExpression)  
      void setQuery​(String query)
      To use a custom query.
      void setRemove​(boolean isRemove)
      Indicates to use entityManager.remove(entity).
      void setResultClass​(Class<?> resultClass)
      Defines the type of the returned payload (we will call entityManager.createNativeQuery(nativeQuery, resultClass) instead of entityManager.createNativeQuery(nativeQuery)).
      void setSharedEntityManager​(boolean sharedEntityManager)
      Whether to use Spring's SharedEntityManager for the consumer/producer.
      void setSkipLockedEntity​(boolean skipLockedEntity)
      To configure whether to use NOWAIT on lock and silently skip the entity.
      void setTransacted​(boolean transacted)
      Whether to run the consumer in transacted mode, by which all messages will either commit or rollback, when the entire batch has been processed.
      void setTransactionManager​(org.springframework.transaction.PlatformTransactionManager transactionManager)
      To use the PlatformTransactionManager for managing transactions.
      void setUseExecuteUpdate​(Boolean useExecuteUpdate)
      To configure whether to use executeUpdate() when producer executes a query.
      void setUsePassedInEntityManager​(boolean usePassedIn)
      If set to true, then Camel will use the EntityManager from the header JpaConstants.ENTITY_MANAGER instead of the configured entity manager on the component/endpoint.
      void setUsePersist​(boolean usePersist)
      Indicates to use entityManager.persist(entity) instead of entityManager.merge(entity).
      protected void validate()  
      • Methods inherited from class org.apache.camel.support.ScheduledPollEndpoint

        configureConsumer, configureScheduledPollConsumerProperties, doConfigureConsumer, doStart, doStop, getBackoffErrorThreshold, getBackoffIdleThreshold, getBackoffMultiplier, getDefaultDelay, getDelay, getInitialDelay, getPollStrategy, getRepeatCount, getRunLoggingLevel, getScheduledExecutorService, getScheduler, getSchedulerProperties, getTimeUnit, isGreedy, isSendEmptyMessageWhenIdle, isStartScheduler, isUseFixedDelay, setBackoffErrorThreshold, setBackoffIdleThreshold, setBackoffMultiplier, setDelay, setGreedy, setInitialDelay, setPollStrategy, setRepeatCount, setRunLoggingLevel, setScheduledExecutorService, setScheduler, setSchedulerProperties, setSendEmptyMessageWhenIdle, setStartScheduler, setTimeUnit, setUseFixedDelay
      • Methods inherited from class org.apache.camel.support.DefaultEndpoint

        configureExchange, configurePollingConsumer, createAsyncProducer, createExchange, createExchange, equals, getCamelContext, getEndpointKey, getEndpointUri, getExceptionHandler, getExchangePattern, getId, getPollingConsumerBlockTimeout, getPollingConsumerQueueSize, hashCode, isAutowiredEnabled, isBridgeErrorHandler, isLazyStartProducer, isLenientProperties, isPollingConsumerBlockWhenFull, isPollingConsumerCopy, isSingleton, setAutowiredEnabled, setBridgeErrorHandler, setCamelContext, setComponent, setEndpointUri, setEndpointUriIfNotSpecified, setExceptionHandler, setExchangePattern, setLazyStartProducer, setPollingConsumerBlockTimeout, setPollingConsumerBlockWhenFull, setPollingConsumerCopy, setPollingConsumerQueueSize, setProperties, toString
      • Methods inherited from class org.apache.camel.support.service.BaseService

        build, doBuild, doFail, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
      • Methods inherited from interface org.apache.camel.Endpoint

        getEndpointBaseUri, isSingletonProducer
      • Methods inherited from interface org.apache.camel.Service

        build, close, init, start, stop
      • Methods inherited from interface org.apache.camel.ShutdownableService

        shutdown
      • Methods inherited from interface org.apache.camel.StatefulService

        getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending
      • Methods inherited from interface org.apache.camel.SuspendableService

        isSuspended, resume, suspend
    • Constructor Detail

      • JpaEndpoint

        public JpaEndpoint()
    • Method Detail

      • getComponent

        public JpaComponent getComponent()
        Overrides:
        getComponent in class org.apache.camel.support.DefaultEndpoint
      • createProducer

        public org.apache.camel.Producer createProducer()
                                                 throws Exception
        Throws:
        Exception
      • createConsumer

        public org.apache.camel.Consumer createConsumer​(org.apache.camel.Processor processor)
                                                 throws Exception
        Throws:
        Exception
      • createPollingConsumer

        public org.apache.camel.PollingConsumer createPollingConsumer()
                                                               throws Exception
        Specified by:
        createPollingConsumer in interface org.apache.camel.Endpoint
        Overrides:
        createPollingConsumer in class org.apache.camel.support.DefaultEndpoint
        Throws:
        Exception
      • configureProperties

        public void configureProperties​(Map<String,​Object> options)
        Specified by:
        configureProperties in interface org.apache.camel.Endpoint
        Overrides:
        configureProperties in class org.apache.camel.support.ScheduledPollEndpoint
      • createEndpointUri

        protected String createEndpointUri()
        Overrides:
        createEndpointUri in class org.apache.camel.support.DefaultEndpoint
      • getProducerExpression

        public org.apache.camel.Expression getProducerExpression()
      • setProducerExpression

        public void setProducerExpression​(org.apache.camel.Expression producerExpression)
      • getMaximumResults

        public int getMaximumResults()
      • setMaximumResults

        public void setMaximumResults​(int maximumResults)
        Set the maximum number of results to retrieve on the Query.
      • getEntityType

        public Class<?> getEntityType()
      • setEntityType

        public void setEntityType​(Class<?> entityType)
        The JPA annotated class to use as entity.
      • getEntityManagerFactory

        public javax.persistence.EntityManagerFactory getEntityManagerFactory()
      • setEntityManagerFactory

        public void setEntityManagerFactory​(javax.persistence.EntityManagerFactory entityManagerFactory)
        The EntityManagerFactory to use.
      • getTransactionManager

        public org.springframework.transaction.PlatformTransactionManager getTransactionManager()
      • setTransactionManager

        public void setTransactionManager​(org.springframework.transaction.PlatformTransactionManager transactionManager)
        To use the PlatformTransactionManager for managing transactions.
      • getEntityManagerProperties

        public Map<String,​Object> getEntityManagerProperties()
        Additional properties for the entity manager to use.
      • setEntityManagerProperties

        public void setEntityManagerProperties​(Map<String,​Object> entityManagerProperties)
      • getPersistenceUnit

        public String getPersistenceUnit()
      • setPersistenceUnit

        public void setPersistenceUnit​(String persistenceUnit)
        The JPA persistence unit used by default.
      • isConsumeDelete

        public boolean isConsumeDelete()
      • setConsumeDelete

        public void setConsumeDelete​(boolean consumeDelete)
        If true, the entity is deleted after it is consumed; if false, the entity is not deleted.
      • isConsumeLockEntity

        public boolean isConsumeLockEntity()
      • setConsumeLockEntity

        public void setConsumeLockEntity​(boolean consumeLockEntity)
        Specifies whether or not to set an exclusive lock on each entity bean while processing the results from polling.
      • isFlushOnSend

        public boolean isFlushOnSend()
      • setFlushOnSend

        public void setFlushOnSend​(boolean flushOnSend)
        Flushes the EntityManager after the entity bean has been persisted.
      • getMaxMessagesPerPoll

        public int getMaxMessagesPerPoll()
      • setMaxMessagesPerPoll

        public void setMaxMessagesPerPoll​(int maxMessagesPerPoll)
        An integer value to define the maximum number of messages to gather per poll. By default, no maximum is set. Can be used to avoid polling many thousands of messages when starting up the server. Set a value of 0 or negative to disable.
      • isUsePersist

        public boolean isUsePersist()
      • setUsePersist

        public void setUsePersist​(boolean usePersist)
        Indicates to use entityManager.persist(entity) instead of entityManager.merge(entity). Note: entityManager.persist(entity) doesn't work for detached entities (where the EntityManager has to execute an UPDATE instead of an INSERT query)!
      • isRemove

        public boolean isRemove()
      • setRemove

        public void setRemove​(boolean isRemove)
        Indicates to use entityManager.remove(entity).
      • isJoinTransaction

        public boolean isJoinTransaction()
      • setJoinTransaction

        public void setJoinTransaction​(boolean joinTransaction)
        The camel-jpa component will join transaction by default. You can use this option to turn this off, for example if you use LOCAL_RESOURCE and join transaction doesn't work with your JPA provider. This option can also be set globally on the JpaComponent, instead of having to set it on all endpoints.
      • isUsePassedInEntityManager

        public boolean isUsePassedInEntityManager()
      • setUsePassedInEntityManager

        public void setUsePassedInEntityManager​(boolean usePassedIn)
        If set to true, then Camel will use the EntityManager from the header JpaConstants.ENTITY_MANAGER instead of the configured entity manager on the component/endpoint. This allows end users to control which entity manager will be in use.
      • isSharedEntityManager

        public boolean isSharedEntityManager()
      • setSharedEntityManager

        public void setSharedEntityManager​(boolean sharedEntityManager)
        Whether to use Spring's SharedEntityManager for the consumer/producer. Note in most cases joinTransaction should be set to false as this is not an EXTENDED EntityManager.
      • getQuery

        public String getQuery()
      • setQuery

        public void setQuery​(String query)
        To use a custom query.
      • getNamedQuery

        public String getNamedQuery()
      • setNamedQuery

        public void setNamedQuery​(String namedQuery)
        To use a named query.
      • getNativeQuery

        public String getNativeQuery()
      • setNativeQuery

        public void setNativeQuery​(String nativeQuery)
        To use a custom native query. You may want to use the option resultClass also when using native queries.
      • getLockModeType

        public javax.persistence.LockModeType getLockModeType()
      • setLockModeType

        public void setLockModeType​(javax.persistence.LockModeType lockModeType)
        To configure the lock mode on the consumer.
      • setParameters

        public void setParameters​(Map<String,​Object> parameters)

        This key/value mapping is used for building the query parameters. It is expected to be of the generic type java.util.Map where the keys are the named parameters of a given JPA query and the values are their corresponding effective values you want to select for.

        When it's used for producer, Simple expression can be used as a parameter value. It allows you to retrieve parameter values from the message body, header and etc.

      • getResultClass

        public Class<?> getResultClass()
      • setResultClass

        public void setResultClass​(Class<?> resultClass)
        Defines the type of the returned payload (we will call entityManager.createNativeQuery(nativeQuery, resultClass) instead of entityManager.createNativeQuery(nativeQuery)). Without this option, we will return an object array. Only has an affect when using in conjunction with native query when consuming data.
      • isTransacted

        public boolean isTransacted()
      • setTransacted

        public void setTransacted​(boolean transacted)
        Whether to run the consumer in transacted mode, by which all messages will either commit or rollback, when the entire batch has been processed. The default behavior (false) is to commit all the previously successfully processed messages, and only rollback the last failed message.
      • isSkipLockedEntity

        public boolean isSkipLockedEntity()
      • setSkipLockedEntity

        public void setSkipLockedEntity​(boolean skipLockedEntity)
        To configure whether to use NOWAIT on lock and silently skip the entity.
      • setDeleteHandler

        public void setDeleteHandler​(DeleteHandler<Object> deleteHandler)
        To use a custom DeleteHandler to delete the row after the consumer is done processing the exchange
      • setPreDeleteHandler

        public void setPreDeleteHandler​(DeleteHandler<Object> preDeleteHandler)
        To use a custom Pre-DeleteHandler to delete the row after the consumer has read the entity.
      • getUseExecuteUpdate

        public Boolean getUseExecuteUpdate()
      • setUseExecuteUpdate

        public void setUseExecuteUpdate​(Boolean useExecuteUpdate)
        To configure whether to use executeUpdate() when producer executes a query. When you use INSERT, UPDATE or DELETE statement as a named query, you need to specify this option to 'true'.
      • isFindEntity

        public boolean isFindEntity()
      • setFindEntity

        public void setFindEntity​(boolean findEntity)
        If enabled then the producer will find a single entity by using the message body as key and entityType as the class type. This can be used instead of a query to find a single entity.
      • validate

        protected void validate()
      • createEntityManagerFactory

        protected javax.persistence.EntityManagerFactory createEntityManagerFactory()
      • createTransactionManager

        protected org.springframework.transaction.PlatformTransactionManager createTransactionManager()
      • createEntityManager

        @Deprecated
        protected javax.persistence.EntityManager createEntityManager()
        Deprecated.
        use getEntityManagerFactory() to get hold of factory and create an entity manager using the factory.
      • createTransactionTemplate

        protected org.springframework.transaction.support.TransactionTemplate createTransactionTemplate()
      • createProducerExpression

        protected org.apache.camel.Expression createProducerExpression()
      • doInit

        protected void doInit()
                       throws Exception
        Overrides:
        doInit in class org.apache.camel.support.DefaultEndpoint
        Throws:
        Exception