H2 Database Plugin

  • Tags: persistence
  • Latest: 0.2.6
  • Last Updated: 18 May 2009
  • Grails version: 1.1.1 > *
  • Authors: Mingfai Ma
1 vote
Dependency:
compile ":h2:0.2.6"

 Documentation

Summary

Description

H2 Database is probably the best Java in-memory database. It supports different deployment mode from in-memory/embedded to standalone and clustered server. The H2 Database project is created Thomas Mueller who is also the original developer of HSQL.

Features

  • included h2*.jar
  • Start servlet console, standalone console, and tcp server by configuration.
  • register a Spring data source
  • database creation and a plugable DBInitializer model
    • DBInitializer - you define a class with a init(dataSource) method and configure it in Config.groovy

Configuration

  • please check the sample Config.groovy of your version at the svn repository, the following is a sample for 0.2:
    plugins { 
      h2 {
        /**
         * For console.standalone, tcpserver, and pgserver, 'disable' is a special option, and the rest are H2 Server options.
         * Check http://www.h2database.com/javadoc/org/h2/tools/Server.html#r8
         */
        console {
          servlet {
            disable = false; mapping = '/h2-console/*' //must end with '/*'
          }
          standalone { // refer to the -web* options
            disable = false; webPort = 8443; webAllowOthers = true; webSSL = true; 
          }
        }
        tcpserver { disable = false; tcpPort = 8043; tcpAllowOthers = true }
        pgserver { disable = false; pgPort = 5432; pgAllowOthers = true; baseDir = './data/h2'; trace = '' }
        database { //
          sample { // a Spring DriverManagerDataSource will be created as "${databaseName}DataSource"
            /**
             * refer to: http://www.h2database.com/html/features.html#database_url
             */
            url = "jdbc:h2:./data/h2/sample;MODE=MYSQL"; user = "sa"; //password = ""
            init {
              //disable = true; initClass = "org.grails.plugins.h2.DBInitializer" // create a new instance and call its init( dataSource) method  
            }
          }
        }
      }
    }
    
  • Notice: if you to disable a feature, you should omit a configuration rather than set it to false
  • Sample dataSource configuration, refer to H2 Docs about URL:
    dataSource { 
    	pooled = false; //it is recommended not to use connection pool unless file encryption is enabled 
    	driverClassName = "org.h2.Driver" 
    	username = "sa" 
    	password = "" 
    } 
    
    // environment specific settings 
    environments { 
    	development { 
    		dataSource { 
    			dbCreate = "create-drop" // one of 'create', 'create-drop','update' 
    			url = "jdbc:h2:mem:devDB" 
    		} 
    	} 
    	test { 
    		dataSource { 
    			dbCreate = "update" 
    			url = "jdbc:h2:mem:testDb" 
    		} 
    	} 
    	production { 
    		dataSource { 
    			dbCreate = "update" 
    			url = "jdbc:h2:file:~/.h2" //or any other path 
    		} 
    	} 
    } 
    

Version and Compatibility

  • remarks: h2 has a short release period that new version comes out maybe more than once per month. you are recommended to download and replace the h2*.jar in your local project, and inform the Author to release an update if there are major changes.
  • The plugin is tested with Grails 1.1 beta 3
  • Refer to the CHANGES.txt for update history

roadmap

  • refer to the TODO.txt for planned tasks
Author: Mingfai Ma (mingfai.ma at gmail dot com)