Finish DocEx declarations
This commit is contained in:
parent
ca8c8e79de
commit
7e91a7b73f
@ -84,7 +84,9 @@ fun <T : Any> Connection.customScalar(
|
||||
* Create a document table if necessary
|
||||
*
|
||||
* @param tableName The table whose existence should be ensured (may include schema)
|
||||
* @throws DocumentException If the dialect is not configured
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
fun Connection.ensureTable(tableName: String) =
|
||||
Definition.ensureTable(tableName, this)
|
||||
|
||||
@ -94,7 +96,9 @@ fun Connection.ensureTable(tableName: String) =
|
||||
* @param tableName The table to be indexed (may include schema)
|
||||
* @param indexName The name of the index to create
|
||||
* @param fields One or more fields to be indexed<
|
||||
* @throws DocumentException If any dependent process does
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
fun Connection.ensureFieldIndex(tableName: String, indexName: String, fields: Collection<String>) =
|
||||
Definition.ensureFieldIndex(tableName, indexName, fields, this)
|
||||
|
||||
@ -116,7 +120,9 @@ fun Connection.ensureDocumentIndex(tableName: String, indexType: DocumentIndex)
|
||||
*
|
||||
* @param tableName The table into which the document should be inserted (may include schema)
|
||||
* @param document The document to be inserted
|
||||
* @throws DocumentException If IDs are misconfigured, or if the database command fails
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
fun <TDoc> Connection.insert(tableName: String, document: TDoc) =
|
||||
Document.insert(tableName, document, this)
|
||||
|
||||
@ -125,7 +131,9 @@ fun <TDoc> Connection.insert(tableName: String, document: TDoc) =
|
||||
*
|
||||
* @param tableName The table in which the document should be saved (may include schema)
|
||||
* @param document The document to be saved
|
||||
* @throws DocumentException If the database command fails
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
fun <TDoc> Connection.save(tableName: String, document: TDoc) =
|
||||
Document.save(tableName, document, this)
|
||||
|
||||
@ -135,7 +143,9 @@ fun <TDoc> Connection.save(tableName: String, document: TDoc) =
|
||||
* @param tableName The table in which the document should be replaced (may include schema)
|
||||
* @param docId The ID of the document to be replaced
|
||||
* @param document The document to be replaced
|
||||
* @throws DocumentException If no dialect has been configured, or if the database command fails
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
fun <TKey, TDoc> Connection.update(tableName: String, docId: TKey, document: TDoc) =
|
||||
Document.update(tableName, docId, document, this)
|
||||
|
||||
@ -198,7 +208,9 @@ fun Connection.countByJsonPath(tableName: String, path: String) =
|
||||
* @param tableName The name of the table in which document existence should be checked
|
||||
* @param docId The ID of the document to be checked
|
||||
* @return True if the document exists, false if not
|
||||
* @throws DocumentException If no dialect has been configured
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
fun <TKey> Connection.existsById(tableName: String, docId: TKey) =
|
||||
Exists.byId(tableName, docId, this)
|
||||
|
||||
@ -209,7 +221,9 @@ fun <TKey> Connection.existsById(tableName: String, docId: TKey) =
|
||||
* @param fields The fields which should be compared
|
||||
* @param howMatched How the fields should be matched
|
||||
* @return True if any matching documents exist, false if not
|
||||
* @throws DocumentException If no dialect has been configured, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmOverloads
|
||||
fun Connection.existsByFields(tableName: String, fields: Collection<Field<*>>, howMatched: FieldMatch? = null) =
|
||||
Exists.byFields(tableName, fields, howMatched, this)
|
||||
@ -247,7 +261,9 @@ fun Connection.existsByJsonPath(tableName: String, path: String) =
|
||||
* @param clazz The class of the document to be returned
|
||||
* @param orderBy Fields by which the query should be ordered (optional, defaults to no ordering)
|
||||
* @return A list of documents from the given table
|
||||
* @throws DocumentException If query execution fails
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmOverloads
|
||||
fun <TDoc> Connection.findAll(tableName: String, clazz: Class<TDoc>, orderBy: Collection<Field<*>>? = null) =
|
||||
Find.all(tableName, clazz, orderBy, this)
|
||||
@ -259,7 +275,9 @@ fun <TDoc> Connection.findAll(tableName: String, clazz: Class<TDoc>, orderBy: Co
|
||||
* @param docId The ID of the document to retrieve
|
||||
* @param clazz The class of the document to be returned
|
||||
* @return The document if it is found, `null` otherwise
|
||||
* @throws DocumentException If no dialect has been configured
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
fun <TKey, TDoc> Connection.findById(tableName: String, docId: TKey, clazz: Class<TDoc>) =
|
||||
Find.byId(tableName, docId, clazz, this)
|
||||
|
||||
@ -272,7 +290,9 @@ fun <TKey, TDoc> Connection.findById(tableName: String, docId: TKey, clazz: Clas
|
||||
* @param howMatched How the fields should be matched
|
||||
* @param orderBy Fields by which the query should be ordered (optional, defaults to no ordering)
|
||||
* @return A list of documents matching the field comparison
|
||||
* @throws DocumentException If no dialect has been configured, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmOverloads
|
||||
fun <TDoc> Connection.findByFields(
|
||||
tableName: String,
|
||||
@ -332,6 +352,7 @@ fun <TDoc> Connection.findByJsonPath(
|
||||
* @param howMatched How the fields should be matched (optional, defaults to `FieldMatch.ALL`)
|
||||
* @param orderBy Fields by which the query should be ordered (optional, defaults to no ordering)
|
||||
* @return The first document matching the field comparison, or `null` if no matches are found
|
||||
* @throws DocumentException If no dialect has been configured, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmOverloads
|
||||
@ -392,7 +413,9 @@ fun <TDoc> Connection.findFirstByJsonPath(
|
||||
* @param tableName The name of the table in which a document should be patched
|
||||
* @param docId The ID of the document to be patched
|
||||
* @param patch The object whose properties should be replaced in the document
|
||||
* @throws DocumentException If no dialect has been configured
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
fun <TKey, TPatch> Connection.patchById(tableName: String, docId: TKey, patch: TPatch) =
|
||||
Patch.byId(tableName, docId, patch, this)
|
||||
|
||||
@ -403,7 +426,9 @@ fun <TKey, TPatch> Connection.patchById(tableName: String, docId: TKey, patch: T
|
||||
* @param fields The fields which should be compared
|
||||
* @param patch The object whose properties should be replaced in the document
|
||||
* @param howMatched How the fields should be matched
|
||||
* @throws DocumentException If no dialect has been configured, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
fun <TPatch> Connection.patchByFields(
|
||||
tableName: String,
|
||||
fields: Collection<Field<*>>,
|
||||
@ -448,7 +473,9 @@ fun <TPatch> Connection.patchByJsonPath(tableName: String, path: String, patch:
|
||||
* @param tableName The name of the table in which the document's fields should be removed
|
||||
* @param docId The ID of the document to have fields removed
|
||||
* @param toRemove The names of the fields to be removed
|
||||
* @throws DocumentException If no dialect has been configured
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
fun <TKey> Connection.removeFieldsById(tableName: String, docId: TKey, toRemove: Collection<String>) =
|
||||
RemoveFields.byId(tableName, docId, toRemove, this)
|
||||
|
||||
@ -459,7 +486,9 @@ fun <TKey> Connection.removeFieldsById(tableName: String, docId: TKey, toRemove:
|
||||
* @param fields The fields which should be compared
|
||||
* @param toRemove The names of the fields to be removed
|
||||
* @param howMatched How the fields should be matched
|
||||
* @throws DocumentException If no dialect has been configured, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
fun Connection.removeFieldsByFields(
|
||||
tableName: String,
|
||||
fields: Collection<Field<*>>,
|
||||
@ -503,7 +532,9 @@ fun Connection.removeFieldsByJsonPath(tableName: String, path: String, toRemove:
|
||||
*
|
||||
* @param tableName The name of the table from which documents should be deleted
|
||||
* @param docId The ID of the document to be deleted
|
||||
* @throws DocumentException If no dialect has been configured
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
fun <TKey> Connection.deleteById(tableName: String, docId: TKey) =
|
||||
Delete.byId(tableName, docId, this)
|
||||
|
||||
@ -513,7 +544,9 @@ fun <TKey> Connection.deleteById(tableName: String, docId: TKey) =
|
||||
* @param tableName The name of the table from which documents should be deleted
|
||||
* @param fields The fields which should be compared
|
||||
* @param howMatched How the fields should be matched
|
||||
* @throws DocumentException If no dialect has been configured, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmOverloads
|
||||
fun Connection.deleteByFields(tableName: String, fields: Collection<Field<*>>, howMatched: FieldMatch? = null) =
|
||||
Delete.byFields(tableName, fields, howMatched, this)
|
||||
@ -536,5 +569,6 @@ fun <TContains> Connection.deleteByContains(tableName: String, criteria: TContai
|
||||
* @param path The JSON path comparison to match
|
||||
* @throws DocumentException If called on a SQLite connection
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
fun Connection.deleteByJsonPath(tableName: String, path: String) =
|
||||
Delete.byJsonPath(tableName, path, this)
|
||||
|
@ -4,6 +4,7 @@ import solutions.bitbadger.documents.*
|
||||
import solutions.bitbadger.documents.extensions.customNonQuery
|
||||
import solutions.bitbadger.documents.query.DeleteQuery
|
||||
import java.sql.Connection
|
||||
import kotlin.jvm.Throws
|
||||
|
||||
/**
|
||||
* Functions to delete documents
|
||||
@ -16,7 +17,9 @@ object Delete {
|
||||
* @param tableName The name of the table from which documents should be deleted
|
||||
* @param docId The ID of the document to be deleted
|
||||
* @param conn The connection on which the deletion should be executed
|
||||
* @throws DocumentException If no dialect has been configured
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TKey> byId(tableName: String, docId: TKey, conn: Connection) =
|
||||
conn.customNonQuery(
|
||||
@ -29,7 +32,9 @@ object Delete {
|
||||
*
|
||||
* @param tableName The name of the table from which documents should be deleted
|
||||
* @param docId The ID of the document to be deleted
|
||||
* @throws DocumentException If no connection string has been set
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TKey> byId(tableName: String, docId: TKey) =
|
||||
Configuration.dbConn().use { byId(tableName, docId, it) }
|
||||
@ -41,7 +46,9 @@ object Delete {
|
||||
* @param fields The fields which should be compared
|
||||
* @param howMatched How the fields should be matched
|
||||
* @param conn The connection on which the deletion should be executed
|
||||
* @throws DocumentException If no dialect has been configured, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun byFields(tableName: String, fields: Collection<Field<*>>, howMatched: FieldMatch? = null, conn: Connection) {
|
||||
@ -55,7 +62,9 @@ object Delete {
|
||||
* @param tableName The name of the table from which documents should be deleted
|
||||
* @param fields The fields which should be compared
|
||||
* @param howMatched How the fields should be matched
|
||||
* @throws DocumentException If no connection string has been set, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun byFields(tableName: String, fields: Collection<Field<*>>, howMatched: FieldMatch? = null) =
|
||||
@ -79,7 +88,7 @@ object Delete {
|
||||
*
|
||||
* @param tableName The name of the table from which documents should be deleted
|
||||
* @param criteria The object for which JSON containment should be checked
|
||||
* @throws DocumentException If called on a SQLite connection
|
||||
* @throws DocumentException If no connection string has been set, or if called on a SQLite connection
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
@ -104,7 +113,7 @@ object Delete {
|
||||
*
|
||||
* @param tableName The name of the table from which documents should be deleted
|
||||
* @param path The JSON path comparison to match
|
||||
* @throws DocumentException If called on a SQLite connection
|
||||
* @throws DocumentException If no connection string has been set, or if called on a SQLite connection
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
|
@ -2,12 +2,14 @@ package solutions.bitbadger.documents.jvm
|
||||
|
||||
import solutions.bitbadger.documents.AutoId
|
||||
import solutions.bitbadger.documents.Configuration
|
||||
import solutions.bitbadger.documents.DocumentException
|
||||
import solutions.bitbadger.documents.Field
|
||||
import solutions.bitbadger.documents.extensions.customNonQuery
|
||||
import solutions.bitbadger.documents.query.DocumentQuery
|
||||
import solutions.bitbadger.documents.query.Where
|
||||
import solutions.bitbadger.documents.query.statementWhere
|
||||
import java.sql.Connection
|
||||
import kotlin.jvm.Throws
|
||||
|
||||
/**
|
||||
* Functions for manipulating documents
|
||||
@ -20,7 +22,9 @@ object Document {
|
||||
* @param tableName The table into which the document should be inserted (may include schema)
|
||||
* @param document The document to be inserted
|
||||
* @param conn The connection on which the query should be executed
|
||||
* @throws DocumentException If IDs are misconfigured, or if the database command fails
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TDoc> insert(tableName: String, document: TDoc, conn: Connection) {
|
||||
val strategy = Configuration.autoIdStrategy
|
||||
@ -37,7 +41,10 @@ object Document {
|
||||
*
|
||||
* @param tableName The table into which the document should be inserted (may include schema)
|
||||
* @param document The document to be inserted
|
||||
* @throws DocumentException If no connection string has been set; if IDs are misconfigured; or if the database
|
||||
* command fails
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TDoc> insert(tableName: String, document: TDoc) =
|
||||
Configuration.dbConn().use { insert(tableName, document, it) }
|
||||
@ -48,7 +55,9 @@ object Document {
|
||||
* @param tableName The table in which the document should be saved (may include schema)
|
||||
* @param document The document to be saved
|
||||
* @param conn The connection on which the query should be executed
|
||||
* @throws DocumentException If the database command fails
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TDoc> save(tableName: String, document: TDoc, conn: Connection) =
|
||||
conn.customNonQuery(DocumentQuery.save(tableName), listOf(Parameters.json(":data", document)))
|
||||
@ -58,7 +67,9 @@ object Document {
|
||||
*
|
||||
* @param tableName The table in which the document should be saved (may include schema)
|
||||
* @param document The document to be saved
|
||||
* @throws DocumentException If no connection string has been set, or if the database command fails
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TDoc> save(tableName: String, document: TDoc) =
|
||||
Configuration.dbConn().use { save(tableName, document, it) }
|
||||
@ -70,7 +81,9 @@ object Document {
|
||||
* @param docId The ID of the document to be replaced
|
||||
* @param document The document to be replaced
|
||||
* @param conn The connection on which the query should be executed
|
||||
* @throws DocumentException If no dialect has been configured, or if the database command fails
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TKey, TDoc> update(tableName: String, docId: TKey, document: TDoc, conn: Connection) =
|
||||
conn.customNonQuery(
|
||||
@ -87,7 +100,9 @@ object Document {
|
||||
* @param tableName The table in which the document should be replaced (may include schema)
|
||||
* @param docId The ID of the document to be replaced
|
||||
* @param document The document to be replaced
|
||||
* @throws DocumentException If no connection string has been set, or if the database command fails
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TKey, TDoc> update(tableName: String, docId: TKey, document: TDoc) =
|
||||
Configuration.dbConn().use { update(tableName, docId, document, it) }
|
||||
|
@ -4,6 +4,7 @@ import solutions.bitbadger.documents.*
|
||||
import solutions.bitbadger.documents.extensions.customScalar
|
||||
import solutions.bitbadger.documents.query.ExistsQuery
|
||||
import java.sql.Connection
|
||||
import kotlin.jvm.Throws
|
||||
|
||||
/**
|
||||
* Functions to determine whether documents exist
|
||||
@ -17,7 +18,9 @@ object Exists {
|
||||
* @param docId The ID of the document to be checked
|
||||
* @param conn The connection on which the existence check should be executed
|
||||
* @return True if the document exists, false if not
|
||||
* @throws DocumentException If no dialect has been configured
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TKey> byId(tableName: String, docId: TKey, conn: Connection) =
|
||||
conn.customScalar(
|
||||
@ -33,7 +36,9 @@ object Exists {
|
||||
* @param tableName The name of the table in which document existence should be checked
|
||||
* @param docId The ID of the document to be checked
|
||||
* @return True if the document exists, false if not
|
||||
* @throws DocumentException If no connection string has been set
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TKey> byId(tableName: String, docId: TKey) =
|
||||
Configuration.dbConn().use { byId(tableName, docId, it) }
|
||||
@ -46,7 +51,9 @@ object Exists {
|
||||
* @param howMatched How the fields should be matched
|
||||
* @param conn The connection on which the existence check should be executed
|
||||
* @return True if any matching documents exist, false if not
|
||||
* @throws DocumentException If no dialect has been configured, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun byFields(
|
||||
@ -71,7 +78,9 @@ object Exists {
|
||||
* @param fields The fields which should be compared
|
||||
* @param howMatched How the fields should be matched
|
||||
* @return True if any matching documents exist, false if not
|
||||
* @throws DocumentException If no connection string has been set, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun byFields(tableName: String, fields: Collection<Field<*>>, howMatched: FieldMatch? = null) =
|
||||
@ -102,7 +111,7 @@ object Exists {
|
||||
* @param tableName The name of the table in which document existence should be checked
|
||||
* @param criteria The object for which JSON containment should be checked
|
||||
* @return True if any matching documents exist, false if not
|
||||
* @throws DocumentException If called on a SQLite connection
|
||||
* @throws DocumentException If no connection string has been set, or if called on a SQLite connection
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
@ -134,7 +143,7 @@ object Exists {
|
||||
* @param tableName The name of the table in which document existence should be checked
|
||||
* @param path The JSON path comparison to match
|
||||
* @return True if any matching documents exist, false if not
|
||||
* @throws DocumentException If called on a SQLite connection
|
||||
* @throws DocumentException If no connection string has been set, or if called on a SQLite connection
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
|
@ -6,6 +6,7 @@ import solutions.bitbadger.documents.extensions.customSingle
|
||||
import solutions.bitbadger.documents.query.FindQuery
|
||||
import solutions.bitbadger.documents.query.orderBy
|
||||
import java.sql.Connection
|
||||
import kotlin.jvm.Throws
|
||||
|
||||
/**
|
||||
* Functions to find and retrieve documents
|
||||
@ -20,7 +21,9 @@ object Find {
|
||||
* @param orderBy Fields by which the query should be ordered (optional, defaults to no ordering)
|
||||
* @param conn The connection over which documents should be retrieved
|
||||
* @return A list of documents from the given table
|
||||
* @throws DocumentException If query execution fails
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TDoc> all(tableName: String, clazz: Class<TDoc>, orderBy: Collection<Field<*>>? = null, conn: Connection) =
|
||||
conn.customList(FindQuery.all(tableName) + (orderBy?.let(::orderBy) ?: ""), listOf(), clazz, Results::fromData)
|
||||
@ -32,7 +35,9 @@ object Find {
|
||||
* @param clazz The class of the document to be returned
|
||||
* @param orderBy Fields by which the query should be ordered (optional, defaults to no ordering)
|
||||
* @return A list of documents from the given table
|
||||
* @throws DocumentException If no connection string has been set, or if query execution fails
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun <TDoc> all(tableName: String, clazz: Class<TDoc>, orderBy: Collection<Field<*>>? = null) =
|
||||
@ -45,7 +50,9 @@ object Find {
|
||||
* @param clazz The class of the document to be returned
|
||||
* @param conn The connection over which documents should be retrieved
|
||||
* @return A list of documents from the given table
|
||||
* @throws DocumentException If query execution fails
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TDoc> all(tableName: String, clazz: Class<TDoc>, conn: Connection) =
|
||||
all(tableName, clazz, null, conn)
|
||||
@ -58,7 +65,9 @@ object Find {
|
||||
* @param clazz The class of the document to be returned
|
||||
* @param conn The connection over which documents should be retrieved
|
||||
* @return The document if it is found, `null` otherwise
|
||||
* @throws DocumentException If no dialect has been configured
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TKey, TDoc> byId(tableName: String, docId: TKey, clazz: Class<TDoc>, conn: Connection) =
|
||||
conn.customSingle(
|
||||
@ -75,7 +84,9 @@ object Find {
|
||||
* @param docId The ID of the document to retrieve
|
||||
* @param clazz The class of the document to be returned
|
||||
* @return The document if it is found, `null` otherwise
|
||||
* @throws DocumentException If no connection string has been set
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TKey, TDoc> byId(tableName: String, docId: TKey, clazz: Class<TDoc>) =
|
||||
Configuration.dbConn().use { byId(tableName, docId, clazz, it) }
|
||||
@ -90,7 +101,9 @@ object Find {
|
||||
* @param orderBy Fields by which the query should be ordered (optional, defaults to no ordering)
|
||||
* @param conn The connection over which documents should be retrieved
|
||||
* @return A list of documents matching the field comparison
|
||||
* @throws DocumentException If no dialect has been configured, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TDoc> byFields(
|
||||
tableName: String,
|
||||
@ -118,7 +131,9 @@ object Find {
|
||||
* @param howMatched How the fields should be matched
|
||||
* @param orderBy Fields by which the query should be ordered (optional, defaults to no ordering)
|
||||
* @return A list of documents matching the field comparison
|
||||
* @throws DocumentException If no connection string has been set, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun <TDoc> byFields(
|
||||
@ -139,7 +154,9 @@ object Find {
|
||||
* @param howMatched How the fields should be matched
|
||||
* @param conn The connection over which documents should be retrieved
|
||||
* @return A list of documents matching the field comparison
|
||||
* @throws DocumentException If no dialect has been configured, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TDoc> byFields(
|
||||
tableName: String,
|
||||
@ -185,7 +202,7 @@ object Find {
|
||||
* @param clazz The class of the document to be returned
|
||||
* @param orderBy Fields by which the query should be ordered (optional, defaults to no ordering)
|
||||
* @return A list of documents matching the JSON containment query
|
||||
* @throws DocumentException If called on a SQLite connection
|
||||
* @throws DocumentException If no connection string has been set, or if called on a SQLite connection
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
@ -248,7 +265,7 @@ object Find {
|
||||
* @param clazz The class of the document to be returned
|
||||
* @param orderBy Fields by which the query should be ordered (optional, defaults to no ordering)
|
||||
* @return A list of documents matching the JSON Path match query
|
||||
* @throws DocumentException If called on a SQLite connection
|
||||
* @throws DocumentException If no connection string has been set, or if called on a SQLite connection
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
@ -281,7 +298,9 @@ object Find {
|
||||
* @param orderBy Fields by which the query should be ordered (optional, defaults to no ordering)
|
||||
* @param conn The connection over which documents should be retrieved
|
||||
* @return The first document matching the field comparison, or `null` if no matches are found
|
||||
* @throws DocumentException If no dialect has been configured, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TDoc> firstByFields(
|
||||
tableName: String,
|
||||
@ -309,7 +328,9 @@ object Find {
|
||||
* @param howMatched How the fields should be matched (optional, defaults to `FieldMatch.ALL`)
|
||||
* @param orderBy Fields by which the query should be ordered (optional, defaults to no ordering)
|
||||
* @return The first document matching the field comparison, or `null` if no matches are found
|
||||
* @throws DocumentException If no connection string has been set, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun <TDoc> firstByFields(
|
||||
@ -330,7 +351,9 @@ object Find {
|
||||
* @param howMatched How the fields should be matched (optional, defaults to `FieldMatch.ALL`)
|
||||
* @param conn The connection over which documents should be retrieved
|
||||
* @return The first document matching the field comparison, or `null` if no matches are found
|
||||
* @throws DocumentException If no dialect has been configured, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TDoc> firstByFields(
|
||||
tableName: String,
|
||||
@ -395,7 +418,7 @@ object Find {
|
||||
* @param clazz The class of the document to be returned
|
||||
* @param orderBy Fields by which the query should be ordered (optional, defaults to no ordering)
|
||||
* @return The first document matching the JSON containment query, or `null` if no matches are found
|
||||
* @throws DocumentException If called on a SQLite connection
|
||||
* @throws DocumentException If no connection string has been set, or if called on a SQLite connection
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
@ -458,7 +481,7 @@ object Find {
|
||||
* @param clazz The class of the document to be returned
|
||||
* @param orderBy Fields by which the query should be ordered (optional, defaults to no ordering)
|
||||
* @return The first document matching the JSON Path match query, or `null` if no matches are found
|
||||
* @throws DocumentException If called on a SQLite connection
|
||||
* @throws DocumentException If no connection string has been set, or if called on a SQLite connection
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
|
@ -4,6 +4,7 @@ import solutions.bitbadger.documents.*
|
||||
import solutions.bitbadger.documents.extensions.customNonQuery
|
||||
import solutions.bitbadger.documents.query.PatchQuery
|
||||
import java.sql.Connection
|
||||
import kotlin.jvm.Throws
|
||||
|
||||
/**
|
||||
* Functions to patch (partially update) documents
|
||||
@ -17,7 +18,9 @@ object Patch {
|
||||
* @param docId The ID of the document to be patched
|
||||
* @param patch The object whose properties should be replaced in the document
|
||||
* @param conn The connection on which the update should be executed
|
||||
* @throws DocumentException If no dialect has been configured
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TKey, TPatch> byId(tableName: String, docId: TKey, patch: TPatch, conn: Connection) =
|
||||
conn.customNonQuery(
|
||||
@ -34,7 +37,9 @@ object Patch {
|
||||
* @param tableName The name of the table in which a document should be patched
|
||||
* @param docId The ID of the document to be patched
|
||||
* @param patch The object whose properties should be replaced in the document
|
||||
* @throws DocumentException If no connection string has been set
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TKey, TPatch> byId(tableName: String, docId: TKey, patch: TPatch) =
|
||||
Configuration.dbConn().use { byId(tableName, docId, patch, it) }
|
||||
@ -47,7 +52,9 @@ object Patch {
|
||||
* @param patch The object whose properties should be replaced in the document
|
||||
* @param howMatched How the fields should be matched
|
||||
* @param conn The connection on which the update should be executed
|
||||
* @throws DocumentException If no dialect has been configured, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TPatch> byFields(
|
||||
tableName: String,
|
||||
@ -72,7 +79,9 @@ object Patch {
|
||||
* @param fields The fields which should be compared
|
||||
* @param patch The object whose properties should be replaced in the document
|
||||
* @param howMatched How the fields should be matched
|
||||
* @throws DocumentException If no connection string has been set, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun <TPatch> byFields(
|
||||
@ -106,7 +115,7 @@ object Patch {
|
||||
* @param tableName The name of the table in which documents should be patched
|
||||
* @param criteria The object against which JSON containment should be checked
|
||||
* @param patch The object whose properties should be replaced in the document
|
||||
* @throws DocumentException If called on a SQLite connection
|
||||
* @throws DocumentException If no connection string has been set, or if called on a SQLite connection
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
@ -136,7 +145,7 @@ object Patch {
|
||||
* @param tableName The name of the table in which documents should be patched
|
||||
* @param path The JSON path comparison to match
|
||||
* @param patch The object whose properties should be replaced in the document
|
||||
* @throws DocumentException If called on a SQLite connection
|
||||
* @throws DocumentException If no connection string has been set, or if called on a SQLite connection
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
|
@ -4,6 +4,7 @@ import solutions.bitbadger.documents.*
|
||||
import solutions.bitbadger.documents.extensions.customNonQuery
|
||||
import solutions.bitbadger.documents.query.RemoveFieldsQuery
|
||||
import java.sql.Connection
|
||||
import kotlin.jvm.Throws
|
||||
|
||||
/**
|
||||
* Functions to remove fields from documents
|
||||
@ -31,7 +32,9 @@ object RemoveFields {
|
||||
* @param docId The ID of the document to have fields removed
|
||||
* @param toRemove The names of the fields to be removed
|
||||
* @param conn The connection on which the update should be executed
|
||||
* @throws DocumentException If no dialect has been configured
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TKey> byId(tableName: String, docId: TKey, toRemove: Collection<String>, conn: Connection) {
|
||||
val nameParams = Parameters.fieldNames(toRemove)
|
||||
@ -50,7 +53,9 @@ object RemoveFields {
|
||||
* @param tableName The name of the table in which the document's fields should be removed
|
||||
* @param docId The ID of the document to have fields removed
|
||||
* @param toRemove The names of the fields to be removed
|
||||
* @throws DocumentException If no connection string has been set
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun <TKey> byId(tableName: String, docId: TKey, toRemove: Collection<String>) =
|
||||
Configuration.dbConn().use { byId(tableName, docId, toRemove, it) }
|
||||
@ -63,7 +68,9 @@ object RemoveFields {
|
||||
* @param toRemove The names of the fields to be removed
|
||||
* @param howMatched How the fields should be matched
|
||||
* @param conn The connection on which the update should be executed
|
||||
* @throws DocumentException If no dialect has been configured, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
fun byFields(
|
||||
tableName: String,
|
||||
@ -87,7 +94,9 @@ object RemoveFields {
|
||||
* @param fields The fields which should be compared
|
||||
* @param toRemove The names of the fields to be removed
|
||||
* @param howMatched How the fields should be matched
|
||||
* @throws DocumentException If no connection string has been set, or if parameters are invalid
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun byFields(
|
||||
@ -128,7 +137,7 @@ object RemoveFields {
|
||||
* @param tableName The name of the table in which document fields should be removed
|
||||
* @param criteria The object against which JSON containment should be checked
|
||||
* @param toRemove The names of the fields to be removed
|
||||
* @throws DocumentException If called on a SQLite connection
|
||||
* @throws DocumentException If no connection string has been set, or if called on a SQLite connection
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
@ -160,7 +169,7 @@ object RemoveFields {
|
||||
* @param tableName The name of the table in which document fields should be removed
|
||||
* @param path The JSON path comparison to match
|
||||
* @param toRemove The names of the fields to be removed
|
||||
* @throws DocumentException If called on a SQLite connection
|
||||
* @throws DocumentException If no connection string has been set, or if called on a SQLite connection
|
||||
*/
|
||||
@Throws(DocumentException::class)
|
||||
@JvmStatic
|
||||
|
@ -0,0 +1,48 @@
|
||||
package solutions.bitbadger.documents.java;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import solutions.bitbadger.documents.AutoId;
|
||||
import solutions.bitbadger.documents.Configuration;
|
||||
import solutions.bitbadger.documents.Dialect;
|
||||
import solutions.bitbadger.documents.DocumentException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* Unit tests for the `Configuration` object
|
||||
*/
|
||||
@DisplayName("JVM | Java | Configuration")
|
||||
final public class ConfigurationTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Default ID field is `id`")
|
||||
public void defaultIdField() {
|
||||
assertEquals("id", Configuration.idField, "Default ID field incorrect");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Default Auto ID strategy is `DISABLED`")
|
||||
public void defaultAutoId() {
|
||||
assertEquals(AutoId.DISABLED, Configuration.autoIdStrategy, "Default Auto ID strategy should be `disabled`");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Default ID string length should be 16")
|
||||
public void defaultIdStringLength() {
|
||||
assertEquals(16, Configuration.idStringLength, "Default ID string length should be 16");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Dialect is derived from connection string")
|
||||
public void dialectIsDerived() throws DocumentException {
|
||||
try {
|
||||
assertThrows(DocumentException.class, Configuration::dialect);
|
||||
Configuration.setConnectionString("jdbc:postgresql:db");
|
||||
assertEquals(Dialect.POSTGRESQL, Configuration.dialect());
|
||||
} finally {
|
||||
Configuration.setConnectionString(null);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
package solutions.bitbadger.documents.java.support;
|
||||
|
||||
import solutions.bitbadger.documents.DocumentException;
|
||||
import solutions.bitbadger.documents.jvm.Document;
|
||||
import solutions.bitbadger.documents.support.ThrowawayDatabase;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static solutions.bitbadger.documents.support.TypesKt.TEST_TABLE;
|
||||
|
||||
public class JsonDocument {
|
||||
@ -69,8 +71,12 @@ public class JsonDocument {
|
||||
new JsonDocument("five", "purple", 18));
|
||||
|
||||
public static void load(ThrowawayDatabase db, String tableName) {
|
||||
for (JsonDocument doc : testDocuments) {
|
||||
Document.insert(tableName, doc, db.getConn());
|
||||
try {
|
||||
for (JsonDocument doc : testDocuments) {
|
||||
Document.insert(tableName, doc, db.getConn());
|
||||
}
|
||||
} catch (DocumentException ex) {
|
||||
fail("Could not load test documents", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user