My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
package org.ds.biz.user;

import java.util.Date;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;

public class TestInheritance
{
public static void main(String[] args)
{
try
{
// insertData();

Session session = HibernateUtil.getSessionFactory().openSession();

Criteria criteria1 = session.createCriteria(AccountTransaction.class);

List list1 = criteria1.list();

int size1 = list1.size();

System.out.println("size of list (all transactions) : " + size1);

session.close();

session = HibernateUtil.getSessionFactory().openSession();

Criteria criteria2 = session.createCriteria(MoneyTransaction.class);

List list2 = criteria2.list();

int size2 = list2.size();

System.out.println("size of list (money transactions) : " + size2);

session.close();

session = HibernateUtil.getSessionFactory().openSession();

Criteria criteria3 = session.createCriteria(StockTransaction.class);

List list3 = criteria3.list();

int size3 = list3.size();

System.out.println("size of list (stock transactions) : " + size3);

session.close();

}
catch (Throwable t)
{
System.out.println("Caught an exception. Error message : " + t.getMessage());
t.printStackTrace();
}
}

private static void insertData()
{
Date today = new Date();
MoneyTransaction mt1 = new MoneyTransaction();
mt1.setDeposit(true);
mt1.setDescription("Wire Transfer 1");
mt1.setFee(10.0);
mt1.setMoneyAmount(1000.00);
mt1.setDate(today);

MoneyTransaction mt2 = new MoneyTransaction();
mt2.setDeposit(true);
mt2.setDescription("Cheque Deposit 1");
mt2.setFee(10.0);
mt2.setMoneyAmount(5500.00);
mt2.setDate(new Date(today.getTime() - (long)(86400 * 1000)));

StockTransaction st1 = new StockTransaction();
st1.setCompanyName("General Electric");
st1.setDescription("Good time to buy GE");
st1.setFee(19.00);
st1.setNumShares(100);
st1.setPricePerShare(11.64);
st1.setSale(false);
st1.setStockSymbol("GE");
st1.setDate(new Date(today.getTime() + (long)(86400 * 1000)));

StockTransaction st2 = new StockTransaction();
st2.setCompanyName("Target");
st2.setDescription("Seem like a value buy right now");
st2.setFee(19.00);
st2.setNumShares(50);
st2.setPricePerShare(38.23);
st2.setSale(false);
st2.setStockSymbol("TGT");
st2.setDate(new Date(today.getTime() + (long)(2 * 86400 * 1000)));

StockTransaction st3 = new StockTransaction();
st3.setCompanyName("Intel");
st3.setDescription("No way but up :-)");
st3.setFee(19.00);
st3.setNumShares(100);
st3.setPricePerShare(15.89);
st3.setSale(false);
st3.setStockSymbol("INTC");
st3.setDate(new Date(today.getTime() + (long)(3 * 86400 * 1000)));

// save an object
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction tx = session.beginTransaction();

Long id1 = (Long) session.save(mt1);
Long id2 = (Long) session.save(mt2);
Long id3 = (Long) session.save(st1);
Long id4 = (Long) session.save(st2);
Long id5 = (Long) session.save(st3);

tx.commit();
session.close();

System.out.println("IDs : " + id1 + ", " + id2 + ", " + id3 + ", " + id4 + ", " + id5 + ".");
}
}

Change log

r52 by kartick.suriamoorthy on Jun 23, 2009   Diff
test code to test the transaction
(account, money, and stock) classes.
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 3435 bytes, 124 lines
Powered by Google Project Hosting