1 /*-
2  * Copyright (c) 2001, 2020 Oracle and/or its affiliates.  All rights reserved.
3  *
4  * See the file LICENSE for license information.
5  *
6  * $Id$
7  */
8 package db_gui.datapage;
9 
10 import db_gui.datapage.BDBDataInitializable;
11 import com.sleepycat.db.DatabaseEntry;
12 
13 import java.net.URL;
14 import java.util.ResourceBundle;
15 
16 /**
17  * Implements the heap Put and Browse data panels of the Data Access Page.
18  */
19 public class HeapController extends BDBDataInitializable {
20     private DatabaseEntry currentGetKey;
21     final static private String FXMLResource = "/db_gui/datapage/FXMLHeap.fxml";
22 
23     /**
24      * Initializes the controller class.
25      */
26     @Override
initialize(URL url, ResourceBundle rb)27     public void initialize(URL url, ResourceBundle rb) {
28         super.initialize(url, rb);
29     }
30 
31     /**
32      * Clears the fields when the Clear button is pressed.
33      */
34     @Override
clearAllFields()35     public void clearAllFields() {
36         currentGetKey = null;
37         super.clearAllFields();
38     }
39 
40     /**
41      * New heap records are appended to the database, so no key is defined when
42      * adding one to the database.
43      *
44      * @return - An empty DatabaseEntry object.
45      */
46     @Override
getPutKeyDatabaseEntry()47     public DatabaseEntry getPutKeyDatabaseEntry() {
48         return new DatabaseEntry();
49     }
50 
51     /**
52      * The heap key is not user readable, so it is not displayed.
53      *
54      * @param key - Unused.
55      */
56     @Override
setPutKeyDatabaseEntry(DatabaseEntry key)57     public void setPutKeyDatabaseEntry(DatabaseEntry key) {
58         // no-op
59     }
60 
61     /**
62      * Users cannot enter keys for the database when using a heap, so the
63      * Get functionality is not provided on the Heap Data page.  If users want
64      * to browse Heap data they can only use the cursor Next and Previous
65      * functions, and the current key is stored in the GetKey field.
66      *
67      * @return - The DatabaseEntry for the current key.
68      */
69     @Override
getGetKeyDatabaseEntry()70     public DatabaseEntry getGetKeyDatabaseEntry() {
71         return currentGetKey;
72     }
73 
74     /**
75      * Users cannot enter keys for the database when using a heap, so the
76      * Get functionality is not provided on the Heap Data page.  If users want
77      * to browse Heap data they can only use the cursor Next and Previous
78      * functions, and the current key is stored in the GetKey field.
79      *
80      * @param key - The DatabaseEntry of the current Get key.
81      */
82     @Override
setGetKeyDatabaseEntry(DatabaseEntry key)83     public void setGetKeyDatabaseEntry(DatabaseEntry key) {
84         currentGetKey = key;
85     }
86 
87     /**
88      * Whether the current Get key is set or not.
89      *
90      * @return True if the Get key is set, false otherwise.
91      */
92     @Override
getGetKeySet()93     public boolean getGetKeySet() {
94         return currentGetKey != null;
95     }
96 
97     /**
98      * Whether to append or put new records into the database.
99      *
100      * @return - True, since heap records are appended to the database.
101      */
102     @Override
getAppendRecords()103     public boolean getAppendRecords() {
104         return true;
105     }
106 
107 }
108