| author | indvdum (gotoindvdum[at]gmail[dot]com) |
| Sun, 11 Nov 2012 03:17:06 +0400 | |
| changeset 8 | eec474867dbe |
| parent 5 | ccb029c396aa |
| permissions | -rw-r--r-- |
| indvdum@2 | 1 |
package ru.indvdum.jpa.dao |
| indvdum@2 | 2 |
|
| indvdum@2 | 3 |
/** |
| indvdum@2 | 4 |
* @author indvdum (gotoindvdum[at]gmail[dot]com) |
| indvdum@2 | 5 |
* @since 03.11.2011 13:53:32 |
| indvdum@2 | 6 |
* |
| indvdum@2 | 7 |
*/ |
| indvdum@5 | 8 |
class JPAPropertySelector {
|
| indvdum@2 | 9 |
public static final String SHOWSQL = "custom.showsql" |
| indvdum@2 | 10 |
public static final String SYNCHRONIZEDB = "custom.synchronize" |
| indvdum@2 | 11 |
public static final String SCHEMANAME = "custom.schemaname" |
| indvdum@2 | 12 |
public static final String DBDICTIONARY = "custom.dbdictionary" |
| indvdum@2 | 13 |
public static final String RUNTIMEENHANCEMENT = "custom.runtimeenhancement" |
| indvdum@2 | 14 |
|
| indvdum@2 | 15 |
private static Properties properties = new Properties() |
| indvdum@2 | 16 |
|
| indvdum@2 | 17 |
private static boolean isProperty(String propertyName) {
|
| indvdum@2 | 18 |
return Boolean.valueOf(properties.getProperty(propertyName)).booleanValue() |
| indvdum@2 | 19 |
} |
| indvdum@2 | 20 |
|
| indvdum@2 | 21 |
private static String getSystemProperty(String propertyName) {
|
| indvdum@2 | 22 |
properties.getProperty(propertyName) |
| indvdum@2 | 23 |
} |
| indvdum@2 | 24 |
|
| indvdum@2 | 25 |
static void setSystemProperty(String propertyName, String propertyValue) {
|
| indvdum@2 | 26 |
properties.setProperty(propertyName, propertyValue) |
| indvdum@2 | 27 |
} |
| indvdum@2 | 28 |
|
| indvdum@2 | 29 |
static Map select() {
|
| indvdum@2 | 30 |
Map<String, String> emfProperties = [:] |
| indvdum@2 | 31 |
|
| indvdum@2 | 32 |
if(isProperty(SHOWSQL)) {
|
| indvdum@2 | 33 |
emfProperties["openjpa.Log"] = "DefaultLevel=INFO, Tool=INFO, SQL=TRACE" |
| indvdum@2 | 34 |
emfProperties["openjpa.ConnectionFactoryProperties"] = "PrintParameters=true, PrettyPrint=true" |
| indvdum@2 | 35 |
} |
| indvdum@2 | 36 |
|
| indvdum@2 | 37 |
if(isProperty(SYNCHRONIZEDB)) {
|
| indvdum@2 | 38 |
emfProperties["openjpa.jdbc.SynchronizeMappings"] = "buildSchema(ForeignKeys=true)" |
| indvdum@2 | 39 |
} |
| indvdum@2 | 40 |
|
| indvdum@2 | 41 |
if(getSystemProperty(SCHEMANAME) != null) {
|
| indvdum@2 | 42 |
emfProperties["openjpa.jdbc.Schema"] = getSystemProperty(SCHEMANAME) |
| indvdum@2 | 43 |
} |
| indvdum@2 | 44 |
|
| indvdum@2 | 45 |
if(getSystemProperty(DBDICTIONARY)) {
|
| indvdum@2 | 46 |
emfProperties["openjpa.jdbc.DBDictionary"] = getSystemProperty(DBDICTIONARY) |
| indvdum@2 | 47 |
} |
| indvdum@2 | 48 |
|
| indvdum@2 | 49 |
if(getSystemProperty(RUNTIMEENHANCEMENT)) {
|
| indvdum@2 | 50 |
emfProperties["openjpa.RuntimeUnenhancedClasses"] = getSystemProperty(RUNTIMEENHANCEMENT) |
| indvdum@2 | 51 |
} |
| indvdum@2 | 52 |
|
| indvdum@2 | 53 |
return emfProperties |
| indvdum@2 | 54 |
} |
| indvdum@2 | 55 |
} |