@@ -186,6 +186,42 @@ public void prepare(Collection<BlockInfo> removed, Collection<BlockInfo> news,
186
186
session .release (luChanges );
187
187
}
188
188
}
189
+
190
+ //only for testing
191
+ @ Override
192
+ public void deleteBlocksForFile (long inodeID ) throws StorageException {
193
+ HopsSession session = connector .obtainSession ();
194
+
195
+ HopsQueryBuilder qb = session .getQueryBuilder ();
196
+ HopsQueryDomainType <BlockInfoDTO > dobj = qb .createQueryDefinition (BlockInfoDTO .class );
197
+ HopsPredicate pred1 = dobj .get ("iNodeId" ).equal (dobj .param ("inodeIdParam" ));
198
+ dobj .where (pred1 );
199
+
200
+ HopsQuery <BlockInfoDTO > query = session .createQuery (dobj );
201
+ query .setParameter ("inodeIdParam" , inodeID );
202
+ List <BlockInfoDTO > dtos = query .getResultList ();
203
+
204
+ session .deletePersistentAll (dtos );
205
+ session .release (dtos );
206
+
207
+ deleteBlockLoopupForFile (inodeID );
208
+ }
209
+
210
+ private void deleteBlockLoopupForFile (long inodeID ) throws StorageException {
211
+ HopsSession session = connector .obtainSession ();
212
+
213
+ HopsQueryBuilder qb = session .getQueryBuilder ();
214
+ HopsQueryDomainType <BlockLookUpClusterj .BlockLookUpDTO > dobj =
215
+ qb .createQueryDefinition (BlockLookUpClusterj .BlockLookUpDTO .class );
216
+ HopsPredicate pred = dobj .get ("iNodeId" ).equal (dobj .param ("inodeIdParam" ));
217
+ dobj .where (pred );
218
+ HopsQuery <BlockLookUpClusterj .BlockLookUpDTO > query = session .createQuery (dobj );
219
+ query .setParameter ("inodeIdParam" , inodeID );
220
+ List <BlockLookUpClusterj .BlockLookUpDTO > dtos = query .getResultList ();
221
+
222
+ session .deletePersistentAll (dtos );
223
+ session .release (dtos );
224
+ }
189
225
190
226
@ Override
191
227
public BlockInfo findById (long blockId , long inodeId ) throws StorageException {
@@ -240,28 +276,32 @@ public List<BlockInfo> findByInodeIds(long[] inodeIds)
240
276
return lbis ;
241
277
}
242
278
243
- public BlockInfo scanByBlockId (long blockId ) throws StorageException {
279
+ @ Override
280
+ public List <BlockInfo > findAllBlocks () throws StorageException {
244
281
HopsSession session = connector .obtainSession ();
245
282
HopsQueryBuilder qb = session .getQueryBuilder ();
246
283
HopsQueryDomainType <BlockInfoClusterj .BlockInfoDTO > dobj =
247
284
qb .createQueryDefinition (BlockInfoClusterj .BlockInfoDTO .class );
248
- HopsPredicate pred1 = dobj .get ("blockId" ).equal (dobj .param ("blockIdParam" ));
249
- dobj .where (pred1 );
250
285
HopsQuery <BlockInfoClusterj .BlockInfoDTO > query = session .createQuery (dobj );
251
- query . setParameter ( "blockIdParam" , blockId );
286
+
252
287
List <BlockInfoDTO > biDtos = query .getResultList ();
253
- BlockInfo bi = createBlockInfo (biDtos . get ( 0 ) );
288
+ List < BlockInfo > lbis = createBlockInfoList (biDtos );
254
289
session .release (biDtos );
255
- return bi ;
290
+ return lbis ;
256
291
}
257
292
258
293
@ Override
259
- public List <BlockInfo > findAllBlocks () throws StorageException {
294
+ public List <BlockInfo > findAllBlocks (long startID , long endID ) throws StorageException {
260
295
HopsSession session = connector .obtainSession ();
261
296
HopsQueryBuilder qb = session .getQueryBuilder ();
262
- HopsQueryDomainType <BlockInfoClusterj .BlockInfoDTO > dobj =
263
- qb .createQueryDefinition (BlockInfoClusterj .BlockInfoDTO .class );
264
- HopsQuery <BlockInfoClusterj .BlockInfoDTO > query = session .createQuery (dobj );
297
+ HopsQueryDomainType <BlockInfoDTO > qdty = qb .createQueryDefinition (BlockInfoDTO .class );
298
+ HopsPredicate pred1 = qdty .get ("blockId" ).greaterEqual (qdty .param ("blockIdParam1" ));
299
+ HopsPredicate pred2 = qdty .get ("blockId" ).lessThan (qdty .param ("blockIdParam2" ));
300
+ qdty .where (pred1 .and (pred2 ));
301
+
302
+ HopsQuery <BlockInfoDTO > query = session .createQuery (qdty );
303
+ query .setParameter ("blockIdParam1" , startID );
304
+ query .setParameter ("blockIdParam2" , endID );
265
305
266
306
List <BlockInfoDTO > biDtos = query .getResultList ();
267
307
List <BlockInfo > lbis = createBlockInfoList (biDtos );
0 commit comments