Services

A service is the entry point to the server-side of the application.

Defining a Service

A service binds together a bunch of logical operations and connects them to the relevant DAOs. Therefore, the service must be injected with all relevant DAOs when it is instantiated. This is done in Spring.

The following definition needs only appear once in the Spring configuration as it defines the parent service:

 <bean id="service" abstract="true" />

Define your service as a concrete bean:

 <bean parent="service" id="authorizationService"
        class="net.sf.shineframework.tolls.services.impl.AuthorizationServiceImpl">
        <property name="groupDao" ref="groupDao" />
 </bean>

Creating a Service

Services and Transactions

Each service method must use the @Transactional annotation to define the method as a transaction entry point. This definition, in addition to the regular Spring-based aop advices that start and end transactions, will also activate the following advices when necessary:

  • TxRollbackAdvice - rolls back the transaction in case it fails. The fail status is determined by the user context isFailed() method.
  • GenericExceptionHandlerOnThrownAdvice - currently it only handles an UnexpectedRollbackException by simple adding a message with the key "unexpectedRollback" defined as an error message in the framework.

    Methods marked as @Transactional are encouraged to make proper use of the readOnly property of this annotation.

Programming Conventions

  • Your service interfaces should be placed in a package called: net.sf.shineframework.XXX.services whereas XXX is the name of your project.
  • Your service implementation class should be placed in a package called: net.sf.shineframework.XXX.services.impl whereas XXX is the name of your project.