Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.cfg;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.Timestamp;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.Version;
import org.hibernate.bytecode.spi.BytecodeProvider;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.ConfigHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.jboss.logging.Logger;
/**
* Provides access to configuration info passed in Properties objects.
*
* Hibernate has two property scopes:
*
*
Factory-level properties may be passed to the SessionFactory when it
* instantiated. Each instance might have different property values. If no
* properties are specified, the factory calls Environment.getProperties().
*
System-level properties are shared by all factory instances and are always
* determined by the Environment properties.
*
* The only system-level properties are
*
*
hibernate.jdbc.use_streams_for_binary
*
hibernate.cglib.use_reflection_optimizer
*
* Environment properties are populated by calling System.getProperties()
* and then from a resource named /hibernate.properties if it exists. System
* properties override properties specified in hibernate.properties.
*
* The SessionFactory is controlled by the following properties.
* Properties may be either be System properties, properties
* defined in a resource named /hibernate.properties or an instance of
* java.util.Properties passed to
* Configuration.buildSessionFactory()
*
*
*
property
meaning
*
*
hibernate.dialect
*
classname of org.hibernate.dialect.Dialect subclass
*
*
*
hibernate.connection.provider_class
*
classname of org.hibernate.service.jdbc.connections.spi.ConnectionProvider
* subclass (if not specified hueristics are used)
*
*
hibernate.connection.username
database username
*
hibernate.connection.password
database password
*
*
hibernate.connection.url
*
JDBC URL (when using java.sql.DriverManager)
*
*
*
hibernate.connection.driver_class
*
classname of JDBC driver
*
*
*
hibernate.connection.isolation
*
JDBC transaction isolation level (only when using
* java.sql.DriverManager)
*
*
*
hibernate.connection.pool_size
*
the maximum size of the connection pool (only when using
* java.sql.DriverManager)
*
*
*
*
hibernate.connection.datasource
*
databasource JNDI name (when using javax.sql.Datasource)
*
*
*
hibernate.jndi.url
JNDI InitialContext URL
*
*
*
hibernate.jndi.class
JNDI InitialContext classname
*
*
*
hibernate.max_fetch_depth
*
maximum depth of outer join fetching
*
*
*
hibernate.jdbc.batch_size
*
enable use of JDBC2 batch API for drivers which support it
*
*
*
hibernate.jdbc.fetch_size
*
set the JDBC fetch size
*
*
*
hibernate.jdbc.use_scrollable_resultset
*
enable use of JDBC2 scrollable resultsets (you only need this specify
* this property when using user supplied connections)
*
*
*
hibernate.jdbc.use_getGeneratedKeys
*
enable use of JDBC3 PreparedStatement.getGeneratedKeys() to retrieve
* natively generated keys after insert. Requires JDBC3+ driver and JRE1.4+
*
*
*
hibernate.hbm2ddl.auto
*
enable auto DDL export
*
*
*
hibernate.default_schema
*
use given schema name for unqualified tables (always optional)
*
*
*
hibernate.default_catalog
*
use given catalog name for unqualified tables (always optional)
*
*
*
hibernate.session_factory_name
*
If set, the factory attempts to bind this name to itself in the
* JNDI context. This name is also used to support cross JVM
* Session (de)serialization.
*
*
*
hibernate.transaction.jta.platform
*
classname of org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform
* implementor
*
*
*
hibernate.transaction.factory_class
*
the factory to use for instantiating Transactions.
* (Defaults to JdbcTransactionFactory.)
*
*
*
hibernate.query.substitutions
query language token substitutions
*
*
*
* @see org.hibernate.SessionFactory
* @author Gavin King
*/
public final class Environment implements AvailableSettings {
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, Environment.class.getName());
private static final BytecodeProvider BYTECODE_PROVIDER_INSTANCE;
private static final boolean ENABLE_BINARY_STREAMS;
private static final boolean ENABLE_REFLECTION_OPTIMIZER;
private static final boolean JVM_HAS_TIMESTAMP_BUG;
private static final Properties GLOBAL_PROPERTIES;
private static final Map ISOLATION_LEVELS;
private static final Map OBSOLETE_PROPERTIES = new HashMap();
private static final Map RENAMED_PROPERTIES = new HashMap();
/**
* Issues warnings to the user when any obsolete or renamed property names are used.
*
* @param configurationValues The specified properties.
*/
public static void verifyProperties(Map,?> configurationValues) {
final Map propertiesToAdd = new HashMap();
for ( Map.Entry entry : configurationValues.entrySet() ) {
final Object replacementKey = OBSOLETE_PROPERTIES.get( entry.getKey() );
if ( replacementKey != null ) {
LOG.unsupportedProperty( entry.getKey(), replacementKey );
}
final Object renamedKey = RENAMED_PROPERTIES.get( entry.getKey() );
if ( renamedKey != null ) {
LOG.renamedProperty( entry.getKey(), renamedKey );
propertiesToAdd.put( renamedKey, entry.getValue() );
}
}
configurationValues.putAll( propertiesToAdd );
}
static {
Version.logVersion();
Map temp = new HashMap();
temp.put( Connection.TRANSACTION_NONE, "NONE" );
temp.put( Connection.TRANSACTION_READ_UNCOMMITTED, "READ_UNCOMMITTED" );
temp.put( Connection.TRANSACTION_READ_COMMITTED, "READ_COMMITTED" );
temp.put( Connection.TRANSACTION_REPEATABLE_READ, "REPEATABLE_READ" );
temp.put( Connection.TRANSACTION_SERIALIZABLE, "SERIALIZABLE" );
ISOLATION_LEVELS = Collections.unmodifiableMap( temp );
GLOBAL_PROPERTIES = new Properties();
//Set USE_REFLECTION_OPTIMIZER to false to fix HHH-227
GLOBAL_PROPERTIES.setProperty( USE_REFLECTION_OPTIMIZER, Boolean.FALSE.toString() );
try {
InputStream stream = ConfigHelper.getResourceAsStream( "/hibernate.properties" );
try {
GLOBAL_PROPERTIES.load(stream);
LOG.propertiesLoaded( ConfigurationHelper.maskOut( GLOBAL_PROPERTIES, PASS ) );
}
catch (Exception e) {
LOG.unableToLoadProperties();
}
finally {
try{
stream.close();
}
catch (IOException ioe){
LOG.unableToCloseStreamError( ioe );
}
}
}
catch (HibernateException he) {
LOG.propertiesNotFound();
}
try {
Properties systemProperties = System.getProperties();
// Must be thread-safe in case an application changes System properties during Hibernate initialization.
// See HHH-8383.
synchronized (systemProperties) {
GLOBAL_PROPERTIES.putAll(systemProperties);
}
} catch (SecurityException se) {
LOG.unableToCopySystemProperties();
}
verifyProperties(GLOBAL_PROPERTIES);
ENABLE_BINARY_STREAMS = ConfigurationHelper.getBoolean(USE_STREAMS_FOR_BINARY, GLOBAL_PROPERTIES);
if ( ENABLE_BINARY_STREAMS ) {
LOG.usingStreams();
}
ENABLE_REFLECTION_OPTIMIZER = ConfigurationHelper.getBoolean(USE_REFLECTION_OPTIMIZER, GLOBAL_PROPERTIES);
if ( ENABLE_REFLECTION_OPTIMIZER ) {
LOG.usingReflectionOptimizer();
}
BYTECODE_PROVIDER_INSTANCE = buildBytecodeProvider( GLOBAL_PROPERTIES );
long x = 123456789;
JVM_HAS_TIMESTAMP_BUG = new Timestamp(x).getTime() != x;
if ( JVM_HAS_TIMESTAMP_BUG ) {
LOG.usingTimestampWorkaround();
}
}
public static BytecodeProvider getBytecodeProvider() {
return BYTECODE_PROVIDER_INSTANCE;
}
/**
* Does this JVM's implementation of {@link java.sql.Timestamp} have a bug in which the following is true:
* new java.sql.Timestamp( x ).getTime() != x
*
*
* NOTE : IBM JDK 1.3.1 the only known JVM to exhibit this behavior.
*
* @return True if the JVM's {@link Timestamp} implementa
*/
public static boolean jvmHasTimestampBug() {
return JVM_HAS_TIMESTAMP_BUG;
}
/**
* Should we use streams to bind binary types to JDBC IN parameters?
*
* @return True if streams should be used for binary data handling; false otherwise.
*
* @see #USE_STREAMS_FOR_BINARY
*/
public static boolean useStreamsForBinary() {
return ENABLE_BINARY_STREAMS;
}
/**
* Should we use reflection optimization?
*
* @return True if reflection optimization should be used; false otherwise.
*
* @see #USE_REFLECTION_OPTIMIZER
* @see #getBytecodeProvider()
* @see BytecodeProvider#getReflectionOptimizer
*/
public static boolean useReflectionOptimizer() {
return ENABLE_REFLECTION_OPTIMIZER;
}
/**
* Disallow instantiation
*/
private Environment() {
throw new UnsupportedOperationException();
}
/**
* Return System properties, extended by any properties specified
* in hibernate.properties.
* @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 java.sql.Connection
* @return a human-readable name
*/
public static String isolationLevelToString(int isolation) {
return ISOLATION_LEVELS.get( isolation );
}
public static BytecodeProvider buildBytecodeProvider(Properties properties) {
String provider = ConfigurationHelper.getString( BYTECODE_PROVIDER, properties, "javassist" );
LOG.bytecodeProvider( provider );
return buildBytecodeProvider( provider );
}
private static BytecodeProvider buildBytecodeProvider(String providerName) {
if ( "javassist".equals( providerName ) ) {
return new org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl();
}
LOG.unknownBytecodeProvider( providerName );
return new org.hibernate.bytecode.internal.javassist.BytecodeProviderImpl();
}
}