API Reference

Table of contents

  1. config
    1. JaloquentConfig
  2. exception
    1. JaloquentException (base)
    2. StorageException
    3. ValidationException
    4. ModelNotFoundException
  3. model
    1. BaseModel (abstract)
    2. Model (abstract, extends BaseModel)
      1. Attribute access
      2. Mass-assignment
      3. Persistence shortcuts
    3. Fillable
    4. ModelRepository<T extends BaseModel>
      1. Constructors
      2. Operations
    5. TableRegistry
    6. ModelFactory<T> (functional interface)
    7. PivotModel (final, extends Model)
    8. Factory<T extends Model> (abstract)
    9. FactoryCount<T> (final)
    10. HasFactory (marker interface)
  4. relation
    1. HasOne<T> (final)
    2. HasMany<T> (final)
    3. BelongsTo<T> (final)
    4. BelongsToMany<T, P> (final)
  5. repository
    1. Repository<T, ID> (interface)
    2. AbstractRepository<T, ID> (abstract, implements Repository)
  6. store
    1. DataStore (interface)
    2. JdbcStore (interface, extends DataStore)

config

JaloquentConfig

Static configuration — all members are static.

Method Type Description
enableLogging(boolean) void Toggle SLF4J logging on / off globally
isLoggingEnabled() boolean Query the current logging state
setLogger(Logger) void Inject a custom SLF4J logger
getLogger(Class<?>) Logger Returns active logger; null if logging is disabled
enableMetrics(boolean) void Toggle Micrometer metrics on / off globally
isMetricsEnabled() boolean Query the current metrics state
setMeterRegistry(MeterRegistry) void Inject a custom MeterRegistry
getMeterRegistry() MeterRegistry Returns active registry; null if metrics are disabled

exception

JaloquentException (base)

Constructor Description
JaloquentException(String message) Simple message
JaloquentException(String message, Throwable cause) Wraps another exception
JaloquentException(Throwable cause) Re-throws

StorageException

Extends JaloquentException. Same three constructors. Thrown on persistence / I/O failures.

ValidationException

Extends JaloquentException. Same three constructors. Thrown on semantic validation failures.

ModelNotFoundException

Extends JaloquentException. Same three constructors. Thrown when a required lookup returns no result.


model

BaseModel (abstract)

Member Description
BaseModel(String id) Protected constructor
getId() Return the primary key
setId(String id) Set the primary key
getStoragePath(String prefix) Returns prefix/id; bare id when prefix is blank
abstract toMap() Serialize state to Map<String, Object>
abstract fromMap(Map<String,Object>) Populate state from flat map

Model (abstract, extends BaseModel)

Attribute access

Method Returns Description
set(String key, Object value) Model Set one attribute; "id" key routes to setId
get(String key) Object Get raw attribute value; "id" routes to getId
getAs(String key, Class<T>) T Type-coercing get; null when absent or unconvertible
getAs(String key, Class<T>, T def) T Same; returns def instead of null
attributes() Map<String, Object> Unmodifiable snapshot of the attribute map
toMap() Map<String, Object> Mutable copy of all attributes
fromMap(Map<String,Object>) void Populate attributes; "id" key updates id field

Mass-assignment

Method Returns Description
setFillable(String... keys) void Declare mass-assignable keys
setGuarded(String... keys) void Declare blocked keys
getFillable() Set<String> Unmodifiable fillable set
getGuarded() Set<String> Unmodifiable guarded set
fill(Map<String,Object>) void Permissive mass-assign; respects guarded; id always blocked
update(Map<String,Object>) void Strict mass-assign; only explicitly-declared fillable keys

Persistence shortcuts

Method Returns Description
save(ModelRepository<T>) Model Upsert via repo; returns this for chaining
delete(ModelRepository<T>) void Delete by current id via repo
static find(ModelRepository<T>, String id) T Look up by id; null if not found
static queryBuilder() QueryBuilder New QueryBuilder instance

Relation factories (protected, call from subclass methods)

Method Returns Description
hasOne(repo, foreignKey) HasOne<T> FK on related model; local key defaults to "id"
hasOne(repo, foreignKey, localKey) HasOne<T> FK on related model; explicit local key
hasMany(repo, foreignKey) HasMany<T> FK on related model; local key defaults to "id"
hasMany(repo, foreignKey, localKey) HasMany<T> FK on related model; explicit local key
belongsTo(repo, foreignKey) BelongsTo<T> FK on this model pointing to related model’s PK
belongsToMany(relatedRepo, pivotRepo, pivotFactory, foreignKey, relatedKey) BelongsToMany<T,P> Many-to-many via pivot

Fillable

Method Returns Description
setFillable(String... keys) void Replace fillable set
setGuarded(String... keys) void Replace guarded set
getFillable() Set<String> Unmodifiable fillable set
getGuarded() Set<String> Unmodifiable guarded set
isFillable(String key) boolean Permissive check (id always false)
isExplicitlyFillable(String key) boolean Strict check (id always false)

ModelRepository<T extends BaseModel>

Constructors

Constructor Description
ModelRepository(store, prefix, factory) Uses SqlDialect.STANDARD
ModelRepository(store, prefix, factory, dialect) Explicit SQL dialect

Operations

Method Returns Description
save(T model) void Upsert
find(String id) Optional<T> Look up by primary key
exists(String id) boolean Check existence
delete(String id) void Delete by primary key
query(Query q) List<T> Parameterized SELECT
deleteWhere(String column, Object value) void DELETE WHERE column = ?
deleteWhere(Query q) void DELETE matching query conditions
deleteAll(List<String> ids) void Bulk DELETE WHERE id IN (…)
deleteWhereInSubquery(String column, Query sub) void DELETE WHERE column IN (subquery) — SQL only
deleteWhereExists(Query sub) void DELETE WHERE EXISTS (subquery) — SQL only

TableRegistry

Method Returns Description
static register(String prefix, String tableName, Map<String,String> columns) void Register or overwrite table entry
static get(String prefix) TableMeta Returns metadata; null if absent
static all() Map<String, TableMeta> Unmodifiable view of all entries

TableRegistry.TableMeta

Method Returns Description
tableName() String SQL table name
columns() Map<String, String> Unmodifiable column name → SQL type map

ModelFactory<T> (functional interface)

T create(String id, Map<String, Object> data);

Lambda factory used in ModelRepository constructor to reconstruct model instances from persisted data.


PivotModel (final, extends Model)

Member Description
static final ModelFactory<PivotModel> FACTORY Pre-built factory constant
PivotModel(String id) Construct by id
toMap() Mutable copy of all attributes
fromMap(Map<String,Object>) Applies all entries via set()

Factory<T extends Model> (abstract)

Method Returns Description
Factory() Auto-discovers model class; en-US Jaker
Factory(Faker) Custom Jaker; auto-discovers model class
Factory(Class<T>) Explicit model class; default Jaker
Factory(Faker, Class<T>) Explicit both
abstract definition(Faker) Map<String, Object> Return fake attributes for one instance
state(Map<String,Object>) Factory<T> Merge attribute overrides; chainable
count(int) FactoryCount<T> Switch to batch mode
make() T Build one transient model
make(int) List<T> Build N transient models
create(ModelRepository<T>) T Build + persist one model
create(int, ModelRepository<T>) List<T> Build + persist N models
static discover(Class<M>) Factory<M> Locate and instantiate MFactory by naming convention

FactoryCount<T> (final)

Method Returns Description
make() List<T> Build N transient models
create(ModelRepository<T>) List<T> Build + persist N models

HasFactory (marker interface)

Implement on a model to signal that a corresponding Factory class exists. No methods — purely a marker.


relation

HasOne<T> (final)

Method Returns Description
where(String column, Object value) HasOne<T> Add WHERE equals constraint
orderBy(String column, boolean asc) HasOne<T> Sort for deterministic row selection
get() Optional<T> Execute; returns first match
exists() boolean True if at least one related record exists

HasMany<T> (final)

Method Returns Description
where(String column, Object value) HasMany<T> Add WHERE equals constraint
orderBy(String column, boolean asc) HasMany<T> Sort results
limit(int n) HasMany<T> Cap result count
get() List<T> Execute; returns all matching records
count() long Number of matching related records

BelongsTo<T> (final)

Method Returns Description
get() Optional<T> Look up related model using FK value
exists() boolean True if FK is set and related record exists

BelongsToMany<T, P> (final)

Method Returns Description
where(String column, Object value) BelongsToMany<T,P> Add constraint on related model query
orderBy(String column, boolean asc) BelongsToMany<T,P> Sort related models
get() List<T> Resolve pivot rows, then load related models
attach(String relatedId) void Create pivot entry
attach(String relatedId, Map<String,Object> extra) void Create pivot entry with extra columns
detach(String relatedId) void Delete pivot entry
detachAll() void Bulk delete all pivot rows for this parent
sync(List<String> desiredIds) void Attach missing, detach removed; single bulk DELETE
count() long Number of related records through pivot

repository

Repository<T, ID> (interface)

Method Returns Description
find(ID id) Optional<T> Look up by primary key
findAll() List<T> Return all persisted entities
save(T entity) void Persist or update
delete(ID id) void Remove by primary key

AbstractRepository<T, ID> (abstract, implements Repository)

Convenience base backed by DataStore with SLF4J + Micrometer instrumentation.

Implement in subclass:

Method Returns Description
toMap(T entity) Map<String, Object> Serialize
fromMap(Map<String,Object>) T Deserialize
extractId(T entity) ID Extract the primary key

Protected accessor:

Method Returns Description
store() DataStore The underlying data store

store

DataStore (interface)

Method Returns Description
save(String path, Map<String,Object> data) void Write / overwrite entry at path
load(String path) Optional<Map<String,Object>> Read entry
delete(String path) void Remove entry (no-op if absent)
exists(String path) boolean Existence check

JdbcStore (interface, extends DataStore)

Method Returns Description
query(String sql, List<Object> params) List<Map<String,Object>> Parameterized SELECT
executeUpdate(String sql, List<Object> params) int Parameterized INSERT / UPDATE / DELETE; returns affected row count