HHH-8207 - Locale conversion is broken

This commit is contained in:
Steve Ebersole 2013-05-01 10:34:05 -05:00
parent a1d190d674
commit 4d04dfc088
14 changed files with 144 additions and 14 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 javax.persistence.AttributeConverter;
import javax.persistence.Convert;
@ -37,6 +37,9 @@ import org.hibernate.cfg.Configuration;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.type.AbstractStandardBasicType;
import org.hibernate.type.BasicType;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.java.StringTypeDescriptor;
import org.junit.Test;
@ -49,7 +52,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
/**
* Tests the principle of adding "AttributeConverter" to the mix of {@link Type} resolution
* Tests the principle of adding "AttributeConverter" to the mix of {@link org.hibernate.type.Type} resolution
*
* @author Steve Ebersole
*/

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

@ -21,13 +21,16 @@
* 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.sql.Blob;
import java.sql.SQLException;
import org.junit.Test;
import org.hibernate.engine.jdbc.BlobProxy;
import org.hibernate.type.descriptor.java.BlobTypeDescriptor;
import org.hibernate.type.descriptor.java.DataHelper;
import org.hibernate.type.descriptor.java.PrimitiveByteArrayTypeDescriptor;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

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;