Difference between revisions of "DTO Service DSL"

From OS.bee documentation
Jump to: navigation, search
(package definition)
(package definition)
Line 33: Line 33:
  
 
* For every dtoservice, a new .java files will be generated, <dtoservice name>.java. This .java files is generated in folder ./src-gen/<package name>/.  
 
* For every dtoservice, a new .java files will be generated, <dtoservice name>.java. This .java files is generated in folder ./src-gen/<package name>/.  
   In this file, a java class extended from AbstractDTOServiceWithMutablePersistence named of <dtoservice name> will be generated.
+
   In this file, a java class extended from AbstractDTOServiceWithMutablePersistence named of <dtoservice name> will be generated:
   This java class defines the EntityManagerFactory, it is used to support instantiation of EntityManager .
+
   This java class defines the EntityManagerFactory, it is used to support instantiation of EntityManager.
 
   An EntityManager instance is associated with a persistence context.  
 
   An EntityManager instance is associated with a persistence context.  
 
   A persistence context is a set of entity instances in which for any persistent entity identity there is a unique entity instance. Within the persistence context, the entity instances and their lifecycle are managed.  
 
   A persistence context is a set of entity instances in which for any persistent entity identity there is a unique entity instance. Within the persistence context, the entity instances and their lifecycle are managed.  

Revision as of 13:59, 23 November 2017

Introduction

Dto Service model works for the DTO when it needs to communicate with persistence unit. All necessary information about the persistence which is not defined in DTO model will be read here.

DTO Service DSL

The DTO Sevice model is automatically generated when DTO has been defined. It defines which persistence unit the DTO should communicate with and self-defined select-clause can also be defined here.

The main semantic elements of the DTO Service DSL are:

  • package - The root element that contains all the other elements. A model can contain multiple packages.
  • dtoservice - define the DTO service name and which DTO it serves to .
  • mutable persistenceUnit - define the persistence Unit, which the DTO will communicate with.
  • def - define the java function with dto parameter for the service.

Syntax

package definition

Syntax:

package <service name> {
	dtoservice <dtoservice name> provides <dto name> {
		mutable persistenceUnit <persistenceUnit name>

		[def <jvmType> <function name> (<dtotype name> <var name> )
			{<block expression>}
		]
	}
	. . .
}


  • For every dtoservice, a new .java files will be generated, <dtoservice name>.java. This .java files is generated in folder ./src-gen/<package name>/.
 In this file, a java class extended from AbstractDTOServiceWithMutablePersistence named of <dtoservice name> will be generated:
 This java class defines the EntityManagerFactory, it is used to support instantiation of EntityManager.
 An EntityManager instance is associated with a persistence context. 
 A persistence context is a set of entity instances in which for any persistent entity identity there is a unique entity instance. Within the persistence context, the entity instances and their lifecycle are managed. 
 The EntityManager API is used to create and remove persistent entity instances, to find entities by their primary key, and to query over entities.
 The set of entities that can be managed by a given EntityManager instance is defined by a persistence unit. 
 A persistence unit defines the set of all classes that are related or grouped by the application, and which must be colocated in their mapping to a single database.


  • In the self-defined java function, you can define any database select-clause as you want.

Example:

package net.osbee.sample.foodmart.dtos.service {
	dtoservice McurrencyNameStreamDtoService provides McurrencyNameStreamDto{
		mutable persistenceUnit businessdata
	}

	dtoservice CashSlipDtoService provides CashSlipDto {
		mutable persistenceUnit businessdata

		def double calcTotal( CashSlipDto slip ) {
			val ql = createJPQL( "select sum(p.price) from CashSlipPosition p where p.slip.id = :headerUUID"
			, # {"headerUUID" -> slip.^id} )
			val result = this.findValues( ql )
			return result.get( 00 ) as Double
		}

	}
}

Copyright Notice

All rights are reserved by Compex Systemhaus GmbH. In particular, duplications, translations, microfilming, saving and processing in electronic systems are protected by copyright. Use of this manual is only authorized with the permission of Compex Systemhaus GmbH. Infringements of the law shall be punished in accordance with civil and penal laws. We have taken utmost care in putting together texts and images. Nevertheless, the possibility of errors cannot be completely ruled out. The Figures and information in this manual are only given as approximations unless expressly indicated as binding. Amendments to the manual due to amendments to the standard software remain reserved. Please note that the latest amendments to the manual can be accessed through our helpdesk at any time. The contractually agreed regulations of the licensing and maintenance of the standard software shall apply with regard to liability for any errors in the documentation. Guarantees, particularly guarantees of quality or durability can only be assumed for the manual insofar as its quality or durability are expressly stipulated as guaranteed. If you would like to make a suggestion, the Compex Team would be very pleased to hear from you.

(c) 2016-2024 Compex Systemhaus GmbH