cborm
Install
v3.x
v3.x
  • Introduction
  • Intro
    • Release History
      • What's New With 3.9.0
      • What's New With 3.8.0
      • What's New With 3.7.0
      • What's New With 3.6.0
      • What's New With 3.5.0
      • What's New With 3.4.0
      • What's New With 3.3.0
      • What's New With 3.2.x
      • What's New With 3.1.0
      • What's New With 3.0.0
    • About This Book
    • Author
  • Getting Started
    • Overview
    • Installation
    • Basic Crud - Services
    • Basic Crud - ActiveEntity
  • Base ORM Service
    • Overview
    • Service Properties
    • Concrete Services
    • Service Methods
      • Criteria Queries
        • getRestrictions
        • newCriteria
      • Creation - Population
        • new
        • populate
        • populateFromJSON
        • populateFromQuery
        • populateFromXML
      • Counters
        • count
        • countWhere
        • exists
      • Deleting Entities
        • delete
        • deleteAll
        • deleteByID
        • deleteByQuery
        • deleteWhere
      • Entity Convenience Methods
        • getDirtyPropertyNames
        • getEntityGivenName
        • getEntityMetadata
        • getKey
        • getKeyValue
        • getPropertyNames
        • getTableName
        • isDirty
        • refresh
      • Finders
        • findit
        • findOrFail
        • findByExample
        • findWhere
        • findAll
        • findAllWhere
      • Getters
        • get
        • getOrFail
        • getAll
      • ORM Session
        • clear
        • evict
        • evictCollection
        • evictQueries
        • getSessionStatistics
        • isSessionDirty
        • merge
        • sessionContains
      • Querying
        • executeQuery
        • list
      • Saving Entities
        • save
        • saveAll
      • Utility Methods
        • autoCast
        • createService
        • idCast
        • nullValue
        • when
    • Dynamic Finders- Counters
      • Method Signatures
      • Method Expressions
      • Query Options
    • Automatic Java Types
  • Virtual Services
    • Overview
    • Service Properties
    • Concrete Virtual Services
  • Active Record
    • Active Entity Overview
    • Constructor Properties
    • Usage
    • Validation
  • Criteria Queries
    • Criteria Builder
      • Getting Started
      • Restrictions
        • Value Casting
        • SQL Restrictions
      • Modifiers
      • Results
      • Associations
      • Projections & Aggregates
    • Detached Criteria Builder
      • Getting Started
      • Projections
      • Subqueries
      • DetachedSQLProjection()
      • Criterias
      • Associations
    • Help! I'm Not Getting the Result I expected!
  • Advanced Features
    • Automatic REST Crud
    • Hibernate Logging
    • Mementifier
    • ORM Events
      • Custom Event Handler
    • Unique Property Validation
Powered by GitBook
On this page
  • Injection Virtual Services
  • Requesting Virtual Services
  • Mapping Virtual Services

Was this helpful?

Edit on Git
Export as PDF
  1. Virtual Services

Overview

PreviousAutomatic Java TypesNextService Properties

Last updated 3 years ago

Was this helpful?

The virtual entity service is another support class that can help you create virtual service layers that are bounded to a specific ORM entity for convenience. This class inherits from our Base ORM Service and allows you to do everything the base class provides, except you do not need to specify to which entityName or entity you are working with.

You can also use this class as a base class and template out its methods to more concrete usages. The idea behind this virtual entity service layer is to allow you to have a very nice abstraction to all the CF ORM capabilities (hibernate) and promote best practices.

Tip: Please remember that you can use ANY method found in the except that you will not pass an argument of entityName anymore as you have now been bounded to that specific entity.

Injection Virtual Services

The WireBox injection DSL has an injection namespace called entityService that can be used to wire in a Virtual Entity Service bound to ANY entity in your application. You will use this DSL in conjunction with the name of the entity to manage it.

Inject Content

Description

entityService:{entity}

A virtual service based on the {entity}

component{
    // Virtual service layer based on the User entity
    property name="userService" inject="entityService:User";
    
}

Requesting Virtual Services

You can also request a virtual service via the getInstance() method in your handlers or view a wirebox.getInstance() call:

userService = getInstance( dsl="entityService:User" );

usersFound = userService.count();
user = userService.new( {firstName="Luis",lastName="Majano",Awesome=true} );
userService.save( user );

user = userService.get( "123" );

var users = userService.newCriteria()
    .like("lastName", "%maj%")
    .isTrue("isActive")
    .list(sortOrder="lastName");

Mapping Virtual Services

You can also leverage the WireBox Binder to map your virtual services so you can abstract the object's constructions or add constructor arguments to their definition and have full control:

config/WireBox.cfc
function configure(){
    
    map( "UserService" )
        .to( "cborm.models.VirtualEntityService" )
        .initArg( name="entityName", value="User" )
        .initArg( name="useQueryCaching", value="true" )
        .initArg( name="defaultAsQuery", value="false" );
}

Now you can just use it via the UserService alias:

handlers/user.cfc
component{
    
    // Inject Alias
    property name="userService" inject="UserService";
    
    function index( event, rc, prc ){
        var usersFound = userService.count();
        var user = userService.new( {firstName="Luis",lastName="Majano",Awesome=true} );
        userService.save( user );
        
        var user = userService.get( "123" );
        
        var users = userService.newCriteria()
            .like("lastName", "%maj%")
            .isTrue("isActive")
            .list(sortOrder="lastName");
    }

}
Base ORM Service