1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/main/java/ru/indvdum/jpa/dao/PropertySelector.groovy Fri Nov 09 03:00:49 2012 +0400
1.3 @@ -0,0 +1,55 @@
1.4 +package ru.indvdum.jpa.dao
1.5 +
1.6 +/**
1.7 + * @author indvdum (gotoindvdum[at]gmail[dot]com)
1.8 + * @since 03.11.2011 13:53:32
1.9 + *
1.10 + */
1.11 +class PropertySelector {
1.12 + public static final String SHOWSQL = "custom.showsql"
1.13 + public static final String SYNCHRONIZEDB = "custom.synchronize"
1.14 + public static final String SCHEMANAME = "custom.schemaname"
1.15 + public static final String DBDICTIONARY = "custom.dbdictionary"
1.16 + public static final String RUNTIMEENHANCEMENT = "custom.runtimeenhancement"
1.17 +
1.18 + private static Properties properties = new Properties()
1.19 +
1.20 + private static boolean isProperty(String propertyName) {
1.21 + return Boolean.valueOf(properties.getProperty(propertyName)).booleanValue()
1.22 + }
1.23 +
1.24 + private static String getSystemProperty(String propertyName) {
1.25 + properties.getProperty(propertyName)
1.26 + }
1.27 +
1.28 + static void setSystemProperty(String propertyName, String propertyValue) {
1.29 + properties.setProperty(propertyName, propertyValue)
1.30 + }
1.31 +
1.32 + static Map select() {
1.33 + Map<String, String> emfProperties = [:]
1.34 +
1.35 + if(isProperty(SHOWSQL)) {
1.36 + emfProperties["openjpa.Log"] = "DefaultLevel=INFO, Tool=INFO, SQL=TRACE"
1.37 + emfProperties["openjpa.ConnectionFactoryProperties"] = "PrintParameters=true, PrettyPrint=true"
1.38 + }
1.39 +
1.40 + if(isProperty(SYNCHRONIZEDB)) {
1.41 + emfProperties["openjpa.jdbc.SynchronizeMappings"] = "buildSchema(ForeignKeys=true)"
1.42 + }
1.43 +
1.44 + if(getSystemProperty(SCHEMANAME) != null) {
1.45 + emfProperties["openjpa.jdbc.Schema"] = getSystemProperty(SCHEMANAME)
1.46 + }
1.47 +
1.48 + if(getSystemProperty(DBDICTIONARY)) {
1.49 + emfProperties["openjpa.jdbc.DBDictionary"] = getSystemProperty(DBDICTIONARY)
1.50 + }
1.51 +
1.52 + if(getSystemProperty(RUNTIMEENHANCEMENT)) {
1.53 + emfProperties["openjpa.RuntimeUnenhancedClasses"] = getSystemProperty(RUNTIMEENHANCEMENT)
1.54 + }
1.55 +
1.56 + return emfProperties
1.57 + }
1.58 +}