Some questions

2 views
Skip to first unread message

jokoul webster

unread,
Nov 5, 2009, 1:42:10 AM11/5/09
to jEmbedded Discussion Group
Hi:
Declaration Transaction is a good mechanism of Spring, so I would
like to register all Business Services in Spring Context in order to
control transaction with AOP,but now,if I wanna add some JEmbedded
annotations such as @include,@annotatedService,etc to a Business
Service which has already been registerd in Spring Context,I think:
1:Spring can not know these business services with JEmbedded
annotations;
2:Spring Declaration Transaction would not work
3:Also,Spring Cache would not work

So,what can I do?

Adolfo Estevez

unread,
Nov 5, 2009, 8:37:39 AM11/5/09
to jEmbedded Discussion Group

It wouldn't work that way but what you can actually do is:

1 - Using @SpringContext annotation declare a Spring
ApplicationContext with your DAO's, TransactionManager,
BusinessServices etc. The transaction demarcation will be at the
BusinessService level.

2- using the @Inject ref="businessSevice" annotation compose another
@Service that actually would do the rest of the stuff (invoking a ws,
etc).

@SpringContext(....)
@AnnotateService (id="managerService)
public ManagerService {

@Inject(ref="service")
private BusinessService service = null;


public makeStuff() {

try {
service.insertIntoDatabase();
invoke.otheService();
}
catch(DataAccessException e) {
{
...
}

}

3 - If the BusinessService throws and exception it will execute a
rollback and also you can catch this exception in the "high level
service".


Another option you'd have it's to inject into the service the
TransactionManagerPlatform and handle the transactions yourself. In
fact I have a @Transaction annotation in the DatabaseIntegrationTest
moudle that behaves like that. I will have a look for the next
version.

By the way I'm working on the docs, not this week as I'm giving a
course but I will resume the work this weekend.

Take care

Adolfo

jokoul webster

unread,
Nov 6, 2009, 2:11:17 AM11/6/09
to jEmbedded Discussion Group
Hi Adolfo:
But you know,there will be so many Spring configuration files
wihtin a application,and most of them are related each other,so if I
write @SpringContext(....) annotation will have to find all related
Spring configuration files and the parameters would be too long,for
example @SpringContext(file1,file2,file3,file4.......) .
And actually in my project I use dynamic module mechanism,that
means all Spring configuration files would be loaded
(reloaded,removed...) based on whether current module is reloaded or
not,so,my Spring context is dynamic too,I cannot simply use
@SpringContext(....) ,this way,what can I do.
Any advice would be appreciated,thanks.

JK.Webster

Adolfo Estevez

unread,
Nov 6, 2009, 9:53:21 AM11/6/09
to jEmbedded Discussion Group
Hi Jokoul,

Yeah I see what you mean, didn't know you context was so complex :)
are you using oSGI?

Ok what you can do it's to use the other integration method with
Spring that I provided thta it's exporting the jEmbedded container
into the Spring context, a layer or just a service:

1) Exporting a service from the jembedded repo to the spring context:


your-spring-context.xml file

<bean id="echoMuleService"
class="org.jsemantic.jembedded.support.spring.exporter.ServiceExporter">
<property name="id" value="echoMuleService"/>

<property name="annotatedClasses">
<list>

<value>org.jsemantic.jembedded.examples.services.mule.EchoMuleService</
value>
</list>
</property>
</bean>

now you can inject this jembedded-service-bean whenever you needed it
as it would be available in the spring-context.

2) Maybe the best option it's to configure the services into a layer
and export it to the spring-context, this way you could apply the
transactionality support at the layer level:


your-spring-context.xml file

<import resource="classpath:META-INF/properties-service/properties-
service.xml"/>

<bean id="servicesLayer"
class="org.jsemantic.jembedded.support.spring.exporter.ServiceLayerExporter">

<property name="exportedLayer" value="${layer.services}"/>
<property name="annotatedClasses">
<list>
<value>${layer.integration}</value>
<value>${layer.business}</value>
<value>${layer.services}</value>
</list>
</property>
</bean>

This way you make available the ServicesLayer to the spring context.

2) Exporting the full jEmbedded container into the spring-context:

your-spring-context.xml file

<bean id="handler"
class="org.jsemantic.jembedded.support.spring.EmbeddedContainerRunner">
<property name="annotatedClasses">
<list>
<value>class1</value>
<value>class2</value>
<value>class3</value>
</list>
</property>
</bean>

then you would have the handler available in the spring-context, maybe
it's not the best approach.

Hope this helps, I think the second option would work and in fact I
will implement it in the case study.


Take care

Adolfo

jokoul webster

unread,
Nov 7, 2009, 5:28:50 AM11/7/09
to jembedded-dis...@googlegroups.com
Hi Adolfo:
    From your advice,if I use "ServiceLayerExporter" or "ServiceExporter" then how I can configuration AOP's pointcut expression,for example :
===================================================================
<bean id="invoicesService" class="org.jsemantic.jembedded.support.spring.exporter.ServiceExporter">
  <property name="id" value="invoicesService"/>  
  <property name="annotatedClasses">
   <list>
    <value>org.jsemantic.services.examples.energy.invoice.InvoiceService</value>
   </list>
  </property>
 </bean>
 
 <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource"/>
 </bean>
 
 <tx:advice id="txAdvice" transaction-manager="txManager" >
  <tx:attributes>
   <tx:method name="get*" read-only="true"/>
   <tx:method name="load*" read-only="true"/>
   <tx:method name="select*" read-only="true"/>
   <tx:method name="query*" read-only="true"/>
   <tx:method name="criteria*" read-only="true"/>
   <tx:method name="find*" read-only="true"/>
   
   <tx:method name="generate*" read-only="false" propagation="REQUIRED" rollback-for="Exception"/>
  </tx:attributes>
 </tx:advice>
 
 <aop:config>
  <aop:pointcut id="serviceOperation"   
  expression="execution(* org.jsemantic.services.examples.energy..*Service.*(..))"/>   
  <aop:advisor pointcut-ref="serviceOperation" advice-ref="txAdvice"  />
 </aop:config>
===================================================================
you can see I have configurated this AOP expression with "org.jsemantic.services.examples.energy..*Service.*(..))",this way I wanna intercept org.jsemantic.services.examples.energy.invoice.InvoiceService which has been exported by jembedded,but in fact the Spring Declaration Transaction doesn't work,can you help me?Thanks.

Adolfo Estevez

unread,
Nov 7, 2009, 3:16:35 PM11/7/09
to jEmbedded Discussion Group
Hi,

I guess it's because InvoicesService it's an abstract service and in
fact a proxy it's generated to handle it, so that can be the problem.
Can you try with a regular service? It's a wild guess. I'll try myself
tomorrow.

Take care

Adolfo

Adolfo Estevez

unread,
Nov 9, 2009, 2:17:09 AM11/9/09
to jEmbedded Discussion Group
Hi Jokoul,

Sorry I didn't realize that you were using the actual InvoiceService
that I included with the case study.

This service it's an example of what I name embedded services because
it embeds everything it needs to work and can be imported as a whole,
in this case a Derby database. What it's more this database it's
created using a @SpringContext annotation and its file as a
persistence-layer.xml:


<import resource="classpath:META-INF/invoices-service/properties-
service/properties-service.xml"/>

<bean id="dataSource"
class="org.jsemantic.services.jdbc.service.datasource.derby.DerbyDataSource">
<property name="dbName" value="${dataSource.derby.uri}" />
<property name="user" value="${dataSource.derby.user}" />
<property name="password" value="${dataSource.derby.password}" />
<property name="databaseCreationScript" value="$
{dataSource.derby.createSchemaScript}"/>
<property name="dataCreationScript" value="$
{dataSource.derby.populateSchemaScript}"/>
</bean>

<bean id="customerDao"
class="org.jsemantic.services.examples.energy.invoice.dao.CustomerDAO"
autowire="autodetect"/>

So you need to put the the transactional stuff here in order to work,
as the datasource wasn't exposed in your declaration file, only the
service.

You can use the exception throwed by the InvoiceService if you need it
to participate in other transaction.

Hope this helps

Adolfo






On 7 nov, 11:28, jokoul webster <jokoulwebs...@gmail.com> wrote:

mens jamie

unread,
Nov 9, 2009, 3:48:19 AM11/9/09
to jembedded-dis...@googlegroups.com
Hi Adolfo:
    Thanks,but I do have my <bean id="dataSource" ....> in another Spring configuration file and have used @SpringRepository annotation to import it,if there is no "dataSource" bean registerd in Spring context I wouldn't run my example successfully,my trouble is only that the declaration transaction mechanism could't work.
 
 
JK.Webster

Adolfo Estevez

unread,
Nov 9, 2009, 4:46:14 AM11/9/09
to jEmbedded Discussion Group
Ok, I'll test it myself then, I'm finishing the Spring Integration
docs.

Adolfo
Reply all
Reply to author
Forward
0 new messages