Skip to content

Commit 45cb934

Browse files
committed
RDBC-644 API Syntax
Simplified 'BulkInsert.store_with_entity' into 'BulkInsert.store' The original 'store' has been changed to 'store_as' - indicating that it requires providing certain document id
1 parent f09c18b commit 45cb934

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

ravendb/documents/bulk_insert_operation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,17 +194,17 @@ def _fill_metadata_if_needed(self, entity: object, metadata: MetadataAsDictionar
194194
if python_type is not None:
195195
metadata[constants.Documents.Metadata.RAVEN_PYTHON_TYPE] = python_type
196196

197-
def store_by_entity(self, entity: object, metadata: Optional[MetadataAsDictionary] = None) -> str:
197+
def store(self, entity: object, metadata: Optional[MetadataAsDictionary] = None) -> str:
198198
key = (
199199
self._get_id(entity)
200200
if metadata is None or constants.Documents.Metadata.ID not in metadata
201201
else metadata[constants.Documents.Metadata.ID]
202202
)
203203

204-
self.store(entity, key, metadata or MetadataAsDictionary())
204+
self.store_as(entity, key, metadata or MetadataAsDictionary())
205205
return key
206206

207-
def store(
207+
def store_as(
208208
self, entity: object, key: str, metadata: Optional[MetadataAsDictionary] = MetadataAsDictionary()
209209
) -> None:
210210
try:

ravendb/tests/jvm_migrated_tests/client_tests/subscriptions_tests/test_basic_subscription.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,9 +571,9 @@ def test_should_pull_documents_after_bulk_insert(self):
571571
key = self.store.subscriptions.create_for_class(User, SubscriptionCreationOptions())
572572
with self.store.subscriptions.get_subscription_worker(SubscriptionWorkerOptions(key), User) as subscription:
573573
with self.store.bulk_insert() as bulk_insert:
574-
bulk_insert.store_by_entity(User())
575-
bulk_insert.store_by_entity(User())
576-
bulk_insert.store_by_entity(User())
574+
bulk_insert.store(User())
575+
bulk_insert.store(User())
576+
bulk_insert.store(User())
577577

578578
users: List[User] = []
579579
third_user_processed = Event()

ravendb/tests/jvm_migrated_tests/client_tests/test_bulk_inserts.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ def test_simple_bulk_insert_should_work(self):
2222
foo_bar4 = FooBar("Mega Jane")
2323

2424
with self.store.bulk_insert() as bulk_insert:
25-
bulk_insert.store_by_entity(foo_bar1)
26-
bulk_insert.store_by_entity(foo_bar2)
27-
bulk_insert.store_by_entity(foo_bar3)
28-
bulk_insert.store_by_entity(foo_bar4)
25+
bulk_insert.store(foo_bar1)
26+
bulk_insert.store(foo_bar2)
27+
bulk_insert.store(foo_bar3)
28+
bulk_insert.store(foo_bar4)
2929

3030
with self.store.open_session() as session:
3131
doc1 = session.load("FooBars/1-A", FooBar)
@@ -46,7 +46,7 @@ def test_simple_bulk_insert_should_work(self):
4646
def test_should_not_accept_ids_ending_with_pipe_line(self):
4747
with self.store.bulk_insert() as bulk_insert:
4848
self.assertRaisesWithMessage(
49-
bulk_insert.store,
49+
bulk_insert.store_as,
5050
RuntimeError,
5151
"Document ids cannot end with '|', but was called with foobars|",
5252
FooBar(),
@@ -60,7 +60,7 @@ def test_can_modify_metadata_with_bulk_insert(self):
6060
foobar = FooBar("Jon Snow")
6161
metadata = MetadataAsDictionary()
6262
metadata[constants.Documents.Metadata.EXPIRES] = expiration_date
63-
bulk_insert.store_by_entity(foobar, metadata)
63+
bulk_insert.store(foobar, metadata)
6464

6565
with self.store.open_session() as session:
6666
entity = session.load("FooBars/1-A", FooBar)
@@ -70,7 +70,7 @@ def test_can_modify_metadata_with_bulk_insert(self):
7070
def test_killed_to_early(self):
7171
with self.assertRaises(BulkInsertAbortedException):
7272
with self.store.bulk_insert() as bulk_insert:
73-
bulk_insert.store_by_entity(FooBar())
73+
bulk_insert.store(FooBar())
7474
time.sleep(0.1) # todo: wait for operation to be created first, then try to kill it
7575
bulk_insert.abort()
76-
bulk_insert.store_by_entity(FooBar())
76+
bulk_insert.store(FooBar())
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from ravendb.infrastructure.entities import User
2+
from ravendb.tests.test_base import TestBase
3+
4+
5+
class TestRDBC387(TestBase):
6+
def setUp(self):
7+
super(TestRDBC387, self).setUp()
8+
9+
def test_should_store_single_id(self):
10+
with self.store.open_session() as session:
11+
u = User(name="John")
12+
session.store(u)
13+
session.save_changes()
14+
user_id_via_session_id = u.Id
15+
16+
with self.store.bulk_insert() as bulk_insert:
17+
u = User(name="Marcin")
18+
bulk_insert.store(u)
19+
user_id_via_bulk_insert = u.Id
20+
21+
with self.store.open_session() as session:
22+
session_user = session.load(user_id_via_session_id, dict)
23+
bulk_insert_user = session.load(user_id_via_bulk_insert, dict)
24+
25+
self.assertIsNone(session_user.get("id", None))
26+
self.assertIsNone(bulk_insert_user.get("id", None))
27+
28+
self.assertIsNone(session_user.get("Id", None))
29+
self.assertIsNone(bulk_insert_user.get("Id", None))

ravendb/tests/jvm_migrated_tests/issues_tests/test_ravenDB_16301.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_can_use_conditional_load_lazily(self):
1919
# Store 100 companies using bulk insert - it won't store identity property on the server
2020
with self.store.bulk_insert() as bulk_insert:
2121
for i in range(100):
22-
bulk_insert.store_by_entity(Company())
22+
bulk_insert.store(Company())
2323

2424
conditional_loads: List[Lazy[ConditionalLoadResult[Company]]] = []
2525

0 commit comments

Comments
 (0)