Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
lmajano committed Aug 10, 2022
2 parents 85e8cb9 + c51a5e8 commit 5b8fc02
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 57 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ on:
jobs:
tests:
uses: coldbox-modules/cborm/.github/workflows/tests.yml@development
secrets:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

# Format PR
format:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ jobs:
env:
DB_USER: root
DB_PASSWORD: root
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
cfengine: [ "lucee@5", "adobe@2016", "adobe@2018", "adobe@2021" ]
experimental: [false]
include:
- cfengine: "[email protected]"
experimental: true
steps:
- name: Checkout Repository
uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Engine + Secrets + databases
.env
.engine/**
test-harness/.engine
.db/**

# Dependencies
Expand Down
6 changes: 3 additions & 3 deletions box.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name":"ColdBox ORM Extensions",
"version":"3.8.0",
"version":"3.9.0",
"location":"https://downloads.ortussolutions.com/ortussolutions/coldbox-modules/cborm/@build.version@/[email protected]@.zip",
"author":"Ortus Solutions <[email protected]",
"homepage":"https://github.com/coldbox-modules/cborm",
Expand Down Expand Up @@ -55,8 +55,8 @@
"cfpm":"echo '\".engine/adobe2021/WEB-INF/cfusion/bin/cfpm.sh\"' | run",
"cfpm:install":"echo '\".engine/adobe2021/WEB-INF/cfusion/bin/cfpm.sh\" install ${1}' | run",
"install:2021":"run-script cfpm:install zip,debugger,orm,mysql,postgresql,sqlserver,feed",
"install:dependencies" : "install && cd test-harness && install",
"startdbs": "!docker-compose -f docker-compose.yml up"
"install:dependencies":"install && cd test-harness && install",
"startdbs":"!docker-compose -f docker-compose.yml up"
},
"installPaths":{
"cbvalidation":"modules/cbvalidation/",
Expand Down
15 changes: 15 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

----

## [v3.9.0] => 2022-AUG-10

### Added

* New `when( boolean, success, fail )` fluent construct for `ActiveEntity`, `VirtualEntityService` and the `BaseORMService` to allow for fluent chaining of operations on an entity or it's service.
* Migration to new ColdBox Virtual App Testing approaches
* Removed unecessary on load logging to increase performance
* Hibernate 5.4 on Lucee experimental testing

### Fixed

* `countWhere()` invalid SQL exception if no arguments are provided: https://github.com/coldbox-modules/cborm/pull/54

----

## [v3.8.0] => 2022-MAR-09

### Fixed
Expand Down
4 changes: 0 additions & 4 deletions dsl/OrmDsl.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@
component accessors="true" {

property name="injector";
property name="log";


/**
* Constructor as per interface
*/
public any function init( required any injector ){
variables.injector = arguments.injector;
variables.log = arguments.injector.getLogBox().getLogger( this );

return this;
}

Expand Down
58 changes: 43 additions & 15 deletions models/BaseORMService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,33 @@ component accessors="true" {
/************************************ UTILITY METHODS ************************************/
/*****************************************************************************************/

/**
* Functional construct for if statements operating over this service and family of services
*
* The success/failure closures accept the entity in question as the first argument
* <pre>
* when( true|false, ( entity )=> {}, ( entity )=> {} )
* </pre>
*
* @target The boolean evaluator, it has to evaluate to true or false
* @success The closure/lambda to execute if the boolean value is true
* @failure The closure/lambda to execute if the boolean value is false
*
* @return Returns the same object so you can further use chaining
*/
BaseORMService function when(
required boolean target,
required success,
failure
){
if ( arguments.target ) {
arguments.success( this );
} else if ( !isNull( arguments.failure ) ) {
arguments.failure( this );
}
return this;
}

/**
* Lazy loading of the ORM utility according to the CFML engine you are on
* - LuceeORMUtil : For Lucee Engines
Expand Down Expand Up @@ -1614,24 +1641,25 @@ component accessors="true" {
var options = { datasource : getOrm().getEntityDatasource( arguments.entityName ) };

// Do we have arguments?
var params = {};
if ( structCount( arguments ) > 1 ) {
sqlBuffer.append( " WHERE" );
}

// Go over Params and incorporate them
var params = arguments
// filter out reserved names
.filter( function( key, value ){
return ( !listFindNoCase( "entityName", arguments.key ) );
} )
.reduce( function( accumulator, key, value ){
accumulator[ key ] = value;
sqlBuffer.append( " #key# = :#key# AND" );
return accumulator;
}, {} );

// Finalize ANDs
sqlBuffer.append( " 1 = 1" );
// Go over Params and incorporate them
params = arguments
// filter out reserved names
.filter( function( key, value ){
return ( !listFindNoCase( "entityName", arguments.key ) );
} )
.reduce( function( accumulator, key, value ){
accumulator[ key ] = value;
sqlBuffer.append( " #key# = :#key# AND" );
return accumulator;
}, {} );

// Finalize ANDs
sqlBuffer.append( " 1 = 1" );
}

// Caching?
if ( getUseQueryCaching() ) {
Expand Down
2 changes: 1 addition & 1 deletion [email protected][email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"jvm":{
"heapSize":"1024",
"args":"-Dlucee.extensions='https://ext.lucee.org/hibernate-orm-5.4.29.6-BETA.lex'"
"args":"-Dlucee.extensions='https://ext.lucee.org/hibernate-orm-5.4.29.15-BETA.lex'"
},
"openBrowser":"false",
"cfconfig": {
Expand Down
8 changes: 4 additions & 4 deletions [email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"rewrites":{
"enable":"true"
},
"webroot":"test-harness",
"webroot":"test-harness",
"aliases":{
"/moduleroot/cborm":"./"
}
Expand All @@ -20,7 +20,7 @@
"heapSize":"1024"
},
"openBrowser":"false",
"cfconfig": {
"file" : ".cfconfig.json"
}
"cfconfig":{
"file":".cfconfig.json"
}
}
9 changes: 4 additions & 5 deletions test-harness/Application.cfc
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/**
********************************************************************************
Copyright 2005-2007 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
www.ortussolutions.com
********************************************************************************
* Copyright 2005-2007 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
* www.ortussolutions.com
* ---
*/
component {

Expand All @@ -11,7 +10,7 @@ component {
request.MODULE_PATH = "cborm";

// Application properties
this.name = hash( getCurrentTemplatePath() );
this.name = "cborm test harness";
this.sessionManagement = true;
this.sessionTimeout = createTimespan( 0, 0, 15, 0 );
this.setClientCookies = true;
Expand Down
32 changes: 17 additions & 15 deletions test-harness/tests/Application.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,31 @@

// request start
public boolean function onRequestStart( String targetPage ){
if ( url.keyExists( "fwreinit" ) ) {
ormReload();
cleanupApp();
if ( structKeyExists( server, "lucee" ) ) {

// Set a high timeout for long running tests
setting requestTimeout="9999";
// New ColdBox Virtual Application Starter
request.coldBoxVirtualApp = new coldbox.system.testing.VirtualApp( appMapping = "/root" );

// ORM Reload for fresh results
if( structKeyExists( url, "fwreinit" ) ){
if( structKeyExists( server, "lucee" ) ){
pagePoolClear();
}
ormReload();
request.coldBoxVirtualApp.shutdown();
}

// If hitting the runner or specs, prep our virtual app
if ( getBaseTemplatePath().replace( expandPath( "/tests" ), "" ).reFindNoCase( "(runner|specs)" ) ) {
request.coldBoxVirtualApp.startup();
}

return true;
}

public function onRequestEnd(){
cleanupApp();
}

private function cleanupApp(){
// CB 6 graceful shutdown
if ( !isNull( application.cbController ) ) {
application.cbController.getLoaderService().processShutdown();
}

structDelete( application, "cbController" );
structDelete( application, "wirebox" );
request.coldBoxVirtualApp.shutdown();
}

}
9 changes: 0 additions & 9 deletions test-harness/tests/resources/BaseTest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ component extends="coldbox.system.testing.BaseTestCase" appMapping="/root" {
super.afterAll();
}

function reset(){
// CB 6 graceful shutdown
if ( !isNull( application.cbController ) ) {
application.cbController.getLoaderService().processShutdown();
}
structDelete( application, "wirebox" );
structDelete( application, "cbController" );
}

function withRollback( target ){
transaction {
try {
Expand Down
21 changes: 20 additions & 1 deletion test-harness/tests/specs/ActiveEntityTest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
function setup(){
ormCloseSession();
ormClearSession();

super.setup();
// If Lucee, close the current ORM session to avoid stackoverflow bug
activeUser = getMockBox().prepareMock( entityNew( "ActiveUser" ) );
Expand All @@ -17,6 +16,26 @@
testCatID = "3A2C516C-41CE-41D3-A9224EA690ED1128";
}

function testWhenOperations(){
var results = "";

activeUser.when( false, function( user ){
results = true;
}, function( user ){
results = false;
} );

expect( results ).toBeFalse();

activeUser.when( true, function( user ){
results = true;
}, function( user ){
results = false;
} );

expect( results ).toBeTrue();
}

function testEvictionByEntityObject(){
ormClearSession();
var test = entityLoad( "ActiveUser", testUserID, true );
Expand Down
3 changes: 3 additions & 0 deletions test-harness/tests/specs/BaseORMServiceTest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,9 @@

count = ormService.countWhere( entityName = "Category", category = "Training" );
assertEquals( 1, count );

count = ormService.countWhere( entityName = "Category" );
assertTrue( count > 1 );
}

function testList(){
Expand Down

0 comments on commit 5b8fc02

Please sign in to comment.