HHH-6101 - Clean up checks for java 1.3 versus 1.4
This commit is contained in:
parent
6504cb6d78
commit
38068e1495
|
@ -561,10 +561,7 @@ public final class Environment {
|
|||
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_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();
|
||||
|
@ -642,43 +639,22 @@ public final class Environment {
|
|||
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();
|
||||
}
|
||||
|
||||
if (ENABLE_BINARY_STREAMS) LOG.usingStreams();
|
||||
if (ENABLE_REFLECTION_OPTIMIZER) LOG.usingReflectionOptimizer();
|
||||
BYTECODE_PROVIDER_INSTANCE = buildBytecodeProvider( GLOBAL_PROPERTIES );
|
||||
|
||||
boolean getGeneratedKeysSupport;
|
||||
try {
|
||||
Statement.class.getMethod("getGeneratedKeys", (Class[])null);
|
||||
getGeneratedKeysSupport = true;
|
||||
}
|
||||
catch (NoSuchMethodException nsme) {
|
||||
getGeneratedKeysSupport = false;
|
||||
}
|
||||
JVM_SUPPORTS_GET_GENERATED_KEYS = getGeneratedKeysSupport;
|
||||
if (!JVM_SUPPORTS_GET_GENERATED_KEYS) LOG.generatedKeysNotSupported();
|
||||
|
||||
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.linkedMapsAndSetsNotSupported();
|
||||
|
||||
long x = 123456789;
|
||||
JVM_HAS_TIMESTAMP_BUG = new Timestamp(x).getTime() != x;
|
||||
if (JVM_HAS_TIMESTAMP_BUG) LOG.usingTimestampWorkaround();
|
||||
|
||||
Timestamp t = new Timestamp(0);
|
||||
t.setNanos(5 * 1000000);
|
||||
JVM_HAS_JDK14_TIMESTAMP = t.getTime() == 5;
|
||||
if (JVM_HAS_JDK14_TIMESTAMP) LOG.usingJdk14TimestampHandling();
|
||||
else LOG.usingPreJdk14TimestampHandling();
|
||||
if (JVM_HAS_TIMESTAMP_BUG) {
|
||||
LOG.usingTimestampWorkaround();
|
||||
}
|
||||
}
|
||||
|
||||
public static BytecodeProvider getBytecodeProvider() {
|
||||
|
@ -698,49 +674,6 @@ public final class Environment {
|
|||
return JVM_HAS_TIMESTAMP_BUG;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this JVM handle {@link java.sql.Timestamp} in the JDK 1.4 compliant way wrt to nano rolling>
|
||||
*
|
||||
* @return True if the JDK 1.4 (JDBC3) specification for {@link java.sql.Timestamp} nano rolling is adhered to.
|
||||
*
|
||||
* @deprecated Starting with 3.3 Hibernate requires JDK 1.4 or higher
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean jvmHasJDK14Timestamp() {
|
||||
return JVM_HAS_JDK14_TIMESTAMP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this JVM support {@link java.util.LinkedHashSet} and {@link java.util.LinkedHashMap}?
|
||||
* <p/>
|
||||
* Note, this is true for JDK 1.4 and above; hence the deprecation.
|
||||
*
|
||||
* @return True if {@link java.util.LinkedHashSet} and {@link java.util.LinkedHashMap} are available.
|
||||
*
|
||||
* @deprecated Starting with 3.3 Hibernate requires JDK 1.4 or higher
|
||||
* @see java.util.LinkedHashSet
|
||||
* @see java.util.LinkedHashMap
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean jvmSupportsLinkedHashCollections() {
|
||||
return JVM_SUPPORTS_LINKED_HASH_COLLECTIONS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this JDK/JVM define the JDBC {@link Statement} interface with a 'getGeneratedKeys' method?
|
||||
* <p/>
|
||||
* Note, this is true for JDK 1.4 and above; hence the deprecation.
|
||||
*
|
||||
* @return True if generated keys can be retrieved via Statement; false otherwise.
|
||||
*
|
||||
* @see Statement
|
||||
* @deprecated Starting with 3.3 Hibernate requires JDK 1.4 or higher
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean jvmSupportsGetGeneratedKeys() {
|
||||
return JVM_SUPPORTS_GET_GENERATED_KEYS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should we use streams to bind binary types to JDBC IN parameters?
|
||||
*
|
||||
|
|
|
@ -1361,11 +1361,8 @@ public final class HbmBinder {
|
|||
|
||||
Attribute orderNode = node.attribute( "order-by" );
|
||||
if ( orderNode != null ) {
|
||||
if ( Environment.jvmSupportsLinkedHashCollections() || ( collection instanceof Bag ) ) {
|
||||
collection.setOrderBy( orderNode.getValue() );
|
||||
}
|
||||
else LOG.attributeIgnored();
|
||||
}
|
||||
Attribute whereNode = node.attribute( "where" );
|
||||
if ( whereNode != null ) {
|
||||
collection.setWhere( whereNode.getValue() );
|
||||
|
|
|
@ -22,14 +22,14 @@
|
|||
* Boston, MA 02110-1301 USA
|
||||
*/
|
||||
package org.hibernate.cfg.annotations;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.annotations.OrderBy;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.mapping.Collection;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.annotations.OrderBy;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.mapping.Collection;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
|
||||
/**
|
||||
* Bind a set.
|
||||
*
|
||||
|
@ -52,10 +52,8 @@ public class SetBinder extends CollectionBinder {
|
|||
|
||||
@Override
|
||||
public void setSqlOrderBy(OrderBy orderByAnn) {
|
||||
// *annotation* binder, jdk 1.5, ... am i missing something?
|
||||
if ( orderByAnn != null ) {
|
||||
if (Environment.jvmSupportsLinkedHashCollections()) super.setSqlOrderBy(orderByAnn);
|
||||
else LOG.orderByAttributeIgnored();
|
||||
super.setSqlOrderBy( orderByAnn );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,10 +90,6 @@ public interface CoreMessageLogger extends BasicLogger {
|
|||
void attemptToMapColumnToNoTargetColumn( String loggableString,
|
||||
String name );
|
||||
|
||||
@LogMessage( level = WARN )
|
||||
@Message( value = "Attribute \"order-by\" ignored in JDK1.3 or less", id = 5 )
|
||||
void attributeIgnored();
|
||||
|
||||
@LogMessage( level = INFO )
|
||||
@Message( value = "Autocommit mode: %s", id = 6 )
|
||||
void autoCommitMode( boolean autocommit );
|
||||
|
@ -524,10 +520,6 @@ public interface CoreMessageLogger extends BasicLogger {
|
|||
@Message( value = "Found mapping document in jar: %s", id = 109 )
|
||||
void foundMappingDocument( String name );
|
||||
|
||||
@LogMessage( level = INFO )
|
||||
@Message( value = "JVM does not support Statement.getGeneratedKeys()", id = 110 )
|
||||
void generatedKeysNotSupported();
|
||||
|
||||
@LogMessage( level = INFO )
|
||||
@Message( value = "Generate SQL with comments: %s", id = 111 )
|
||||
void generateSqlWithComments( String enabledDisabled );
|
||||
|
@ -724,10 +716,6 @@ public interface CoreMessageLogger extends BasicLogger {
|
|||
@Message( value = "Lazy property fetching available for: %s", id = 157 )
|
||||
void lazyPropertyFetchingAvailable( String name );
|
||||
|
||||
@LogMessage( level = INFO )
|
||||
@Message( value = "JVM does not support LinkedHashMap, LinkedHashSet - ordered maps and sets disabled", id = 158 )
|
||||
void linkedMapsAndSetsNotSupported();
|
||||
|
||||
@LogMessage( level = WARN )
|
||||
@Message( value = "In CollectionLoadContext#endLoadingCollections, localLoadingCollectionKeys contained [%s], but no LoadingCollectionEntry was found in loadContexts", id = 159 )
|
||||
void loadingCollectionKeyNotFound( CollectionKey collectionKey );
|
||||
|
@ -861,10 +849,6 @@ public interface CoreMessageLogger extends BasicLogger {
|
|||
@Message( value = "@OrderBy not allowed for an indexed collection, annotation ignored.", id = 189 )
|
||||
void orderByAnnotationIndexedCollection();
|
||||
|
||||
@LogMessage( level = WARN )
|
||||
@Message( value = "Attribute \"order-by\" ignored in JDK1.3 or less", id = 190 )
|
||||
void orderByAttributeIgnored();
|
||||
|
||||
@LogMessage( level = INFO )
|
||||
@Message( value = "Order SQL inserts for batching: %s", id = 191 )
|
||||
void orderSqlInsertsForBatching( String enabledDisabled );
|
||||
|
@ -1744,18 +1728,10 @@ public interface CoreMessageLogger extends BasicLogger {
|
|||
@Message( value = "Using Hibernate built-in connection pool (not for production use!)", id = 402 )
|
||||
void usingHibernateBuiltInConnectionPool();
|
||||
|
||||
@LogMessage( level = INFO )
|
||||
@Message( value = "Using JDK 1.4 java.sql.Timestamp handling", id = 403 )
|
||||
void usingJdk14TimestampHandling();
|
||||
|
||||
@LogMessage( level = ERROR )
|
||||
@Message( value = "Don't use old DTDs, read the Hibernate 3.x Migration Guide!", id = 404 )
|
||||
void usingOldDtd();
|
||||
|
||||
@LogMessage( level = INFO )
|
||||
@Message( value = "Using pre JDK 1.4 java.sql.Timestamp handling", id = 405 )
|
||||
void usingPreJdk14TimestampHandling();
|
||||
|
||||
@LogMessage( level = INFO )
|
||||
@Message( value = "Using bytecode reflection optimizer", id = 406 )
|
||||
void usingReflectionOptimizer();
|
||||
|
|
|
@ -93,11 +93,6 @@ public class JdbcTimestampTypeDescriptor extends AbstractTypeDescriptor<Date> {
|
|||
int n1 = oneIsTimestamp ? ( (Timestamp) one ).getNanos() : 0;
|
||||
int n2 = anotherIsTimestamp ? ( (Timestamp) another ).getNanos() : 0;
|
||||
|
||||
if ( !Environment.jvmHasJDK14Timestamp() ) {
|
||||
t1 += n1 / 1000000;
|
||||
t2 += n2 / 1000000;
|
||||
}
|
||||
|
||||
if ( t1 != t2 ) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -34,12 +34,12 @@ public class BackquoteTest extends BaseUnitTestCase {
|
|||
private ServiceRegistry serviceRegistry;
|
||||
|
||||
@Before
|
||||
protected void setUp() {
|
||||
public void setUp() {
|
||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
|
||||
}
|
||||
|
||||
@After
|
||||
protected void tearDown() {
|
||||
public void tearDown() {
|
||||
if (serviceRegistry != null) ServiceRegistryBuilder.destroy(serviceRegistry);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ import org.hibernate.service.ServiceRegistry;
|
|||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.testing.ServiceRegistryBuilder;
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
|
@ -56,15 +57,16 @@ public class FetchProfileTest extends BaseUnitTestCase {
|
|||
private ServiceRegistry serviceRegistry;
|
||||
|
||||
@Before
|
||||
protected void setUp() {
|
||||
public void setUp() {
|
||||
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( Environment.getProperties() );
|
||||
}
|
||||
|
||||
@After
|
||||
protected void tearDown() {
|
||||
public void tearDown() {
|
||||
if (serviceRegistry != null) ServiceRegistryBuilder.destroy(serviceRegistry);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFetchProfileConfigured() {
|
||||
Configuration config = new Configuration();
|
||||
config.addAnnotatedClass( Customer.class );
|
||||
|
@ -85,6 +87,7 @@ public class FetchProfileTest extends BaseUnitTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongAssociationName() {
|
||||
Configuration config = new Configuration();
|
||||
config.addAnnotatedClass( Customer2.class );
|
||||
|
@ -100,6 +103,7 @@ public class FetchProfileTest extends BaseUnitTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongClass() {
|
||||
Configuration config = new Configuration();
|
||||
config.addAnnotatedClass( Customer3.class );
|
||||
|
@ -115,6 +119,7 @@ public class FetchProfileTest extends BaseUnitTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedFetchMode() {
|
||||
Configuration config = new Configuration();
|
||||
config.addAnnotatedClass( Customer4.class );
|
||||
|
@ -130,6 +135,7 @@ public class FetchProfileTest extends BaseUnitTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXmlOverride() {
|
||||
Configuration config = new Configuration();
|
||||
config.addAnnotatedClass( Customer5.class );
|
||||
|
@ -162,6 +168,7 @@ public class FetchProfileTest extends BaseUnitTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPackageConfiguredFetchProfile() {
|
||||
Configuration config = new Configuration();
|
||||
config.addAnnotatedClass( Customer.class );
|
||||
|
|
Loading…
Reference in New Issue