Using Gradle in Practice

January 14, 2011 Leave a comment

DEAR RSS SUBSCRIBERS, ATTENTION: You are reading this post with the old RSS feed subscribed, just unsubscribe and add the new RSS feed from http://blog.andresteingress.com/feed

Categories: Uncategorized

New Year, Renewed Blog

DEAR RSS SUBSCRIBERS, ATTENTION: You are reading this post with the old RSS feed subscribed, just unsubscribe and add the new RSS feed from http://blog.andresteingress.com/feed

As you might have noticed, I decided to self-host my blog. Blog posts referring to posts hosted at wordpress.com will be automatically redirected – bookmarks and old RSS feed items are still working.

There were several reasons which let me to the decision to self-host this blog:

  • ad-free – I wanted to let Grails-Inside become ad-free, because ads are way intrusive for me – if people like stuff on this blog they can still use flattr to donate some cents.
  • faster page delivery – wordpress.com has a huge blog base, a self-hosted blog can provide faster page delivery and thus better reading experience.
  • usage restrictions – self-hosting means you’re not bound to wordpress’ restrictions on storage, plugin usage etc., getting rid of some of these restrictions has been a major requirement for content I am planning to deliver at this place during this year.

As far as I know, the migration process from wordpress.com over to my self-hosted wordpress installation went flawlessly (all posts, comments, categories etc. moved over to the new installation). If you experience issues, please let me know in this or the affected posts comment section.

Happy hacking (and reading)!

Categories: Uncategorized

Merry Christmas and a Happy New Year!

December 23, 2010 4 comments

I wanted to thank all readers for their feedback and support. Flattr this Writing this blog makes a lot of fun and I am looking forward to future posts.

I wanted to make you a Groovy christmas present – just throw it in your preferred Groovy console and execute it :-)

String.metaClass.or = { other ->
    return "$delegate$other"
}

String.metaClass.div = { other ->
    return " " * other + delegate
}

[(','/11 | 'i' | '!' * 6 | ';' | ',' ),
('.'/6  | ',' | ';' | 'i' | '!' * 5 | '\'' | '`' | ',' | 'u' * 2 | ',' | 'o' | '$' * 2 | 'bo.'),
('!' * 7 / 4 | '\'.e' | '$' * 14 | '.' ),
('!' * 7 / 3 | ' ' | '$' * 17 | 'P' ),
('!' * 7 / 3 | ',`' | '$' * 8 | 'P""`,,`"' ),
('i' / 2 | '!' * 8 | ',' |'$' * 4 | '",oed' | '$' * 6 ),
('!' * 9 / 1 | '\'P".,e' | '$' * 8 | '"\'?' ),
('`' / 1 | '!' * 8 | ' z$\'J' | '$' * 5 | '\'.,$bd$b,'),
('`' / 2 | '!' * 6 | 'f;$\'d' | '$' * 13 | 'P\',c,.' ),
('!' * 6 / 3 | ' $B,"?' | '$' * 5 | 'P\',uggg' | '$' * 5 | 'P"' ),
('!' * 6 / 3 | '.' | '$' * 4 | 'be."\'zd' | '$' * 3 | 'P".,uooe' | '$' * 2 | 'r' ),
('`' / 3 | '!' * 3 | '\',' | '$' * 9 | 'c,"",ud' | '$' * 9 | 'L' ),
('!' * 2 / 4 | ' ' | '$' * 29),
('!\'j' / 4 | '$' * 29 ),
('d@@,?' / 2 | '$' * 28 | 'P'),
('?@@f:' / 2 | '$' * 27 | '\''),
('""' / 3 | ' `' | '$' * 26 | 'F'),
('`3' / 7 | '$' * 22 | 'F' ),
('`"' / 10 | '$' * 4 | 'P?' | '$' * 7 | '"`' ),
('`""' / 19), "Merry Christmas and a Happy New Year!"].each { println it }  
Categories: groovy

GContracts @ Grailspodcast Episode 118

December 21, 2010 2 comments

Guess who’s on Grailspodcast Episode 118 [0] ;-) Yeah, right.

I had the pleasure to chat with Glen Smith [1] about Groovy, Grails, GContracts [2] and some other stuff i recently blogged about [3].

This is the direct download link for the mp3 (58,6 MB)
This is the iTunes link

[0] Grailspodcast Homepage
[1] Glen Smith
[2] GContracts @ Github
[3] The Microframework Approach

Categories: announcement

Funktionale Webtests mit Geb @ jaxenter.de

December 21, 2010 1 comment

Auf Jaxenter [0] ist ein Artikel von mir über Geb [1], einem neuen Webautomations- und Testframework auf Basis von Groovy und Seleniums WebDriver API, erschienen:

Funktionale Webtests mit Geb

Lesen und glücklich werden!

[0] Jaxenter – Funktionale Webtests mit Geb
[1] Geb Homepage

Categories: grails, groovy

The Micro Framework Approach

December 3, 2010 5 comments


Flattr this
The demand for Grails and Groovy is clearly raising these days – at least here in Austria and Germany. Although most of my workshops have their individual adaptions (depending on the previous knowledge and programming language experience of participants) there are parts which can more or less be found unmodified in every workshop: Groovy essentials/advanced topics and what I call micro framework examples. This article is about the idea behind micro framework examples and why I find them that useful as workshop examples.

What is a Micro Framework Example?

I strongly believe that true understanding on patterns behind frameworks like Hibernate and Spring can’t easily be treat in a bunch of slides. Explaining patterns is one thing but to actually see how those are applied is another one. One approach I’ve found to be really useful in workshops is the use of micro framework examples. A micro framework example implements the core functionality behind a specific framework – reduced to the very fundamentals. One advantage to implement a micro framework example together with participants is to force triggering a thinking process of what functionality is needed and how it can be implemented. Another side-effect is that it allows to slightly introduce the original frameworks ubiquitous language simply by using the same class and method names.

Let me give you an example. The most threatening topic for many of my clients is to understand Hibernate and its persistence patterns. One approach to create a better understanding would be to implement a micro Hibernate framework example. This can be done in a simple Groovy script MicroHibernate.groovy which defines two classes and a simple test case. The first class implements the registry pattern and is called SessionFactory:

class SessionFactory {

    private def storage

    def SessionFactory(def storage)  {
        this.storage = storage
    }

    def newStorageConnection()  {
        return storage
    }
}

The SessionFactory acts as the main access point to get a reference to some storage connection. In the micro framework example this will simply be a Map. Dealing with SQL or even a real database would uselessly complicate the example and we want to concentrate on the core essentials. Let’s go on to the next class which implements the persistence context pattern:


class Session {

    static Log log = LogFactory.getLog(Session)

    private def sessionFactory

    def Session(def sessionFactory) { this.sessionFactory = sessionFactory }

    def snapshots = [:] // a Map(Domain-Class, Map(Identifier, Properties))
    def identityMap = [:] // a Map(Domain-Class, Map(Identifier, ObjectRef))
    def modifiedPersistentObjects = [:] // a Map(Domain-Class, List(Identifier))
    
    def propertyChanged(def obj)  {
        if (!modifiedPersistentObjects[obj.getClass()]) modifiedPersistentObjects[obj.getClass()] = []

        modifiedPersistentObjects[obj.getClass()] << obj.id

        log.info "propertyChanged of object: ${obj} with id ${obj.id}"
    }

    def load(Class<?> domainClassType, Long identifier)  {
        
        if (identityMap[domainClassType] && identityMap[domainClassType][identifier])  {
            return identityMap[domainClassType][identifier]
        }
        
        def conn = sessionFactory.newStorageConnection()
        def loadedObj = conn[domainClassType][identifier]
        if (!loadedObj) throw new Exception("Object of type ${domainClassType} with id ${identifier} could not be found!")
        
        if (!snapshots[domainClassType]) snapshots[domainClassType] = [:]
        if (!identityMap[domainClassType]) identityMap[domainClassType] = [:]


        def properties = loadedObj.getProperty("props")
        snapshots[domainClassType][identifier] = properties.inject([:], { m, property -> m[property] = loadedObj[property]; m })

        log.info "create snapshot of ${domainClassType} id ${identifier} with properties ${snapshots[domainClassType][identifier]}"

        identityMap[domainClassType][identifier] = loadedObj
        
        loadedObj.metaClass.getId = { -> identifier } 
        loadedObj.metaClass.setProperty = { String name, Object arg ->
            def metaProperty = delegate.metaClass.getMetaProperty(name)

            if (metaProperty)  {
                owner.propertyChanged(loadedObj)
                
                metaProperty.setProperty(delegate, arg)
            }
        }
        
        return loadedObj
    }
}

A Session object can be used to retrieve already persistent objects and to persist so-called transient objects. I like to start by implementing the load method which loads a persistent object from the storage connection of the current session factory. Of course, this is not an example for Groovy beginners but with a little knowledge of MOP and with some programming guidance it should not be a big thing to understand what is going on. At the end let’s define some test case which shows how both classes are actually used:

def storage = [:]

class Person {
    String name

    String toString() { name }

    static props = ['name']
}

storage[Person] = [:]
storage[Person][1 as Long] = new Person(name: 'Max Mustermann')
storage[Person][2 as Long] = new Person(name: 'Erika Mustermann')

def sessionFactory = new SessionFactory(storage)
def session = sessionFactory.newSession()

def person = session.load(Person, 1)

Interestingly, even without considering SQL, DB connection handling, threading issues etc. participants already get a feeling of several Hibernate gotchas beginners otherwise often struggle with:

  • the first level cache
  • the need for proxies or MOP modifications
  • Hibernate’s use of object snapshots
  • the IdentityMap pattern
  • repeatable read transaction isolation level
  • etc.

It is amazing how much can be explained by implementing some framework’s core functionality in about 5 minutes. The Session functionality gets than extended by flush, discard and save/delete functionality. If programmers have been through the process of implementing such a micro Hibernate example they often get a basic and fundamental understanding of how an orm framework could work and what the main challenging problems are. By keeping the class and method names in sync with the concrete Hibernate implementations participants learn the framework’s basic domain language.

GSamples – A Repository for Sharing Workshop Examples

The example mentioned above is available in a public github repository what I called GSamples [0], a collection of Groovy and Grails workshop examples. At the time of publishing this article it contains two micro framework examples, the other one is a simple dependency injection container. In addition, GSamples holds Groovy scripts dealing with Groovy Essentials and another one dealing with advanced Groovy topics like the Meta-Object Protocol and Closures. Feel free to extend, distribute or use it!

[0] GSamples – https://github.com/andresteingress/gsamples

Grails Quickie: How to Load Dependency Sources and Javadocs

November 18, 2010 1 comment

Once you start a new Grails project and you want to access all the source code of dependent libraries, you have to manually reference the according source files. This is a boring, time-consuming and error-prone task – something like mvn dependency:sources is definitely missing. Luckily, there exists a workaround which can be done using the eclipse-scripts [0] plugin:

grails install-plugin eclipse-scripts 
grails compile 
grails download-sources-and-javadocs 
# run twice to download everything 
grails download-sources-and-javadocs 
# grails create-eclipse-files # run this one to create .classpath/.project Eclipse/STS files

Executing download-sources-and-javadocs loads the docs and copies them into the Ivy cache directory.

Thanks to Lari Hotari who came up with this solution on the Grails mailing-list [1].

[0] Eclipse Helper Scripts Plugin
[1] Nabble Grails User Mailing-List – Grails Dependency Sources

Categories: grails, plugins
Follow

Get every new post delivered to your Inbox.