@@ -2,93 +2,16 @@ import 'package:meta/meta.dart';
22import 'package:hive/hive.dart' ;
33import 'package:sentry/sentry.dart' ;
44
5- import 'sentry_hive_impl .dart' ;
5+ import 'sentry_box_base .dart' ;
66
77///
88@experimental
9- class SentryBox <E > implements Box <E > {
9+ class SentryBox <E > extends SentryBoxBase < E > implements Box <E > {
1010
1111 final Box <E > _box;
12- final Hub _hub;
1312
14- // ignore: public_member_api_docs
15- SentryBox (this ._box, @internal Hub ? hub) : _hub = hub ?? HubAdapter ();
16-
17- @override
18- Future <int > add (E value) async {
19- return _asyncWrapInSpan ('add' , () async {
20- return await _box.add (value);
21- });
22- }
23-
24- @override
25- Future <Iterable <int >> addAll (Iterable <E > values) async {
26- return _asyncWrapInSpan ('addAll' , () async {
27- return await _box.addAll (values);
28- });
29- }
30-
31- @override
32- Future <int > clear () async {
33- return _asyncWrapInSpan ('clear' , () async {
34- return await _box.clear ();
35- });
36- }
37-
38- @override
39- Future <void > close () async {
40- return _asyncWrapInSpan ('close' , () async {
41- return await _box.close ();
42- });
43- }
44-
45- @override
46- Future <void > compact () async {
47- return _asyncWrapInSpan ('compact' , () async {
48- return await _box.compact ();
49- });
50- }
51-
52- @override
53- bool containsKey (key) {
54- return _box.containsKey (key);
55- }
56-
57- @override
58- Future <void > delete (key) async {
59- return _asyncWrapInSpan ('delete' , () async {
60- return await _box.delete (key);
61- });
62- }
63-
64- @override
65- // ignore: strict_raw_type
66- Future <void > deleteAll (Iterable keys) async {
67- return _asyncWrapInSpan ('deleteAll' , () async {
68- return await _box.deleteAll (keys);
69- });
70- }
71-
72- @override
73- Future <void > deleteAt (int index) async {
74- return _asyncWrapInSpan ('deleteAt' , () async {
75- return await _box.deleteAt (index);
76- });
77- }
78-
79- @override
80- Future <void > deleteFromDisk () async {
81- return _asyncWrapInSpan ('deleteFromDisk' , () async {
82- return await _box.deleteFromDisk ();
83- });
84- }
85-
86- @override
87- Future <void > flush () async {
88- return _asyncWrapInSpan ('flush' , () async {
89- return await _box.flush ();
90- });
91- }
13+ ///
14+ SentryBox (this ._box, @internal Hub hub) : super (_box, hub);
9215
9316 @override
9417 E ? get (key, {E ? defaultValue}) {
@@ -100,102 +23,17 @@ class SentryBox<E> implements Box<E> {
10023 return _box.getAt (index);
10124 }
10225
103- @override
104- bool get isEmpty => _box.isEmpty;
105-
106- @override
107- bool get isNotEmpty => _box.isNotEmpty;
108-
109- @override
110- bool get isOpen => _box.isOpen;
111-
112- @override
113- dynamic keyAt (int index) {
114- return _box.keyAt (index);
115- }
116-
117- @override
118- // ignore: strict_raw_type
119- Iterable get keys => _box.keys;
120-
121- @override
122- bool get lazy => _box.lazy;
123-
124- @override
125- int get length => _box.length;
126-
127- @override
128- String get name => _box.name;
129-
130- @override
131- String ? get path => _box.path;
132-
133- @override
134- Future <void > put (key, E value) async {
135- return _asyncWrapInSpan ('put' , () async {
136- return await _box.put (key, value);
137- });
138- }
139-
140- @override
141- Future <void > putAll (Map <dynamic , E > entries) async {
142- return _asyncWrapInSpan ('putAll' , () async {
143- return await _box.putAll (entries);
144- });
145- }
146-
147- @override
148- Future <void > putAt (int index, E value) async {
149- return _asyncWrapInSpan ('putAt' , () async {
150- return await _box.putAt (index, value);
151- });
152- }
153-
15426 @override
15527 Map <dynamic , E > toMap () {
15628 return _box.toMap ();
15729 }
15830
15931 @override
32+ // TODO: implement values
16033 Iterable <E > get values => _box.values;
16134
16235 @override
16336 Iterable <E > valuesBetween ({startKey, endKey}) {
16437 return _box.valuesBetween (startKey: startKey, endKey: endKey);
16538 }
166-
167- @override
168- Stream <BoxEvent > watch ({key}) {
169- return _box.watch (key: key);
170- }
171-
172- // Helper
173-
174- Future <T > _asyncWrapInSpan <T >(String description, Future <T > Function () execute) async {
175- final currentSpan = _hub.getSpan ();
176- final span = currentSpan? .startChild (
177- SentryHiveImpl .dbOp,
178- description: description,
179- );
180-
181- // ignore: invalid_use_of_internal_member
182- span? .origin = SentryTraceOrigins .autoDbHiveBox;
183-
184- span? .setData (SentryHiveImpl .dbSystemKey, SentryHiveImpl .dbSystem);
185- span? .setData (SentryHiveImpl .dbNameKey, name);
186-
187- try {
188- final result = await execute ();
189- span? .status = SpanStatus .ok ();
190-
191- return result;
192- } catch (exception) {
193- span? .throwable = exception;
194- span? .status = SpanStatus .internalError ();
195-
196- rethrow ;
197- } finally {
198- await span? .finish ();
199- }
200- }
20139}
0 commit comments