Package org.machanism.machai.bindex
Class BindexRepository
java.lang.Object
org.machanism.machai.bindex.BindexRepository
MongoDB-backed repository for persisting and retrieving
Bindex
documents.
The repository stores the serialized Bindex JSON in a dedicated field (see
BINDEX_PROPERTY_NAME) and provides helper operations commonly needed
by higher-level components such as Picker and tool integrations.
Connection details are resolved from configuration/environment:
- When
BINDEX_REPO_URLis configured, it is used as the MongoDB connection URI. - Otherwise a default cluster URI is used, with credentials optionally
sourced from
BINDEX_REG_PASSWORD.
- Since:
- 0.0.2
- Author:
- Viktor Tovstyi
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBindexRepository(com.mongodb.client.MongoCollection<org.bson.Document> collection) Creates a repository using an existing collection.BindexRepository(Configurator config) Creates a repository instance backed by a MongoDB collection. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the underlyingMongoClientif this repository created it.deleteBindex(Bindex bindex) Deletes a Bindex document from the database.(package private) org.bson.DocumentfindFirst(org.bson.conversions.Bson filter) Single overridable seam for querying the first matching document.(package private) org.bson.DocumentfindFirst(org.bson.Document filter) Retrieves aBindexinstance from the database by its Bindex id.static com.mongodb.client.MongoCollection<org.bson.Document> getCollection(Configurator config) Provides direct access to the underlying MongoDB collection.getRegistredId(Bindex bindex) Looks up the registered database ID for a Bindex (if it exists).
-
Field Details
-
BINDEX_PROPERTY_NAME
MongoDB field name used to store the serialized Bindex JSON payload.- See Also:
-
BINDEX_SCHEMA_RESOURCE
- See Also:
-
DB_URL
- See Also:
-
BINDEX_REG_PASSWORD_PROP_NAME
- See Also:
-
-
Constructor Details
-
BindexRepository
Creates a repository instance backed by a MongoDB collection.- Parameters:
config- configurator used to resolveBINDEX_REPO_URL- Throws:
IllegalArgumentException- ifconfigisnull
-
BindexRepository
BindexRepository(com.mongodb.client.MongoCollection<org.bson.Document> collection) Creates a repository using an existing collection.Package-private constructor used for tests to avoid MongoDB driver initialization.
-
-
Method Details
-
getCollection
public static com.mongodb.client.MongoCollection<org.bson.Document> getCollection(Configurator config) Provides direct access to the underlying MongoDB collection.Used by components such as
Pickerwhich operate on aggregation pipelines and need the rawMongoCollection.- Parameters:
config- configurator (kept for backward compatibility with callers)- Returns:
- MongoDB collection handle
-
close
public void close()Closes the underlyingMongoClientif this repository created it.This allows callers to use try-with-resources:
try (BindexRepository repo = new BindexRepository(config)) { ... } -
getRegistredId
Looks up the registered database ID for a Bindex (if it exists).- Parameters:
bindex- Bindex instance- Returns:
- MongoDB object id as string, or
nullif not present - Throws:
IllegalArgumentException- ifbindexisnull
-
getBindex
Retrieves aBindexinstance from the database by its Bindex id.- Parameters:
id- Bindex id (theidfield in the stored document)- Returns:
- parsed
Bindex, ornullif not present - Throws:
IllegalArgumentException- ifidisnullor the stored JSON cannot be parsed
-
deleteBindex
Deletes a Bindex document from the database.- Parameters:
bindex- Bindex to delete (byBindex.getId())- Returns:
- the deleted Bindex id
- Throws:
IllegalArgumentException- ifbindexisnull
-
findFirst
org.bson.Document findFirst(org.bson.conversions.Bson filter) Single overridable seam for querying the first matching document. -
findFirst
org.bson.Document findFirst(org.bson.Document filter)
-