enable db url postfix after get url from db allocation

This commit is contained in:
Strong Liu 2011-10-24 21:56:16 +08:00
parent bdba5898c9
commit 007980d8bf
2 changed files with 24 additions and 1 deletions

View File

@ -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'

View File

@ -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