HHH-8207 - Locale conversion is broken

Conflicts:
	hibernate-core/src/test/java/org/hibernate/test/type/AttributeConverterTest.java
This commit is contained in:
Steve Ebersole 2013-08-15 13:07:05 -04:00 committed by Brett Meyer
parent f7653aa7e3
commit 700ec50bea
14 changed files with 141 additions and 116 deletions

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.type;
package org.hibernate.test.type;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -33,6 +33,15 @@ import org.junit.Test;
import org.hibernate.HibernateException;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.hibernate.type.AbstractSingleColumnStandardBasicType;
import org.hibernate.type.BasicType;
import org.hibernate.type.BasicTypeRegistry;
import org.hibernate.type.CompositeCustomType;
import org.hibernate.type.CustomType;
import org.hibernate.type.Type;
import org.hibernate.type.UUIDBinaryType;
import org.hibernate.type.UUIDCharType;
import org.hibernate.type.descriptor.java.StringTypeDescriptor;
import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
import org.hibernate.usertype.CompositeUserType;

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.type;
package org.hibernate.test.type;
import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
@ -45,6 +45,39 @@ import org.hibernate.Session;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.util.SerializationHelper;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.type.AbstractSingleColumnStandardBasicType;
import org.hibernate.type.BigDecimalType;
import org.hibernate.type.BigIntegerType;
import org.hibernate.type.BinaryType;
import org.hibernate.type.BooleanType;
import org.hibernate.type.ByteType;
import org.hibernate.type.CalendarDateType;
import org.hibernate.type.CalendarType;
import org.hibernate.type.CharArrayType;
import org.hibernate.type.CharacterArrayType;
import org.hibernate.type.CharacterType;
import org.hibernate.type.ClassType;
import org.hibernate.type.CurrencyType;
import org.hibernate.type.DateType;
import org.hibernate.type.DoubleType;
import org.hibernate.type.FloatType;
import org.hibernate.type.ImageType;
import org.hibernate.type.IntegerType;
import org.hibernate.type.LocaleType;
import org.hibernate.type.LongType;
import org.hibernate.type.MaterializedBlobType;
import org.hibernate.type.MaterializedClobType;
import org.hibernate.type.NumericBooleanType;
import org.hibernate.type.SerializableType;
import org.hibernate.type.ShortType;
import org.hibernate.type.StringType;
import org.hibernate.type.TextType;
import org.hibernate.type.TimeType;
import org.hibernate.type.TimeZoneType;
import org.hibernate.type.TimestampType;
import org.hibernate.type.TrueFalseType;
import org.hibernate.type.YesNoType;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertFalse;

View File

@ -21,11 +21,13 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.type.descriptor.java;
package org.hibernate.test.type.descriptor.java;
import java.io.Serializable;
import java.sql.Blob;
import java.sql.Clob;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.junit.Before;
import org.junit.Test;

View File

@ -21,9 +21,11 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.type.descriptor.java;
package org.hibernate.test.type.descriptor.java;
import java.math.BigDecimal;
import org.hibernate.type.descriptor.java.BigDecimalTypeDescriptor;
/**
* @author Steve Ebersole
*/

View File

@ -21,9 +21,11 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.type.descriptor.java;
package org.hibernate.test.type.descriptor.java;
import java.math.BigInteger;
import org.hibernate.type.descriptor.java.BigIntegerTypeDescriptor;
/**
* @author Steve Ebersole
*/

View File

@ -22,24 +22,19 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.type.descriptor.java;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.sql.Blob;
import java.sql.SQLException;
import org.hibernate.engine.jdbc.BlobImplementer;
import org.junit.Test;
import org.hibernate.engine.jdbc.BlobProxy;
import org.hibernate.testing.TestForIssue;
import org.hibernate.type.descriptor.java.AbstractDescriptorTest;
import org.hibernate.type.descriptor.java.BlobTypeDescriptor;
import org.hibernate.type.descriptor.java.DataHelper;
import org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* @author Steve Ebersole
@ -89,14 +84,4 @@ public class BlobDescriptorTest extends AbstractDescriptorTest<Blob> {
fail( "SQLException accessing blob : " + e.getMessage() );
}
}
@Test
@TestForIssue( jiraKey = "HHH-8193" )
public void testStreamResetOnAccess() throws IOException {
byte[] bytes = new byte[] { 1, 2, 3, 4 };
BlobImplementer blob = (BlobImplementer) BlobProxy.generateProxy( bytes );
int value = blob.getUnderlyingStream().getInputStream().read();
// Call to BlobImplementer#getUnderlyingStream() should mark input stream for reset.
assertEquals( bytes.length, blob.getUnderlyingStream().getInputStream().available() );
}
}

View File

@ -21,9 +21,11 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.type.descriptor.java;
package org.hibernate.test.type.descriptor.java;
import org.hibernate.type.descriptor.java.BooleanTypeDescriptor;
/**
* @author Steve Ebersole
*/

View File

@ -0,0 +1,69 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2013, 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.test.type.descriptor.java;
import java.util.Locale;
import java.util.StringTokenizer;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.type.descriptor.java.LocaleTypeDescriptor;
import org.junit.Test;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import static org.junit.Assert.assertEquals;
/**
* Tests of the {@link LocaleTypeDescriptor} class.
*
* @author Christian Beikov
* @author Steve Ebersole
*/
public class LocaleTypeDescriptorTest extends BaseUnitTestCase {
@Test
public void testConversionFromString() {
assertEquals( toLocale( "de", null, null ), LocaleTypeDescriptor.INSTANCE.fromString( "de" ) );
assertEquals( toLocale( "de", "DE", null ), LocaleTypeDescriptor.INSTANCE.fromString( "de_DE" ) );
assertEquals( toLocale( null, "DE", null ), LocaleTypeDescriptor.INSTANCE.fromString( "_DE" ) );
assertEquals( toLocale( null, null, "ch" ), LocaleTypeDescriptor.INSTANCE.fromString( "__ch" ) );
assertEquals( toLocale( null, "DE", "ch" ), LocaleTypeDescriptor.INSTANCE.fromString( "_DE_ch" ) );
assertEquals( toLocale( "de", null, "ch" ), LocaleTypeDescriptor.INSTANCE.fromString( "de__ch" ) );
assertEquals( toLocale( "de", "DE", "ch" ), LocaleTypeDescriptor.INSTANCE.fromString( "de_DE_ch" ) );
}
public Locale toLocale(String lang, String region, String variant) {
final Locale.Builder builder = new Locale.Builder();
if ( StringHelper.isNotEmpty( lang ) ) {
builder.setLanguage( lang );
}
if ( StringHelper.isNotEmpty( region ) ) {
builder.setRegion( region );
}
if ( StringHelper.isNotEmpty( variant ) ) {
builder.setVariant( variant );
}
return builder.build();
}
}

View File

@ -21,9 +21,11 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.type.descriptor.java;
package org.hibernate.test.type.descriptor.java;
import org.hibernate.type.descriptor.java.StringTypeDescriptor;
/**
* @author Steve Ebersole
*/

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.type.descriptor.sql;
package org.hibernate.test.type.descriptor.sql;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.type.descriptor.sql;
package org.hibernate.test.type.descriptor.sql;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.type.descriptor.sql;
package org.hibernate.test.type.descriptor.sql;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;

View File

@ -21,7 +21,7 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.type.descriptor.sql;
package org.hibernate.test.type.descriptor.sql;
import java.sql.Clob;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -36,6 +36,9 @@ import org.hibernate.type.descriptor.ValueBinder;
import org.hibernate.type.descriptor.ValueExtractor;
import org.hibernate.type.descriptor.WrapperOptions;
import org.hibernate.type.descriptor.java.StringTypeDescriptor;
import org.hibernate.type.descriptor.sql.ClobTypeDescriptor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;
import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

View File

@ -1,84 +0,0 @@
/*
* 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.type.descriptor.java;
import java.sql.Blob;
import java.sql.SQLException;
import org.junit.Test;
import org.hibernate.engine.jdbc.BlobProxy;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
/**
* @author Steve Ebersole
*/
public class BlobDescriptorTest extends AbstractDescriptorTest<Blob> {
final Blob original = BlobProxy.generateProxy( new byte[] { 1, 2, 3 } );
final Blob copy = BlobProxy.generateProxy( new byte[] { 1, 2, 3 } );
final Blob different = BlobProxy.generateProxy( new byte[] { 3, 2, 1 } );
public BlobDescriptorTest() {
super( BlobTypeDescriptor.INSTANCE );
}
@Override
protected Data<Blob> getTestData() {
return new Data<Blob>( original, copy, different );
}
@Override
protected boolean shouldBeMutable() {
return false;
}
@Test
@Override
public void testEquality() {
// blobs of the same internal value are not really comparable
assertFalse( original == copy );
assertTrue( BlobTypeDescriptor.INSTANCE.areEqual( original, original ) );
assertFalse( BlobTypeDescriptor.INSTANCE.areEqual( original, copy ) );
assertFalse( BlobTypeDescriptor.INSTANCE.areEqual( original, different ) );
}
@Test
@Override
public void testExternalization() {
// blobs of the same internal value are not really comparable
String externalized = BlobTypeDescriptor.INSTANCE.toString( original );
Blob consumed = BlobTypeDescriptor.INSTANCE.fromString( externalized );
try {
PrimitiveByteArrayTypeDescriptor.INSTANCE.areEqual(
DataHelper.extractBytes( original.getBinaryStream() ),
DataHelper.extractBytes( consumed.getBinaryStream() )
);
}
catch ( SQLException e ) {
fail( "SQLException accessing blob : " + e.getMessage() );
}
}
}