Configurez les fichiers XML de la configuration JPA. Pour configurer un JPALoader ou JPAEntityLoader, voir Plug-in pour communiquer avec les bases de données.
Configuration d'un rappel de transaction JPATxCallback avec la configuration du chargeur. L'exemple suivant est un fichier de descripteur XML ObjectGrid (objectgrid.xml), qui dispose d'un bean JPAEntityLoader et d'un bean JPATxCallback configurés :
configuration d'un chargeur avec rappel - Exemple XML
<?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>
Si vous souhaitez configurer un JPAPropertyFactory, vous devez utiliser une configuration de type Spring. Voici un exemple de fichier de configuration XML,JPAEM_spring.xml qui configure un bean Spring à utiliser pour les configurations eXtreme Scale.
configuration d'un chargeur avec une fabrique de propriétés JPA - Exemple XML
<?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>
Le fichier de configuration XML Objectgrid.xml est
présenté ci-après. Notez que le nom ObjectGrid est JPAEM, qui correspond au nom ObjectGrid dans le fichier de configuration Spring JPAEM_spring.xml.
Configuration du chargeur JPAEM - Exemple de XML
<?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>
Une entité peut être annotée avec les annotations JPA et les annotations
du gestionnaire d'entités d'eXtreme Scale. Chaque
annotation possède un équivalent XML qui peut être utilisé.
eXtreme Scale a donc ajouté l'espace
de noms Spring. Vous pouvez également les configurer à l'aide de la prise en charge de l'espace
de noms Spring. Pour plus d'informations, voir
Présentation de l'infrastructure Spring.