Java 実装
提供されている各コンポーネントは o.s.i.jpa.core.JpaExecutor
クラスを使用し、このクラスは o.s.i.jpa.core.JpaOperations
インターフェースの実装を使用します。JpaOperations
は一般的なデータアクセスオブジェクト (DAO) のように動作し、find、persist、executeUpdate などのメソッドを提供します。ほとんどのユースケースでは、既定の実装 (o.s.i.jpa.core.DefaultJpaOperations
) で十分です。ただし、カスタム動作が必要な場合は、独自の実装を指定できます。
JpaExecutor
を初期化するには、次のいずれかを受け入れるコンストラクターのいずれかを使用する必要があります。
EntityManagerFactory
EntityManager
JpaOperations
次の例は、JpaExecutor
を entityManagerFactory
で初期化し、送信ゲートウェイで使用する方法を示しています。
@Bean
public JpaExecutor jpaExecutor() {
JpaExecutor executor = new JpaExecutor(this.entityManagerFactory);
executor.setJpaParameters(Collections.singletonList(new JpaParameter("firstName", null, "#this")));
executor.setUsePayloadAsParameterSource(true);
executor.setExpectSingleResult(true);
return executor;
}
@ServiceActivator(inputChannel = "getEntityChannel")
@Bean
public MessageHandler retrievingJpaGateway() {
JpaOutboundGateway gateway = new JpaOutboundGateway(jpaExecutor());
gateway.setGatewayType(OutboundGatewayType.RETRIEVING);
gateway.setOutputChannelName("resultsChannel");
return gateway;
}