📄 environment.java
字号:
/** * Validate connection when returning connection to pool (optional, true or false) */ public static final String DBCP_VALIDATION_ONRETURN = "hibernate.dbcp.testOnReturn"; /** * Query to execute for connection validation (optional, requires either * <tt>DBCP_VALIDATION_ONBORROW</tt> or <tt>DBCP_VALIDATION_ONRETURN</tt>) */ public static final String DBCP_VALIDATION_QUERY = "hibernate.dbcp.validationQuery"; /** * Maximum number of checked out statements for DBCP */ public static final String DBCP_PS_MAXACTIVE = "hibernate.dbcp.ps.maxActive"; /** * Maximum number of idle statements for DBCP */ public static final String DBCP_PS_MAXIDLE = "hibernate.dbcp.ps.maxIdle"; /** * Maximum idle time for statements in DBCP (ms) */ public static final String DBCP_PS_MAXWAIT = "hibernate.dbcp.ps.maxWait"; /** * Action to take in case of an exhausted DBCP statement pool ( 0 = fail, 1 = block, 2= grow) */ public static final String DBCP_PS_WHENEXHAUSTED = "hibernate.dbcp.ps.whenExhaustedAction"; /** * Proxool/Hibernate property prefix */ public static final String PROXOOL_PREFIX = "hibernate.proxool"; /** * Proxool property to configure the Proxool Provider using an XML (<tt>/path/to/file.xml</tt>) */ public static final String PROXOOL_XML = "hibernate.proxool.xml"; /** * Proxool property to configure the Proxool Provider using a properties file (<tt>/path/to/proxool.properties</tt>) */ public static final String PROXOOL_PROPERTIES = "hibernate.proxool.properties"; /** * Proxool property to configure the Proxool Provider from an already existing pool (<tt>true</tt> / <tt>false</tt>) */ public static final String PROXOOL_EXISTING_POOL = "hibernate.proxool.existing_pool"; /** * Proxool property with the Proxool pool alias to use * (Required for <tt>PROXOOL_EXISTING_POOL</tt>, <tt>PROXOOL_PROPERTIES</tt>, or * <tt>PROXOOL_XML</tt>) */ public static final String PROXOOL_POOL_ALIAS = "hibernate.proxool.pool_alias"; /** * <tt>TransactionFactory</tt> implementor to use for creating <tt>Transaction</tt>s */ public static final String TRANSACTION_STRATEGY = "hibernate.transaction.factory_class"; /** * <tt>TransactionManagerLookup</tt> implementor to use for obtaining the <tt>TransactionManager</tt> */ public static final String TRANSACTION_MANAGER_STRATEGY = "hibernate.transaction.manager_lookup_class"; /** * JNDI name of JTA <tt>UserTransaction</tt> object */ public static final String USER_TRANSACTION = "jta.UserTransaction"; /** * The <tt>CacheProvider</tt> implementation class */ public static final String CACHE_PROVIDER = "hibernate.cache.provider_class"; /** * The <tt>CacheProvider</tt> implementation class */ public static final String USE_QUERY_CACHE = "hibernate.cache.use_query_cache"; /** * The <tt>CacheProvider</tt> region name prefix */ public static final String CACHE_REGION_PREFIX = "hibernate.cache.region_prefix"; /** * Optimize the cache for mimimal puts instead of minimal gets */ public static final String USE_MINIMAL_PUTS = "hibernate.cache.use_minimal_puts"; /** * Use CGLIB <tt>MetaClass</tt> to optimize property access */ public static final String USE_REFLECTION_OPTIMIZER = "hibernate.cglib.use_reflection_optimizer"; /** * A comma-seperated list of token substitutions to use when translating a Hibernate * query to SQL */ public static final String QUERY_SUBSTITUTIONS = "hibernate.query.substitutions"; /** * A comma-seperated list of packages that need not be specified in a query * @deprecated */ public static final String QUERY_IMPORTS = "hibernate.query.imports"; /** * Auto export/update schema using hbm2ddl tool. Valid values are <tt>update</tt>, <tt>create</tt> * and <tt>create-drop</tt>. */ public static final String HBM2DDL_AUTO = "hibernate.hbm2ddl.auto"; //Obsolete properties: private static final String OUTPUT_STYLESHEET_OLD ="hibernate.output_stylesheet"; private static final String CONNECTION_PROVIDER_OLD ="hibernate.connection_provider"; private static final String DRIVER_OLD ="hibernate.driver"; private static final String ISOLATION_OLD ="hibernate.isolation"; private static final String USER_OLD ="hibernate.username"; private static final String PASS_OLD ="hibernate.password"; private static final String POOL_SIZE_OLD ="hibernate.pool_size"; private static final String STATEMENT_CACHE_SIZE_OLD ="hibernate.statement_cache_size"; private static final String DATASOURCE_OLD ="hibernate.datasource"; private static final String TRANSACTION_STRATEGY_OLD = "hibernate.transaction_factory"; private static final String URL_OLD ="hibernate.url"; private static final String USE_STREAMS_FOR_BINARY_OLD = "hibernate.use_streams_for_binary"; private static final String STATEMENT_FETCH_SIZE_OLD = "hibernate.statement.fetch_size"; private static final String USE_SCROLLABLE_RESULTSET_OLD = "hibernate.use_scrollable_resultset"; /** * Use JDBC2 batch updates * @deprecated */ public static final String USE_JDBC_BATCH = "hibernate.use_jdbc_batch"; private static final boolean ENABLE_BINARY_STREAMS; private static final boolean ENABLE_REFLECTION_OPTIMIZER; private static final boolean JVM_SUPPORTS_LINKED_HASH_COLLECTIONS; private static final boolean JVM_HAS_TIMESTAMP_BUG; private static final boolean JVM_SUPPORTS_GET_GENERATED_KEYS; private static final Properties GLOBAL_PROPERTIES; private static final HashMap ISOLATION_LEVELS = new HashMap(); private static final Map OBSOLETE_PROPERTIES = new HashMap(); private static final Log log = LogFactory.getLog(Environment.class); /** * Issues warnings to the user when any obsolete property names are used. */ public static void verifyProperties(Properties props) { Iterator iter = props.keySet().iterator(); while ( iter.hasNext() ) { Object oldProp = iter.next(); Object newProp = OBSOLETE_PROPERTIES.get(oldProp); if ( newProp!=null ) log.warn("Usage of obsolete property: " + oldProp + " no longer supported, use: " + newProp); } } static { log.info("Hibernate " + VERSION); ISOLATION_LEVELS.put( new Integer(Connection.TRANSACTION_NONE), "NONE" ); ISOLATION_LEVELS.put( new Integer(Connection.TRANSACTION_READ_UNCOMMITTED), "READ_UNCOMMITTED" ); ISOLATION_LEVELS.put( new Integer(Connection.TRANSACTION_READ_COMMITTED), "READ_COMMITTED" ); ISOLATION_LEVELS.put( new Integer(Connection.TRANSACTION_REPEATABLE_READ), "REPEATABLE_READ" ); ISOLATION_LEVELS.put( new Integer(Connection.TRANSACTION_SERIALIZABLE), "SERIALIZABLE" ); OBSOLETE_PROPERTIES.put(CONNECTION_PROVIDER_OLD, CONNECTION_PROVIDER); OBSOLETE_PROPERTIES.put(DRIVER_OLD, DRIVER); OBSOLETE_PROPERTIES.put(ISOLATION_OLD, ISOLATION); OBSOLETE_PROPERTIES.put(URL_OLD, URL); OBSOLETE_PROPERTIES.put(PASS_OLD, PASS); OBSOLETE_PROPERTIES.put(USER_OLD, USER); OBSOLETE_PROPERTIES.put(POOL_SIZE_OLD, POOL_SIZE); OBSOLETE_PROPERTIES.put(STATEMENT_CACHE_SIZE_OLD, STATEMENT_CACHE_SIZE); OBSOLETE_PROPERTIES.put(DATASOURCE_OLD, DATASOURCE); OBSOLETE_PROPERTIES.put(TRANSACTION_STRATEGY_OLD, TRANSACTION_STRATEGY); OBSOLETE_PROPERTIES.put(OUTPUT_STYLESHEET_OLD, OUTPUT_STYLESHEET); OBSOLETE_PROPERTIES.put(USE_JDBC_BATCH, STATEMENT_BATCH_SIZE); OBSOLETE_PROPERTIES.put(USE_SCROLLABLE_RESULTSET_OLD, USE_SCROLLABLE_RESULTSET); OBSOLETE_PROPERTIES.put(USE_STREAMS_FOR_BINARY_OLD, USE_STREAMS_FOR_BINARY); OBSOLETE_PROPERTIES.put(STATEMENT_FETCH_SIZE_OLD, STATEMENT_FETCH_SIZE); GLOBAL_PROPERTIES = new Properties(); GLOBAL_PROPERTIES.setProperty( USE_REFLECTION_OPTIMIZER, Boolean.TRUE.toString() ); InputStream stream = Environment.class.getResourceAsStream("/hibernate.properties"); if ( stream==null ) { log.info("hibernate.properties not found"); } else { try { GLOBAL_PROPERTIES.load(stream); log.info("loaded properties from resource hibernate.properties: " + GLOBAL_PROPERTIES); } catch (Exception e) { log.error("problem loading properties from hibernate.properties"); } finally { try{ stream.close(); } catch (IOException ioe){ log.error("could not close stream on hibernate.properties", ioe); } } } GLOBAL_PROPERTIES.putAll( System.getProperties() ); verifyProperties(GLOBAL_PROPERTIES); ENABLE_BINARY_STREAMS = PropertiesHelper.getBoolean(USE_STREAMS_FOR_BINARY, GLOBAL_PROPERTIES); ENABLE_REFLECTION_OPTIMIZER = PropertiesHelper.getBoolean(USE_REFLECTION_OPTIMIZER, GLOBAL_PROPERTIES); if (ENABLE_BINARY_STREAMS) log.info("using java.io streams to persist binary types"); if (ENABLE_REFLECTION_OPTIMIZER) log.info("using CGLIB reflection optimizer"); boolean getGeneratedKeysSupport; try { Statement.class.getDeclaredMethod("getGeneratedKeys", null); getGeneratedKeysSupport = true; } catch (NoSuchMethodException nsme) { getGeneratedKeysSupport = false; } JVM_SUPPORTS_GET_GENERATED_KEYS = getGeneratedKeysSupport; if (!JVM_SUPPORTS_GET_GENERATED_KEYS) log.info("JVM does not support Statement.getGeneratedKeys()"); boolean linkedHashSupport; try { Class.forName("java.util.LinkedHashSet"); linkedHashSupport = true; } catch (ClassNotFoundException cnfe) { linkedHashSupport = false; } JVM_SUPPORTS_LINKED_HASH_COLLECTIONS = linkedHashSupport; if (!JVM_SUPPORTS_LINKED_HASH_COLLECTIONS) log.info("JVM does not support LinkedHasMap, LinkedHashSet - ordered maps and sets disabled"); JVM_HAS_TIMESTAMP_BUG = new Timestamp(123456789).getTime() != 123456789; if (JVM_HAS_TIMESTAMP_BUG) log.info("using workaround for JVM bug in java.sql.Timestamp"); } /** * Does this JVM support dynamic proxies. (Now return true because CGLIB * proxies work on all supported JDK) */ public static boolean jvmSupportsProxies() { return true;//jvmSupportsProxies; } /** * Does this JVM have the IBM JDK 1.3.1. The bug is <tt>new Timestamp(x).getTime()!=x</tt>. */ public static boolean jvmHasTimestampBug() { return JVM_HAS_TIMESTAMP_BUG; } /** * Does this JVM support <tt>LinkedHashSet</tt>, <tt>LinkedHashMap</tt>. * @see java.util.LinkedHashSet * @see java.util.LinkedHashMap */ public static boolean jvmSupportsLinkedHashCollections() { return JVM_SUPPORTS_LINKED_HASH_COLLECTIONS; } public static boolean jvmSupportsGetGeneratedKeys() { return JVM_SUPPORTS_GET_GENERATED_KEYS; } /** * Should we use streams to bind binary types to JDBC IN parameters. * Property <tt>hibernate.jdbc.use_streams_for_binary</tt>. * @see Environment#USE_STREAMS_FOR_BINARY */ public static boolean useStreamsForBinary() { return ENABLE_BINARY_STREAMS; } /** * Should we use CGLIB reflection optimizer. * Property <tt>hibernate.jdbc.use_refection_optimizer</tt>. * @see Environment#USE_REFLECTION_OPTIMIZER */ public static boolean useReflectionOptimizer() { return ENABLE_REFLECTION_OPTIMIZER; } private Environment() { throw new UnsupportedOperationException(); } /** * Return <tt>System</tt> properties, extended by any properties specified * in <tt>hibernate.properties</tt>. * @return Properties */ public static Properties getProperties() { Properties copy = new Properties(); copy.putAll(GLOBAL_PROPERTIES); return copy; } /** * Get the name of a JDBC transaction isolation level * * @see java.sql.Connection * @param isolation as defined by <tt>java.sql.Connection</tt> * @return a human-readable name */ public static String isolationLevelToString(int isolation) { return (String) ISOLATION_LEVELS.get( new Integer(isolation) ); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -