From 007980d8bf6803fe97916677c5e1c9e61769c9ad Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Mon, 24 Oct 2011 21:56:16 +0800 Subject: [PATCH] enable db url postfix after get url from db allocation --- buildSrc/readme.txt | 6 ++++++ .../hudson/util/DBAllocationHelper.groovy | 19 ++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/buildSrc/readme.txt b/buildSrc/readme.txt index 054bac7a96..536d8325a0 100644 --- a/buildSrc/readme.txt +++ b/buildSrc/readme.txt @@ -47,6 +47,12 @@ This feature is disabled by default, to enable it, you need system property 'hib for example, if you want to run matrix test on postgresql84, default DB profile, you can './gradlew clean test matrix_postgresql84 -Dhibernate-matrix-dballocation=postgresql84' +some DBs need we tweak url with some configurations after get it from DB allocator, so, we can use this system property: +"hibernate-matrix-dballocation-url-postfix-${dbname} = configurations" +for example: + +-Dhibernate-matrix-dballocation-url-postfix-sybase155="?SQLINITSTRING=set quoted_identifier on&DYNAMIC_PREPARE=true" + what does this command do actually? 1. test run 'src/test/java' on default H2, test results in 'target/test-results' diff --git a/buildSrc/src/main/groovy/hudson/util/DBAllocationHelper.groovy b/buildSrc/src/main/groovy/hudson/util/DBAllocationHelper.groovy index d9e78b93f3..222b163c52 100644 --- a/buildSrc/src/main/groovy/hudson/util/DBAllocationHelper.groovy +++ b/buildSrc/src/main/groovy/hudson/util/DBAllocationHelper.groovy @@ -40,6 +40,7 @@ public class DBAllocationHelper { private static final String URL_PROP = "hibernate.connection.url"; private static final String USERNAME_PROP = "hibernate.connection.username"; private static final String PASSWORD_PROP = "hibernate.connection.password"; + private static final String DB_ALLOCATION_URL_POSTFIX = "hibernate-matrix-dballocation-url-postfix"; //DBAllocator supports the following DBs private static def supportedDB = ["oracle9i", "oracle10g", "oracle11gR1", "oracle11gR2", "oracle11gR2RAC", "oracle11gR1RAC", @@ -64,7 +65,7 @@ public class DBAllocationHelper { Properties prop = db.properties log.lifecycle("DBAllocating finished for DB[${node.name}], uuid is [${prop['uuid']}]") map[DRIVER_PROP] = prop["db.jdbc_class"] - map[URL_PROP] = prop["db.jdbc_url"] + map[URL_PROP] = prop["db.jdbc_url"] + getURLPostfix(node.name) map[USERNAME_PROP] = prop["db.username"] map[PASSWORD_PROP] = prop["db.password"] map["uuid"] = prop["uuid"]; @@ -78,6 +79,22 @@ public class DBAllocationHelper { } return cache.get(node); } + + private static String getURLPostfix(String dbName) { + for ( String key: System.properties ) { + if ( key.startsWith(DB_ALLOCATION_URL_POSTFIX) ) { + String db = key.substring(DB_ALLOCATION_URL_POSTFIX.length() + 1, key.length()) + if ( db.equalsIgnoreCase(dbName) ) { + String postfix = System.properties[key]; + log.debug("found URL postfix[%s] for DB[%s]", postfix, db ); + return postfix; + } + else { + continue; + } + } + } + } /** * use -Dhibernate-matrix-dballocation=all to enable DBAllocation for all matrix node * or