@@ -78,45 +78,64 @@ public class BerkeleyDbStats {
7878
7979 public BerkeleyDbStats getStats () {
8080 BerkeleyDbStats berkeleyDbStats = new BerkeleyDbStats ();
81- berkeleyDbStats .conceptCount = store .getPrimaryIndex (Integer .class , Concept .class ).count ();
82- berkeleyDbStats .mapsToRelationshipCount = store .getPrimaryIndex (Integer .class , MapsToRelationship .class ).count ();
83- berkeleyDbStats .parentChildCount = store .getPrimaryIndex (Integer .class , ParentChildRelationShip .class ).count ();
81+ if (isOpenForReading || isOpenForWriting ) {
82+ berkeleyDbStats .conceptCount = store .getPrimaryIndex (Integer .class , Concept .class ).count ();
83+ berkeleyDbStats .mapsToRelationshipCount = store .getPrimaryIndex (Integer .class , MapsToRelationship .class ).count ();
84+ berkeleyDbStats .parentChildCount = store .getPrimaryIndex (Integer .class , ParentChildRelationShip .class ).count ();
85+ }
8486 return berkeleyDbStats ;
8587 }
8688
8789 public void put (Concept concept ) {
88- conceptDataAccessor .primaryIndex .putNoReturn (concept );
90+ if (isOpenForWriting ) {
91+ conceptDataAccessor .primaryIndex .putNoReturn (concept );
92+ }
8993 }
9094
9195 public void put (MapsToRelationship mapsToRelationship ) {
92- mapsToRelationshipDataAccessor .primaryIndex .putNoReturn (mapsToRelationship );
96+ if (isOpenForWriting ) {
97+ mapsToRelationshipDataAccessor .primaryIndex .putNoReturn (mapsToRelationship );
98+ }
9399 }
94100
95101 public void putAtcToRxNorm (String atc , int conceptId ) {
96- AtcToRxNorm atcToRxNorm = atcToRxNormDataAccessor .primaryIndex .get (atc );
97- if (atcToRxNorm == null ) {
98- atcToRxNorm = new AtcToRxNorm (atc );
102+ if (isOpenForWriting ) {
103+ AtcToRxNorm atcToRxNorm = atcToRxNormDataAccessor .primaryIndex .get (atc );
104+ if (atcToRxNorm == null ) {
105+ atcToRxNorm = new AtcToRxNorm (atc );
106+ }
107+ atcToRxNorm .conceptIds .add (conceptId );
108+ atcToRxNormDataAccessor .primaryIndex .putNoReturn (atcToRxNorm );
99109 }
100- atcToRxNorm .conceptIds .add (conceptId );
101- atcToRxNormDataAccessor .primaryIndex .putNoReturn (atcToRxNorm );
102110 }
103111
104112 public void put (ParentChildRelationShip parentChildRelationship ) {
105- parentChildRelationshipDataAccessor .primaryIndex .putNoReturn (parentChildRelationship );
113+ if (isOpenForWriting ) {
114+ parentChildRelationshipDataAccessor .primaryIndex .putNoReturn (parentChildRelationship );
115+ }
106116 }
107117
108118 public EntityCursor <Concept > getConceptCursor () {
109- return conceptDataAccessor .primaryIndex .entities ();
119+ if (isOpenForReading || isOpenForWriting ) {
120+ return conceptDataAccessor .primaryIndex .entities ();
121+ }
122+ return null ;
110123 }
111124
112125 public MapsToRelationship getMapsToRelationship (int conceptId ) {
113- return mapsToRelationshipDataAccessor .primaryIndex .get (conceptId );
126+ if (isOpenForReading || isOpenForWriting ) {
127+ return mapsToRelationshipDataAccessor .primaryIndex .get (conceptId );
128+ }
129+ return null ;
114130 }
115131
116132 public List <MapsToRelationship > getMapsToRelationshipsByConceptId2 (int conceptId ) {
133+ List <MapsToRelationship > relationships = new ArrayList <MapsToRelationship >();
134+ if (!(isOpenForReading || isOpenForWriting )) {
135+ return relationships ;
136+ }
117137 EntityIndex <Integer , MapsToRelationship > subIndex = mapsToRelationshipDataAccessor .secondaryIndex .subIndex (conceptId );
118138 EntityCursor <MapsToRelationship > cursor = subIndex .entities ();
119- List <MapsToRelationship > relationships = new ArrayList <MapsToRelationship >();
120139 try {
121140 for (MapsToRelationship relationship : cursor )
122141 relationships .add (relationship );
@@ -127,17 +146,23 @@ public List<MapsToRelationship> getMapsToRelationshipsByConceptId2(int conceptId
127146 }
128147
129148 public Set <Integer > getRxNormConceptIds (String atc ) {
130- AtcToRxNorm atcToRxNorm = atcToRxNormDataAccessor .primaryIndex .get (atc );
131- if (atcToRxNorm == null )
132- return Collections .emptySet ();
133- else
134- return atcToRxNorm .conceptIds ;
149+ if (isOpenForReading || isOpenForWriting ) {
150+ AtcToRxNorm atcToRxNorm = atcToRxNormDataAccessor .primaryIndex .get (atc );
151+ if (atcToRxNorm == null )
152+ return Collections .emptySet ();
153+ else
154+ return atcToRxNorm .conceptIds ;
155+ }
156+ return Collections .emptySet ();
135157 }
136158
137159 public List <ParentChildRelationShip > getParentChildRelationshipsByParentConceptId (int conceptId ) {
160+ List <ParentChildRelationShip > relationships = new ArrayList <ParentChildRelationShip >();
161+ if (!(isOpenForReading || isOpenForWriting )) {
162+ return relationships ;
163+ }
138164 EntityIndex <Integer , ParentChildRelationShip > subIndex = parentChildRelationshipDataAccessor .secondaryIndexParent .subIndex (conceptId );
139165 EntityCursor <ParentChildRelationShip > cursor = subIndex .entities ();
140- List <ParentChildRelationShip > relationships = new ArrayList <ParentChildRelationShip >();
141166 try {
142167 for (ParentChildRelationShip relationship : cursor )
143168 relationships .add (relationship );
@@ -148,9 +173,12 @@ public List<ParentChildRelationShip> getParentChildRelationshipsByParentConceptI
148173 }
149174
150175 public List <ParentChildRelationShip > getParentChildRelationshipsByChildConceptId (int conceptId ) {
176+ List <ParentChildRelationShip > relationships = new ArrayList <ParentChildRelationShip >();
177+ if (!(isOpenForReading || isOpenForWriting )) {
178+ return relationships ;
179+ }
151180 EntityIndex <Integer , ParentChildRelationShip > subIndex = parentChildRelationshipDataAccessor .secondaryIndexChild .subIndex (conceptId );
152181 EntityCursor <ParentChildRelationShip > cursor = subIndex .entities ();
153- List <ParentChildRelationShip > relationships = new ArrayList <ParentChildRelationShip >();
154182 try {
155183 for (ParentChildRelationShip relationship : cursor )
156184 relationships .add (relationship );
@@ -161,14 +189,19 @@ public List<ParentChildRelationShip> getParentChildRelationshipsByChildConceptId
161189 }
162190
163191 public Concept getConcept (int conceptId ) {
164- return conceptDataAccessor .primaryIndex .get (conceptId );
192+ if (isOpenForReading || isOpenForWriting ) {
193+ return conceptDataAccessor .primaryIndex .get (conceptId );
194+ }
195+ return null ;
165196 }
166197
167198 public void shutdown () throws DatabaseException {
168199 try {
169200 if (isOpenForReading || isOpenForWriting ) {
170201 store .close ();
171202 dbEnvironment .close ();
203+ isOpenForReading = false ;
204+ isOpenForWriting = false ;
172205 }
173206 } catch (DatabaseException dbe ) {
174207 throw new RuntimeException (dbe );
0 commit comments