KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > cfg > Environment


1 //$Id: Environment.java,v 1.40 2005/07/04 02:40:28 oneovthafew Exp $
2
package org.hibernate.cfg;
3
4 import java.io.IOException JavaDoc;
5 import java.io.InputStream JavaDoc;
6 import java.sql.Connection JavaDoc;
7 import java.sql.Statement JavaDoc;
8 import java.sql.Timestamp JavaDoc;
9 import java.util.HashMap JavaDoc;
10 import java.util.Iterator JavaDoc;
11 import java.util.Map JavaDoc;
12 import java.util.Properties JavaDoc;
13
14 import org.apache.commons.logging.Log;
15 import org.apache.commons.logging.LogFactory;
16
17 import org.hibernate.util.PropertiesHelper;
18
19
20 /**
21  * Provides access to configuration info passed in <tt>Properties</tt> objects.
22  * <br><br>
23  * Hibernate has two property scopes:
24  * <ul>
25  * <li><b>Factory-level</b> properties may be passed to the <tt>SessionFactory</tt> when it
26  * instantiated. Each instance might have different property values. If no
27  * properties are specified, the factory calls <tt>Environment.getProperties()</tt>.
28  * <li><b>System-level</b> properties are shared by all factory instances and are always
29  * determined by the <tt>Environment</tt> properties.
30  * </ul>
31  * The only system-level properties are
32  * <ul>
33  * <li><tt>hibernate.jdbc.use_streams_for_binary</tt>
34  * <li><tt>hibernate.cglib.use_reflection_optimizer</tt>
35  * </ul>
36  * <tt>Environment</tt> properties are populated by calling <tt>System.getProperties()</tt>
37  * and then from a resource named <tt>/hibernate.properties</tt> if it exists. System
38  * properties override properties specified in <tt>hibernate.properties</tt>.<br>
39  * <br>
40  * The <tt>SessionFactory</tt> is controlled by the following properties.
41  * Properties may be either be <tt>System</tt> properties, properties
42  * defined in a resource named <tt>/hibernate.properties</tt> or an instance of
43  * <tt>java.util.Properties</tt> passed to
44  * <tt>Configuration.buildSessionFactory()</tt><br>
45  * <br>
46  * <table>
47  * <tr><td><b>property</b></td><td><b>meaning</b></td></tr>
48  * <tr>
49  * <td><tt>hibernate.dialect</tt></td>
50  * <td>classname of <tt>org.hibernate.dialect.Dialect</tt> subclass</td>
51  * </tr>
52  * <tr>
53  * <td><tt>hibernate.cache.provider_class</tt></td>
54  * <td>classname of <tt>org.hibernate.cache.CacheProvider</tt>
55  * subclass (if not specified EHCache is used)</td>
56  * </tr>
57  * <tr>
58  * <td><tt>hibernate.connection.provider_class</tt></td>
59  * <td>classname of <tt>org.hibernate.connection.ConnectionProvider</tt>
60  * subclass (if not specified hueristics are used)</td>
61  * </tr>
62  * <tr><td><tt>hibernate.connection.username</tt></td><td>database username</td></tr>
63  * <tr><td><tt>hibernate.connection.password</tt></td><td>database password</td></tr>
64  * <tr>
65  * <td><tt>hibernate.connection.url</tt></td>
66  * <td>JDBC URL (when using <tt>java.sql.DriverManager</tt>)</td>
67  * </tr>
68  * <tr>
69  * <td><tt>hibernate.connection.driver_class</tt></td>
70  * <td>classname of JDBC driver</td>
71  * </tr>
72  * <tr>
73  * <td><tt>hibernate.connection.isolation</tt></td>
74  * <td>JDBC transaction isolation level (only when using
75  * <tt>java.sql.DriverManager</tt>)
76  * </td>
77  * </tr>
78  * <td><tt>hibernate.connection.pool_size</tt></td>
79  * <td>the maximum size of the connection pool (only when using
80  * <tt>java.sql.DriverManager</tt>)
81  * </td>
82  * </tr>
83  * <tr>
84  * <td><tt>hibernate.connection.datasource</tt></td>
85  * <td>databasource JNDI name (when using <tt>javax.sql.Datasource</tt>)</td>
86  * </tr>
87  * <tr>
88  * <td><tt>hibernate.jndi.url</tt></td><td>JNDI <tt>InitialContext</tt> URL</td>
89  * </tr>
90  * <tr>
91  * <td><tt>hibernate.jndi.class</tt></td><td>JNDI <tt>InitialContext</tt> classname</td>
92  * </tr>
93  * <tr>
94  * <td><tt>hibernate.max_fetch_depth</tt></td>
95  * <td>maximum depth of outer join fetching</td>
96  * </tr>
97  * <tr>
98  * <td><tt>hibernate.jdbc.batch_size</tt></td>
99  * <td>enable use of JDBC2 batch API for drivers which support it</td>
100  * </tr>
101  * <tr>
102  * <td><tt>hibernate.jdbc.fetch_size</tt></td>
103  * <td>set the JDBC fetch size</td>
104  * </tr>
105  * <tr>
106  * <td><tt>hibernate.jdbc.use_scrollable_resultset</tt></td>
107  * <td>enable use of JDBC2 scrollable resultsets (you only need this specify
108  * this property when using user supplied connections)</td>
109  * </tr>
110  * <tr>
111  * <td><tt>hibernate.jdbc.use_getGeneratedKeys</tt></td>
112  * <td>enable use of JDBC3 PreparedStatement.getGeneratedKeys() to retrieve
113  * natively generated keys after insert. Requires JDBC3+ driver and JRE1.4+</td>
114  * </tr>
115  * <tr>
116  * <td><tt>hibernate.hbm2ddl.auto</tt></td>
117  * <td>enable auto DDL export</td>
118  * </tr>
119  * <tr>
120  * <td><tt>hibernate.default_schema</tt></td>
121  * <td>use given schema name for unqualified tables (always optional)</td>
122  * </tr>
123  * <tr>
124  * <td><tt>hibernate.default_catalog</tt></td>
125  * <td>use given catalog name for unqualified tables (always optional)</td>
126  * </tr>
127  * <tr>
128  * <td><tt>hibernate.session_factory_name</tt></td>
129  * <td>If set, the factory attempts to bind this name to itself in the
130  * JNDI context. This name is also used to support cross JVM <tt>
131  * Session</tt> (de)serialization.</td>
132  * </tr>
133  * <tr>
134  * <td><tt>hibernate.transaction.manager_lookup_class</tt></td>
135  * <td>classname of <tt>org.hibernate.transaction.TransactionManagerLookup</tt>
136  * implementor</td>
137  * </tr>
138  * <tr>
139  * <td><tt>hibernate.transaction.factory_class</tt></td>
140  * <td>the factory to use for instantiating <tt>Transaction</tt>s.
141  * (Defaults to <tt>JDBCTransactionFactory</tt>.)</td>
142  * </tr>
143  * <tr>
144  * <td><tt>hibernate.query.substitutions</tt></td><td>query language token substitutions</td>
145  * </tr>
146  * </table>
147  *
148  * @see org.hibernate.SessionFactory
149  * @author Gavin King
150  */

151 public final class Environment {
152
153     public static final String JavaDoc VERSION = "3.1 beta 1";
154
155     /**
156      * <tt>ConnectionProvider</tt> implementor to use when obtaining connections
157      */

158     public static final String JavaDoc CONNECTION_PROVIDER ="hibernate.connection.provider_class";
159     /**
160      * JDBC driver class
161      */

162     public static final String JavaDoc DRIVER ="hibernate.connection.driver_class";
163     /**
164      * JDBC transaction isolation level
165      */

166     public static final String JavaDoc ISOLATION ="hibernate.connection.isolation";
167     /**
168      * JDBC URL
169      */

170     public static final String JavaDoc URL ="hibernate.connection.url";
171     /**
172      * JDBC user
173      */

174     public static final String JavaDoc USER ="hibernate.connection.username";
175     /**
176      * JDBC password
177      */

178     public static final String JavaDoc PASS ="hibernate.connection.password";
179     /**
180      * JDBC autocommit mode
181      */

182     public static final String JavaDoc AUTOCOMMIT ="hibernate.connection.autocommit";
183     /**
184      * Maximum number of inactive connections for Hibernate's connection pool
185      */

186     public static final String JavaDoc POOL_SIZE ="hibernate.connection.pool_size";
187     /**
188      * <tt>java.sql.Datasource</tt> JNDI name
189      */

190     public static final String JavaDoc DATASOURCE ="hibernate.connection.datasource";
191     /**
192      * prefix for arbitrary JDBC connection properties
193      */

194     public static final String JavaDoc CONNECTION_PREFIX = "hibernate.connection";
195
196     /**
197      * JNDI initial context class, <tt>Context.INITIAL_CONTEXT_FACTORY</tt>
198      */

199     public static final String JavaDoc JNDI_CLASS ="hibernate.jndi.class";
200     /**
201      * JNDI provider URL, <tt>Context.PROVIDER_URL</tt>
202      */

203     public static final String JavaDoc JNDI_URL ="hibernate.jndi.url";
204     /**
205      * prefix for arbitrary JNDI <tt>InitialContext</tt> properties
206      */

207     public static final String JavaDoc JNDI_PREFIX = "hibernate.jndi";
208     /**
209      * JNDI name to bind to <tt>SessionFactory</tt>
210      */

211     public static final String JavaDoc SESSION_FACTORY_NAME = "hibernate.session_factory_name";
212
213     /**
214      * Hibernate SQL <tt>Dialect</tt> class
215      */

216     public static final String JavaDoc DIALECT ="hibernate.dialect";
217     /**
218      * A default database schema (owner) name to use for unqualified tablenames
219      */

220     public static final String JavaDoc DEFAULT_SCHEMA = "hibernate.default_schema";
221     /**
222      * A default database catalog name to use for unqualified tablenames
223      */

224     public static final String JavaDoc DEFAULT_CATALOG = "hibernate.default_catalog";
225
226     /**
227      * Enable logging of generated SQL to the console
228      */

229     public static final String JavaDoc SHOW_SQL ="hibernate.show_sql";
230     /**
231      * Add comments to the generated SQL
232      */

233     public static final String JavaDoc USE_SQL_COMMENTS ="hibernate.use_sql_comments";
234     /**
235      * Maximum depth of outer join fetching
236      */

237     public static final String JavaDoc MAX_FETCH_DEPTH = "hibernate.max_fetch_depth";
238     /**
239      * The default batch size for batch fetching
240      */

241     public static final String JavaDoc DEFAULT_BATCH_FETCH_SIZE = "hibernate.default_batch_fetch_size";
242     /**
243      * Use <tt>java.io</tt> streams to read / write binary data from / to JDBC
244      */

245     public static final String JavaDoc USE_STREAMS_FOR_BINARY = "hibernate.jdbc.use_streams_for_binary";
246     /**
247      * Use JDBC scrollable <tt>ResultSet</tt>s. This property is only necessary when there is
248      * no <tt>ConnectionProvider</tt>, ie. the user is supplying JDBC connections.
249      */

250     public static final String JavaDoc USE_SCROLLABLE_RESULTSET = "hibernate.jdbc.use_scrollable_resultset";
251     /**
252      * Tells the JDBC driver to attempt to retrieve row Id with the JDBC 3.0 PreparedStatement.getGeneratedKeys()
253      * method. In general, performance will be better if this property is set to true and the underlying
254      * JDBC driver supports getGeneratedKeys().
255      */

256     public static final String JavaDoc USE_GET_GENERATED_KEYS = "hibernate.jdbc.use_get_generated_keys";
257     /**
258      * Gives the JDBC driver a hint as to the number of rows that should be fetched from the database
259      * when more rows are needed. If <tt>0</tt>, JDBC driver default settings will be used.
260      */

261     public static final String JavaDoc STATEMENT_FETCH_SIZE = "hibernate.jdbc.fetch_size";
262     /**
263      * Maximum JDBC batch size. A nonzero value enables batch updates.
264      */

265     public static final String JavaDoc STATEMENT_BATCH_SIZE = "hibernate.jdbc.batch_size";
266     /**
267      * Select a custom batcher.
268      */

269     public static final String JavaDoc BATCH_STRATEGY = "hibernate.jdbc.factory_class";
270     /**
271      * Should versioned data be included in batching?
272      */

273     public static final String JavaDoc BATCH_VERSIONED_DATA = "hibernate.jdbc.batch_versioned_data";
274     /**
275      * An XSLT resource used to generate "custom" XML
276      */

277     public static final String JavaDoc OUTPUT_STYLESHEET ="hibernate.xml.output_stylesheet";
278
279     /**
280      * Maximum size of C3P0 connection pool
281      */

282     public static final String JavaDoc C3P0_MAX_SIZE = "hibernate.c3p0.max_size";
283     /**
284      * Minimum size of C3P0 connection pool
285      */

286     public static final String JavaDoc C3P0_MIN_SIZE = "hibernate.c3p0.min_size";
287
288     /**
289      * Maximum idle time for C3P0 connection pool
290      */

291     public static final String JavaDoc C3P0_TIMEOUT = "hibernate.c3p0.timeout";
292     /**
293      * Maximum size of C3P0 statement cache
294      */

295     public static final String JavaDoc C3P0_MAX_STATEMENTS = "hibernate.c3p0.max_statements";
296     /**
297      * Number of connections acquired when pool is exhausted
298      */

299     public static final String JavaDoc C3P0_ACQUIRE_INCREMENT = "hibernate.c3p0.acquire_increment";
300     /**
301      * Idle time before a C3P0 pooled connection is validated
302      */

303     public static final String JavaDoc C3P0_IDLE_TEST_PERIOD = "hibernate.c3p0.idle_test_period";
304
305     /**
306      * Proxool/Hibernate property prefix
307      */

308     public static final String JavaDoc PROXOOL_PREFIX = "hibernate.proxool";
309     /**
310      * Proxool property to configure the Proxool Provider using an XML (<tt>/path/to/file.xml</tt>)
311      */

312     public static final String JavaDoc PROXOOL_XML = "hibernate.proxool.xml";
313     /**
314      * Proxool property to configure the Proxool Provider using a properties file (<tt>/path/to/proxool.properties</tt>)
315      */

316     public static final String JavaDoc PROXOOL_PROPERTIES = "hibernate.proxool.properties";
317     /**
318      * Proxool property to configure the Proxool Provider from an already existing pool (<tt>true</tt> / <tt>false</tt>)
319      */

320     public static final String JavaDoc PROXOOL_EXISTING_POOL = "hibernate.proxool.existing_pool";
321     /**
322      * Proxool property with the Proxool pool alias to use
323      * (Required for <tt>PROXOOL_EXISTING_POOL</tt>, <tt>PROXOOL_PROPERTIES</tt>, or
324      * <tt>PROXOOL_XML</tt>)
325      */

326     public static final String JavaDoc PROXOOL_POOL_ALIAS = "hibernate.proxool.pool_alias";
327
328     /**
329      * Enable automatic session close at end of transaction
330      */

331     public static final String JavaDoc AUTO_CLOSE_SESSION = "hibernate.transaction.auto_close_session";
332     /**
333      * Enable automatic flush during the JTA <tt>beforeCompletion()</tt> callback
334      */

335     public static final String JavaDoc FLUSH_BEFORE_COMPLETION = "hibernate.transaction.flush_before_completion";
336     /**
337      * Specifies how Hibernate should release JDBC connections.
338      */

339     public static final String JavaDoc RELEASE_CONNECTIONS = "hibernate.connection.release_mode";
340     /**
341      * <tt>TransactionFactory</tt> implementor to use for creating <tt>Transaction</tt>s
342      */

343     public static final String JavaDoc TRANSACTION_STRATEGY = "hibernate.transaction.factory_class";
344     /**
345      * <tt>TransactionManagerLookup</tt> implementor to use for obtaining the <tt>TransactionManager</tt>
346      */

347     public static final String JavaDoc TRANSACTION_MANAGER_STRATEGY = "hibernate.transaction.manager_lookup_class";
348     /**
349      * JNDI name of JTA <tt>UserTransaction</tt> object
350      */

351     public static final String JavaDoc USER_TRANSACTION = "jta.UserTransaction";
352
353     /**
354      * The <tt>CacheProvider</tt> implementation class
355      */

356     public static final String JavaDoc CACHE_PROVIDER = "hibernate.cache.provider_class";
357     /**
358      * The <tt>CacheProvider</tt> JNDI namespace, if pre-bound to JNDI.
359      */

360     public static final String JavaDoc CACHE_NAMESPACE = "hibernate.cache.jndi";
361     /**
362      * Enable the query cache (disabled by default)
363      */

364     public static final String JavaDoc USE_QUERY_CACHE = "hibernate.cache.use_query_cache";
365     /**
366      * The <tt>QueryCacheFactory</tt> implementation class.
367      */

368     public static final String JavaDoc QUERY_CACHE_FACTORY = "hibernate.cache.query_cache_factory";
369     /**
370      * Enable the second-level cache (enabled by default)
371      */

372     public static final String JavaDoc USE_SECOND_LEVEL_CACHE = "hibernate.cache.use_second_level_cache";
373     /**
374      * Optimize the cache for mimimal puts instead of minimal gets
375      */

376     public static final String JavaDoc USE_MINIMAL_PUTS = "hibernate.cache.use_minimal_puts";
377     /**
378      * The <tt>CacheProvider</tt> region name prefix
379      */

380     public static final String JavaDoc CACHE_REGION_PREFIX = "hibernate.cache.region_prefix";
381     /**
382      * Enable use of structured second-level cache entries
383      */

384     public static final String JavaDoc USE_STRUCTURED_CACHE = "hibernate.cache.use_structured_entries";
385
386     /**
387      * Enable statistics collection
388      */

389     public static final String JavaDoc GENERATE_STATISTICS = "hibernate.generate_statistics";
390
391     public static final String JavaDoc USE_IDENTIFIER_ROLLBACK = "hibernate.use_identifier_rollback";
392
393     /**
394      * Use CGLIB <tt>MetaClass</tt> to optimize property access
395      */

396     public static final String JavaDoc USE_REFLECTION_OPTIMIZER = "hibernate.cglib.use_reflection_optimizer";
397
398     /**
399      * The classname of the HQL query parser factory
400      */

401     public static final String JavaDoc QUERY_TRANSLATOR = "hibernate.query.factory_class";
402     /**
403      * A comma-seperated list of token substitutions to use when translating a Hibernate
404      * query to SQL
405      */

406     public static final String JavaDoc QUERY_SUBSTITUTIONS = "hibernate.query.substitutions";
407     /**
408      * Auto export/update schema using hbm2ddl tool. Valid values are <tt>update</tt>, <tt>create</tt>
409      * and <tt>create-drop</tt>.
410      */

411     public static final String JavaDoc HBM2DDL_AUTO = "hibernate.hbm2ddl.auto";
412
413     /**
414      * The {@link org.hibernate.exception.SQLExceptionConverter} to use for converting SQLExceptions
415      * to Hibernate's JDBCException hierarchy. The default is to use the configured
416      * {@link org.hibernate.dialect.Dialect}'s preferred SQLExceptionConverter.
417      */

418     public static final String JavaDoc SQL_EXCEPTION_CONVERTER = "hibernate.jdbc.sql_exception_converter";
419
420     /**
421      * Enable wrapping of JDBC result sets in order to speed up column name lookups for
422      * broken JDBC drivers
423      */

424     public static final String JavaDoc WRAP_RESULT_SETS = "hibernate.jdbc.wrap_result_sets";
425
426     /**
427      * Enable ordering of update statements by primary key value
428      */

429     public static final String JavaDoc ORDER_UPDATES = "hibernate.order_updates";
430
431     /**
432      * The EntityMode in which set the Session opened from the SessionFactory.
433      */

434     public static final String JavaDoc DEFAULT_ENTITY_MODE = "hibernate.default_entity_mode";
435
436
437     private static final boolean ENABLE_BINARY_STREAMS;
438     private static final boolean ENABLE_REFLECTION_OPTIMIZER;
439     private static final boolean JVM_SUPPORTS_LINKED_HASH_COLLECTIONS;
440     private static final boolean JVM_HAS_TIMESTAMP_BUG;
441     private static final boolean JVM_HAS_JDK14_TIMESTAMP;
442     private static final boolean JVM_SUPPORTS_GET_GENERATED_KEYS;
443
444     private static final Properties JavaDoc GLOBAL_PROPERTIES;
445     private static final HashMap JavaDoc ISOLATION_LEVELS = new HashMap JavaDoc();
446     private static final Map JavaDoc OBSOLETE_PROPERTIES = new HashMap JavaDoc();
447
448     private static final Log log = LogFactory.getLog(Environment.class);
449
450     /**
451      * Issues warnings to the user when any obsolete property names are used.
452      */

453     public static void verifyProperties(Properties JavaDoc props) {
454         Iterator JavaDoc iter = props.keySet().iterator();
455         while ( iter.hasNext() ) {
456             Object JavaDoc oldProp = iter.next();
457             Object JavaDoc newProp = OBSOLETE_PROPERTIES.get(oldProp);
458             if ( newProp!=null ) log.warn("Usage of obsolete property: " + oldProp + " no longer supported, use: " + newProp);
459         }
460     }
461
462     static {
463
464         log.info("Hibernate " + VERSION);
465
466         ISOLATION_LEVELS.put( new Integer JavaDoc(Connection.TRANSACTION_NONE), "NONE" );
467         ISOLATION_LEVELS.put( new Integer JavaDoc(Connection.TRANSACTION_READ_UNCOMMITTED), "READ_UNCOMMITTED" );
468         ISOLATION_LEVELS.put( new Integer JavaDoc(Connection.TRANSACTION_READ_COMMITTED), "READ_COMMITTED" );
469         ISOLATION_LEVELS.put( new Integer JavaDoc(Connection.TRANSACTION_REPEATABLE_READ), "REPEATABLE_READ" );
470         ISOLATION_LEVELS.put( new Integer JavaDoc(Connection.TRANSACTION_SERIALIZABLE), "SERIALIZABLE" );
471
472         GLOBAL_PROPERTIES = new Properties JavaDoc();
473         GLOBAL_PROPERTIES.setProperty( USE_REFLECTION_OPTIMIZER, Boolean.TRUE.toString() );
474
475         InputStream JavaDoc stream = Environment.class.getResourceAsStream("/hibernate.properties");
476         if ( stream==null ) {
477             log.info("hibernate.properties not found");
478         }
479         else {
480             try {
481                 GLOBAL_PROPERTIES.load(stream);
482                 log.info( "loaded properties from resource hibernate.properties: " + PropertiesHelper.maskOut(GLOBAL_PROPERTIES, PASS) );
483             }
484             catch (Exception JavaDoc e) {
485                 log.error("problem loading properties from hibernate.properties");
486             }
487             finally {
488                 try{
489                     stream.close();
490                 }
491                 catch (IOException JavaDoc ioe){
492                     log.error("could not close stream on hibernate.properties", ioe);
493                 }
494             }
495         }
496
497         try {
498         GLOBAL_PROPERTIES.putAll( System.getProperties() );
499         }
500         catch (SecurityException JavaDoc se) {
501             log.warn("could not copy system properties, system properties will be ignored");
502         }
503
504         verifyProperties(GLOBAL_PROPERTIES);
505
506         ENABLE_BINARY_STREAMS = PropertiesHelper.getBoolean(USE_STREAMS_FOR_BINARY, GLOBAL_PROPERTIES);
507         ENABLE_REFLECTION_OPTIMIZER = PropertiesHelper.getBoolean(USE_REFLECTION_OPTIMIZER, GLOBAL_PROPERTIES);
508
509         if (ENABLE_BINARY_STREAMS) log.info("using java.io streams to persist binary types");
510         if (ENABLE_REFLECTION_OPTIMIZER) log.info("using CGLIB reflection optimizer");
511
512         boolean getGeneratedKeysSupport;
513         try {
514             Statement JavaDoc.class.getMethod("getGeneratedKeys", null);
515             getGeneratedKeysSupport = true;
516         }
517         catch (NoSuchMethodException JavaDoc nsme) {
518             getGeneratedKeysSupport = false;
519         }
520         JVM_SUPPORTS_GET_GENERATED_KEYS = getGeneratedKeysSupport;
521         if (!JVM_SUPPORTS_GET_GENERATED_KEYS) log.info("JVM does not support Statement.getGeneratedKeys()");
522
523         boolean linkedHashSupport;
524         try {
525             Class.forName("java.util.LinkedHashSet");
526             linkedHashSupport = true;
527         }
528         catch (ClassNotFoundException JavaDoc cnfe) {
529             linkedHashSupport = false;
530         }
531         JVM_SUPPORTS_LINKED_HASH_COLLECTIONS = linkedHashSupport;
532         if (!JVM_SUPPORTS_LINKED_HASH_COLLECTIONS) log.info("JVM does not support LinkedHasMap, LinkedHashSet - ordered maps and sets disabled");
533
534         JVM_HAS_TIMESTAMP_BUG = new Timestamp JavaDoc(123456789).getTime() != 123456789;
535         if (JVM_HAS_TIMESTAMP_BUG) log.info("using workaround for JVM bug in java.sql.Timestamp");
536         Timestamp JavaDoc t = new Timestamp JavaDoc(0);
537         t.setNanos(5 * 1000000);
538         JVM_HAS_JDK14_TIMESTAMP = t.getTime() == 5;
539         if (JVM_HAS_JDK14_TIMESTAMP) {
540             log.info("using JDK 1.4 java.sql.Timestamp handling");
541         }
542         else {
543             log.info("using pre JDK 1.4 java.sql.Timestamp handling");
544         }
545     }
546
547     /**
548      * Does this JVM have the IBM JDK 1.3.1. The bug is <tt>new Timestamp(x).getTime()!=x</tt>.
549      */

550     public static boolean jvmHasTimestampBug() {
551         return JVM_HAS_TIMESTAMP_BUG;
552     }
553
554     /**
555      * Does this JVM handle <tt>Timestamp</tt> in the JDK 1.4 compliant way?
556      */

557     public static boolean jvmHasJDK14Timestamp() {
558         return JVM_HAS_JDK14_TIMESTAMP;
559     }
560
561     /**
562      * Does this JVM support <tt>LinkedHashSet</tt>, <tt>LinkedHashMap</tt>.
563      * @see java.util.LinkedHashSet
564      * @see java.util.LinkedHashMap
565      */

566     public static boolean jvmSupportsLinkedHashCollections() {
567         return JVM_SUPPORTS_LINKED_HASH_COLLECTIONS;
568     }
569
570     public static boolean jvmSupportsGetGeneratedKeys() {
571         return JVM_SUPPORTS_GET_GENERATED_KEYS;
572     }
573
574     /**
575      * Should we use streams to bind binary types to JDBC IN parameters.
576      * Property <tt>hibernate.jdbc.use_streams_for_binary</tt>.
577      * @see Environment#USE_STREAMS_FOR_BINARY
578      */

579     public static boolean useStreamsForBinary() {
580         return ENABLE_BINARY_STREAMS;
581     }
582
583     /**
584      * Should we use CGLIB reflection optimizer.
585      * Property <tt>hibernate.jdbc.use_refection_optimizer</tt>.
586      * @see Environment#USE_REFLECTION_OPTIMIZER
587      */

588     public static boolean useReflectionOptimizer() {
589         return ENABLE_REFLECTION_OPTIMIZER;
590     }
591
592     private Environment() { throw new UnsupportedOperationException JavaDoc(); }
593
594     /**
595      * Return <tt>System</tt> properties, extended by any properties specified
596      * in <tt>hibernate.properties</tt>.
597      * @return Properties
598      */

599     public static Properties JavaDoc getProperties() {
600         Properties JavaDoc copy = new Properties JavaDoc();
601         copy.putAll(GLOBAL_PROPERTIES);
602         return copy;
603     }
604
605     /**
606      * Get the name of a JDBC transaction isolation level
607      *
608      * @see java.sql.Connection
609      * @param isolation as defined by <tt>java.sql.Connection</tt>
610      * @return a human-readable name
611      */

612     public static String JavaDoc isolationLevelToString(int isolation) {
613         return (String JavaDoc) ISOLATION_LEVELS.get( new Integer JavaDoc(isolation) );
614     }
615
616 }
617
618
619
620
621
622
623
624
Popular Tags