HHH-10516 - Incorrect coalesce function for InformixDialect

HHH-10846 - InformixDialect has incorrect substring function
This commit is contained in:
Nikita 2016-06-14 09:29:27 +02:00 committed by Vlad Mihalcea
parent 7ed51f44dd
commit 309b1b27b0
5 changed files with 184 additions and 11 deletions

View File

@ -150,6 +150,7 @@ subprojects { subProject ->
testRuntime( libraries.postgresql )
testRuntime( libraries.mysql )
testRuntime( libraries.mariadb )
testRuntime( libraries.informix )
if (db.equalsIgnoreCase("oracle")) {
dependencies {
testRuntime( libraries.oracle )

View File

@ -71,6 +71,13 @@ ext {
'jdbc.user' : 'hibernate_orm_test',
'jdbc.pass' : 'hibernate_orm_test',
'jdbc.url' : 'jdbc:sqlserver://localhost;instance=SQLEXPRESS;databaseName=hibernate_orm_test'
],
informix : [
'db.dialect' : 'org.hibernate.dialect.InformixDialect',
'jdbc.driver': 'com.informix.jdbc.IfxDriver',
'jdbc.user' : 'informix',
'jdbc.pass' : 'in4mix',
'jdbc.url' : 'jdbc:informix-sqli://192.168.99.100:9088/sysuser:INFORMIXSERVER=dev;user=informix;password=in4mix'
]
]
}

View File

@ -10,6 +10,8 @@ import java.sql.SQLException;
import java.sql.Types;
import java.util.Locale;
import org.hibernate.dialect.function.NvlFunction;
import org.hibernate.dialect.function.SQLFunctionTemplate;
import org.hibernate.dialect.function.VarArgsSQLFunction;
import org.hibernate.dialect.identity.IdentityColumnSupport;
import org.hibernate.dialect.identity.InformixIdentityColumnSupport;
@ -72,7 +74,11 @@ public class InformixDialect extends Dialect {
registerColumnType( Types.VARCHAR, 32739, "lvarchar($l)" );
registerFunction( "concat", new VarArgsSQLFunction( StandardBasicTypes.STRING, "(", "||", ")" ) );
registerFunction( "substring", new SQLFunctionTemplate(StandardBasicTypes.STRING, "substring(?1 FROM ?2 FOR ?3)"));
registerFunction( "substr", new SQLFunctionTemplate( StandardBasicTypes.STRING, "substr(?1, ?2, ?3)"));
registerFunction( "coalesce", new NvlFunction());
registerFunction( "nvl", new NvlFunction());
uniqueDelegate = new InformixUniqueDelegate( this );
}

View File

@ -0,0 +1,158 @@
package org.hibernate.engine.query;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.dialect.InformixDialect;
import org.hibernate.testing.RequiresDialect;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* @author Vlad Mihalcea
*/
@RequiresDialect(InformixDialect.class)
public class InformixFunctionTest extends BaseCoreFunctionalTestCase {
private Event event;
@Override
protected void prepareTest() throws Exception {
Session s = openSession();
try {
Transaction transaction = s.beginTransaction();
event = new Event();
event.country = "Romania";
event.city = "Cluj-Napoca";
s.persist( event );
transaction.commit();
}
finally {
s.close();
}
}
@Test
@TestForIssue( jiraKey = "HHH-10846" )
public void testConcat() throws Exception {
Session s = openSession();
try {
s.beginTransaction();
String location = (String) session.createQuery(
"select concat(e.country, ' - ', e.city) " +
"from Event e " +
"where e.id = :id")
.setParameter( "id", event.id )
.getSingleResult();
assertEquals( "Romania - Cluj-Napoca", location);
s.getTransaction().commit();
}
finally {
s.close();
}
}
@Test
@TestForIssue( jiraKey = "HHH-10846" )
public void testSubstring() throws Exception {
Session s = openSession();
try {
s.beginTransaction();
String location = (String) session.createQuery(
"select substring(e.city, 0, 5) " +
"from Event e " +
"where e.id = :id")
.setParameter( "id", event.id )
.getSingleResult();
assertEquals( "Cluj", location);
s.getTransaction().commit();
}
finally {
s.close();
}
}
@Test
@TestForIssue( jiraKey = "HHH-10846" )
public void testSubstr() throws Exception {
Session s = openSession();
try {
s.beginTransaction();
String location = (String) session.createQuery(
"select substr(e.city, 0, 4) " +
"from Event e " +
"where e.id = :id")
.setParameter( "id", event.id )
.getSingleResult();
assertEquals( "Cluj", location);
s.getTransaction().commit();
}
finally {
s.close();
}
}
@Test
@TestForIssue( jiraKey = "HHH-10846" )
public void testCoalesceAndNvl() throws Exception {
Session s = openSession();
try {
s.beginTransaction();
String location = (String) session.createQuery(
"select coalesce(e.district, 'N/A') " +
"from Event e " +
"where e.id = :id")
.setParameter( "id", event.id )
.getSingleResult();
assertEquals( "N/A", location);
location = (String) session.createQuery(
"select nvl(e.district, 'N/A') " +
"from Event e " +
"where e.id = :id")
.setParameter( "id", event.id )
.getSingleResult();
assertEquals( "N/A", location);
s.getTransaction().commit();
}
finally {
s.close();
}
}
@Override
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] {
Event.class
};
}
@Entity(name = "Event")
public static class Event {
@Id
@GeneratedValue
private Long id;
@Column
private String country;
private String city;
private String district;
}
}

View File

@ -52,11 +52,11 @@ ext {
logging_processor: 'org.jboss.logging:jboss-logging-processor:2.0.0.Final',
// jaxb task
jaxb: 'com.sun.xml.bind:jaxb-xjc:2.2.5',
jaxb2_basics: 'org.jvnet.jaxb2_commons:jaxb2-basics:0.6.3',
jaxb2_ant: 'org.jvnet.jaxb2_commons:jaxb2-basics-ant:0.6.3',
jaxb2_jaxb: 'org.jvnet.jaxb2_commons:jaxb2-basics-jaxb:2.2.4-1',
jaxb2_jaxb_xjc: 'org.jvnet.jaxb2_commons:jaxb2-basics-jaxb-xjc:2.2.4-1',
jaxb: 'com.sun.xml.bind:jaxb-xjc:2.2.5',
jaxb2_basics: 'org.jvnet.jaxb2_commons:jaxb2-basics:0.6.3',
jaxb2_ant: 'org.jvnet.jaxb2_commons:jaxb2-basics-ant:0.6.3',
jaxb2_jaxb: 'org.jvnet.jaxb2_commons:jaxb2-basics-jaxb:2.2.4-1',
jaxb2_jaxb_xjc: 'org.jvnet.jaxb2_commons:jaxb2-basics-jaxb-xjc:2.2.4-1',
// Animal Sniffer Ant Task and Java 1.6 API signature file
// not using 1.9 for the time being due to MANIMALSNIFFER-34
@ -80,13 +80,14 @@ ext {
shrinkwrap_api: 'org.jboss.shrinkwrap:shrinkwrap-api:1.0.0-beta-6',
shrinkwrap: 'org.jboss.shrinkwrap:shrinkwrap-impl-base:1.0.0-beta-6',
h2: "com.h2database:h2:${h2Version}",
hsqldb: "org.hsqldb:hsqldb:2.3.2",
hsqldb: "org.hsqldb:hsqldb:2.3.2",
derby: "org.apache.derby:derby:10.11.1.1",
postgresql: 'org.postgresql:postgresql:9.4-1202-jdbc41',
mysql: 'mysql:mysql-connector-java:5.1.38',
postgresql: 'org.postgresql:postgresql:9.4-1202-jdbc41',
mysql: 'mysql:mysql-connector-java:5.1.38',
mariadb: 'org.mariadb.jdbc:mariadb-java-client:1.1.7',
oracle: 'com.oracle.ojdbc:ojdbc7:12.1.0.2.0',
mssql: 'com.microsoft.sqlserver:sqljdbc4:4.0',
oracle: 'com.oracle.ojdbc:ojdbc7:12.1.0.2.0',
mssql: 'com.microsoft.sqlserver:sqljdbc4:4.0',
informix: 'com.ibm.informix:jdbc:4.10.7.20160517',
jboss_jta: "org.jboss.jbossts:jbossjta:4.16.4.Final",
xapool: "com.experlog:xapool:1.5.0",
mockito: 'org.mockito:mockito-core:1.9.0',