Uses 3057K of libraries. Click here for Pure Java version (1044L/7K/24K).
1 | !752 |
2 | |
3 | lib 1004017 // Berkeley DB |
4 | |
5 | import com.sleepycat.je.DatabaseException; |
6 | import com.sleepycat.je.Environment; |
7 | import com.sleepycat.je.EnvironmentConfig; |
8 | |
9 | import com.sleepycat.persist.EntityStore; |
10 | import com.sleepycat.persist.StoreConfig; |
11 | |
12 | import com.sleepycat.persist.model.Entity; |
13 | import com.sleepycat.persist.model.PrimaryKey; |
14 | import com.sleepycat.persist.model.SecondaryKey; |
15 | import static com.sleepycat.persist.model.Relationship.MANY_TO_ONE; |
16 | |
17 | import com.sleepycat.je.DatabaseException; |
18 | import com.sleepycat.persist.EntityStore; |
19 | import com.sleepycat.persist.PrimaryIndex; |
20 | import com.sleepycat.persist.SecondaryIndex; |
21 | |
22 | public static class SimpleDA {
|
23 | // Open the indices |
24 | public SimpleDA(EntityStore store) |
25 | throws DatabaseException {
|
26 | |
27 | // Primary key for ExampleEntity classes |
28 | pIdx = store.getPrimaryIndex( |
29 | String.class, ExampleEntity.class); |
30 | |
31 | // Secondary key for ExampleEntity classes |
32 | // Last field in the getSecondaryIndex() method must be |
33 | // the name of a class member; in this case, an |
34 | // ExampleEntity.class data member. |
35 | sIdx = store.getSecondaryIndex( |
36 | pIdx, String.class, "aSecondaryKey"); |
37 | } |
38 | |
39 | // Index Accessors |
40 | PrimaryIndex<String,ExampleEntity> pIdx; |
41 | SecondaryIndex<String,String,ExampleEntity> sIdx; |
42 | } |
43 | |
44 | @Entity |
45 | public static class ExampleEntity {
|
46 | // The primary key must be unique in the database. |
47 | @PrimaryKey |
48 | private String aPrimaryKey; |
49 | |
50 | @SecondaryKey(relate=MANY_TO_ONE) |
51 | private String aSecondaryKey; |
52 | |
53 | void setPKey(S x) { aPrimaryKey = x; }
|
54 | void setSKey(S x) { aSecondaryKey = x; }
|
55 | } |
56 | |
57 | p {
|
58 | Environment myEnv; |
59 | EntityStore store; |
60 | |
61 | bool readOnly = false; |
62 | File envHome = mkdir(getProgramDir("#1004019"));
|
63 | |
64 | print("Opening Berkely DB in " + envHome.getAbsolutePath());
|
65 | |
66 | EnvironmentConfig myEnvConfig = new EnvironmentConfig(); |
67 | StoreConfig storeConfig = new StoreConfig(); |
68 | |
69 | myEnvConfig.setAllowCreate(!readOnly); |
70 | storeConfig.setAllowCreate(!readOnly); |
71 | |
72 | // Open the environment and entity store |
73 | myEnv = new Environment(envHome, myEnvConfig); |
74 | store = new EntityStore(myEnv, "EntityStore", storeConfig); |
75 | |
76 | print("Retrieving stuff");
|
77 | |
78 | SimpleDA da = new SimpleDA(store); |
79 | |
80 | ExampleEntity sec1 = da.pIdx.get("keyone");
|
81 | ExampleEntity sec2 = da.pIdx.get("keytwo");
|
82 | |
83 | print("keyone => " + structure(sec1));
|
84 | print("keytwo => " + structure(sec2));
|
85 | |
86 | print("Closing");
|
87 | |
88 | if (store != null) |
89 | store.close(); |
90 | if (myEnv != null) |
91 | myEnv.close(); |
92 | } |
Began life as a copy of #1004019
download show line numbers debug dex old transpilations
Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
| ID | Author/Program | Comment | Date |
|---|---|---|---|
| 1283 | stefan | Works!! | 2016-08-03 18:22:12 |
| Snippet ID: | #1004020 |
| Snippet name: | Test Berkeley DB 3 (Retrieving) |
| Eternal ID of this version: | #1004020/1 |
| Text MD5: | eccdc799ecf1a1be08fd005b3f0baf2c |
| Transpilation MD5: | 79c7d85b672e3cc7ec6804366cc83ddb |
| Author: | stefan |
| Category: | javax / databases |
| Type: | JavaX source code |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2016-08-03 18:02:55 |
| Source code size: | 2639 bytes / 92 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 1045 / 1162 |
| Referenced in: | [show references] |