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