← Back to Stormify Documentation

StormifyJ

class StormifyJ(dataSource: DataSource, registrars: EntityRegistrar)

Java-facing wrapper around Stormify. Exposes all CRUD, query, and transaction operations as idiomatic Java methods: takes Class<T> parameters (instead of Kotlin KClass<T>), returns Java collections, and accepts Consumer<T> / Runnable in place of Kotlin lambdas.

Construct directly from a javax.sql.DataSource:

StormifyJ stormify = new StormifyJ(hikariDataSource);
stormify.asDefault();

From Kotlin code, prefer Stormify directly — this wrapper exists for Java consumers.

Constructors

Link copied to clipboard
constructor(dataSource: DataSource, vararg registrars: EntityRegistrar)
constructor(jdbcDataSource: DataSource, vararg registrars: EntityRegistrar)

Convenience constructor that accepts any javax.sql.DataSource (HikariCP, plain JDBC driver, etc.).

Types

Link copied to clipboard
object Companion

Accessors for the library-wide default StormifyJ wrapper.

Properties

Link copied to clipboard

Whether strict mapping mode is enabled. See Stormify.isStrictMode.

Link copied to clipboard
var logger: Logger

The logger used by the underlying Stormify instance.

Link copied to clipboard
Link copied to clipboard

The auto-detected SQL dialect for this data source. See Stormify.sqlDialect.

Functions

Link copied to clipboard
Link copied to clipboard

Registers the underlying Stormify instance as the library-wide default and caches this wrapper in StormifyJ.getDefault, so Java callers can retrieve the Java-friendly wrapper (not just the raw Stormify) via a single static call. Returns this wrapper for fluent chaining.

Runs block with this wrapper as the default, restoring the previous default when the block exits. Use for scoped overrides such as per-request tenants.

fun <R> asDefault(block: Function<StormifyJ, R>): R

Returning variant of asDefault — see the Consumer overload for semantics.

Link copied to clipboard
fun <T : StormifyAware> attach(target: T): T

Attaches the underlying Stormify instance to target so the target can use it for database operations without receiving it as an explicit parameter.

Link copied to clipboard
fun <T : Any> create(item: T): T

Inserts item into its mapped table and returns the (possibly key-populated) entity.

fun <T : Any> create(items: Collection<T>): List<T>

Batch INSERT of items in a single round trip.

Link copied to clipboard
fun delete(deletedItem: Any)

DELETE's the row corresponding to deletedItem using its primary key.

fun <T : Any> delete(items: Collection<T>)

Batch DELETE of items.

Link copied to clipboard
fun executeUpdate(query: String, vararg params: Any?): Int

Executes an INSERT / UPDATE / DELETE and returns the affected row count.

Link copied to clipboard
fun <T : Any> findAll(baseClass: Class<T>, whereClause: String = "", vararg arguments: Any?): List<T>

Convenience over read for SELECT * FROM <table> <whereClause>.

Link copied to clipboard
fun <T : Any> findById(baseClass: Class<T>, id: Any): T?

Looks up a single row of baseClass by its primary key id. Returns null if not found.

Link copied to clipboard
fun <M : Any, T : Any> getDetails(parent: M, detailsClass: Class<T>, propertyName: String? = null): List<T>

Returns the detail rows of type detailsClass that reference parent. Use propertyName to disambiguate when the detail class has multiple foreign keys pointing at the same parent type.

fun <M : Any, T : Any> getDetails(parent: M, detailsClass: Class<T>, referenceField: ReferencePath): List<T>

Type-safe variant of getDetails that accepts an annotation-processor-generated reference path (e.g. Paths.AuditEntry_.createdBy()) instead of a string. The compiler guarantees the referenced property exists on the child type, so typos and renames surface at build time rather than on first query.

Link copied to clipboard
fun getTableInfo(baseClass: Class<*>): TableInfo<Any?>

Returns the TableInfo metadata for baseClass, building it on first access.

Link copied to clipboard
fun <T : Any> populate(entity: T): T

Populates entity from the database by its primary key. Used internally by AutoTable.

Link copied to clipboard
fun procedure(name: String, vararg args: Any?)

Invokes the stored procedure name with args. Output and bidirectional parameters should be passed as Sp.Out / Sp.InOut instances; all other values are auto-wrapped as IN.

Link copied to clipboard
fun <T : Any> read(baseClass: Class<T>, query: String, vararg params: Any?): List<T>

Executes a SELECT and returns the rows as a list of baseClass instances.

Link copied to clipboard
fun <T : Any> readCursor(baseClass: Class<T>, query: String, consumer: Consumer<T>, vararg params: Any?): Int

Executes a SELECT and streams each row to consumer — avoids materializing the full result.

Link copied to clipboard
fun <T : Any> readOne(baseClass: Class<T>, query: String, vararg params: Any?): T?

Executes a SELECT and returns the first row as a baseClass instance, or null if empty.

Link copied to clipboard
Link copied to clipboard

Runs block inside a database transaction. On return the transaction commits; on any exception it rolls back. All operations inside block share the same connection.

Link copied to clipboard
fun <T : Any> update(updatedItem: T): T

UPDATE's the row corresponding to updatedItem using its primary key.

fun <T : Any> update(items: Collection<T>): List<T>

Batch UPDATE of items.