1 | public void testSaveOrUpdateTree() {↵ | | 1 | public void testSaveOrUpdateTreeWithGeneratedId() {↵
|
2 | clearCounts();↵ | | 2 | clearCounts();↵
|
|
3 | Session s = openSession();↵ | | 3 | Session s = openSession();↵
|
4 | Transaction tx = s.beginTransaction();↵ | | 4 | Transaction tx = s.beginTransaction();↵
|
5 | Node root = new Node( "root" );↵ | | 5 | NumberedNode root = new NumberedNode( "root" );↵
|
6 | Node child = new Node( "child" );↵ | | 6 | NumberedNode child = new NumberedNode( "child" );↵
|
7 | root.addChild( child );↵ | | 7 | root.addChild( child );↵
|
8 | s.saveOrUpdate( root );↵ | | 8 | s.saveOrUpdate( root );↵
|
9 | tx.commit();↵ | | 9 | tx.commit();↵
|
10 | s.close();↵ | | 10 | s.close();↵
|
|
11 | assertInsertCount( 2 );↵ | | 11 | assertInsertCount( 2 );↵
|
12 | clearCounts();↵ | | 12 | clearCounts();↵
|
|
13 | root.setDescription( "The root node" );↵ | | 13 | root.setDescription( "The root node" );↵
|
14 | child.setDescription( "The child node" );↵ | | 14 | child.setDescription( "The child node" );↵
|
|
15 | Node secondChild = new Node( "second child" );↵ | | 15 | NumberedNode secondChild = new NumberedNode( "second child" );↵
|
|
16 | root.addChild( secondChild );↵ | | 16 | root.addChild( secondChild );↵
|
|
17 | s = openSession();↵ | | 17 | s = openSession();↵
|
18 | tx = s.beginTransaction();↵ | | 18 | tx = s.beginTransaction();↵
|
19 | s.saveOrUpdate( root );↵ | | 19 | s.saveOrUpdate( root );↵
|
20 | tx.commit();↵ | | 20 | tx.commit();↵
|
21 | s.close();↵ | | 21 | s.close();↵
|
|
22 | assertInsertCount( 1 );↵ | | 22 | assertInsertCount( 1 );↵
|
23 | assertUpdateCount( 2 );↵ | | 23 | assertUpdateCount( 2 );↵
|
|
24 | s = openSession();↵ | | 24 | s = openSession();↵
|
25 | tx = s.beginTransaction();↵ | | 25 | tx = s.beginTransaction();↵
|
26 | s.createQuery( "delete from Node where parent is not null" ).executeUpdate();↵ | | 26 | s.createQuery( "delete from NumberedNode where parent is not null" ).executeUpdate();↵
|
27 | s.createQuery( "delete from Node" ).executeUpdate();↵ | | 27 | s.createQuery( "delete from NumberedNode" ).executeUpdate();↵
|
28 | tx.commit();↵ | | 28 | tx.commit();↵
|
29 | s.close();↵ | | 29 | s.close();↵
|
30 | | | 30 |
|