You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@aries.apache.org by Giuseppe Gerla <gi...@gmail.com> on 2015/02/02 10:45:45 UTC

Property placeholder in jpa Namespace

Hi all,
linked to my pull request #19 to fix ARIES-1023 and ARIES-1079, I'd like to
discuss with you another feature.
In my system I'm using spring-orm to create an EntityManagerFactory to be
injected into my data service. I use a persistence.xml with only classes
list and NO properties declared.
I use the spring file to define the jpa properties in this way

<?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:context="
http://www.springframework.org/schema/context"
xsi:schemaLocation="
       http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">

<osgix:cm-properties id="dataSourceProperties"
persistent-id="sensormix.jpa.persistenceunit">
<prop key="sensormix_db.driverClassName">org.hsqldb.jdbcDriver</prop>
<prop key="sensormix_db.url">jdbc:hsqldb:mem:sensormix_db</prop>
<prop key="sensormix_db.username">sa</prop>
<prop key="sensormix_db.password"></prop>
</osgix:cm-properties>
 <context:property-placeholder
properties-ref="dataSourceProperties" />

<bean id="emf"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="sensormix_db" />
<property name="jpaVendorAdapter">
<bean
class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
<property name="showSql" value="true" />
</bean>
</property>
<property name="jpaProperties">
<props>
<prop key="eclipselink.ddl-generation">create-tables</prop>
<prop key="eclipselink.logging.level">INFO</prop>
<prop key="eclipselink.weaving">false</prop>
<prop
key="javax.persistence.jdbc.driver">${sensormix_db.driverClassName}</prop>
<prop key="javax.persistence.jdbc.url">${sensormix_db.url}</prop>
<prop key="javax.persistence.jdbc.user">${sensormix_db.username}</prop>
<prop key="javax.persistence.jdbc.password">${sensormix_db.password}</prop>
</props>
</property>
</bean>

<!-- Beans of Test Application -->
<bean id="sensormixService"
class="com.google.developers.gdgfirenze.dataservice.SensormixServiceJpaImpl">
<property name="entityManagerFactory" ref="emf" />
</bean>

</beans>

As you can see, some values are parameters that are set using the
property-placeholder. I think this is a very convenient way to manage the
dynamic change of jpa properties.

I try to do the same with Aries Jpa, in this way

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0" xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0">

<cm:property-placeholder persistent-id="sensormix.jpa.persistenceunit"
update-strategy="reload" >
</cm:property-placeholder>
 <bean
class="com.google.developers.gdgfirenze.dataservice.SensormixServiceJpaImpl">
<jpa:unit property="entityManagerFactory" unitname="sensormix_db" />
<jpa:context property="entityManager" unitname="sensormix_db">
<jpa:map>
<entry key="eclipselink.ddl-generation" value="create-tables" />
<entry key="eclipselink.logging.level" value="INFO" />
<entry key="javax.persistence.jdbc.driver"
value="${sensormix_db.driverClassName}" />
<entry key="javax.persistence.jdbc.url" value="${sensormix_db.url}" />
<entry key="javax.persistence.jdbc.user" value="${sensormix_db.username}" />
<entry key="javax.persistence.jdbc.password"
value="${sensormix_db.password}" />
</jpa:map>
</jpa:context>
</bean>
</blueprint>

but it seems that the NSHandler class is not able to resolve the parametric
value. I think this is because the properties map is in the jpa namespace.

Do you think that this is a new feature that we can add to Aries Jpa?


Regards
Giuseppe