Skip to content

Commit ed867b2

Browse files
committed
HHH-7070 : Put operations in transactions and added cleanup code (test case only)
1 parent 5adf730 commit ed867b2

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

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

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.Date;
3333

3434
import org.hibernate.Query;
35+
import org.hibernate.Session;
3536
import org.hibernate.dialect.SybaseASE15Dialect;
3637
import org.hibernate.testing.RequiresDialect;
3738
import org.hibernate.testing.TestForIssue;
@@ -54,44 +55,77 @@ public String[] getMappings() {
5455

5556
@Override
5657
protected void prepareTest() throws Exception {
58+
final Session s = openSession();
59+
s.getTransaction().begin();
5760
Product product = new Product();
5861
product.setPrice(new BigDecimal(0.5));
59-
product.setDate(calendar.getTime());
60-
openSession().save(product);
62+
product.setDate( calendar.getTime() );
63+
s.save( product );
64+
s.getTransaction().commit();
65+
s.close();
66+
}
67+
68+
@Override
69+
protected void cleanupTest() throws Exception {
70+
final Session s = openSession();
71+
s.getTransaction().begin();
72+
s.createQuery( "delete from Product" ).executeUpdate();
73+
s.getTransaction().commit();
74+
s.close();
6175
}
6276

6377
@Test
6478
public void testCharLengthFunction() {
65-
Query query = session.createQuery("select char_length('123456') from Product");
79+
final Session s = openSession();
80+
s.getTransaction().begin();
81+
Query query = session.createQuery( "select char_length('123456') from Product" );
6682
assertEquals(6, ((Number) query.uniqueResult()).intValue());
83+
s.getTransaction().commit();
84+
s.close();
6785
}
6886

6987
@Test
7088
@TestForIssue(jiraKey = "HHH-7070")
7189
public void testDateaddFunction() {
72-
Query query = session.createQuery("select dateadd(dd, 1, p.date) from Product p");
90+
final Session s = openSession();
91+
s.getTransaction().begin();
92+
Query query = session.createQuery( "select dateadd(dd, 1, p.date) from Product p" );
7393
assertTrue(calendar.getTime().before((Date) query.uniqueResult()));
94+
s.getTransaction().commit();
95+
s.close();
7496
}
7597

7698
@Test
7799
@TestForIssue(jiraKey = "HHH-7070")
78100
public void testDatepartFunction() {
79-
Query query = session.createQuery("select datepart(month, p.date) from Product p");
101+
final Session s = openSession();
102+
s.getTransaction().begin();
103+
Query query = session.createQuery( "select datepart(month, p.date) from Product p" );
80104
assertEquals(calendar.get(MONTH) + 1, ((Number) query.uniqueResult()).intValue());
105+
s.getTransaction().commit();
106+
s.close();
81107
}
82108

83109
@Test
84110
@TestForIssue(jiraKey = "HHH-7070")
85111
public void testDatediffFunction() {
86-
Query query = session.createQuery("SELECT DATEDIFF( DAY, '1999/07/19 00:00', '1999/07/23 23:59' ) from Product");
112+
final Session s = openSession();
113+
s.getTransaction().begin();
114+
Query query = session.createQuery( "SELECT DATEDIFF( DAY, '1999/07/19 00:00', '1999/07/23 23:59' ) from Product" );
87115
assertEquals(4, ((Number) query.uniqueResult()).intValue());
116+
s.getTransaction().commit();
117+
s.close();
88118
}
89119

90120
@Test
91121
@TestForIssue(jiraKey = "HHH-7070")
92122
public void testAtn2Function() {
123+
final Session s = openSession();
124+
s.getTransaction().begin();
93125
Query query = session.createQuery("select atn2(p.price, .48) from Product p");
94-
assertEquals(0.805803, ((Number) query.uniqueResult()).doubleValue(), 0.000001);
126+
assertEquals(0.805803, ((Number) query.uniqueResult()).doubleValue(), 0.000001 );
127+
s.getTransaction().commit();
128+
s.close();
95129
}
96130

97131
}

0 commit comments

Comments
 (0)