Code Monkey home page Code Monkey logo

cborm's Introduction

Welcome To The ColdBox ORM Module

cborm CI

This module will enhance your experience when working with the ColdFusion (CFML) ORM powered by Hibernate. It will not only enhance it with dynamic goodness but give you a fluent and human approach to working with Hibernate. It will finally make working with ORM NOT SUCK!

Features

  • Service Layers with all the methods you could probably think off to help you get started in any project
  • Virtual service layers so you can create virtual services for any entity in your application
  • ActiveEntity our implementation of Active Record for ORM
  • Fluent queries via Hibernate's criteria and detached criteria queries with some Dynamic CFML goodness
  • Dynamic finders and counters
  • Entity population from json, structs, xml, and queryies including building up their relationships
  • Entity validation
  • Includes the Mementifier project to produce memento states from any entity, great for producing JSON
  • Ability for finders and queries to be returned as Java streams using our cbStreams project.
  • Automatic REST CRUD, stop wasting time building resources and just leverage our base resource: https://coldbox-orm.ortusbooks.com/orm-events/automatic-rest-crud
# A quick preview of some functionality

var book = new Book().findByTitle( "My Awesome Book" );
var book = new Book().getOrFail( 2 );

property name="userService" inject="entityService:User";

return userService.list();
return userService.list( asStream=true );

userService
	.newCriteria()
	.eq( "name", "luis" )
	.isTrue( "isActive" )
	.getOrFail();

userService
	.newCriteria()
	.isTrue( "isActive" )
	.joinTo( "role" )
		.eq( "name", "admin" )
	.asStream()
	.list();

userService
	.newCriteria()
	.withProjections( property="id,fname:firstName,lname:lastName,age" )
	.isTrue( "isActive" )
	.joinTo( "role" )
		.eq( "name", "admin" )
	.asStruct()
	.list();

In other words, it makes using an ORM not SUCK! ๐Ÿš€

LICENSE

Apache License, Version 2.0.

IMPORTANT LINKS

Source & Changelog

Documentation

Issues

Support

SYSTEM REQUIREMENTS

  • Lucee 5+
    • Hibernate 3.5.x
    • Hibernate 5.x via the new hibernate extension
  • ColdFusion 2018
    • Hibernate 5.2.11
  • ColdFusion 2021
    • Hibernate 5.2.11

INSTRUCTIONS

Use CommandBox cli to install:

box install cborm

Unfortunately, due to the way that ORM is loaded by ColdFusion, if you are using the ORM EventHandler or ActiveEntity or any ColdBox Proxies that require ORM, you must create an Application Mapping in the Application.cfc like this:

this.mappings[ "/cborm" ] = COLDBOX_APP_ROOT_PATH & "modules/cborm";

This is due to the fact that the ORM event listener starts before ColdBox, so no dynamic mappings exist yet. Important: Make sure you ALWAYS lazy load dependencies in your event handlers to avoid chicken and the egg issues.

WireBox DSL

The module also registers a new WireBox DSL called entityservice which can produce virtual or base ORM entity services:

  • entityservice - Inject a global ORM service so you can work with ANY entity
  • entityservice:{entityName} - Inject a Virtual entity service according to entityName

Settings

Here are the module settings you can place in your config/Coldbox.cfc under the moduleSettings.cborm structure:

moduleSettings = {
	cborm = {
		// Resource Settings
		resources : {
			// Enable the ORM Resource Event Loader
			eventLoader  : false,
			// Prefix to use on all the registered pre/post{Entity}{Action} events
			eventPrefix : "",
			// Pagination max rows
			maxRows      : 25,
			// Pagination max row limit: 0 = no limit
			maxRowsLimit : 500
		},
		// WireBox Injection Bridge
		injection : {
			enabled : true,
			include : "",
			exclude : ""
		}
	}
};

Validation

We have also migrated the UniqueValidator from the validation module into our ORM module. It is mapped into wirebox as UniqueValidator@cborm so you can use in your constraints like so:

this.constraints = {
    "name"  : {
              "required":true,
              "validator":"UniqueValidator@cborm"
            }
};

Contributing

All contributions welcome! Feel free to fix a typo, add a feature ๐Ÿš€, or add a testbox spec for a newly discovered issue ๐Ÿ›

If you want to get hacking on CBORM, here's how to start:

  1. Make sure you have CommandBox installed: https://www.ortussolutions.com/products/commandbox#download
  2. Star, Fork, and Clone down this repo: https://github.com/coldbox-modules/cborm
  3. Start a MySQL 5+ service or you can use our docker-compose.yml file. Just make sure you have Docker installed. run-script startdbs or run it manually below.
docker run \
    -e MYSQL_RANDOM_ROOT_PASSWORD=yes \
    -e MYSQL_USER=other \
    -e MYSQL_PASSWORD=ortussolutions \
    -e MYSQL_DATABASE=coolblog \
    -v "$PWD/test-harness/tests/resources":/docker-entrypoint-initdb.d \
    -p 3306:3306 \
    --detach \
    --name cborm_mysql \
    mysql
  1. Copy .env.template to .env and enter the database credentials used in step 2 above โ˜
  2. Install the project dependencies with CommandBox box run-script install:dependencies
  3. Start a test server - box start [email protected] (You can use adobe or other engines)
  4. Hack away! :laptop:

Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp www.ortussolutions.com


HONOR GOES TO GOD ABOVE ALL

Because of His grace, this project exists. If you don't like this, then don't read it, its not for you.

"Therefore being justified by faith, we have peace with God through our Lord Jesus Christ: By whom also we have access by faith into this grace wherein we stand, and rejoice in hope of the glory of God. And not only so, but we glory in tribulations also: knowing that tribulation worketh patience; And patience, experience; and experience, hope: And hope maketh not ashamed; because the love of God is shed abroad in our hearts by the Holy Ghost which is given unto us. ." Romans 5:5

THE DAILY BREAD

"I am the way, and the truth, and the life; no one comes to the Father, but by me (JESUS)" Jn 14:1-12

cborm's People

Contributors

balbinoortus avatar bdw429s avatar elpete avatar existdissolve avatar grantcopley avatar jclausen avatar lmajano avatar michaelborn avatar sanaullah avatar sigmaprojects avatar wphampton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cborm's Issues

Allow params and typing to criteria SQLRestriction

The java method accepts params and typing of params ( https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/main/java/org/hibernate/criterion/Restrictions.java#L463 ), while the CBORM implementation accepts only the first argument of an SQL strings.

Implement the ability for the method to accept an array of params as the second argument and either auto-type or allow a third argument of types.

This will allow search building which might require native DBMS functionality to stay SQL injection-safe

entity.save() errors on Lucee 5

See the repo for the test case: https://github.com/elpete/cborm-lucee-5-error

The quick version: on Lucee 5 entitySave( myEntity ) works while myEntity.save() does not. myEntity.save() works on Lucee 4 without modification.

The error:

Messages: lucee.runtime.orm.ORMDatasourceConnection cannot be cast to lucee.runtime.db.DatasourceConnectionImpl

Dynamic Finders Incorrectly Identifying Properties in compileHQLFromDynamicMethod()

In BaseORMService.cfc around line 1055 is this chunk of code:

var methodGrammars = REMatchNoCase( "((?!(and|or|$))\w)+(#ALL_CONDITIONALS_REGEX#)?(and|or|$)", method );

Let's say you have an entity with properties of handle and sport and name and you attempt a Dynamic Finder like this findAllByHandleAndSportAndName('a','b','c');
Then it will split it up like this:

Array
1 Hand
2 leAnd
3 Spor
4 tAnd
5 Name

I think it should have done this:

Array
1 HandleAnd
2 SportAnd
3 Name

I haven't been able to fix that RegEx yet with the negative lookahead and would appreciate some assistance. @sigmaprojects did some related work in #4. Also there was some related discussion in the ColdBox Google Group a while back.

BaseORMService.merge doesn't seem to merge entities back into session

Using the merge function doesn't seems to attach the specified entity to the session.

BaseORMService.merge(entity) is using Coldfusion's entityMerge which returns a new object attached to the session. However, the original object passed as an argument will not be attached.

Did I do something wrong or misunderstood how the framework is working?

On a side note, the doc specifies that the merge() function returns void which isn't correct.

exists() Method Concerns

exists() in BaseORMService is not universally functional because the property name of id is hard coded in to the HQL.

In addition, this method will not work on entities which have an entity name which is a reserved word in the DBMS platform ( e.g. Case ).

The key property should be dynamically retrieved for the HQL in ormExecuteQuery.

In addition, investigate if there is a ways to provide escaping for entities and property names which are reserved words : e.g [Case] for SQL Server, "Case" for MySQL and Postgres, etc

Dynamic `not` prefixed restrictions

Add a method in Restrictions.cfc for isNotIn which wraps the isIn statement in an isNot:

any function isNotIn(required string property, required any propertyValue){
		// infalte to array if simple values
		if( isSimpleValue(arguments.propertyValue) ){ arguments.propertyValue = listToArray( arguments.propertyValue); }
		return isNot( variables.restrictions.in(arguments.property, arguments.propertyValue) );
}

Variable scoping in SQLHelper.cfc

When using criteria.maxResults(10) I was having a strange error on cborm/models/sql/SQLHelper.cfc line 202.

After some debugging I found out that we have a global udf function called 'factory' and it was taking this function instead of the local var.

I had to scope the factory variable like variables.factory.

Since "factory" can be a wide used variable or function name, I think it should be var scoped on cborm/models/sql/SQLHelper.cfc. Same could happen with other component variables

CBORM errors on newer Lucee versions because log4j appenders have moved

CBORM causes an error on Lucee 5.3.9.141 because lucee.commons.io.log.log4j.layout.ClassicLayout no longer exists.

Error finding log4j.layout.ClassicLayout on newer Lucee versions

See https://github.com/coldbox-modules/cborm/blob/development/models/util/ORMUtilSupport.cfc#L32-L39:

/**
 * Redirect all Hibernate logs to system.out
 */
if ( listFindNoCase( "Lucee", server.coldfusion.productname ) ) {
	var printWriter     = getPageContext().getConfig().getOutWriter();
	var layout          = createObject( "java", "lucee.commons.io.log.log4j.layout.ClassicLayout" );
	var consoleAppender = createObject( "java", "lucee.commons.io.log.log4j.appender.ConsoleAppender" ).init(
		printWriter,
		layout
	);
	hibernateLog.addAppender( consoleAppender );
	writeDump( var = "** Lucee Hibernate Logging Redirected", output = "console" );
}

It appears this moved to lucee.commons.io.log.log4j2.layout.ClassicLayout.

Ditto for lucee.commons.io.log.log4j.appender.ConsoleAppender, which moved to lucee.commons.io.log.log4j2.appender.ConsoleAppender

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.