-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-8579 force english locale for query alias generation
- Loading branch information
Showing
3 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
hibernate-core/src/test/java/org/hibernate/test/locale/IAmAFoo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors | ||
* as indicated by the @authors tag. All rights reserved. | ||
* See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* 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, v. 2.1. | ||
* This program is distributed in the hope that it will be useful, but WITHOUT A | ||
* 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, | ||
* v.2.1 along with this distribution; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
*/ | ||
package org.hibernate.test.locale; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
|
||
/** | ||
* @author Brett Meyer | ||
*/ | ||
@Entity(name="IAmAFoo") | ||
// This needs to start with an I. | ||
public class IAmAFoo { | ||
@Id @GeneratedValue | ||
private long id; | ||
|
||
@Column | ||
private String foo; | ||
|
||
public long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getFoo() { | ||
return foo; | ||
} | ||
|
||
public void setFoo(String foo) { | ||
this.foo = foo; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
hibernate-core/src/test/java/org/hibernate/test/locale/LocaleQueryAliasTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* JBoss, Home of Professional Open Source | ||
* Copyright 2013 Red Hat Inc. and/or its affiliates and other contributors | ||
* as indicated by the @authors tag. All rights reserved. | ||
* See the copyright.txt in the distribution for a | ||
* full listing of individual contributors. | ||
* | ||
* 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, v. 2.1. | ||
* This program is distributed in the hope that it will be useful, but WITHOUT A | ||
* 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, | ||
* v.2.1 along with this distribution; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | ||
* MA 02110-1301, USA. | ||
*/ | ||
package org.hibernate.test.locale; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.util.Collections; | ||
import java.util.Locale; | ||
|
||
import org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory; | ||
import org.hibernate.hql.spi.QueryTranslator; | ||
import org.hibernate.hql.spi.QueryTranslatorFactory; | ||
import org.hibernate.testing.TestForIssue; | ||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
/** | ||
* @author Brett Meyer | ||
*/ | ||
@TestForIssue(jiraKey = "HHH-8579") | ||
public class LocaleQueryAliasTest extends BaseCoreFunctionalTestCase { | ||
|
||
private static final String asciiRegex = "^\\p{ASCII}*$"; | ||
|
||
@Test | ||
public void testAliasWithLocale() { | ||
// Without the HHH-8579 fix, this will generate non-ascii query aliases. | ||
String hql = "from IAmAFoo"; | ||
|
||
QueryTranslatorFactory ast = new ASTQueryTranslatorFactory(); | ||
QueryTranslator queryTranslator = ast.createQueryTranslator( | ||
hql, hql, Collections.EMPTY_MAP, sessionFactory() ); | ||
queryTranslator.compile( Collections.EMPTY_MAP, false ); | ||
String sql = queryTranslator.getSQLString(); | ||
|
||
assertTrue( sql.matches( asciiRegex ) ); | ||
} | ||
|
||
@BeforeClass | ||
public static void beforeClass() { | ||
// Turkish will generate a "dotless i" when toLowerCase is used on "I". | ||
Locale.setDefault(Locale.forLanguageTag("tr-TR")); | ||
} | ||
|
||
@Override | ||
protected Class<?>[] getAnnotatedClasses() { | ||
return new Class<?>[] { IAmAFoo.class }; | ||
} | ||
} |