indvdum@2: package ru.indvdum.jpa.dao indvdum@2: indvdum@2: /** indvdum@2: * @author indvdum (gotoindvdum[at]gmail[dot]com) indvdum@2: * @since 03.11.2011 13:53:32 indvdum@2: * indvdum@2: */ indvdum@2: class PropertySelector { indvdum@2: public static final String SHOWSQL = "custom.showsql" indvdum@2: public static final String SYNCHRONIZEDB = "custom.synchronize" indvdum@2: public static final String SCHEMANAME = "custom.schemaname" indvdum@2: public static final String DBDICTIONARY = "custom.dbdictionary" indvdum@2: public static final String RUNTIMEENHANCEMENT = "custom.runtimeenhancement" indvdum@2: indvdum@2: private static Properties properties = new Properties() indvdum@2: indvdum@2: private static boolean isProperty(String propertyName) { indvdum@2: return Boolean.valueOf(properties.getProperty(propertyName)).booleanValue() indvdum@2: } indvdum@2: indvdum@2: private static String getSystemProperty(String propertyName) { indvdum@2: properties.getProperty(propertyName) indvdum@2: } indvdum@2: indvdum@2: static void setSystemProperty(String propertyName, String propertyValue) { indvdum@2: properties.setProperty(propertyName, propertyValue) indvdum@2: } indvdum@2: indvdum@2: static Map select() { indvdum@2: Map emfProperties = [:] indvdum@2: indvdum@2: if(isProperty(SHOWSQL)) { indvdum@2: emfProperties["openjpa.Log"] = "DefaultLevel=INFO, Tool=INFO, SQL=TRACE" indvdum@2: emfProperties["openjpa.ConnectionFactoryProperties"] = "PrintParameters=true, PrettyPrint=true" indvdum@2: } indvdum@2: indvdum@2: if(isProperty(SYNCHRONIZEDB)) { indvdum@2: emfProperties["openjpa.jdbc.SynchronizeMappings"] = "buildSchema(ForeignKeys=true)" indvdum@2: } indvdum@2: indvdum@2: if(getSystemProperty(SCHEMANAME) != null) { indvdum@2: emfProperties["openjpa.jdbc.Schema"] = getSystemProperty(SCHEMANAME) indvdum@2: } indvdum@2: indvdum@2: if(getSystemProperty(DBDICTIONARY)) { indvdum@2: emfProperties["openjpa.jdbc.DBDictionary"] = getSystemProperty(DBDICTIONARY) indvdum@2: } indvdum@2: indvdum@2: if(getSystemProperty(RUNTIMEENHANCEMENT)) { indvdum@2: emfProperties["openjpa.RuntimeUnenhancedClasses"] = getSystemProperty(RUNTIMEENHANCEMENT) indvdum@2: } indvdum@2: indvdum@2: return emfProperties indvdum@2: } indvdum@2: }