14
14
from rdflib .plugins .stores .regexmatching import PYTHON_REGEX , REGEXTerm
15
15
from rdflib .store import CORRUPTED_STORE , VALID_STORE , NodePickler , Store
16
16
from six import text_type
17
- from six .moves import reduce
18
17
from sqlalchemy import MetaData
19
18
from sqlalchemy .sql import expression , select
20
19
@@ -305,14 +304,12 @@ def destroy(self, configuration):
305
304
if self .engine is None :
306
305
self .engine = self .open (configuration , create = False )
307
306
308
- with self .engine .connect () as connection :
309
- trans = connection .begin ()
307
+ with self .engine .begin ():
310
308
try :
311
309
self .metadata .drop_all (self .engine )
312
- trans .commit ()
313
310
except Exception :
314
311
_logger .exception ("unable to drop table." )
315
- trans . rollback ()
312
+ raise
316
313
317
314
# Triple Methods
318
315
@@ -325,7 +322,7 @@ def add(self, triple, context=None, quoted=False):
325
322
)
326
323
327
324
statement = self ._add_ignore_on_conflict (statement )
328
- with self .engine .connect () as connection :
325
+ with self .engine .begin () as connection :
329
326
try :
330
327
connection .execute (statement , params )
331
328
except Exception :
@@ -349,16 +346,13 @@ def addN(self, quads):
349
346
command_dict .setdefault ("statement" , statement )
350
347
command_dict .setdefault ("params" , []).append (params )
351
348
352
- with self .engine .connect () as connection :
353
- trans = connection .begin ()
349
+ with self .engine .begin () as connection :
354
350
try :
355
351
for command in commands_dict .values ():
356
352
statement = self ._add_ignore_on_conflict (command ['statement' ])
357
353
connection .execute (statement , command ["params" ])
358
- trans .commit ()
359
354
except Exception :
360
355
_logger .exception ("AddN failed." )
361
- trans .rollback ()
362
356
raise
363
357
364
358
def _add_ignore_on_conflict (self , statement ):
@@ -385,8 +379,7 @@ def remove(self, triple, context):
385
379
asserted_type_table = self .tables ["type_statements" ]
386
380
literal_table = self .tables ["literal_statements" ]
387
381
388
- with self .engine .connect () as connection :
389
- trans = connection .begin ()
382
+ with self .engine .begin () as connection :
390
383
try :
391
384
if not predicate or predicate != RDF .type :
392
385
# Need to remove predicates other than rdf:type
@@ -413,11 +406,9 @@ def remove(self, triple, context):
413
406
414
407
clause = self .build_clause (quoted_table , subject , predicate , obj , context )
415
408
connection .execute (quoted_table .delete (clause ))
416
-
417
- trans .commit ()
418
409
except Exception :
419
410
_logger .exception ("Removal failed." )
420
- trans . rollback ()
411
+ raise
421
412
422
413
def _triples_helper (self , triple , context = None ):
423
414
subject , predicate , obj = triple
@@ -716,6 +707,7 @@ def bind(self, prefix, namespace):
716
707
connection .execute (binds_table .insert ().values (prefix = prefix , uri = namespace ))
717
708
except Exception :
718
709
_logger .exception ("Namespace binding failed." )
710
+ raise
719
711
720
712
def prefix (self , namespace ):
721
713
"""Prefix."""
@@ -817,17 +809,15 @@ def _remove_context(self, context):
817
809
asserted_type_table = self .tables ["type_statements" ]
818
810
literal_table = self .tables ["literal_statements" ]
819
811
820
- with self .engine .connect () as connection :
821
- trans = connection .begin ()
812
+ with self .engine .begin () as connection :
822
813
try :
823
814
for table in [quoted_table , asserted_table ,
824
815
asserted_type_table , literal_table ]:
825
816
clause = self .build_context_clause (context , table )
826
817
connection .execute (table .delete (clause ))
827
- trans .commit ()
828
818
except Exception :
829
819
_logger .exception ("Context removal failed." )
830
- trans . rollback ()
820
+ raise
831
821
832
822
def _verify_store_exists (self ):
833
823
"""
0 commit comments