HHH-10345 - HHH-3422 still a problem with oracle

This commit is contained in:
Steve Ebersole 2016-02-09 22:35:12 -06:00
parent 13bbddfd30
commit 177bbfe5e3
2 changed files with 48 additions and 4 deletions

View File

@ -6,12 +6,18 @@
*/
package org.hibernate.dialect;
import org.hibernate.boot.model.TypeContributions;
import org.hibernate.cfg.Environment;
import org.hibernate.dialect.identity.IdentityColumnSupport;
import org.hibernate.dialect.identity.Oracle12cIdentityColumnSupport;
import org.hibernate.dialect.pagination.LimitHandler;
import org.hibernate.dialect.pagination.SQL2008StandardLimitHandler;
import org.hibernate.engine.config.spi.ConfigurationService;
import org.hibernate.engine.config.spi.StandardConverters;
import org.hibernate.id.enhanced.SequenceStyleGenerator;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.type.MaterializedBlobType;
import org.hibernate.type.WrappedMaterializedBlobType;
/**
* An SQL dialect for Oracle 12c.
@ -19,11 +25,31 @@ import org.hibernate.id.enhanced.SequenceStyleGenerator;
* @author zhouyanming (zhouyanming@gmail.com)
*/
public class Oracle12cDialect extends Oracle10gDialect {
public static final String PREFER_LONG_RAW = "hibernate.dialect.oracle.prefer_long_raw";
public Oracle12cDialect() {
super();
getDefaultProperties().setProperty( Environment.BATCH_VERSIONED_DATA, "true" );
}
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes( typeContributions, serviceRegistry );
// account for Oracle's deprecated support for LONGVARBINARY...
// prefer BLOB, unless the user opts out of it
boolean preferLong = serviceRegistry.getService( ConfigurationService.class ).getSetting(
PREFER_LONG_RAW,
StandardConverters.BOOLEAN,
false
);
if ( !preferLong ) {
typeContributions.contributeType( MaterializedBlobType.INSTANCE, "byte[]", byte[].class.getName() );
typeContributions.contributeType( WrappedMaterializedBlobType.INSTANCE, "Byte[]", Byte[].class.getName() );
}
}
@Override
protected void registerDefaultProperties() {
super.registerDefaultProperties();

View File

@ -22,18 +22,17 @@ import org.hibernate.dialect.Oracle10gDialect;
import org.hibernate.dialect.Oracle12cDialect;
import org.hibernate.dialect.Oracle8iDialect;
import org.hibernate.dialect.Oracle9iDialect;
import org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.type.BinaryType;
import org.hibernate.type.BlobType;
import org.hibernate.type.CharArrayType;
import org.hibernate.type.ClobType;
import org.hibernate.type.MaterializedBlobType;
import org.hibernate.type.MaterializedClobType;
import org.hibernate.type.PrimitiveCharacterArrayClobType;
import org.hibernate.type.Type;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.Test;
@ -69,19 +68,38 @@ public class OracleLongLobTypeTest extends BaseUnitTestCase {
}
@Test
@TestForIssue( jiraKey = "HHH-10345" )
public void testOracle12() {
check( Oracle12cDialect.class, Primitives.class, BinaryType.class, CharArrayType.class );
check( Oracle12cDialect.class, Primitives.class, MaterializedBlobType.class, CharArrayType.class );
check( Oracle12cDialect.class, LobPrimitives.class, MaterializedBlobType.class, PrimitiveCharacterArrayClobType.class );
check( Oracle12cDialect.class, LobLocators.class, BlobType.class, ClobType.class );
}
@Test
@TestForIssue( jiraKey = "HHH-10345" )
public void testOracle12PreferLongRaw() {
check( Oracle12cDialect.class, Primitives.class, BinaryType.class, CharArrayType.class, true );
check( Oracle12cDialect.class, LobPrimitives.class, MaterializedBlobType.class, PrimitiveCharacterArrayClobType.class, true );
check( Oracle12cDialect.class, LobLocators.class, BlobType.class, ClobType.class, true );
}
private void check(
Class<? extends Dialect> dialectClass,
Class entityClass,
Class<? extends Type> binaryTypeClass,
Class<? extends Type> charTypeClass) {
check( dialectClass, entityClass, binaryTypeClass, charTypeClass, false );
}
private void check(
Class<? extends Dialect> dialectClass,
Class entityClass,
Class<? extends Type> binaryTypeClass,
Class<? extends Type> charTypeClass,
boolean preferLongRaw) {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
.applySetting( AvailableSettings.DIALECT, dialectClass.getName() )
.applySetting( Oracle12cDialect.PREFER_LONG_RAW, Boolean.toString( preferLongRaw ) )
.applySetting( "hibernate.temp.use_jdbc_metadata_defaults", false )
.build();