Um Utilitário de Carga do Java Persistence API (JPA) é uma implementação de plug-in que utiliza JPA para interagir com o banco de dados.
Os seguintes parâmetros são necessários. Esses parâmetros são configurados no bean JPALoader ou JPAEntityLoader e no bean JPATxCallback.
Diferente dos quatro parâmetros JPA a serem configurados no eXtreme Scale, os metadados JPA são usados para recuperar a chave das entidades JPA. Os metadados JPA podem ser configurados como anotação ou como um arquivo orm.xml especificado no arquivo persistence.xml. Eles não fazem parte da configuração do eXtreme Scale.
Para configurar um JPALoader ou JPAEntityLoader, consulte Plug-ins para a Comunicação com os Bancos de Dados.
Configure um retorno de chamada de transação JPATxCallback junto com a configuração do carregador. O exemplo a seguir é um arquivo descritor XML do ObjectGrid (objectgrid.xml) que possui um JPAEntityLoader e JPATxCallback configurado:
Configurando um utilitário de carga incluindo um retorno de chamada - XML de exemplo
<?xml version="1.0" encoding="UTF-8"?>
<objectGridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ibm.com/ws/objectgrid/config ../objectGrid.xsd"
xmlns="http://ibm.com/ws/objectgrid/config">
<objectGrids>
<objectGrid name="JPAEM" entityMetadataXMLFile="jpaEMD.xml">
<bean id="TransactionCallback"
className="com.ibm.websphere.objectgrid.jpa.JPATxCallback">
<property
name="persistenceUnitName"
type="java.lang.String"
value="employeeEMPU" />
</bean>
<backingMap name="Employee" pluginCollectionRef="Employee" />
</objectGrid>
</objectGrids>
<backingMapPluginCollections>
<backingMapPluginCollection id="Employee">
<bean id="Loader"
className="com.ibm.websphere.objectgrid.jpa.JPAEntityLoader">
<property
name="entityClassName"
type="java.lang.String"
value="com.ibm.ws.objectgrid.jpa.test.entity.Employee"/>
</bean>
</backingMapPluginCollection>
</backingMapPluginCollections>
</objectGridConfig>
Se desejar configurar um JPAPropertyFactory, será necessário usar uma configuração de estilo Spring. A seguir há uma amostra de arquivo de configuração XML, JPAEM_spring.xml, que configura um bean Spring a ser usado para as configurações do eXtreme Scale.
Configurando um utilitário de carga incluindo um factory de propriedade JPA - XML de exemplo
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:objectgrid="http://www.ibm.com/schema/objectgrid"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<objectgrid:JPAEntityLoader id="jpaLoader"
entityClassName="com.ibm.ws.objectgrid.jpa.test.entity.Employee"/>
<objectgrid:JPATxCallback id="jpaTxCallback" persistenceUnitName="employeeEMPU" />
</beans>
O arquivo XML de configuração Objectgrid.xml vem a seguir. Observe que o nome do ObjectGrid é JPAEM, que corresponde ao nome do ObjectGrid no arquivo de configuração Spring JPAEM_spring.xml.
Configuração de um utilitário de carga JPAEM - XML de exemplo
<?xml version="1.0" encoding="UTF-8"?>
<objectGridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ibm.com/ws/objectgrid/config ../objectGrid.xsd"
xmlns="http://ibm.com/ws/objectgrid/config">
<objectGrids>
<objectGrid name="JPAEM" entityMetadataXMLFile="jpaEMD.xml">
<bean id="TransactionCallback"
className="{spring}jpaTxCallback"/>
<backingMap name="Employee" pluginCollectionRef="Employee"
writeBehind="T4"/>
</objectGrid>
</objectGrids>
<backingMapPluginCollections>
<backingMapPluginCollection id="Employee">
<bean id="Loader" className="{spring}jpaLoader" />
</backingMapPluginCollection>
</backingMapPluginCollections>
</objectGridConfig>
Uma entidade pode ser anotada com as anotações do JPA e com as anotações do gerenciador de entidade do eXtreme Scale. Cada anotação possui um XML equivalente que pode ser utilizado. Assim, o eXtreme Scale incluiu o espaço de nomes Spring. Também é possível configurá-los utilizando o suporte a espaço de nomes Spring. Para obter informações adicionais, consulte Visão Geral da Estrutura Spring.