Skip to content

Commit 68fadd9

Browse files
committed
Merge branch '44-deprecate-ObjectBox-add-Store' into 'dev'
Resolve "Deprecate ObjectBox and add Store class" Closes #44 See merge request objectbox/objectbox-python!30
2 parents 8aa7465 + 01dfb65 commit 68fadd9

24 files changed

Lines changed: 122 additions & 82 deletions

benchmark.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import objectbox
22
import time
33
from tests.model import TestEntity
4-
from tests.common import remove_test_dir, load_empty_test_objectbox
4+
from tests.common import remove_test_dir, load_empty_test_default_store
55

66

77
class ObjectBoxPerf:
@@ -10,7 +10,7 @@ class ObjectBoxPerf:
1010
"""
1111

1212
def __init__(self):
13-
self.ob = load_empty_test_objectbox()
13+
self.ob = load_empty_test_default_store()
1414
self.box = objectbox.Box(self.ob, TestEntity)
1515

1616
def remove_all(self):

objectbox/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2023 ObjectBox Ltd. All rights reserved.
1+
# Copyright 2019-2024 ObjectBox Ltd. All rights reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616
from objectbox.box import Box
1717
from objectbox.builder import Builder
1818
from objectbox.model import Model
19+
from objectbox.store import Store
1920
from objectbox.objectbox import ObjectBox
2021
from objectbox.c import NotFoundException, version_core
2122
from objectbox.version import Version
@@ -24,6 +25,7 @@
2425
'Box',
2526
'Builder',
2627
'Model',
28+
'Store',
2729
'ObjectBox',
2830
'NotFoundException',
2931
'version',

objectbox/box.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2021 ObjectBox Ltd. All rights reserved.
1+
# Copyright 2019-2024 ObjectBox Ltd. All rights reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -14,20 +14,20 @@
1414

1515

1616
from objectbox.model.entity import _Entity
17-
from objectbox.objectbox import ObjectBox
17+
from objectbox.store import Store
1818
from objectbox.query_builder import QueryBuilder
1919
from objectbox.condition import QueryCondition
2020
from objectbox.c import *
2121

2222

2323
class Box:
24-
def __init__(self, ob: ObjectBox, entity: _Entity):
24+
def __init__(self, store: Store, entity: _Entity):
2525
if not isinstance(entity, _Entity):
2626
raise Exception("Given type is not an Entity")
2727

28-
self._ob = ob
28+
self._store = store
2929
self._entity = entity
30-
self._c_box = obx_box(ob._c_store, entity.id)
30+
self._c_box = obx_box(store._c_store, entity.id)
3131

3232
def is_empty(self) -> bool:
3333
is_empty = ctypes.c_bool()
@@ -109,7 +109,7 @@ def _put_many(self, objects) -> None:
109109
self._entity.set_object_id(objects[k], ids[k])
110110

111111
def get(self, id: int):
112-
with self._ob.read_tx():
112+
with self._store.read_tx():
113113
c_data = ctypes.c_void_p()
114114
c_size = ctypes.c_size_t()
115115
code : obx_err = obx_box_get(self._c_box, id, ctypes.byref(
@@ -122,7 +122,7 @@ def get(self, id: int):
122122
return self._entity.unmarshal(data)
123123

124124
def get_all(self) -> list:
125-
with self._ob.read_tx():
125+
with self._store.read_tx():
126126
# OBX_bytes_array*
127127
c_bytes_array_p = obx_box_get_all(self._c_box)
128128

@@ -166,7 +166,7 @@ def query(self, condition: Optional[QueryCondition] = None) -> QueryBuilder:
166166
Useful for a user-friendly API design; for example:
167167
``box.query(name_property.equals("Johnny")).build()``
168168
"""
169-
qb = QueryBuilder(self._ob, self)
169+
qb = QueryBuilder(self._store, self)
170170
if condition is not None:
171171
condition.apply(qb)
172172
return qb

objectbox/builder.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2021 ObjectBox Ltd. All rights reserved.
1+
# Copyright 2019-2024 ObjectBox Ltd. All rights reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
1515

1616
from objectbox.c import *
1717
from objectbox.model import Model
18-
from objectbox.objectbox import ObjectBox
18+
from objectbox.store import Store
1919
from objectbox.store_options import StoreOptions
2020

2121

@@ -38,7 +38,7 @@ def model(self, model: Model) -> 'Builder':
3838
self._model._finish()
3939
return self
4040

41-
def build(self) -> 'ObjectBox':
41+
def build(self) -> 'Store':
4242
options = StoreOptions()
4343
try:
4444
if self._directory:
@@ -50,4 +50,4 @@ def build(self) -> 'ObjectBox':
5050
options._free()
5151
raise
5252
c_store = obx_store_open(options._c_handle)
53-
return ObjectBox(c_store)
53+
return Store(c_store)

objectbox/c.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2021 ObjectBox Ltd. All rights reserved.
1+
# Copyright 2019-2024 ObjectBox Ltd. All rights reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

objectbox/model/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2021 ObjectBox Ltd. All rights reserved.
1+
# Copyright 2019-2024 ObjectBox Ltd. All rights reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

objectbox/model/entity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2023 ObjectBox Ltd. All rights reserved.
1+
# Copyright 2019-2024 ObjectBox Ltd. All rights reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

objectbox/model/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2021 ObjectBox Ltd. All rights reserved.
1+
# Copyright 2019-2024 ObjectBox Ltd. All rights reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

objectbox/model/properties.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2023 ObjectBox Ltd. All rights reserved.
1+
# Copyright 2019-2024 ObjectBox Ltd. All rights reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.

objectbox/objectbox.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2019-2023 ObjectBox Ltd. All rights reserved.
1+
# Copyright 2019-2024 ObjectBox Ltd. All rights reserved.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -13,25 +13,11 @@
1313
# limitations under the License.
1414

1515

16-
from objectbox.c import *
17-
import objectbox.transaction
16+
import objectbox.store
17+
from warnings import warn
1818

19-
20-
class ObjectBox:
21-
def __init__(self, c_store: OBX_store_p):
22-
self._c_store = c_store
23-
24-
def __del__(self):
25-
self.close()
26-
27-
def read_tx(self):
28-
return objectbox.transaction.read(self)
29-
30-
def write_tx(self):
31-
return objectbox.transaction.write(self)
32-
33-
def close(self):
34-
c_store_to_close = self._c_store
35-
if c_store_to_close:
36-
self._c_store = None
37-
obx_store_close(c_store_to_close)
19+
class ObjectBox(objectbox.store.Store):
20+
def __init__(self, *args, **kwargs):
21+
"""This throws a deprecation warning on initialization."""
22+
warn(f'{self.__class__.__name__} will be deprecated, use Store from objectbox.store.', DeprecationWarning, stacklevel=2)
23+
super().__init__(*args, **kwargs)

0 commit comments

Comments
 (0)