Skip to content

Commit 5adf730

Browse files
Richard Tingstadgbadner
authored andcommitted
HHH-7070 Fixed some SybaseASE15Dialect function definitions (dateadd, datediff, datepart, atn2)
(cherry picked from commit 7eebb0f)
1 parent cbf255e commit 5adf730

File tree

4 files changed

+113
-5
lines changed

4 files changed

+113
-5
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/SybaseASE15Dialect.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public SybaseASE15Dialect() {
5151
)
5252
);
5353

54-
registerFunction( "atan2", new SQLFunctionTemplate( StandardBasicTypes.DOUBLE, "atn2(?1, ?2" ) );
55-
registerFunction( "atn2", new SQLFunctionTemplate( StandardBasicTypes.DOUBLE, "atn2(?1, ?2" ) );
54+
registerFunction( "atan2", new SQLFunctionTemplate( StandardBasicTypes.DOUBLE, "atn2(?1, ?2)" ) );
55+
registerFunction( "atn2", new SQLFunctionTemplate( StandardBasicTypes.DOUBLE, "atn2(?1, ?2)" ) );
5656

5757
registerFunction( "biginttohex", new SQLFunctionTemplate( StandardBasicTypes.STRING, "biginttohext(?1)" ) );
5858
registerFunction( "char_length", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "char_length(?1)" ) );
@@ -73,9 +73,9 @@ public SybaseASE15Dialect() {
7373
"data_pages", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "data_pages(?1, ?2, ?3, ?4)" )
7474
);
7575
registerFunction( "datalength", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "datalength(?1)" ) );
76-
registerFunction( "dateadd", new SQLFunctionTemplate( StandardBasicTypes.TIMESTAMP, "dateadd" ) );
77-
registerFunction( "datediff", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "datediff" ) );
78-
registerFunction( "datepart", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "datepart" ) );
76+
registerFunction( "dateadd", new SQLFunctionTemplate( StandardBasicTypes.TIMESTAMP, "dateadd(?1, ?2, ?3)" ) );
77+
registerFunction( "datediff", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "datediff(?1, ?2, ?3)" ) );
78+
registerFunction( "datepart", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "datepart(?1, ?2)" ) );
7979
registerFunction( "datetime", new SQLFunctionTemplate( StandardBasicTypes.TIMESTAMP, "datetime" ) );
8080
registerFunction( "db_id", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "db_id(?1)" ) );
8181
registerFunction( "difference", new SQLFunctionTemplate( StandardBasicTypes.INTEGER, "difference(?1,?2)" ) );

hibernate-core/src/test/java/org/hibernate/test/dialect/function/Product.hbm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<property name="length" />
1919
<property name="weight" />
2020
<property name="price" />
21+
<property name="date" />
2122
</class>
2223

2324
</hibernate-mapping>

hibernate-core/src/test/java/org/hibernate/test/dialect/function/Product.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77
package org.hibernate.test.dialect.function;
88
import java.math.BigDecimal;
9+
import java.util.Date;
910

1011
/**
1112
*
@@ -17,6 +18,7 @@ public class Product {
1718
private int length;
1819
private long weight;
1920
private BigDecimal price;
21+
private Date date;
2022

2123
public Long getId() {
2224
return id;
@@ -50,4 +52,12 @@ public void setPrice( BigDecimal price ) {
5052
this.price = price;
5153
}
5254

55+
public Date getDate() {
56+
return date;
57+
}
58+
59+
public void setDate(Date date) {
60+
this.date = date;
61+
}
62+
5363
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* Copyright (c) 2010, Red Hat Inc. or third-party contributors as
5+
* indicated by the @author tags or express copyright attribution
6+
* statements applied by the authors. All third-party contributions are
7+
* distributed under license by Red Hat Inc.
8+
*
9+
* This copyrighted material is made available to anyone wishing to use, modify,
10+
* copy, or redistribute it subject to the terms and conditions of the GNU
11+
* Lesser General Public License, as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16+
* for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this distribution; if not, write to:
20+
* Free Software Foundation, Inc.
21+
* 51 Franklin Street, Fifth Floor
22+
* Boston, MA 02110-1301 USA
23+
*/
24+
package org.hibernate.test.dialect.function;
25+
26+
import static java.util.Calendar.MONTH;
27+
import static org.junit.Assert.assertEquals;
28+
import static org.junit.Assert.assertTrue;
29+
30+
import java.math.BigDecimal;
31+
import java.util.Calendar;
32+
import java.util.Date;
33+
34+
import org.hibernate.Query;
35+
import org.hibernate.dialect.SybaseASE15Dialect;
36+
import org.hibernate.testing.RequiresDialect;
37+
import org.hibernate.testing.TestForIssue;
38+
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
39+
import org.junit.Test;
40+
41+
/**
42+
*
43+
* @author Richard H. Tingstad
44+
*/
45+
@RequiresDialect(value = { SybaseASE15Dialect.class })
46+
public class SybaseASE15FunctionTest extends BaseCoreFunctionalTestCase {
47+
48+
private Calendar calendar = Calendar.getInstance();
49+
50+
@Override
51+
public String[] getMappings() {
52+
return new String[] { "dialect/function/Product.hbm.xml" };
53+
}
54+
55+
@Override
56+
protected void prepareTest() throws Exception {
57+
Product product = new Product();
58+
product.setPrice(new BigDecimal(0.5));
59+
product.setDate(calendar.getTime());
60+
openSession().save(product);
61+
}
62+
63+
@Test
64+
public void testCharLengthFunction() {
65+
Query query = session.createQuery("select char_length('123456') from Product");
66+
assertEquals(6, ((Number) query.uniqueResult()).intValue());
67+
}
68+
69+
@Test
70+
@TestForIssue(jiraKey = "HHH-7070")
71+
public void testDateaddFunction() {
72+
Query query = session.createQuery("select dateadd(dd, 1, p.date) from Product p");
73+
assertTrue(calendar.getTime().before((Date) query.uniqueResult()));
74+
}
75+
76+
@Test
77+
@TestForIssue(jiraKey = "HHH-7070")
78+
public void testDatepartFunction() {
79+
Query query = session.createQuery("select datepart(month, p.date) from Product p");
80+
assertEquals(calendar.get(MONTH) + 1, ((Number) query.uniqueResult()).intValue());
81+
}
82+
83+
@Test
84+
@TestForIssue(jiraKey = "HHH-7070")
85+
public void testDatediffFunction() {
86+
Query query = session.createQuery("SELECT DATEDIFF( DAY, '1999/07/19 00:00', '1999/07/23 23:59' ) from Product");
87+
assertEquals(4, ((Number) query.uniqueResult()).intValue());
88+
}
89+
90+
@Test
91+
@TestForIssue(jiraKey = "HHH-7070")
92+
public void testAtn2Function() {
93+
Query query = session.createQuery("select atn2(p.price, .48) from Product p");
94+
assertEquals(0.805803, ((Number) query.uniqueResult()).doubleValue(), 0.000001);
95+
}
96+
97+
}

0 commit comments

Comments
 (0)