1package persist.gettingStarted; 2 3import java.io.File; 4 5import com.sleepycat.db.DatabaseException; 6import com.sleepycat.db.Environment; 7import com.sleepycat.db.EnvironmentConfig; 8 9import com.sleepycat.persist.EntityStore; 10import com.sleepycat.persist.StoreConfig; 11 12import java.io.FileNotFoundException; 13 14public class SimpleStoreGet { 15 16 private static File envHome = new File("./JEDB"); 17 18 private Environment envmnt; 19 private EntityStore store; 20 private SimpleDA sda; 21 22 // The setup() method opens the environment and store 23 // for us. 24 public void setup() 25 throws DatabaseException { 26 27 try { 28 EnvironmentConfig envConfig = new EnvironmentConfig(); 29 StoreConfig storeConfig = new StoreConfig(); 30 31 // Open the environment and entity store 32 envmnt = new Environment(envHome, envConfig); 33 store = new EntityStore(envmnt, "EntityStore", storeConfig); 34 } catch (FileNotFoundException fnfe) { 35 System.err.println("setup(): " + fnfe.toString()); 36 System.exit(-1); 37 } 38 } 39 40 public void shutdown() 41 throws DatabaseException { 42 43 store.close(); 44 envmnt.close(); 45 } 46 47 48 private void run() 49 throws DatabaseException { 50 51 setup(); 52 53 // Open the data accessor. This is used to store 54 // persistent objects. 55 sda = new SimpleDA(store); 56 57 // Instantiate and store some entity classes 58 SimpleEntityClass sec1 = sda.pIdx.get("keyone"); 59 SimpleEntityClass sec2 = sda.pIdx.get("keytwo"); 60 61 SimpleEntityClass sec4 = sda.sIdx.get("skeythree"); 62 63 System.out.println("sec1: " + sec1.getpKey()); 64 System.out.println("sec2: " + sec2.getpKey()); 65 System.out.println("sec4: " + sec4.getpKey()); 66 67 System.out.println("############ Doing pcursor ##########"); 68 for (SimpleEntityClass seci : sda.sec_pcursor ) { 69 System.out.println("sec from pcursor : " + seci.getpKey() ); 70 } 71 72 sda.pIdx.delete("keyone"); 73 System.out.println("############ Doing pcursor ##########"); 74 System.out.println("sec from pcursor : " + sda.sec_pcursor.first().getpKey()); 75 for (SimpleEntityClass seci : sda.sec_pcursor ) { 76 System.out.println("sec from pcursor : " + seci.getpKey() ); 77 } 78 79 System.out.println("############ Doing scursor ##########"); 80 for (SimpleEntityClass seci : sda.sec_scursor ) { 81 System.out.println("sec from scursor : " + seci.getpKey() ); 82 } 83 84 85 86 sda.close(); 87 shutdown(); 88 } 89 90 public static void main(String args[]) { 91 SimpleStoreGet ssg = new SimpleStoreGet(); 92 try { 93 ssg.run(); 94 } catch (DatabaseException dbe) { 95 System.err.println("SimpleStoreGet: " + dbe.toString()); 96 dbe.printStackTrace(); 97 } catch (Exception e) { 98 System.out.println("Exception: " + e.toString()); 99 e.printStackTrace(); 100 } 101 System.out.println("All done."); 102 } 103 104} 105