Skip to content

Commit

Permalink
HHH-10345 - HHH-3422 still a problem with oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
sebersole committed Feb 10, 2016
1 parent 13bbddf commit 177bbfe
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
Expand Up @@ -6,24 +6,50 @@
*/
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.
*
* @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();
Expand Down
Expand Up @@ -22,18 +22,17 @@
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;
Expand Down Expand Up @@ -69,19 +68,38 @@ public void testOracle10() {
}

@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();

Expand Down

0 comments on commit 177bbfe

Please sign in to comment.