24 #define AFW_IMPLEMENTATION_ID "lmdb"
28 void afw_lmdb_adaptor_session_dump_objects(
47 self->pub.inf = &impl_afw_adaptor_session_inf;
49 self->pub.p = xctx->p;
50 self->adaptor = adaptor;
53 self->indexer = afw_lmdb_adaptor_impl_index_create(
self,
96 if (afw_lmdb_metadata_handles(object_type_id)) {
98 self, object_type_id, criteria, xctx);
104 txn = AFW_LMDB_GET_TRANSACTION();
107 if (object_type_id == NULL) {
109 afw_lmdb_adaptor_session_dump_objects(
self, txn, NULL, criteria,
110 callback, context, p, xctx);
114 else if (afw_adaptor_impl_index_sargable(self->indexer,
115 object_type_id, criteria, xctx))
117 afw_adaptor_impl_index_query(self->indexer, object_type_id,
118 criteria, callback, context, p, xctx);
125 afw_lmdb_adaptor_session_dump_objects(
self, txn, object_type_id,
126 criteria, callback, context, p, xctx);
158 if (
afw_utf8_equal(object_type_id, &afw_s__AdaptiveObjectType_)) {
160 instance->adaptor, object_id, p, xctx);
161 callback(
object, context, xctx);
168 txn = AFW_LMDB_GET_TRANSACTION();
171 dbi = afw_lmdb_internal_open_database(adaptor,
172 txn, &afw_lmdb_s_Primary, 0, p, xctx);
176 afw_lmdb_internal_create_object_from_entry(
self,
177 object_type_id, object_id, dbi, xctx),
202 const afw_uuid_t *uuid;
205 if (suggested_object_id) {
207 uuid_string = suggested_object_id;
216 txn = AFW_LMDB_GET_TRANSACTION();
219 dbi = afw_lmdb_internal_open_database(adaptor,
220 txn, &afw_lmdb_s_Primary, MDB_CREATE, xctx->p, xctx);
223 afw_lmdb_internal_create_entry_from_object(
self,
224 object_type_id, uuid_string,
object, dbi, xctx);
227 afw_adaptor_impl_index_object(self->indexer, object_type_id,
228 object, uuid_string, xctx);
258 if (!object_id || !object_type_id) {
260 "Missing id or object_type.", xctx);
265 txn = AFW_LMDB_GET_TRANSACTION(),
268 dbi = afw_lmdb_internal_open_database(adaptor,
269 txn, &afw_lmdb_s_Primary, 0, xctx->p, xctx);
272 object = afw_lmdb_internal_create_object_from_entry(
self,
273 object_type_id, object_id, dbi, xctx);
278 entry, new_object, xctx);
281 afw_lmdb_internal_replace_entry_from_object(
self, object_type_id,
282 object_id, new_object, dbi, xctx);
285 afw_adaptor_impl_index_reindex_object(self->indexer, object_type_id,
286 object, new_object, object_id, xctx);
314 if (!object_id || !object_type_id) {
316 "Missing id or object_type.", xctx);
321 txn = AFW_LMDB_GET_TRANSACTION();
324 dbi = afw_lmdb_internal_open_database(adaptor,
325 txn, &afw_lmdb_s_Primary, 0, xctx->p, xctx);
328 value = afw_lmdb_internal_create_value_from_entry(
self,
329 object_type_id, object_id, dbi, xctx);
333 "Not a valid object.", xctx);
339 afw_lmdb_internal_replace_entry_from_object(
self,
340 object_type_id, object_id, replacement_object, dbi, xctx);
343 afw_adaptor_impl_index_reindex_object(self->indexer, object_type_id,
344 old_object, replacement_object, object_id, xctx);
366 const afw_uuid_t *uuid;
378 txn = AFW_LMDB_GET_TRANSACTION();
380 dbi = afw_lmdb_internal_open_database(adaptor,
381 txn, &afw_lmdb_s_Primary, 0, xctx->p, xctx);
383 object = afw_lmdb_internal_create_object_from_entry(
self,
384 object_type_id, object_id, dbi, xctx);
392 afw_lmdb_internal_set_key(&raw_key, object_type_id, uuid, xctx->p, xctx);
394 rc = afw_lmdb_internal_delete_entry(
395 AFW_LMDB_GET_TRANSACTION(),
396 dbi, &raw_key, NULL, xctx);
399 "Error deleting value from primary database.", xctx);
404 afw_adaptor_impl_index_unindex_object(self->indexer,
405 object_type_id,
object, object_id, xctx);
447 void afw_lmdb_adaptor_session_dump_objects(
470 dbi = afw_lmdb_internal_open_database(session->adaptor, txn,
471 &afw_lmdb_s_Primary, 0, p, xctx);
474 cursor = afw_lmdb_internal_open_cursor(session, dbi, xctx);
475 if (cursor == NULL) {
477 "Error opening primary database cursor.", xctx);
485 memset(&data, 0,
sizeof(MDB_val));
486 if (object_type_id) {
487 key.mv_data = (
void*)object_type_id->s;
488 key.mv_size = object_type_id->len;
489 rc = mdb_cursor_get(cursor, &key, &data, MDB_SET_RANGE);
492 memset(&key, 0,
sizeof(MDB_val));
493 rc = mdb_cursor_get(cursor, &key, &data, MDB_FIRST);
496 if (rc == MDB_NOTFOUND) {
498 mdb_cursor_close(cursor);
499 callback(NULL, context, xctx);
502 mdb_cursor_close(cursor);
504 "Error getting cursor for primary database.", xctx);
509 raw.ptr = data.mv_data;
510 raw.size = data.mv_size;
511 rawKey.ptr = key.mv_data;
512 rawKey.size = key.mv_size;
518 afw_lmdb_internal_get_key(&rawKey, &object_type, &uuid);
519 if (object_type.len == 0) {
529 session->adaptor->ubjson, &raw, NULL, &session->adaptor->pub.adaptor_id,
530 &object_type, object_id,
true, obj_p, xctx);
533 if (object_type_id) {
536 mdb_cursor_close(cursor);
538 callback(NULL, context, xctx);
548 &object_type, object_id, xctx);
551 abandon = callback(
object, context, xctx);
554 }
while (!abandon && mdb_cursor_get(cursor, &key, &data, MDB_NEXT) == 0);
556 mdb_cursor_close(cursor);
557 callback(NULL, context, xctx);
565 impl_afw_adaptor_session_get_journal_interface(
601 return self->indexer;
611 impl_afw_adaptor_session_get_object_type_cache_interface(
Adaptive Framework Core API.
Helpers for adaptor implementation development.
Helpers for afw_adaptor implementation index development.
Interface afw_interface implementation declares.
afw_lmdb_adaptor_session_t * afw_lmdb_adaptor_session_create(afw_lmdb_adaptor_t *adaptor, afw_xctx_t *xctx)
Internal create a LMDB adaptor session.
Adaptive Framework register generated (afw_lmdb) header.
Helpers for afw_adaptor implementation index development.
Adaptive Framework LMDB Adaptor Internal Header.
afw_lmdb_transaction_t * afw_lmdb_transaction_create(afw_lmdb_adaptor_session_t *session, afw_xctx_t *xctx)
Internal create a LMDB adaptor transaction.
#define AFW_LMDB_END_TRANSACTION()
End an LMDB transaction.
#define AFW_LMDB_BEGIN_TRANSACTION(adaptor, session, flags, exclusive, xctx)
Begin an LMDB transaction.
afw_lmdb_journal_t * afw_lmdb_journal_create(afw_lmdb_adaptor_session_t *session, afw_xctx_t *xctx)
Internal create a LMDB adaptor journal.
afw_lmdb_key_value_t * afw_lmdb_key_value_create(afw_lmdb_adaptor_session_t *session, afw_xctx_t *xctx)
Internal create a LMDB adaptor key/value.
#define AFW_LMDB_COMMIT_TRANSACTION()
Commit a transaction.
afw_adaptor_impl_generic_object_type_object_get(const afw_adaptor_t *adaptor, const afw_utf8_t *object_type_id, const afw_pool_t *p, afw_xctx_t *xctx)
Create a generic object type object.
void impl_afw_adaptor_session_modify_object(const afw_adaptor_session_t *instance, const afw_adaptor_impl_request_t *impl_request, const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, const afw_adaptor_modify_entry_t *const *entry, const afw_object_t *adaptor_type_specific, afw_xctx_t *xctx)
void impl_afw_adaptor_session_replace_object(const afw_adaptor_session_t *instance, const afw_adaptor_impl_request_t *impl_request, const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, const afw_object_t *replacement_object, const afw_object_t *adaptor_type_specific, afw_xctx_t *xctx)
void impl_afw_adaptor_session_delete_object(const afw_adaptor_session_t *instance, const afw_adaptor_impl_request_t *impl_request, const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, const afw_object_t *adaptor_type_specific, afw_xctx_t *xctx)
void impl_afw_adaptor_session_retrieve_objects(const afw_adaptor_session_t *instance, const afw_adaptor_impl_request_t *impl_request, const afw_utf8_t *object_type_id, const afw_query_criteria_t *criteria, void *context, afw_object_cb_t callback, const afw_object_t *adaptor_type_specific, const afw_pool_t *p, afw_xctx_t *xctx)
const afw_adaptor_transaction_t * impl_afw_adaptor_session_begin_transaction(const afw_adaptor_session_t *instance, afw_xctx_t *xctx)
void impl_afw_adaptor_session_destroy(const afw_adaptor_session_t *instance, afw_xctx_t *xctx)
const afw_adaptor_impl_index_t * impl_afw_adaptor_session_get_index_interface(const afw_adaptor_session_t *instance, afw_xctx_t *xctx)
const afw_utf8_t * impl_afw_adaptor_session_add_object(const afw_adaptor_session_t *instance, const afw_adaptor_impl_request_t *impl_request, const afw_utf8_t *object_type_id, const afw_utf8_t *suggested_object_id, const afw_object_t *object, const afw_object_t *adaptor_type_specific, afw_xctx_t *xctx)
void impl_afw_adaptor_session_get_object(const afw_adaptor_session_t *instance, const afw_adaptor_impl_request_t *impl_request, const afw_utf8_t *object_type_id, const afw_utf8_t *object_id, void *context, afw_object_cb_t callback, const afw_object_t *adaptor_type_specific, const afw_pool_t *p, afw_xctx_t *xctx)
const afw_adaptor_key_value_t * impl_afw_adaptor_session_get_key_value_interface(const afw_adaptor_session_t *instance, afw_xctx_t *xctx)
afw_adaptor_modify_entries_apply_to_unnormalized_object(const afw_adaptor_modify_entry_t *const *entries, const afw_object_t *object, afw_xctx_t *xctx)
Apply modify entries to an unnormalized object.
#define afw_value_is_object(A_VALUE)
Macro to determine if value is evaluated object.
afw_value_as_object(const afw_value_t *value, afw_xctx_t *xctx)
Typesafe cast of data type object.
#define AFW_UTF8_FMT_ARG(A_STRING)
Convenience Macro for use with AFW_UTF8_FMT to specify arg.
afw_boolean_t(* afw_object_cb_t)(const afw_object_t *object, void *context, afw_xctx_t *xctx)
Typedef for afw_adaptor_session_object callback.
#define AFW_UTF8_FMT
Format string specifier used for afw_utf8_t.
#define afw_content_type_raw_to_object(instance, raw, source_location, adaptor_id, object_type_id, object_id, cede_p, p, xctx)
Call method raw_to_object of interface afw_content_type.
#define AFW_CATCH_UNHANDLED
Catch an unhandled error that occurs in a AFW_TRY block.
#define AFW_THROW_ERROR_RV_Z(code, rv_source_id, rv, message_z, xctx)
Macro used to set error and rv in xctx and throw it.
#define AFW_ENDTRY
Ends an AFW try block.
#define AFW_TRY
Begin an AFW TRY block.
#define AFW_THROW_ERROR_FZ(code, xctx, format_z,...)
Macro used to set error and 0 rv in xctx and throw it.
#define AFW_MARK_UNHANDLED
Use in an AFW_CATCH or AFW_CATCH_UNHANDLED block to mark error as unhandled and break.
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
#define AFW_CATCH(__CODE_)
Catch a particular error that occurs in a AFW_TRY block.
#define afw_object_release(instance, xctx)
Call method release of interface afw_object.
afw_object_create_clone(const afw_object_t *object, const afw_pool_t *p, afw_xctx_t *xctx)
Clone an object to a specified pool.
#define afw_pool_release(instance, xctx)
Call method release of interface afw_pool.
const afw_pool_t * afw_pool_create(const afw_pool_t *parent, afw_xctx_t *xctx)
Create a new pool.
afw_query_criteria_test_object(const afw_object_t *obj, const afw_query_criteria_t *criteria, const afw_pool_t *p, afw_xctx_t *xctx)
Test object against query criteria.
afw_boolean_t afw_utf8_equal(const afw_utf8_t *s1, const afw_utf8_t *s2)
Check to see if a string equals another string.
afw_uuid_from_utf8(const afw_utf8_t *s, const afw_pool_t *p, afw_xctx_t *xctx)
Convert standard format UUID utf-8 string to uuid.
afw_uuid_create(const afw_pool_t *p, afw_xctx_t *xctx)
Create a UUID.
afw_uuid_to_utf8(const afw_uuid_t *uuid, const afw_pool_t *p, afw_xctx_t *xctx)
Convert uuid to a standard format UUID utf-8 string.
#define afw_xctx_calloc_type(type, xctx)
Macro to allocate cleared memory to hold type in xctx's pool.
Interface afw_adaptor_impl_index public struct.
Internal request info used by afw_adaptor_impl*() functions.
Interface afw_adaptor_journal public struct.
Interface afw_adaptor_key_value public struct.
Interface afw_adaptor_object_type_cache public struct.
Interface afw_adaptor public struct.
Interface afw_adaptor_session public struct.
Interface afw_adaptor_transaction public struct.
Struct for memory pointer and size.
Interface afw_object public struct.
Interface afw_pool public struct.
NFC normalized UTF-8 string.
Interface afw_value public struct.
Interface afw_xctx public struct.