/
InformixDialectTestCase.java
125 lines (109 loc) · 4.51 KB
/
InformixDialectTestCase.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
* 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.community.dialect;
import java.util.Collections;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.engine.query.internal.NativeQueryInterpreterStandardImpl;
import org.hibernate.metamodel.model.domain.internal.JpaMetamodelImpl;
import org.hibernate.metamodel.model.domain.internal.MappingMetamodelImpl;
import org.hibernate.query.criteria.ValueHandlingMode;
import org.hibernate.query.internal.NamedObjectRepositoryImpl;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.sqm.function.SelfRenderingSqmFunction;
import org.hibernate.query.sqm.function.SqmFunctionDescriptor;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.sql.ast.spi.SqlAppender;
import org.hibernate.sql.ast.spi.StringBuilderSqlAppender;
import org.hibernate.type.BasicType;
import org.hibernate.type.descriptor.java.JdbcDateJavaType;
import org.hibernate.type.descriptor.java.JdbcTimestampJavaType;
import org.hibernate.type.descriptor.jdbc.DateJdbcType;
import org.hibernate.type.descriptor.jdbc.TimestampJdbcType;
import org.hibernate.type.spi.TypeConfiguration;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseUnitTestCase;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Testing of patched support for Informix boolean type; see HHH-9894, HHH-10800
*
* @author Greg Jones
*/
public class InformixDialectTestCase extends BaseUnitTestCase {
private static final InformixDialect dialect = new InformixDialect();
private static ServiceRegistry ssr;
private static QueryEngine queryEngine;
@BeforeClass
public static void init() {
TypeConfiguration typeConfiguration = new TypeConfiguration();
final JpaMetamodelImpl jpaMetamodel = new JpaMetamodelImpl( typeConfiguration, new MappingMetamodelImpl( typeConfiguration, ssr ), ssr );
ssr = new StandardServiceRegistryBuilder().build();
queryEngine = new QueryEngine(
null,
null,
jpaMetamodel,
ValueHandlingMode.BIND,
dialect.getPreferredSqlTypeCodeForBoolean(),
false,
new NamedObjectRepositoryImpl( Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap() ),
NativeQueryInterpreterStandardImpl.NATIVE_QUERY_INTERPRETER,
dialect,
ssr
);
}
@AfterClass
public static void tearDown() {
queryEngine.close();
ssr.close();
}
@Test
@TestForIssue(jiraKey = "HHH-9894")
public void testToBooleanValueStringTrue() {
assertEquals( "'t'", dialect.toBooleanValueString( true ) );
}
@Test
@TestForIssue(jiraKey = "HHH-9894")
public void testToBooleanValueStringFalse() {
assertEquals( "'f'", dialect.toBooleanValueString( false ) );
}
@Test
@TestForIssue(jiraKey = "HHH-10800")
public void testCurrentTimestampFunction() {
SqmFunctionDescriptor functionDescriptor = queryEngine.getSqmFunctionRegistry()
.findFunctionDescriptor( "current_timestamp" );
SelfRenderingSqmFunction<Object> sqmExpression = functionDescriptor.generateSqmExpression(
null,
queryEngine,
new TypeConfiguration()
);
BasicType<?> basicType = (BasicType<?>) sqmExpression.getNodeType();
assertEquals( JdbcTimestampJavaType.INSTANCE, basicType.getJavaTypeDescriptor() );
assertEquals( TimestampJdbcType.INSTANCE, basicType.getJdbcType() );
SqlAppender appender = new StringBuilderSqlAppender();
sqmExpression.getRenderingSupport().render( appender, Collections.emptyList(), null );
assertEquals( "current", appender.toString() );
}
@Test
@TestForIssue(jiraKey = "HHH-10800")
public void testCurrentDateFunction() {
SqmFunctionDescriptor functionDescriptor = queryEngine.getSqmFunctionRegistry()
.findFunctionDescriptor( "current_date" );
SelfRenderingSqmFunction<Object> sqmExpression = functionDescriptor.generateSqmExpression(
null,
queryEngine,
new TypeConfiguration()
);
BasicType<?> basicType = (BasicType<?>) sqmExpression.getNodeType();
assertEquals( JdbcDateJavaType.INSTANCE, basicType.getJavaTypeDescriptor() );
assertEquals( DateJdbcType.INSTANCE, basicType.getJdbcType() );
SqlAppender appender = new StringBuilderSqlAppender();
sqmExpression.getRenderingSupport().render( appender, Collections.emptyList(), null );
assertEquals( "today", appender.toString() );
}
}