Anybody using ColdBox With Groovy or Java for Domain Models

Is anybody developing coldbox apps and building their domain models in
java or groovy?

if you are, can you please contact me.

Luis,

Java or Groovy objects are strongly typed objects which would be bit difficult for cf-developers.

Secondly developers needs to know/learn about java.lang.Comparable, java.io.Serializable interface implementation of POJO objects, also persistence would be another issue.

As proof of concept I can try to integrate GORM (Groovy + Hibernate) which have kind of active record implementation.

we can generate POGO objects from xml notation, which will hide complexity of Java.

Here is very simple example of blogpost GROOVY domain class
class Blog {
String title
String body
String email

static constraints = {
title(blank:false)
email(email:true, nullable:true)
body(blank:false)
}
}

If anybody have any cool ideas, Please let us know.

Thanks
Sana

I think that is a pretty cool idea! It would be great to be able to take advantage of GORM via ColdBox if at all possible as it then provides a complete Grails style stack based on Hibernate without having to leave the CF world. I’m guessing you might want to make it optional, but I’d certainly love if there was any way of getting hibernate without having to wait for centaur!

Peter

Peter,

http://www.grails.org/GORM+-+Defining+relationships

What do you think about this syntax for domain classes

if this is easy enough then I will write coldbox GORM loader and
hibernate will be on the way.

In CF like this,
<cfscript>
User.setFirstName('test');
User.setLastName('test'); etc
</cfscript>

may be like this as well ClassPopulate('User', forms/url etc
getCollection()); everything will be done on coldbox end
ClassSave(User);

Generating groovy domain classes from xml, could be bit tricky but
achievable.

Looking forward to your opinion.

Thanks
Sana

I'm planning on trying this with CFGroovy. Unfortunatley I have to
finish some actual work before I get to implementing this. But a new
coworker has some experience with Groovy and so I'm going to pick his
brain and use him as a resource while I try it out for my domain
modeling.

Judah

That seems great Sana,

maybe we can create an ORM helper or plugin that can abstract these interactions with any future ORM. Please go ahead with it and post your progress and ideas so we can all contribute.

luis

This would be awesome! I think if you could model your domains in
groovy and use GORM you would basically have Grails like framework.
The great thing about groovy domains + GORM is how extremely easy it
is to model your domain. Then you can set some constraints and you can
easily check those constraints before saving. Take the following
example of a blog post in a blog application.

class Post {

    String title
    String teaser
    String body
    String alias
    Date posted
    Date lastModified
    Integer views = 0
    Boolean released
    SortedSet comments

    // a post has many comments
    static hasMany = [comments:Comment]

    // table constraints
    static constraints = {
        title(blank:false,length:1..255)
        teaser(blank:false)
        body(blank:false)
        alias(blank:false,length:1..255,unique:true)
        posted(blank:false,min:new Date())
        lastModified(nullable:true)
        views(blank:false)
        released(blank:false,min:false)
    }

}

Now in our controller we can do this
    def update = {
        def postInstance = Post.get( params.id )
        if(postInstance) {
            postInstance.properties = params
            if(!postInstance.hasErrors() && postInstance.save()) {
                flash.message = "Post ${params.id} updated"
                redirect(action:show,id:postInstance.id)
            }
            else {
                render(view:'edit',model:[postInstance:postInstance])
            }
        }
        else {
            flash.message = "Post not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

And obviously we can do the same in our coldbox controller. I just
love this approach because its very easy to follow. I would love to
help out with this as I could see myself using this tomorrow!

Thanks Dan,

I know Sana is working hard on getting started on the integration. We will then see what kind of plugin or extension point we need to build to continue. But the best way to help out is to post here with ideas and talk to Sana.

Luis

Great!

Please feel free if you need any help or event help just testing the
Groovy + GORM stuff Sana