remove a garbage feature (FieldFunction)
This commit is contained in:
parent
75888b94f2
commit
3b221b7b18
|
@ -19,7 +19,6 @@ import org.hibernate.PessimisticLockException;
|
|||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.dialect.function.CommonFunctionFactory;
|
||||
import org.hibernate.dialect.function.FieldFunction;
|
||||
import org.hibernate.dialect.hint.IndexQueryHintHandler;
|
||||
import org.hibernate.dialect.identity.IdentityColumnSupport;
|
||||
import org.hibernate.dialect.identity.MySQLIdentityColumnSupport;
|
||||
|
@ -447,7 +446,6 @@ public class MySQLDialect extends Dialect {
|
|||
functionFactory.sysdateExplicitMicros();
|
||||
}
|
||||
|
||||
queryEngine.getSqmFunctionRegistry().register( "field", new FieldFunction( queryEngine.getTypeConfiguration() ) );
|
||||
functionFactory.listagg_groupConcat();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.dialect.function;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.query.sqm.function.AbstractSqmSelfRenderingFunctionDescriptor;
|
||||
import org.hibernate.query.sqm.produce.function.StandardArgumentsValidators;
|
||||
import org.hibernate.query.sqm.produce.function.StandardFunctionReturnTypeResolvers;
|
||||
import org.hibernate.sql.ast.SqlAstTranslator;
|
||||
import org.hibernate.sql.ast.spi.SqlAppender;
|
||||
import org.hibernate.sql.ast.tree.SqlAstNode;
|
||||
import org.hibernate.sql.ast.tree.expression.Expression;
|
||||
import org.hibernate.sql.ast.tree.expression.SqlTuple;
|
||||
import org.hibernate.sql.ast.tree.expression.SqlTupleContainer;
|
||||
import org.hibernate.type.StandardBasicTypes;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
public class FieldFunction extends AbstractSqmSelfRenderingFunctionDescriptor {
|
||||
|
||||
public FieldFunction(TypeConfiguration typeConfiguration) {
|
||||
super(
|
||||
"field",
|
||||
StandardArgumentsValidators.min( 2 ),
|
||||
StandardFunctionReturnTypeResolvers.invariant(
|
||||
typeConfiguration.getBasicTypeRegistry().resolve( StandardBasicTypes.INTEGER )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(
|
||||
SqlAppender sqlAppender, List<? extends SqlAstNode> sqlAstArguments, SqlAstTranslator<?> walker) {
|
||||
sqlAppender.appendSql( "field(" );
|
||||
sqlAstArguments.get( 0 ).accept( walker );
|
||||
for ( int i = 1; i < sqlAstArguments.size(); i++ ) {
|
||||
sqlAppender.appendSql( ',' );
|
||||
|
||||
final SqlAstNode argument = sqlAstArguments.get( i );
|
||||
final SqlTuple sqlTuple = SqlTupleContainer.getSqlTuple( argument );
|
||||
if ( sqlTuple != null ) {
|
||||
final List<? extends Expression> expressions = sqlTuple.getExpressions();
|
||||
for ( int j = 0; j < expressions.size(); j++ ) {
|
||||
if ( j != 0 ) {
|
||||
sqlAppender.appendSql( ',' );
|
||||
}
|
||||
expressions.get( j ).accept( walker );
|
||||
}
|
||||
}
|
||||
else {
|
||||
argument.accept( walker );
|
||||
}
|
||||
}
|
||||
sqlAppender.appendSql( ")" );
|
||||
}
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.orm.test.ordered;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
import org.hibernate.dialect.MySQLDialect;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
|
||||
import org.hibernate.testing.orm.junit.Jpa;
|
||||
import org.hibernate.testing.orm.junit.RequiresDialect;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
*/
|
||||
@Jpa(
|
||||
annotatedClasses = HqlOrderByIdsTest.Person.class
|
||||
)
|
||||
public class HqlOrderByIdsTest {
|
||||
|
||||
@AfterEach
|
||||
public void tearDown(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction(
|
||||
entityManager ->
|
||||
entityManager.createQuery( "delete from Person" ).executeUpdate()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-10502")
|
||||
@RequiresDialect(value = MySQLDialect.class, majorVersion = 5)
|
||||
public void testIt(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
List<Person> persons = entityManager.createQuery(
|
||||
"SELECT p " +
|
||||
"FROM Person p " +
|
||||
"ORDER BY FIELD(id, :ids) ", Person.class )
|
||||
.setParameter( "ids", Arrays.asList( 3L, 1L, 2L ) )
|
||||
.getResultList();
|
||||
|
||||
} );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-10502")
|
||||
@RequiresDialect(value = MySQLDialect.class, majorVersion = 5)
|
||||
public void testLifecycle(EntityManagerFactoryScope scope) {
|
||||
scope.inTransaction( entityManager -> {
|
||||
Person person1 = new Person();
|
||||
person1.setId( 1L );
|
||||
person1.setName( "John" );
|
||||
|
||||
Person person2 = new Person();
|
||||
person2.setId( 2L );
|
||||
person2.setName( "Doe" );
|
||||
|
||||
Person person3 = new Person();
|
||||
person3.setId( 3L );
|
||||
person3.setName( "J" );
|
||||
|
||||
Person person4 = new Person();
|
||||
person4.setId( 4L );
|
||||
person4.setName( "D" );
|
||||
|
||||
entityManager.persist( person1 );
|
||||
entityManager.persist( person2 );
|
||||
entityManager.persist( person3 );
|
||||
entityManager.persist( person4 );
|
||||
} );
|
||||
|
||||
scope.inTransaction( entityManager -> {
|
||||
List<Person> persons = entityManager.createQuery(
|
||||
"SELECT p " +
|
||||
"FROM Person p " +
|
||||
"WHERE p.id IN (:ids) " +
|
||||
"ORDER BY FIELD(id, :ids) ", Person.class )
|
||||
.setParameter( "ids", Arrays.asList( 3L, 1L, 2L ) )
|
||||
.getResultList();
|
||||
|
||||
assertEquals( 3, persons.size() );
|
||||
int index = 0;
|
||||
assertEquals( 3L, persons.get( index++ ).getId() );
|
||||
assertEquals( 1L, persons.get( index++ ).getId() );
|
||||
assertEquals( 2L, persons.get( index++ ).getId() );
|
||||
} );
|
||||
}
|
||||
|
||||
@Entity(name = "Person")
|
||||
public static class Person {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue