Skip to content

Commit

Permalink
Merge pull request #603 from bradsdavis/WINDUP-643
Browse files Browse the repository at this point in the history
WINDUP-643 - Properly resolve Datasource from property/ref style refe…
  • Loading branch information
lincolnthree committed Jun 16, 2015
2 parents 8959bcc + b959bd8 commit 774bc03
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void perform(GraphRewrite event, EvaluationContext context, SpringBeanMod
processHibernateSessionFactoryBean(event, dsBeanNameRef, hibernateDialect, springDbName);
return;
}
LOG.warning("Did not find bean: " + payload.getSpringBeanName() + " to process.");
LOG.warning("Did not find bean: " + payload.getSpringBeanName() + " to process within: " + springConfig.getFileName());
}

private boolean isLocalSessionFactoryBean(String qualifiedName)
Expand Down Expand Up @@ -223,8 +223,13 @@ private String extractJndiRefBeanName(Element bean)
{
// read ref...
String jndiRef = $(dataSource).attr("ref");
if (StringUtils.isNotBlank(jndiRef))
if (StringUtils.isBlank(jndiRef))
{
LOG.info("Looking at ref child of property tag...");
//look to see if the ref is a child of the property tag...
jndiRef = $(dataSource).child("ref").attr("bean");
}
if(StringUtils.isNotBlank(jndiRef)) {
return jndiRef;
}
}
Expand Down Expand Up @@ -318,6 +323,8 @@ public boolean filter(Context context)
String name = $(context).attr("name");
String idVal = $(context).attr("id");

LOG.info("Matching: " + id + " Against -- ID: " + idVal + " Name: " + name);

return (StringUtils.equals(id, idVal) || StringUtils.equals(id, name));
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void testSpringBeans() throws Exception
Assert.assertTrue(StringUtils.isNotBlank(type));

}
Assert.assertEquals(countDataSources, 9);
Assert.assertEquals(countDataSources, 10);
}
}

Expand Down
13 changes: 13 additions & 0 deletions test-files/spring-hibernate-jndi-test/application-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">

<!-- jee JNDI data source-->
<jee:jndi-lookup id="dataSource10" jndi-name="jdbc/ExampleDataSource10"/>

<!-- jee JNDI data source-->
<jee:jndi-lookup id="dataSource9" jndi-name="jdbc/ExampleDataSource9"/>
Expand Down Expand Up @@ -173,4 +175,15 @@
<property name="packagesToScan" value="org.jboss.windup.example.spring.jpa" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter4"/>
</bean>

<!-- test property/ref referencing in datasource property -->
<bean id="jpaPropertyFactory7" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource">
<ref bean="dataSource10"/>
</property>
<property name="packagesToScan" value="org.jboss.windup.example.spring.jpa" />
<property name="jpaVendorAdapter" ref="jpaVendorAdapter4"/>
</bean>


</beans>

0 comments on commit 774bc03

Please sign in to comment.