Package org.apache.camel.component.jpa
Class JpaEndpoint
java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.support.DefaultEndpoint
org.apache.camel.support.ScheduledPollEndpoint
org.apache.camel.component.jpa.JpaEndpoint
- All Implemented Interfaces:
AutoCloseable,org.apache.camel.CamelContextAware,org.apache.camel.ComponentAware,org.apache.camel.Endpoint,org.apache.camel.IsSingleton,org.apache.camel.Service,org.apache.camel.ShutdownableService,org.apache.camel.spi.HasCamelContext,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,
headersClass=JpaConstants.class)
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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidconfigureProperties(Map<String, Object> options) org.apache.camel.ConsumercreateConsumer(org.apache.camel.Processor processor) protected Stringprotected jakarta.persistence.EntityManagerDeprecated.protected jakarta.persistence.EntityManagerFactoryorg.apache.camel.PollingConsumerorg.apache.camel.Producerprotected org.apache.camel.Expressionprotected DefaultTransactionStrategyprotected voiddoInit()jakarta.persistence.EntityManagerFactoryAdditional properties for the entity manager to use.Class<?> intjakarta.persistence.LockModeTypeintintorg.apache.camel.ExpressiongetQuery()Class<?> booleanbooleanbooleanbooleanbooleanbooleanisRemove()booleanbooleanbooleanbooleanbooleanbooleanvoidsetConsumeDelete(boolean consumeDelete) If true, the entity is deleted after it is consumed; if false, the entity is not deleted.voidsetConsumeLockEntity(boolean consumeLockEntity) Specifies whether to set an exclusive lock on each entity bean while processing the results from polling.voidsetDeleteHandler(DeleteHandler<Object> deleteHandler) To use a custom DeleteHandler to delete the row after the consumer is done processing the exchangevoidsetEntityManagerFactory(jakarta.persistence.EntityManagerFactory entityManagerFactory) TheEntityManagerFactoryto use.voidsetEntityManagerProperties(Map<String, Object> entityManagerProperties) voidsetEntityType(Class<?> entityType) The JPA annotated class to use as entity.voidsetFindEntity(boolean findEntity) If enabled, then the producer will find a single entity by using the message body as a key and entityType as the class type.voidsetFirstResult(int firstResult) Set the position of the first result to retrieve.voidsetFlushOnSend(boolean flushOnSend) Flushes the EntityManager after the entity bean has been persisted.voidsetJoinTransaction(boolean joinTransaction) The camel-jpa component will join transaction by default.voidsetLockModeType(jakarta.persistence.LockModeType lockModeType) To configure the lock mode on the consumer.voidsetMaximumResults(int maximumResults) Set the maximum number of results to retrieve on the Query.voidsetMaxMessagesPerPoll(int maxMessagesPerPoll) An integer value to define the maximum number of messages to gather per poll.voidsetNamedQuery(String namedQuery) To use a named query.voidsetNativeQuery(String nativeQuery) To use a custom native query.voidsetOutputTarget(String outputTarget) To put the query (or find) result in a header or property instead of the body.voidsetParameters(Map<String, Object> parameters) This key/value mapping is used for building the query parameters.voidsetPersistenceUnit(String persistenceUnit) The JPA persistence unit used by default.voidsetPreDeleteHandler(DeleteHandler<Object> preDeleteHandler) To use a custom Pre-DeleteHandler to delete the row after the consumer has read the entity.voidsetProducerExpression(org.apache.camel.Expression producerExpression) voidTo use a custom query.voidsetRemove(boolean isRemove) Indicates to use entityManager.remove(entity).voidsetResultClass(Class<?> resultClass) Defines the type of the returned payload (we will call entityManager.createNativeQuery(nativeQuery, resultClass) instead of entityManager.createNativeQuery(nativeQuery)).voidsetSharedEntityManager(boolean sharedEntityManager) Whether to use Spring's SharedEntityManager for the consumer/producer.voidsetSingleResult(boolean singleResult) If enabled, a query or a find which would return no results or more than one result, will throw an exception instead.voidsetSkipLockedEntity(boolean skipLockedEntity) To configure whether to use NOWAIT on lock and silently skip the entity.voidsetTransacted(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.voidsetTransactionStrategy(TransactionStrategy transactionStrategy) voidsetUseExecuteUpdate(Boolean useExecuteUpdate) To configure whether to use executeUpdate() when producer executes a query.voidsetUsePassedInEntityManager(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.voidsetUsePersist(boolean usePersist) Indicates to use entityManager.persist(entity) instead of entityManager.merge(entity).protected voidvalidate()Methods inherited from class org.apache.camel.support.ScheduledPollEndpoint
configureConsumer, configureScheduledPollConsumerProperties, doConfigureConsumer, 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, setUseFixedDelayMethods 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, toStringMethods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doLifecycleChange, doResume, doShutdown, doStart, doStop, doSuspend, fail, getInternalLock, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspendMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.camel.ComponentAware
getComponentMethods inherited from interface org.apache.camel.Endpoint
getEndpointBaseUri, isRemote, isSingletonProducerMethods inherited from interface org.apache.camel.Service
build, close, init, start, stopMethods inherited from interface org.apache.camel.ShutdownableService
shutdownMethods inherited from interface org.apache.camel.StatefulService
getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspendingMethods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
-
Constructor Details
-
JpaEndpoint
public JpaEndpoint() -
JpaEndpoint
-
-
Method Details
-
getComponent
- Specified by:
getComponentin interfaceorg.apache.camel.ComponentAware- Overrides:
getComponentin classorg.apache.camel.support.DefaultEndpoint
-
createProducer
- Throws:
Exception
-
createConsumer
public org.apache.camel.Consumer createConsumer(org.apache.camel.Processor processor) throws Exception - Throws:
Exception
-
createPollingConsumer
- Specified by:
createPollingConsumerin interfaceorg.apache.camel.Endpoint- Overrides:
createPollingConsumerin classorg.apache.camel.support.DefaultEndpoint- Throws:
Exception
-
configureProperties
- Specified by:
configurePropertiesin interfaceorg.apache.camel.Endpoint- Overrides:
configurePropertiesin classorg.apache.camel.support.ScheduledPollEndpoint
-
createEndpointUri
- Overrides:
createEndpointUriin classorg.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. -
getFirstResult
public int getFirstResult() -
setFirstResult
public void setFirstResult(int firstResult) Set the position of the first result to retrieve. -
getEntityType
-
setEntityType
The JPA annotated class to use as entity. -
getEntityManagerFactory
public jakarta.persistence.EntityManagerFactory getEntityManagerFactory() -
setEntityManagerFactory
public void setEntityManagerFactory(jakarta.persistence.EntityManagerFactory entityManagerFactory) TheEntityManagerFactoryto use. -
getTransactionStrategy
-
setTransactionStrategy
-
getEntityManagerProperties
Additional properties for the entity manager to use. -
setEntityManagerProperties
-
getPersistenceUnit
-
setPersistenceUnit
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 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. It 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. -
getQuery
-
setQuery
To use a custom query. -
getNamedQuery
-
setNamedQuery
To use a named query. -
getNativeQuery
-
setNativeQuery
To use a custom native query. You may want to use the option resultClass also when using native queries. -
getLockModeType
public jakarta.persistence.LockModeType getLockModeType() -
setLockModeType
public void setLockModeType(jakarta.persistence.LockModeType lockModeType) To configure the lock mode on the consumer. -
getParameters
-
setParameters
This key/value mapping is used for building the query parameters. It is expected to be of the generic type java.util.Mapinvalid input: '<'String, Object> 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
-
setResultClass
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 effect when using in conjunction with a 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 roll back 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. -
getDeleteHandler
-
setDeleteHandler
To use a custom DeleteHandler to delete the row after the consumer is done processing the exchange -
getPreDeleteHandler
-
setPreDeleteHandler
To use a custom Pre-DeleteHandler to delete the row after the consumer has read the entity. -
getUseExecuteUpdate
-
setUseExecuteUpdate
To configure whether to use executeUpdate() when producer executes a query. When you use INSERT, UPDATE or a 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 a key and entityType as the class type. This can be used instead of a query to find a single entity. -
isSingleResult
public boolean isSingleResult() -
setSingleResult
public void setSingleResult(boolean singleResult) If enabled, a query or a find which would return no results or more than one result, will throw an exception instead. -
getOutputTarget
-
setOutputTarget
To put the query (or find) result in a header or property instead of the body. If the value starts with the prefix "property:", put the result into the so named property, otherwise into the header. -
validate
protected void validate() -
createEntityManagerFactory
protected jakarta.persistence.EntityManagerFactory createEntityManagerFactory() -
createEntityManager
Deprecated.usegetEntityManagerFactory()to get hold of factory and create an entity manager using the factory. -
createTransactionStrategy
-
createProducerExpression
protected org.apache.camel.Expression createProducerExpression() -
doInit
- Overrides:
doInitin classorg.apache.camel.support.DefaultEndpoint- Throws:
Exception
-
getEntityManagerFactory()to get hold of factory and create an entity manager using the factory.