Service Layer - Update Service Example

The following example is using the Country Hibernate Object to perform an update action on the database(if you have not created the Hibernate Object click here). The developer has to define the Business Class and the xml that will plug it to the application

Normally you should receive from an analyst a descriptive document like the following

Name CountryUpdateBC
Package org.jprovocateur.archetype.businesslayer.country
Description Update a country record
Input Object Country
Execution type UPDATE
Transactional true
InitMetadata Default
Initialize Default
Validate Default
Realization Default

The above table says, create a class with name CountryUpdateService in a specific package with the default behavior.

Implementation of the Service

The implementation of the class is easy since only the default behavior is needed, just create the above class extending the BasisLogic class

CountryUpdateService.java

package org.jprovocateur.archetype.businesslayer.country;

import javax.annotation.Resource;

import org.jprovocateur.archetype.objectmodel.country.Country;
import org.jprovocateur.basis.datalayer.GenericDaoDBInt;
import org.jprovocateur.basis.serviceslayer.BusinessLogicInt;
import org.jprovocateur.basis.serviceslayer.impl.BusinessLogic;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;



@Service("countryUpdateService")
@Scope("prototype")
@Transactional(readOnly = false)
public class CountryUpdateService extends BusinessLogic{
	@Resource(name="genericDaoDB")
	private GenericDaoDBInt dao;

	public GenericDaoDBInt getDao() {
		return dao;
	}

	public String getExecutionType() {
		return BusinessLogicInt.UPDATE;
	}	
	
	
}

Declaring the Service and defining Access Rights

In order to make the service available you have to register it in the database and defined its basic characteristics. All services are registered in table BasisClasses.

Column Value Description
CLASSNAME org.jprovocateur.archetype.businesslayer.country.CountryUpdateService the class of the service
DISABLED 0 defines if the service is disabled, possible values 0(false)/1(true)
Defining the Access Rights

Security is based on roles. Each service are accessible only if the user has one of the configured roles. Jprovocateur is offering a web interface to manage user, roles, service and access rights.

    Important tables in the database are
  • Users:contains the users of the application
  • Roles:roles that have access in the application
  • UsersToRoles:assigned roles of the user.
  • BasisClass:configured services.
  • BCToRoles:roles that allowed to access a business case.

 

JUnit Client Creation

The following JUnit class will run the service.

 
Design downloaded from free website templates.
 
Web Templates created with FlashMint. .