@@ -60,8 +60,8 @@ public void shutdown() {
6060
6161 public void create (int count ) throws DBException , IOException {
6262 FileUtils .deleteQuietly (file );
63- try (BTree btree = new BTree (pool , BTREE_TEST_FILE_ID , BTREE_TEST_FILE_VERSION , false , pool . getCacheManager (), file )) {
64- btree .create ((short ) -1 );
63+ try (final BTree btree = BTree . open (pool , BTREE_TEST_FILE_ID , BTREE_TEST_FILE_VERSION , file , false )) {
64+ // btree.create((short) -1);
6565
6666 String prefixStr = "KEY" ;
6767 for (int i = 1 ; i <= count ; i ++) {
@@ -78,11 +78,9 @@ public void create(int count) throws DBException, IOException {
7878 }
7979
8080 public void rebuild () throws DBException , IOException , TerminatedException {
81- BTree btree = null ;
82- try {
8381 System .out .println ("Loading btree ..." );
84- btree = new BTree (pool , BTREE_TEST_FILE_ID , BTREE_TEST_FILE_VERSION , false , pool . getCacheManager (), file );
85- btree .open ((short )-1 );
82+ try ( final BTree btree = BTree . open (pool , BTREE_TEST_FILE_ID , BTREE_TEST_FILE_VERSION , file , false )) {
83+ // btree.open((short)-1);
8684
8785 System .out .println ("Rebuilding ..." );
8886 btree .rebuild ();
@@ -91,19 +89,13 @@ public void rebuild() throws DBException, IOException, TerminatedException {
9189 btree .dump (writer );
9290 writer .flush ();
9391 }
94- } finally {
95- if (btree != null ) {
96- btree .close ();
97- }
9892 }
9993 }
10094
10195 public void read (int count ) throws DBException , IOException , TerminatedException {
102- BTree btree = null ;
103- try {
104- System .out .println ("Loading btree ..." );
105- btree = new BTree (pool , BTREE_TEST_FILE_ID , BTREE_TEST_FILE_VERSION , false , pool .getCacheManager (), file );
106- btree .open ((short )-1 );
96+ System .out .println ("Loading btree ..." );
97+ try (final BTree btree = BTree .open (pool , BTREE_TEST_FILE_ID , BTREE_TEST_FILE_VERSION , file , false )) {
98+ // btree.open((short)-1);
10799
108100 String prefixStr = "KEY" ;
109101 for (int i = 1 ; i <= count ; i ++) {
@@ -113,10 +105,6 @@ public void read(int count) throws DBException, IOException, TerminatedException
113105 System .out .println ("Key not found: " + i );
114106 }
115107 }
116- } finally {
117- if (btree != null ) {
118- btree .close ();
119- }
120108 }
121109 }
122110
0 commit comments