📄 environment.java
字号:
/** * 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"; /** * Enable automatic session close at end of transaction */ public static final String AUTO_CLOSE_SESSION = "hibernate.transaction.auto_close_session"; /** * Enable automatic flush during the JTA <tt>beforeCompletion()</tt> callback */ public static final String FLUSH_BEFORE_COMPLETION = "hibernate.transaction.flush_before_completion"; /** * Specifies how Hibernate should release JDBC connections. */ public static final String RELEASE_CONNECTIONS = "hibernate.connection.release_mode"; /** * <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> JNDI namespace, if pre-bound to JNDI. */ public static final String CACHE_NAMESPACE = "hibernate.cache.jndi"; /** * Enable the query cache (disabled by default) */ public static final String USE_QUERY_CACHE = "hibernate.cache.use_query_cache"; /** * The <tt>QueryCacheFactory</tt> implementation class. */ public static final String QUERY_CACHE_FACTORY = "hibernate.cache.query_cache_factory"; /** * Enable the second-level cache (enabled by default) */ public static final String USE_SECOND_LEVEL_CACHE = "hibernate.cache.use_second_level_cache"; /** * Optimize the cache for mimimal puts instead of minimal gets */ public static final String USE_MINIMAL_PUTS = "hibernate.cache.use_minimal_puts"; /** * The <tt>CacheProvider</tt> region name prefix */ public static final String CACHE_REGION_PREFIX = "hibernate.cache.region_prefix"; /** * Enable use of structured second-level cache entries */ public static final String USE_STRUCTURED_CACHE = "hibernate.cache.use_structured_entries"; /** * Enable statistics collection */ public static final String GENERATE_STATISTICS = "hibernate.generate_statistics"; public static final String USE_IDENTIFIER_ROLLBACK = "hibernate.use_identifier_rollback"; /** * Use CGLIB <tt>MetaClass</tt> to optimize property access */ public static final String USE_REFLECTION_OPTIMIZER = "hibernate.cglib.use_reflection_optimizer"; /** * The classname of the HQL query parser factory */ public static final String QUERY_TRANSLATOR = "hibernate.query.factory_class"; /** * 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"; /** * 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"; /** * The {@link org.hibernate.exception.SQLExceptionConverter} to use for converting SQLExceptions * to Hibernate's JDBCException hierarchy. The default is to use the configured * {@link org.hibernate.dialect.Dialect}'s preferred SQLExceptionConverter. */ public static final String SQL_EXCEPTION_CONVERTER = "hibernate.jdbc.sql_exception_converter"; /** * Enable wrapping of JDBC result sets in order to speed up column name lookups for * broken JDBC drivers */ public static final String WRAP_RESULT_SETS = "hibernate.jdbc.wrap_result_sets"; /** * Enable ordering of update statements by primary key value */ public static final String ORDER_UPDATES = "hibernate.order_updates"; /** * The EntityMode in which set the Session opened from the SessionFactory. */ public static final String DEFAULT_ENTITY_MODE = "hibernate.default_entity_mode"; 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_HAS_JDK14_TIMESTAMP; 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" ); 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: " + PropertiesHelper.maskOut(GLOBAL_PROPERTIES, PASS) ); } 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); } } } try { GLOBAL_PROPERTIES.putAll( System.getProperties() ); } catch (SecurityException se) { log.warn("could not copy system properties, system properties will be ignored"); } 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.getMethod("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"); Timestamp t = new Timestamp(0); t.setNanos(5 * 1000000); JVM_HAS_JDK14_TIMESTAMP = t.getTime() == 5; if (JVM_HAS_JDK14_TIMESTAMP) { log.info("using JDK 1.4 java.sql.Timestamp handling"); } else { log.info("using pre JDK 1.4 java.sql.Timestamp handling"); } } /** * 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 handle <tt>Timestamp</tt> in the JDK 1.4 compliant way? */ public static boolean jvmHasJDK14Timestamp() { return JVM_HAS_JDK14_TIMESTAMP; } /** * 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 + -