Initial Development #1

Merged
danieljsummers merged 88 commits from v1-rc into main 2025-04-16 01:29:20 +00:00
363 changed files with 11626 additions and 1574 deletions
Showing only changes of commit 50188d939e - Show all commits

13
.idea/compiler.xml generated
View File

@ -6,13 +6,20 @@
<sourceOutputDir name="target/generated-sources/annotations" /> <sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" /> <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" /> <outputRelativeToContentRoot value="true" />
<module name="jvm" /> <module name="core" />
<module name="kotlin" /> <module name="groovy" />
<module name="scala" />
<module name="kotlinx" />
</profile> </profile>
</annotationProcessing> </annotationProcessing>
<bytecodeTargetLevel> <bytecodeTargetLevel>
<module name="common" target="1.8" /> <module name="common" target="1.8" />
<module name="documents" target="9" /> <module name="core8" target="1.8" />
<module name="documents" target="1.5" />
<module name="documents (2)" target="1.5" />
<module name="java" target="17" />
<module name="jvm" target="11" />
<module name="kotlin" target="17" />
<module name="sqlite" target="1.8" /> <module name="sqlite" target="1.8" />
</bytecodeTargetLevel> </bytecodeTargetLevel>
</component> </component>

17
.idea/encodings.xml generated
View File

@ -1,13 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="Encoding"> <component name="Encoding">
<file url="file://$PROJECT_DIR$/core/src/main/kotlin" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/core/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/core/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/core/src/main/kotlin" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/core/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/groovy/src/main/groovy" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/groovy/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/groovy/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/java/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/java/src/main/kotlin" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/java/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/jvm/src/main/kotlin" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/src/jvm/src/main/kotlin" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/jvm/src/main/resources" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/src/jvm/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/kotlin/src/main/kotlin" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/src/kotlin/src/main/kotlin" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/kotlin/src/main/resources" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/src/kotlin/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/kotlinx/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/kotlinx/src/main/kotlin" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/kotlinx/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/kotlin" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/src/main/kotlin" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/scala/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/scala/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/scala/src/main/scala" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/sqlite/src/main/kotlin" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/src/sqlite/src/main/kotlin" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/sqlite/src/main/resources" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/src/sqlite/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/src/main/java" charset="UTF-8" /> <file url="file://$PROJECT_DIR$/src/src/main/java" charset="UTF-8" />

12
.idea/kotlinc.xml generated
View File

@ -1,6 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="Kotlin2JsCompilerArguments">
<option name="moduleKind" value="plain" />
</component>
<component name="Kotlin2JvmCompilerArguments">
<option name="jvmTarget" value="17" />
</component>
<component name="KotlinCommonCompilerArguments">
<option name="apiVersion" value="2.1" />
<option name="languageVersion" value="2.1" />
</component>
<component name="KotlinJpsPluginSettings"> <component name="KotlinJpsPluginSettings">
<option name="version" value="2.1.10" /> <option name="version" value="2.1.20" />
</component> </component>
</project> </project>

4
.idea/modules.xml generated
View File

@ -2,7 +2,9 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/src/jvm/jvm.iml" filepath="$PROJECT_DIR$/src/jvm/jvm.iml" /> <module fileurl="file://$PROJECT_DIR$/src/core/core.iml" filepath="$PROJECT_DIR$/src/core/core.iml" />
<module fileurl="file://$PROJECT_DIR$/src/groovy/groovy.iml" filepath="$PROJECT_DIR$/src/groovy/groovy.iml" />
<module fileurl="file://$PROJECT_DIR$/src/scala/scala.iml" filepath="$PROJECT_DIR$/src/scala/scala.iml" />
</modules> </modules>
</component> </component>
</project> </project>

View File

@ -2,6 +2,6 @@
<project version="4"> <project version="4">
<component name="ScalaCompilerConfiguration"> <component name="ScalaCompilerConfiguration">
<option name="incrementalityType" value="IDEA" /> <option name="incrementalityType" value="IDEA" />
<profile name="Maven 1" modules="jvm" /> <profile name="Maven 1" modules="core,jvm,scala" />
</component> </component>
</project> </project>

8
java.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$/src/java" dumb="true">
<sourceFolder url="file://$MODULE_DIR$/src/java/src/main/java" isTestSource="false" />
</content>
</component>
</module>

50
pom.xml
View File

@ -38,13 +38,57 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.code.style>official</kotlin.code.style> <kotlin.code.style>official</kotlin.code.style>
<kotlin.compiler.jvmTarget>11</kotlin.compiler.jvmTarget> <java.version>17</java.version>
<kotlin.version>2.1.0</kotlin.version> <kotlin.compiler.jvmTarget>${java.version}</kotlin.compiler.jvmTarget>
<kotlin.version>2.1.20</kotlin.version>
<serialization.version>1.8.0</serialization.version> <serialization.version>1.8.0</serialization.version>
<scala.version>3.5.2</scala.version>
<groovy.version>4.0.26</groovy.version>
<surefire.version>3.5.2</surefire.version>
<failsafe.version>3.5.2</failsafe.version>
<jackson.version>2.18.2</jackson.version>
<sqlite.version>3.46.1.2</sqlite.version>
<postgresql.version>42.7.5</postgresql.version>
</properties> </properties>
<modules> <modules>
<module>src</module> <module>./src/core</module>
<module>./src/groovy</module>
<module>./src/kotlinx</module>
<module>./src/scala</module>
</modules> </modules>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>${sqlite.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.16</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project> </project>

8
src/core/core.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
</content>
</component>
</module>

View File

@ -3,61 +3,27 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>solutions.bitbadger.documents</groupId>
<artifactId>jvm</artifactId>
<version>4.0.0-alpha1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent> <parent>
<groupId>solutions.bitbadger</groupId> <groupId>solutions.bitbadger</groupId>
<artifactId>documents</artifactId> <artifactId>documents</artifactId>
<version>4.0.0-alpha1-SNAPSHOT</version> <version>4.0.0-alpha1-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent> </parent>
<groupId>solutions.bitbadger.documents</groupId>
<artifactId>core</artifactId>
<name>${project.groupId}:${project.artifactId}</name> <name>${project.groupId}:${project.artifactId}</name>
<description>Expose a document store interface for PostgreSQL and SQLite (Standard JVM Library)</description> <description>Expose a document store interface for PostgreSQL and SQLite (Core Library)</description>
<url>https://bitbadger.solutions/open-source/relational-documents/jvm/</url> <url>https://bitbadger.solutions/open-source/relational-documents/jvm/</url>
<scm>
<connection>scm:git:https://git.bitbadger.solutions/bit-badger/solutions.bitbadger.documents.git</connection>
<developerConnection>scm:git:https://git.bitbadger.solutions/bit-badger/solutions.bitbadger.documents.git</developerConnection>
<url>https://git.bitbadger.solutions/bit-badger/solutions.bitbadger.documents</url>
</scm>
<properties> <properties>
<jackson.version>2.18.2</jackson.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.code.style>official</kotlin.code.style>
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
</properties> </properties>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala3-library_3</artifactId>
<version>${scala.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-test</artifactId>
<version>${groovy.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.groovy</groupId>
<artifactId>groovy-test-junit5</artifactId>
<version>${groovy.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build> <build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.jetbrains.kotlin</groupId> <groupId>org.jetbrains.kotlin</groupId>
@ -72,6 +38,7 @@
</goals> </goals>
<configuration> <configuration>
<sourceDirs> <sourceDirs>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir> <sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
</sourceDirs> </sourceDirs>
</configuration> </configuration>
@ -84,62 +51,20 @@
</goals> </goals>
<configuration> <configuration>
<sourceDirs> <sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir> <sourceDir>${project.basedir}/src/test/java</sourceDir>
<sourceDir>${project.basedir}/src/test/scala</sourceDir> <sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
</sourceDirs> </sourceDirs>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.9.2</version>
<executions>
<execution>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
<configuration>
<source>${java.version}</source>
</configuration>
<executions>
<execution>
<configuration>
<providerSelection>2.0</providerSelection>
</configuration>
<goals>
<goal>generateTestStubs</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin> <plugin>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version> <version>${surefire.version}</version>
<configuration>
<argLine>
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.util=ALL-UNNAMED
</argLine>
</configuration>
</plugin> </plugin>
<plugin> <plugin>
<artifactId>maven-failsafe-plugin</artifactId> <artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version> <version>${failsafe.version}</version>
<executions> <executions>
<execution> <execution>
<goals> <goals>
@ -160,4 +85,24 @@
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project> </project>

View File

@ -0,0 +1,9 @@
module solutions.bitbadger.documents.core {
requires kotlin.stdlib;
requires kotlin.reflect;
requires java.sql;
exports solutions.bitbadger.documents;
exports solutions.bitbadger.documents.java;
exports solutions.bitbadger.documents.java.extensions;
exports solutions.bitbadger.documents.query;
}

View File

@ -1,8 +1,7 @@
package solutions.bitbadger.documents.jvm package solutions.bitbadger.documents.java
import solutions.bitbadger.documents.* import solutions.bitbadger.documents.*
import solutions.bitbadger.documents.query.CountQuery import solutions.bitbadger.documents.query.CountQuery
import solutions.bitbadger.documents.extensions.customScalar
import java.sql.Connection import java.sql.Connection
import kotlin.jvm.Throws import kotlin.jvm.Throws
@ -22,7 +21,7 @@ object Count {
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun all(tableName: String, conn: Connection) = fun all(tableName: String, conn: Connection) =
conn.customScalar(CountQuery.all(tableName), listOf(), Long::class.java, Results::toCount) Custom.scalar(CountQuery.all(tableName), listOf(), Long::class.java, conn, Results::toCount)
/** /**
* Count all documents in the table * Count all documents in the table
@ -56,10 +55,11 @@ object Count {
conn: Connection conn: Connection
): Long { ): Long {
val named = Parameters.nameFields(fields) val named = Parameters.nameFields(fields)
return conn.customScalar( return Custom.scalar(
CountQuery.byFields(tableName, named, howMatched), CountQuery.byFields(tableName, named, howMatched),
Parameters.addFields(named), Parameters.addFields(named),
Long::class.java, Long::class.java,
conn,
Results::toCount Results::toCount
) )
} }
@ -91,10 +91,11 @@ object Count {
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun <TContains> byContains(tableName: String, criteria: TContains, conn: Connection) = fun <TContains> byContains(tableName: String, criteria: TContains, conn: Connection) =
conn.customScalar( Custom.scalar(
CountQuery.byContains(tableName), CountQuery.byContains(tableName),
listOf(Parameters.json(":criteria", criteria)), listOf(Parameters.json(":criteria", criteria)),
Long::class.java, Long::class.java,
conn,
Results::toCount Results::toCount
) )
@ -123,10 +124,11 @@ object Count {
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun byJsonPath(tableName: String, path: String, conn: Connection) = fun byJsonPath(tableName: String, path: String, conn: Connection) =
conn.customScalar( Custom.scalar(
CountQuery.byJsonPath(tableName), CountQuery.byJsonPath(tableName),
listOf(Parameter(":path", ParameterType.STRING, path)), listOf(Parameter(":path", ParameterType.STRING, path)),
Long::class.java, Long::class.java,
conn,
Results::toCount Results::toCount
) )

View File

@ -1,10 +1,12 @@
package solutions.bitbadger.documents.jvm package solutions.bitbadger.documents.java
import solutions.bitbadger.documents.Configuration import solutions.bitbadger.documents.Configuration
import solutions.bitbadger.documents.DocumentException import solutions.bitbadger.documents.DocumentException
import solutions.bitbadger.documents.Parameter import solutions.bitbadger.documents.Parameter
import java.sql.Connection import java.sql.Connection
import java.sql.ResultSet import java.sql.ResultSet
import java.sql.SQLException
import java.util.*
import kotlin.jvm.Throws import kotlin.jvm.Throws
object Custom { object Custom {
@ -57,7 +59,7 @@ object Custom {
* @param clazz The class of the document to be returned * @param clazz The class of the document to be returned
* @param conn The connection over which the query should be executed * @param conn The connection over which the query should be executed
* @param mapFunc The mapping function between the document and the domain item * @param mapFunc The mapping function between the document and the domain item
* @return The document if one matches the query, `null` otherwise * @return An `Optional` value, with the document if one matches the query
* @throws DocumentException If parameters are invalid * @throws DocumentException If parameters are invalid
*/ */
@Throws(DocumentException::class) @Throws(DocumentException::class)
@ -68,7 +70,7 @@ object Custom {
clazz: Class<TDoc>, clazz: Class<TDoc>,
conn: Connection, conn: Connection,
mapFunc: (ResultSet, Class<TDoc>) -> TDoc mapFunc: (ResultSet, Class<TDoc>) -> TDoc
) = list("$query LIMIT 1", parameters, clazz, conn, mapFunc).singleOrNull() ) = Optional.ofNullable(list("$query LIMIT 1", parameters, clazz, conn, mapFunc).singleOrNull())
/** /**
* Execute a query that returns one or no results * Execute a query that returns one or no results
@ -95,12 +97,16 @@ object Custom {
* @param query The query to retrieve the results * @param query The query to retrieve the results
* @param conn The connection over which the query should be executed * @param conn The connection over which the query should be executed
* @param parameters Parameters to use for the query * @param parameters Parameters to use for the query
* @throws DocumentException If parameters are invalid * @throws DocumentException If parameters are invalid or if the query fails
*/ */
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun nonQuery(query: String, parameters: Collection<Parameter<*>> = listOf(), conn: Connection) { fun nonQuery(query: String, parameters: Collection<Parameter<*>> = listOf(), conn: Connection) {
try {
Parameters.apply(conn, query, parameters).use { it.executeUpdate() } Parameters.apply(conn, query, parameters).use { it.executeUpdate() }
} catch (ex: SQLException) {
throw DocumentException("Unable to execute non-query: ${ex.message}", ex)
}
} }
/** /**
@ -108,7 +114,7 @@ object Custom {
* *
* @param query The query to retrieve the results * @param query The query to retrieve the results
* @param parameters Parameters to use for the query * @param parameters Parameters to use for the query
* @throws DocumentException If no connection string has been set, or if parameters are invalid * @throws DocumentException If no connection string has been set, if parameters are invalid, or if the query fails
*/ */
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
@ -124,7 +130,7 @@ object Custom {
* @param conn The connection over which the query should be executed * @param conn The connection over which the query should be executed
* @param mapFunc The mapping function between the document and the domain item * @param mapFunc The mapping function between the document and the domain item
* @return The scalar value from the query * @return The scalar value from the query
* @throws DocumentException If parameters are invalid * @throws DocumentException If parameters are invalid or if the query fails
*/ */
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
@ -135,10 +141,14 @@ object Custom {
conn: Connection, conn: Connection,
mapFunc: (ResultSet, Class<T>) -> T mapFunc: (ResultSet, Class<T>) -> T
) = Parameters.apply(conn, query, parameters).use { stmt -> ) = Parameters.apply(conn, query, parameters).use { stmt ->
try {
stmt.executeQuery().use { rs -> stmt.executeQuery().use { rs ->
rs.next() rs.next()
mapFunc(rs, clazz) mapFunc(rs, clazz)
} }
} catch (ex: SQLException) {
throw DocumentException("Unable to retrieve scalar value: ${ex.message}", ex)
}
} }
/** /**

View File

@ -1,9 +1,8 @@
package solutions.bitbadger.documents.jvm package solutions.bitbadger.documents.java
import solutions.bitbadger.documents.Configuration import solutions.bitbadger.documents.Configuration
import solutions.bitbadger.documents.DocumentException import solutions.bitbadger.documents.DocumentException
import solutions.bitbadger.documents.DocumentIndex import solutions.bitbadger.documents.DocumentIndex
import solutions.bitbadger.documents.extensions.customNonQuery
import solutions.bitbadger.documents.query.DefinitionQuery import solutions.bitbadger.documents.query.DefinitionQuery
import java.sql.Connection import java.sql.Connection
import kotlin.jvm.Throws import kotlin.jvm.Throws
@ -24,8 +23,8 @@ object Definition {
@JvmStatic @JvmStatic
fun ensureTable(tableName: String, conn: Connection) = fun ensureTable(tableName: String, conn: Connection) =
Configuration.dialect("ensure $tableName exists").let { Configuration.dialect("ensure $tableName exists").let {
conn.customNonQuery(DefinitionQuery.ensureTable(tableName, it)) Custom.nonQuery(DefinitionQuery.ensureTable(tableName, it), conn = conn)
conn.customNonQuery(DefinitionQuery.ensureKey(tableName, it)) Custom.nonQuery(DefinitionQuery.ensureKey(tableName, it), conn = conn)
} }
/** /**
@ -51,7 +50,7 @@ object Definition {
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun ensureFieldIndex(tableName: String, indexName: String, fields: Collection<String>, conn: Connection) = fun ensureFieldIndex(tableName: String, indexName: String, fields: Collection<String>, conn: Connection) =
conn.customNonQuery(DefinitionQuery.ensureIndexOn(tableName, indexName, fields)) Custom.nonQuery(DefinitionQuery.ensureIndexOn(tableName, indexName, fields), conn = conn)
/** /**
* Create an index on field(s) within documents in the specified table if necessary * Create an index on field(s) within documents in the specified table if necessary
@ -77,7 +76,7 @@ object Definition {
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun ensureDocumentIndex(tableName: String, indexType: DocumentIndex, conn: Connection) = fun ensureDocumentIndex(tableName: String, indexType: DocumentIndex, conn: Connection) =
conn.customNonQuery(DefinitionQuery.ensureDocumentIndexOn(tableName, indexType)) Custom.nonQuery(DefinitionQuery.ensureDocumentIndexOn(tableName, indexType), conn = conn)
/** /**
* Create a document index on a table (PostgreSQL only) * Create a document index on a table (PostgreSQL only)

View File

@ -1,7 +1,6 @@
package solutions.bitbadger.documents.jvm package solutions.bitbadger.documents.java
import solutions.bitbadger.documents.* import solutions.bitbadger.documents.*
import solutions.bitbadger.documents.extensions.customNonQuery
import solutions.bitbadger.documents.query.DeleteQuery import solutions.bitbadger.documents.query.DeleteQuery
import java.sql.Connection import java.sql.Connection
import kotlin.jvm.Throws import kotlin.jvm.Throws
@ -22,9 +21,10 @@ object Delete {
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun <TKey> byId(tableName: String, docId: TKey, conn: Connection) = fun <TKey> byId(tableName: String, docId: TKey, conn: Connection) =
conn.customNonQuery( Custom.nonQuery(
DeleteQuery.byId(tableName, docId), DeleteQuery.byId(tableName, docId),
Parameters.addFields(listOf(Field.equal(Configuration.idField, docId, ":id"))) Parameters.addFields(listOf(Field.equal(Configuration.idField, docId, ":id"))),
conn
) )
/** /**
@ -53,7 +53,7 @@ object Delete {
@JvmOverloads @JvmOverloads
fun byFields(tableName: String, fields: Collection<Field<*>>, howMatched: FieldMatch? = null, conn: Connection) { fun byFields(tableName: String, fields: Collection<Field<*>>, howMatched: FieldMatch? = null, conn: Connection) {
val named = Parameters.nameFields(fields) val named = Parameters.nameFields(fields)
conn.customNonQuery(DeleteQuery.byFields(tableName, named, howMatched), Parameters.addFields(named)) Custom.nonQuery(DeleteQuery.byFields(tableName, named, howMatched), Parameters.addFields(named), conn)
} }
/** /**
@ -81,7 +81,7 @@ object Delete {
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun <TContains> byContains(tableName: String, criteria: TContains, conn: Connection) = fun <TContains> byContains(tableName: String, criteria: TContains, conn: Connection) =
conn.customNonQuery(DeleteQuery.byContains(tableName), listOf(Parameters.json(":criteria", criteria))) Custom.nonQuery(DeleteQuery.byContains(tableName), listOf(Parameters.json(":criteria", criteria)), conn)
/** /**
* Delete documents using a JSON containment query (PostgreSQL only) * Delete documents using a JSON containment query (PostgreSQL only)
@ -106,7 +106,7 @@ object Delete {
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun byJsonPath(tableName: String, path: String, conn: Connection) = fun byJsonPath(tableName: String, path: String, conn: Connection) =
conn.customNonQuery(DeleteQuery.byJsonPath(tableName), listOf(Parameter(":path", ParameterType.STRING, path))) Custom.nonQuery(DeleteQuery.byJsonPath(tableName), listOf(Parameter(":path", ParameterType.STRING, path)), conn)
/** /**
* Delete documents using a JSON Path match query (PostgreSQL only) * Delete documents using a JSON Path match query (PostgreSQL only)

View File

@ -1,10 +1,9 @@
package solutions.bitbadger.documents.jvm package solutions.bitbadger.documents.java
import solutions.bitbadger.documents.AutoId import solutions.bitbadger.documents.AutoId
import solutions.bitbadger.documents.Configuration import solutions.bitbadger.documents.Configuration
import solutions.bitbadger.documents.DocumentException import solutions.bitbadger.documents.DocumentException
import solutions.bitbadger.documents.Field import solutions.bitbadger.documents.Field
import solutions.bitbadger.documents.extensions.customNonQuery
import solutions.bitbadger.documents.query.DocumentQuery import solutions.bitbadger.documents.query.DocumentQuery
import solutions.bitbadger.documents.query.Where import solutions.bitbadger.documents.query.Where
import solutions.bitbadger.documents.query.statementWhere import solutions.bitbadger.documents.query.statementWhere
@ -33,7 +32,7 @@ object Document {
} else { } else {
DocumentQuery.insert(tableName, strategy) DocumentQuery.insert(tableName, strategy)
} }
conn.customNonQuery(query, listOf(Parameters.json(":data", document))) Custom.nonQuery(query, listOf(Parameters.json(":data", document)), conn)
} }
/** /**
@ -60,7 +59,7 @@ object Document {
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun <TDoc> save(tableName: String, document: TDoc, conn: Connection) = fun <TDoc> save(tableName: String, document: TDoc, conn: Connection) =
conn.customNonQuery(DocumentQuery.save(tableName), listOf(Parameters.json(":data", document))) Custom.nonQuery(DocumentQuery.save(tableName), listOf(Parameters.json(":data", document)), conn)
/** /**
* Save a document, inserting it if it does not exist and updating it if it does (AKA "upsert") * Save a document, inserting it if it does not exist and updating it if it does (AKA "upsert")
@ -86,12 +85,13 @@ object Document {
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun <TKey, TDoc> update(tableName: String, docId: TKey, document: TDoc, conn: Connection) = fun <TKey, TDoc> update(tableName: String, docId: TKey, document: TDoc, conn: Connection) =
conn.customNonQuery( Custom.nonQuery(
statementWhere(DocumentQuery.update(tableName), Where.byId(":id", docId)), statementWhere(DocumentQuery.update(tableName), Where.byId(":id", docId)),
Parameters.addFields( Parameters.addFields(
listOf(Field.equal(Configuration.idField, docId, ":id")), listOf(Field.equal(Configuration.idField, docId, ":id")),
mutableListOf(Parameters.json(":data", document)) mutableListOf(Parameters.json(":data", document))
) ),
conn
) )
/** /**

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.jvm package solutions.bitbadger.documents.java
import solutions.bitbadger.documents.DocumentSerializer import solutions.bitbadger.documents.DocumentSerializer

View File

@ -1,7 +1,6 @@
package solutions.bitbadger.documents.jvm package solutions.bitbadger.documents.java
import solutions.bitbadger.documents.* import solutions.bitbadger.documents.*
import solutions.bitbadger.documents.extensions.customScalar
import solutions.bitbadger.documents.query.ExistsQuery import solutions.bitbadger.documents.query.ExistsQuery
import java.sql.Connection import java.sql.Connection
import kotlin.jvm.Throws import kotlin.jvm.Throws
@ -23,10 +22,11 @@ object Exists {
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun <TKey> byId(tableName: String, docId: TKey, conn: Connection) = fun <TKey> byId(tableName: String, docId: TKey, conn: Connection) =
conn.customScalar( Custom.scalar(
ExistsQuery.byId(tableName, docId), ExistsQuery.byId(tableName, docId),
Parameters.addFields(listOf(Field.equal(Configuration.idField, docId, ":id"))), Parameters.addFields(listOf(Field.equal(Configuration.idField, docId, ":id"))),
Boolean::class.java, Boolean::class.java,
conn,
Results::toExists Results::toExists
) )
@ -63,10 +63,11 @@ object Exists {
conn: Connection conn: Connection
): Boolean { ): Boolean {
val named = Parameters.nameFields(fields) val named = Parameters.nameFields(fields)
return conn.customScalar( return Custom.scalar(
ExistsQuery.byFields(tableName, named, howMatched), ExistsQuery.byFields(tableName, named, howMatched),
Parameters.addFields(named), Parameters.addFields(named),
Boolean::class.java, Boolean::class.java,
conn,
Results::toExists Results::toExists
) )
} }
@ -98,10 +99,11 @@ object Exists {
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun <TContains> byContains(tableName: String, criteria: TContains, conn: Connection) = fun <TContains> byContains(tableName: String, criteria: TContains, conn: Connection) =
conn.customScalar( Custom.scalar(
ExistsQuery.byContains(tableName), ExistsQuery.byContains(tableName),
listOf(Parameters.json(":criteria", criteria)), listOf(Parameters.json(":criteria", criteria)),
Boolean::class.java, Boolean::class.java,
conn,
Results::toExists Results::toExists
) )
@ -130,10 +132,11 @@ object Exists {
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun byJsonPath(tableName: String, path: String, conn: Connection) = fun byJsonPath(tableName: String, path: String, conn: Connection) =
conn.customScalar( Custom.scalar(
ExistsQuery.byJsonPath(tableName), ExistsQuery.byJsonPath(tableName),
listOf(Parameter(":path", ParameterType.STRING, path)), listOf(Parameter(":path", ParameterType.STRING, path)),
Boolean::class.java, Boolean::class.java,
conn,
Results::toExists Results::toExists
) )

View File

@ -1,11 +1,10 @@
package solutions.bitbadger.documents.jvm package solutions.bitbadger.documents.java
import solutions.bitbadger.documents.* import solutions.bitbadger.documents.*
import solutions.bitbadger.documents.extensions.customList
import solutions.bitbadger.documents.extensions.customSingle
import solutions.bitbadger.documents.query.FindQuery import solutions.bitbadger.documents.query.FindQuery
import solutions.bitbadger.documents.query.orderBy import solutions.bitbadger.documents.query.orderBy
import java.sql.Connection import java.sql.Connection
import java.util.Optional
import kotlin.jvm.Throws import kotlin.jvm.Throws
/** /**
@ -26,7 +25,7 @@ object Find {
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun <TDoc> all(tableName: String, clazz: Class<TDoc>, orderBy: Collection<Field<*>>? = null, conn: Connection) = 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) Custom.list(FindQuery.all(tableName) + (orderBy?.let(::orderBy) ?: ""), listOf(), clazz, conn, Results::fromData)
/** /**
* Retrieve all documents in the given table * Retrieve all documents in the given table
@ -64,16 +63,17 @@ object Find {
* @param docId The ID of the document to retrieve * @param docId The ID of the document to retrieve
* @param clazz The class of the document to be returned * @param clazz The class of the document to be returned
* @param conn The connection over which documents should be retrieved * @param conn The connection over which documents should be retrieved
* @return The document if it is found, `null` otherwise * @return An `Optional` item with the document if it is found
* @throws DocumentException If no dialect has been configured * @throws DocumentException If no dialect has been configured
*/ */
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun <TKey, TDoc> byId(tableName: String, docId: TKey, clazz: Class<TDoc>, conn: Connection) = fun <TKey, TDoc> byId(tableName: String, docId: TKey, clazz: Class<TDoc>, conn: Connection) =
conn.customSingle( Custom.single(
FindQuery.byId(tableName, docId), FindQuery.byId(tableName, docId),
Parameters.addFields(listOf(Field.equal(Configuration.idField, docId, ":id"))), Parameters.addFields(listOf(Field.equal(Configuration.idField, docId, ":id"))),
clazz, clazz,
conn,
Results::fromData Results::fromData
) )
@ -83,7 +83,7 @@ object Find {
* @param tableName The table from which the document should be retrieved * @param tableName The table from which the document should be retrieved
* @param docId The ID of the document to retrieve * @param docId The ID of the document to retrieve
* @param clazz The class of the document to be returned * @param clazz The class of the document to be returned
* @return The document if it is found, `null` otherwise * @return An `Optional` item with the document if it is found
* @throws DocumentException If no connection string has been set * @throws DocumentException If no connection string has been set
*/ */
@Throws(DocumentException::class) @Throws(DocumentException::class)
@ -114,10 +114,11 @@ object Find {
conn: Connection conn: Connection
): List<TDoc> { ): List<TDoc> {
val named = Parameters.nameFields(fields) val named = Parameters.nameFields(fields)
return conn.customList( return Custom.list(
FindQuery.byFields(tableName, named, howMatched) + (orderBy?.let(::orderBy) ?: ""), FindQuery.byFields(tableName, named, howMatched) + (orderBy?.let(::orderBy) ?: ""),
Parameters.addFields(named), Parameters.addFields(named),
clazz, clazz,
conn,
Results::fromData Results::fromData
) )
} }
@ -187,10 +188,11 @@ object Find {
orderBy: Collection<Field<*>>? = null, orderBy: Collection<Field<*>>? = null,
conn: Connection conn: Connection
) = ) =
conn.customList( Custom.list(
FindQuery.byContains(tableName) + (orderBy?.let(::orderBy) ?: ""), FindQuery.byContains(tableName) + (orderBy?.let(::orderBy) ?: ""),
listOf(Parameters.json(":criteria", criteria)), listOf(Parameters.json(":criteria", criteria)),
clazz, clazz,
conn,
Results::fromData Results::fromData
) )
@ -250,10 +252,11 @@ object Find {
orderBy: Collection<Field<*>>? = null, orderBy: Collection<Field<*>>? = null,
conn: Connection conn: Connection
) = ) =
conn.customList( Custom.list(
FindQuery.byJsonPath(tableName) + (orderBy?.let(::orderBy) ?: ""), FindQuery.byJsonPath(tableName) + (orderBy?.let(::orderBy) ?: ""),
listOf(Parameter(":path", ParameterType.STRING, path)), listOf(Parameter(":path", ParameterType.STRING, path)),
clazz, clazz,
conn,
Results::fromData Results::fromData
) )
@ -297,7 +300,7 @@ object Find {
* @param howMatched How the fields should be matched (optional, defaults to `FieldMatch.ALL`) * @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) * @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 * @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 * @return An `Optional` item, with the first document matching the field comparison if found
* @throws DocumentException If no dialect has been configured, or if parameters are invalid * @throws DocumentException If no dialect has been configured, or if parameters are invalid
*/ */
@Throws(DocumentException::class) @Throws(DocumentException::class)
@ -309,12 +312,13 @@ object Find {
howMatched: FieldMatch? = null, howMatched: FieldMatch? = null,
orderBy: Collection<Field<*>>? = null, orderBy: Collection<Field<*>>? = null,
conn: Connection conn: Connection
): TDoc? { ): Optional<TDoc & Any> {
val named = Parameters.nameFields(fields) val named = Parameters.nameFields(fields)
return conn.customSingle( return Custom.single(
FindQuery.byFields(tableName, named, howMatched) + (orderBy?.let(::orderBy) ?: ""), FindQuery.byFields(tableName, named, howMatched) + (orderBy?.let(::orderBy) ?: ""),
Parameters.addFields(named), Parameters.addFields(named),
clazz, clazz,
conn,
Results::fromData Results::fromData
) )
} }
@ -327,7 +331,7 @@ object Find {
* @param clazz The class of the document to be returned * @param clazz The class of the document to be returned
* @param howMatched How the fields should be matched (optional, defaults to `FieldMatch.ALL`) * @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) * @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 * @return An `Optional` item, with the first document matching the field comparison if found
* @throws DocumentException If no connection string has been set, or if parameters are invalid * @throws DocumentException If no connection string has been set, or if parameters are invalid
*/ */
@Throws(DocumentException::class) @Throws(DocumentException::class)
@ -350,7 +354,7 @@ object Find {
* @param clazz The class of the document to be returned * @param clazz The class of the document to be returned
* @param howMatched How the fields should be matched (optional, defaults to `FieldMatch.ALL`) * @param howMatched How the fields should be matched (optional, defaults to `FieldMatch.ALL`)
* @param conn The connection over which documents should be retrieved * @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 * @return An `Optional` item, with the first document matching the field comparison if found
* @throws DocumentException If no dialect has been configured, or if parameters are invalid * @throws DocumentException If no dialect has been configured, or if parameters are invalid
*/ */
@Throws(DocumentException::class) @Throws(DocumentException::class)
@ -371,7 +375,7 @@ object Find {
* @param criteria The object for which JSON containment should be checked * @param criteria The object for which JSON containment should be checked
* @param orderBy Fields by which the query should be ordered (optional, defaults to no ordering) * @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 * @param conn The connection over which documents should be retrieved
* @return The first document matching the JSON containment query, or `null` if no matches are found * @return An `Optional` item, with the first document matching the JSON containment query if found
* @throws DocumentException If called on a SQLite connection * @throws DocumentException If called on a SQLite connection
*/ */
@Throws(DocumentException::class) @Throws(DocumentException::class)
@ -383,10 +387,11 @@ object Find {
orderBy: Collection<Field<*>>? = null, orderBy: Collection<Field<*>>? = null,
conn: Connection conn: Connection
) = ) =
conn.customSingle( Custom.single(
FindQuery.byContains(tableName) + (orderBy?.let(::orderBy) ?: ""), FindQuery.byContains(tableName) + (orderBy?.let(::orderBy) ?: ""),
listOf(Parameters.json(":criteria", criteria)), listOf(Parameters.json(":criteria", criteria)),
clazz, clazz,
conn,
Results::fromData Results::fromData
) )
@ -397,7 +402,7 @@ object Find {
* @param criteria The object for which JSON containment should be checked * @param criteria The object for which JSON containment should be checked
* @param clazz The class of the document to be returned * @param clazz The class of the document to be returned
* @param conn The connection over which documents should be retrieved * @param conn The connection over which documents should be retrieved
* @return The first document matching the JSON containment query, or `null` if no matches are found * @return An `Optional` item, with the first document matching the JSON containment query if found
* @throws DocumentException If called on a SQLite connection * @throws DocumentException If called on a SQLite connection
*/ */
@Throws(DocumentException::class) @Throws(DocumentException::class)
@ -417,7 +422,7 @@ object Find {
* @param criteria The object for which JSON containment should be checked * @param criteria The object for which JSON containment should be checked
* @param clazz The class of the document to be returned * @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) * @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 * @return An `Optional` item, with the first document matching the JSON containment query if found
* @throws DocumentException If no connection string has been set, or 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) @Throws(DocumentException::class)
@ -439,7 +444,7 @@ object Find {
* @param clazz The class of the document to be returned * @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) * @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 * @param conn The connection over which documents should be retrieved
* @return The first document matching the JSON Path match query, or `null` if no matches are found * @return An `Optional` item, with the first document matching the JSON Path match query if found
* @throws DocumentException If called on a SQLite connection * @throws DocumentException If called on a SQLite connection
*/ */
@Throws(DocumentException::class) @Throws(DocumentException::class)
@ -451,10 +456,11 @@ object Find {
orderBy: Collection<Field<*>>? = null, orderBy: Collection<Field<*>>? = null,
conn: Connection conn: Connection
) = ) =
conn.customSingle( Custom.single(
FindQuery.byJsonPath(tableName) + (orderBy?.let(::orderBy) ?: ""), FindQuery.byJsonPath(tableName) + (orderBy?.let(::orderBy) ?: ""),
listOf(Parameter(":path", ParameterType.STRING, path)), listOf(Parameter(":path", ParameterType.STRING, path)),
clazz, clazz,
conn,
Results::fromData Results::fromData
) )
@ -465,7 +471,7 @@ object Find {
* @param path The JSON path comparison to match * @param path The JSON path comparison to match
* @param clazz The class of the document to be returned * @param clazz The class of the document to be returned
* @param conn The connection over which documents should be retrieved * @param conn The connection over which documents should be retrieved
* @return The first document matching the JSON Path match query, or `null` if no matches are found * @return An `Optional` item, with the first document matching the JSON Path match query if found
* @throws DocumentException If called on a SQLite connection * @throws DocumentException If called on a SQLite connection
*/ */
@Throws(DocumentException::class) @Throws(DocumentException::class)
@ -480,7 +486,7 @@ object Find {
* @param path The JSON path comparison to match * @param path The JSON path comparison to match
* @param clazz The class of the document to be returned * @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) * @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 * @return An `Optional` item, with the first document matching the JSON Path match query if found
* @throws DocumentException If no connection string has been set, or 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) @Throws(DocumentException::class)

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.jvm package solutions.bitbadger.documents.java
import solutions.bitbadger.documents.DocumentSerializer import solutions.bitbadger.documents.DocumentSerializer

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.jvm package solutions.bitbadger.documents.java
import solutions.bitbadger.documents.* import solutions.bitbadger.documents.*
import solutions.bitbadger.documents.ParameterName import solutions.bitbadger.documents.ParameterName

View File

@ -1,7 +1,6 @@
package solutions.bitbadger.documents.jvm package solutions.bitbadger.documents.java
import solutions.bitbadger.documents.* import solutions.bitbadger.documents.*
import solutions.bitbadger.documents.extensions.customNonQuery
import solutions.bitbadger.documents.query.PatchQuery import solutions.bitbadger.documents.query.PatchQuery
import java.sql.Connection import java.sql.Connection
import kotlin.jvm.Throws import kotlin.jvm.Throws
@ -23,12 +22,13 @@ object Patch {
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun <TKey, TPatch> byId(tableName: String, docId: TKey, patch: TPatch, conn: Connection) = fun <TKey, TPatch> byId(tableName: String, docId: TKey, patch: TPatch, conn: Connection) =
conn.customNonQuery( Custom.nonQuery(
PatchQuery.byId(tableName, docId), PatchQuery.byId(tableName, docId),
Parameters.addFields( Parameters.addFields(
listOf(Field.equal(Configuration.idField, docId, ":id")), listOf(Field.equal(Configuration.idField, docId, ":id")),
mutableListOf(Parameters.json(":data", patch)) mutableListOf(Parameters.json(":data", patch))
) ),
conn
) )
/** /**
@ -64,11 +64,10 @@ object Patch {
conn: Connection conn: Connection
) { ) {
val named = Parameters.nameFields(fields) val named = Parameters.nameFields(fields)
conn.customNonQuery( Custom.nonQuery(
PatchQuery.byFields(tableName, named, howMatched), Parameters.addFields( PatchQuery.byFields(tableName, named, howMatched),
named, Parameters.addFields(named, mutableListOf(Parameters.json(":data", patch))),
mutableListOf(Parameters.json(":data", patch)) conn
)
) )
} }
@ -104,9 +103,10 @@ object Patch {
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun <TContains, TPatch> byContains(tableName: String, criteria: TContains, patch: TPatch, conn: Connection) = fun <TContains, TPatch> byContains(tableName: String, criteria: TContains, patch: TPatch, conn: Connection) =
conn.customNonQuery( Custom.nonQuery(
PatchQuery.byContains(tableName), PatchQuery.byContains(tableName),
listOf(Parameters.json(":criteria", criteria), Parameters.json(":data", patch)) listOf(Parameters.json(":criteria", criteria), Parameters.json(":data", patch)),
conn
) )
/** /**
@ -134,9 +134,10 @@ object Patch {
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmStatic @JvmStatic
fun <TPatch> byJsonPath(tableName: String, path: String, patch: TPatch, conn: Connection) = fun <TPatch> byJsonPath(tableName: String, path: String, patch: TPatch, conn: Connection) =
conn.customNonQuery( Custom.nonQuery(
PatchQuery.byJsonPath(tableName), PatchQuery.byJsonPath(tableName),
listOf(Parameter(":path", ParameterType.STRING, path), Parameters.json(":data", patch)) listOf(Parameter(":path", ParameterType.STRING, path), Parameters.json(":data", patch)),
conn
) )
/** /**

View File

@ -1,7 +1,6 @@
package solutions.bitbadger.documents.jvm package solutions.bitbadger.documents.java
import solutions.bitbadger.documents.* import solutions.bitbadger.documents.*
import solutions.bitbadger.documents.extensions.customNonQuery
import solutions.bitbadger.documents.query.RemoveFieldsQuery import solutions.bitbadger.documents.query.RemoveFieldsQuery
import java.sql.Connection import java.sql.Connection
import kotlin.jvm.Throws import kotlin.jvm.Throws
@ -38,12 +37,10 @@ object RemoveFields {
@JvmStatic @JvmStatic
fun <TKey> byId(tableName: String, docId: TKey, toRemove: Collection<String>, conn: Connection) { fun <TKey> byId(tableName: String, docId: TKey, toRemove: Collection<String>, conn: Connection) {
val nameParams = Parameters.fieldNames(toRemove) val nameParams = Parameters.fieldNames(toRemove)
conn.customNonQuery( Custom.nonQuery(
RemoveFieldsQuery.byId(tableName, nameParams, docId), RemoveFieldsQuery.byId(tableName, nameParams, docId),
Parameters.addFields( Parameters.addFields(listOf(Field.equal(Configuration.idField, docId, ":id")), translatePath(nameParams)),
listOf(Field.equal(Configuration.idField, docId, ":id")), conn
translatePath(nameParams)
)
) )
} }
@ -81,9 +78,10 @@ object RemoveFields {
) { ) {
val named = Parameters.nameFields(fields) val named = Parameters.nameFields(fields)
val nameParams = Parameters.fieldNames(toRemove) val nameParams = Parameters.fieldNames(toRemove)
conn.customNonQuery( Custom.nonQuery(
RemoveFieldsQuery.byFields(tableName, nameParams, named, howMatched), RemoveFieldsQuery.byFields(tableName, nameParams, named, howMatched),
Parameters.addFields(named, translatePath(nameParams)) Parameters.addFields(named, translatePath(nameParams)),
conn
) )
} }
@ -125,9 +123,10 @@ object RemoveFields {
conn: Connection conn: Connection
) { ) {
val nameParams = Parameters.fieldNames(toRemove) val nameParams = Parameters.fieldNames(toRemove)
conn.customNonQuery( Custom.nonQuery(
RemoveFieldsQuery.byContains(tableName, nameParams), RemoveFieldsQuery.byContains(tableName, nameParams),
listOf(Parameters.json(":criteria", criteria), *nameParams.toTypedArray()) listOf(Parameters.json(":criteria", criteria), *nameParams.toTypedArray()),
conn
) )
} }
@ -157,9 +156,10 @@ object RemoveFields {
@JvmStatic @JvmStatic
fun byJsonPath(tableName: String, path: String, toRemove: Collection<String>, conn: Connection) { fun byJsonPath(tableName: String, path: String, toRemove: Collection<String>, conn: Connection) {
val nameParams = Parameters.fieldNames(toRemove) val nameParams = Parameters.fieldNames(toRemove)
conn.customNonQuery( Custom.nonQuery(
RemoveFieldsQuery.byJsonPath(tableName, nameParams), RemoveFieldsQuery.byJsonPath(tableName, nameParams),
listOf(Parameter(":path", ParameterType.STRING, path), *nameParams.toTypedArray()) listOf(Parameter(":path", ParameterType.STRING, path), *nameParams.toTypedArray()),
conn
) )
} }

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.jvm package solutions.bitbadger.documents.java
import solutions.bitbadger.documents.Configuration import solutions.bitbadger.documents.Configuration
import solutions.bitbadger.documents.Dialect import solutions.bitbadger.documents.Dialect
@ -6,7 +6,6 @@ import solutions.bitbadger.documents.DocumentException
import java.sql.PreparedStatement import java.sql.PreparedStatement
import java.sql.ResultSet import java.sql.ResultSet
import java.sql.SQLException import java.sql.SQLException
import kotlin.jvm.Throws
object Results { object Results {

View File

@ -1,9 +1,9 @@
@file:JvmName("ConnExt") @file:JvmName("ConnExt")
package solutions.bitbadger.documents.extensions package solutions.bitbadger.documents.java.extensions
import solutions.bitbadger.documents.* import solutions.bitbadger.documents.*
import solutions.bitbadger.documents.jvm.* import solutions.bitbadger.documents.java.*
import java.sql.Connection import java.sql.Connection
import java.sql.ResultSet import java.sql.ResultSet
import kotlin.jvm.Throws import kotlin.jvm.Throws
@ -430,6 +430,7 @@ fun <TKey, TPatch> Connection.patchById(tableName: String, docId: TKey, patch: T
* @throws DocumentException If no dialect has been configured, or if parameters are invalid * @throws DocumentException If no dialect has been configured, or if parameters are invalid
*/ */
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmOverloads
fun <TPatch> Connection.patchByFields( fun <TPatch> Connection.patchByFields(
tableName: String, tableName: String,
fields: Collection<Field<*>>, fields: Collection<Field<*>>,
@ -490,6 +491,7 @@ fun <TKey> Connection.removeFieldsById(tableName: String, docId: TKey, toRemove:
* @throws DocumentException If no dialect has been configured, or if parameters are invalid * @throws DocumentException If no dialect has been configured, or if parameters are invalid
*/ */
@Throws(DocumentException::class) @Throws(DocumentException::class)
@JvmOverloads
fun Connection.removeFieldsByFields( fun Connection.removeFieldsByFields(
tableName: String, tableName: String,
fields: Collection<Field<*>>, fields: Collection<Field<*>>,

View File

@ -0,0 +1,20 @@
module solutions.bitbadger.documents.core.tests {
requires solutions.bitbadger.documents.core;
requires com.fasterxml.jackson.databind;
requires java.sql;
requires kotlin.stdlib;
requires kotlin.test.junit5;
requires org.junit.jupiter.api;
requires org.slf4j;
requires annotations;
//requires org.checkerframework.checker.qual;
exports solutions.bitbadger.documents.core.tests;
exports solutions.bitbadger.documents.core.tests.integration;
exports solutions.bitbadger.documents.core.tests.java;
exports solutions.bitbadger.documents.core.tests.java.integration;
opens solutions.bitbadger.documents.core.tests;
opens solutions.bitbadger.documents.core.tests.java;
opens solutions.bitbadger.documents.core.tests.java.integration;
}

View File

@ -1,17 +1,16 @@
package solutions.bitbadger.documents.java; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.AutoId; import solutions.bitbadger.documents.AutoId;
import solutions.bitbadger.documents.DocumentException; import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.java.support.*;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
/** /**
* Unit tests for the `AutoId` enum * Unit tests for the `AutoId` enum
*/ */
@DisplayName("JVM | Java | AutoId") @DisplayName("Core | Java | AutoId")
final public class AutoIdTest { final public class AutoIdTest {
@Test @Test

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java.support; package solutions.bitbadger.documents.core.tests.java;
public class ByteIdClass { public class ByteIdClass {

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -13,7 +13,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
/** /**
* Unit tests for the `Configuration` object * Unit tests for the `Configuration` object
*/ */
@DisplayName("JVM | Java | Configuration") @DisplayName("Core | Java | Configuration")
final public class ConfigurationTest { final public class ConfigurationTest {
@Test @Test

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java.query; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
@ -6,18 +6,18 @@ import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException; import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.Field; import solutions.bitbadger.documents.Field;
import solutions.bitbadger.documents.query.CountQuery; import solutions.bitbadger.documents.query.CountQuery;
import solutions.bitbadger.documents.support.ForceDialect; import solutions.bitbadger.documents.core.tests.ForceDialect;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static solutions.bitbadger.documents.support.TypesKt.TEST_TABLE; import static solutions.bitbadger.documents.core.tests.TypesKt.TEST_TABLE;
/** /**
* Unit tests for the `Count` object * Unit tests for the `Count` object
*/ */
@DisplayName("JVM | Java | Query | CountQuery") @DisplayName("Core | Java | Query | CountQuery")
final public class CountQueryTest { final public class CountQueryTest {
/** /**

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java.query; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
@ -7,18 +7,18 @@ import solutions.bitbadger.documents.Dialect;
import solutions.bitbadger.documents.DocumentException; import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.DocumentIndex; import solutions.bitbadger.documents.DocumentIndex;
import solutions.bitbadger.documents.query.DefinitionQuery; import solutions.bitbadger.documents.query.DefinitionQuery;
import solutions.bitbadger.documents.support.ForceDialect; import solutions.bitbadger.documents.core.tests.ForceDialect;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static solutions.bitbadger.documents.support.TypesKt.TEST_TABLE; import static solutions.bitbadger.documents.core.tests.TypesKt.TEST_TABLE;
/** /**
* Unit tests for the `Definition` object * Unit tests for the `Definition` object
*/ */
@DisplayName("JVM | Java | Query | DefinitionQuery") @DisplayName("Core | Java | Query | DefinitionQuery")
final public class DefinitionQueryTest { final public class DefinitionQueryTest {
/** /**

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java.query; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
@ -6,18 +6,18 @@ import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException; import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.Field; import solutions.bitbadger.documents.Field;
import solutions.bitbadger.documents.query.DeleteQuery; import solutions.bitbadger.documents.query.DeleteQuery;
import solutions.bitbadger.documents.support.ForceDialect; import solutions.bitbadger.documents.core.tests.ForceDialect;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static solutions.bitbadger.documents.support.TypesKt.TEST_TABLE; import static solutions.bitbadger.documents.core.tests.TypesKt.TEST_TABLE;
/** /**
* Unit tests for the `Delete` object * Unit tests for the `Delete` object
*/ */
@DisplayName("JVM | Java | Query | DeleteQuery") @DisplayName("Core | Java | Query | DeleteQuery")
final public class DeleteQueryTest { final public class DeleteQueryTest {
/** /**

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -10,7 +10,7 @@ import static org.junit.jupiter.api.Assertions.*;
/** /**
* Unit tests for the `Dialect` enum * Unit tests for the `Dialect` enum
*/ */
@DisplayName("JVM | Java | Dialect") @DisplayName("Core | Java | Dialect")
final public class DialectTest { final public class DialectTest {
@Test @Test

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -9,7 +9,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
/** /**
* Unit tests for the `DocumentIndex` enum * Unit tests for the `DocumentIndex` enum
*/ */
@DisplayName("JVM | Java | DocumentIndex") @DisplayName("Core | Java | DocumentIndex")
final public class DocumentIndexTest { final public class DocumentIndexTest {
@Test @Test

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java.query; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
@ -7,15 +7,15 @@ import solutions.bitbadger.documents.AutoId;
import solutions.bitbadger.documents.Configuration; import solutions.bitbadger.documents.Configuration;
import solutions.bitbadger.documents.DocumentException; import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.query.DocumentQuery; import solutions.bitbadger.documents.query.DocumentQuery;
import solutions.bitbadger.documents.support.ForceDialect; import solutions.bitbadger.documents.core.tests.ForceDialect;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static solutions.bitbadger.documents.support.TypesKt.TEST_TABLE; import static solutions.bitbadger.documents.core.tests.TypesKt.TEST_TABLE;
/** /**
* Unit tests for the `Document` object * Unit tests for the `Document` object
*/ */
@DisplayName("JVM | Java | Query | DocumentQuery") @DisplayName("Core | Java | Query | DocumentQuery")
final public class DocumentQueryTest { final public class DocumentQueryTest {
/** /**

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java.query; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
@ -6,18 +6,18 @@ import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException; import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.Field; import solutions.bitbadger.documents.Field;
import solutions.bitbadger.documents.query.ExistsQuery; import solutions.bitbadger.documents.query.ExistsQuery;
import solutions.bitbadger.documents.support.ForceDialect; import solutions.bitbadger.documents.core.tests.ForceDialect;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static solutions.bitbadger.documents.support.TypesKt.TEST_TABLE; import static solutions.bitbadger.documents.core.tests.TypesKt.TEST_TABLE;
/** /**
* Unit tests for the `Exists` object * Unit tests for the `Exists` object
*/ */
@DisplayName("JVM | Java | Query | ExistsQuery") @DisplayName("Core | Java | Query | ExistsQuery")
final public class ExistsQueryTest { final public class ExistsQueryTest {
/** /**

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -9,7 +9,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
/** /**
* Unit tests for the `FieldMatch` enum * Unit tests for the `FieldMatch` enum
*/ */
@DisplayName("JVM | Java | FieldMatch") @DisplayName("Core | Java | FieldMatch")
final public class FieldMatchTest { final public class FieldMatchTest {
@Test @Test

View File

@ -1,11 +1,11 @@
package solutions.bitbadger.documents.java; package solutions.bitbadger.documents.core.tests.java;
import kotlin.Pair; import kotlin.Pair;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.*; import solutions.bitbadger.documents.*;
import solutions.bitbadger.documents.support.ForceDialect; import solutions.bitbadger.documents.core.tests.ForceDialect;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -15,7 +15,7 @@ import static org.junit.jupiter.api.Assertions.*;
/** /**
* Unit tests for the `Field` class * Unit tests for the `Field` class
*/ */
@DisplayName("JVM | Java | Field") @DisplayName("Core | Java | Field")
final public class FieldTest { final public class FieldTest {
/** /**

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java.query; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
@ -6,18 +6,18 @@ import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException; import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.Field; import solutions.bitbadger.documents.Field;
import solutions.bitbadger.documents.query.FindQuery; import solutions.bitbadger.documents.query.FindQuery;
import solutions.bitbadger.documents.support.ForceDialect; import solutions.bitbadger.documents.core.tests.ForceDialect;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static solutions.bitbadger.documents.support.TypesKt.TEST_TABLE; import static solutions.bitbadger.documents.core.tests.TypesKt.TEST_TABLE;
/** /**
* Unit tests for the `Find` object * Unit tests for the `Find` object
*/ */
@DisplayName("JVM | Java | Query | FindQuery") @DisplayName("Core | Java | Query | FindQuery")
final public class FindQueryTest { final public class FindQueryTest {
/** /**

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java.support; package solutions.bitbadger.documents.core.tests.java;
public class IntIdClass { public class IntIdClass {

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java.support; package solutions.bitbadger.documents.core.tests.java;
public class LongIdClass { public class LongIdClass {

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -9,7 +9,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
/** /**
* Unit tests for the `Op` enum * Unit tests for the `Op` enum
*/ */
@DisplayName("JVM | Java | Op") @DisplayName("Core | Java | Op")
final public class OpTest { final public class OpTest {
@Test @Test

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -9,7 +9,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
/** /**
* Unit tests for the `ParameterName` class * Unit tests for the `ParameterName` class
*/ */
@DisplayName("JVM | Java | ParameterName") @DisplayName("Core | Java | ParameterName")
final public class ParameterNameTest { final public class ParameterNameTest {
@Test @Test

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@ -11,7 +11,7 @@ import static org.junit.jupiter.api.Assertions.*;
/** /**
* Unit tests for the `Parameter` class * Unit tests for the `Parameter` class
*/ */
@DisplayName("JVM | Java | Parameter") @DisplayName("Core | Java | Parameter")
final public class ParameterTest { final public class ParameterTest {
@Test @Test

View File

@ -1,10 +1,10 @@
package solutions.bitbadger.documents.java.jvm; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.*; import solutions.bitbadger.documents.*;
import solutions.bitbadger.documents.jvm.Parameters; import solutions.bitbadger.documents.java.Parameters;
import java.util.List; import java.util.List;
@ -13,7 +13,7 @@ import static org.junit.jupiter.api.Assertions.*;
/** /**
* Unit tests for the `Parameters` object * Unit tests for the `Parameters` object
*/ */
@DisplayName("JVM | Java | Parameters") @DisplayName("Core | Java | Parameters")
final public class ParametersTest { final public class ParametersTest {
/** /**

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java.query; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
@ -6,18 +6,18 @@ import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException; import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.Field; import solutions.bitbadger.documents.Field;
import solutions.bitbadger.documents.query.PatchQuery; import solutions.bitbadger.documents.query.PatchQuery;
import solutions.bitbadger.documents.support.ForceDialect; import solutions.bitbadger.documents.core.tests.ForceDialect;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static solutions.bitbadger.documents.support.TypesKt.TEST_TABLE; import static solutions.bitbadger.documents.core.tests.TypesKt.TEST_TABLE;
/** /**
* Unit tests for the `Patch` object * Unit tests for the `Patch` object
*/ */
@DisplayName("JVM | Java | Query | PatchQuery") @DisplayName("Core | Java | Query | PatchQuery")
final public class PatchQueryTest { final public class PatchQueryTest {
/** /**

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java.query; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
@ -8,7 +8,7 @@ import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.Field; import solutions.bitbadger.documents.Field;
import solutions.bitbadger.documents.FieldMatch; import solutions.bitbadger.documents.FieldMatch;
import solutions.bitbadger.documents.query.QueryUtils; import solutions.bitbadger.documents.query.QueryUtils;
import solutions.bitbadger.documents.support.ForceDialect; import solutions.bitbadger.documents.core.tests.ForceDialect;
import java.util.List; import java.util.List;
@ -17,7 +17,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
/** /**
* Unit tests for the package-level query functions, presented as `QueryUtils` for Java-compatible use * Unit tests for the package-level query functions, presented as `QueryUtils` for Java-compatible use
*/ */
@DisplayName("JVM | Java | Query | QueryUtils") @DisplayName("Core | Java | Query | QueryUtils")
final public class QueryUtilsTest { final public class QueryUtilsTest {
/** /**

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java.query; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
@ -8,18 +8,18 @@ import solutions.bitbadger.documents.Field;
import solutions.bitbadger.documents.Parameter; import solutions.bitbadger.documents.Parameter;
import solutions.bitbadger.documents.ParameterType; import solutions.bitbadger.documents.ParameterType;
import solutions.bitbadger.documents.query.RemoveFieldsQuery; import solutions.bitbadger.documents.query.RemoveFieldsQuery;
import solutions.bitbadger.documents.support.ForceDialect; import solutions.bitbadger.documents.core.tests.ForceDialect;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import static solutions.bitbadger.documents.support.TypesKt.TEST_TABLE; import static solutions.bitbadger.documents.core.tests.TypesKt.TEST_TABLE;
/** /**
* Unit tests for the `RemoveFields` object * Unit tests for the `RemoveFields` object
*/ */
@DisplayName("JVM | Java | Query | RemoveFieldsQuery") @DisplayName("Core | Java | Query | RemoveFieldsQuery")
final public class RemoveFieldsQueryTest { final public class RemoveFieldsQueryTest {
/** /**

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java.support; package solutions.bitbadger.documents.core.tests.java;
public class ShortIdClass { public class ShortIdClass {

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java.support; package solutions.bitbadger.documents.core.tests.java;
public class StringIdClass { public class StringIdClass {

View File

@ -1,4 +1,4 @@
package solutions.bitbadger.documents.java.query; package solutions.bitbadger.documents.core.tests.java;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
@ -7,7 +7,7 @@ import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.Field; import solutions.bitbadger.documents.Field;
import solutions.bitbadger.documents.FieldMatch; import solutions.bitbadger.documents.FieldMatch;
import solutions.bitbadger.documents.query.Where; import solutions.bitbadger.documents.query.Where;
import solutions.bitbadger.documents.support.ForceDialect; import solutions.bitbadger.documents.core.tests.ForceDialect;
import java.util.List; import java.util.List;
@ -17,7 +17,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
/** /**
* Unit tests for the `Where` object * Unit tests for the `Where` object
*/ */
@DisplayName("JVM | Java | Query | Where") @DisplayName("Core | Java | Query | Where")
final public class WhereTest { final public class WhereTest {
/** /**

View File

@ -0,0 +1,41 @@
package solutions.bitbadger.documents.core.tests.java.integration;
import java.util.List;
public class ArrayDocument {
private String id;
private List<String> values;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public List<String> getValues() {
return values;
}
public void setValues(List<String> values) {
this.values = values;
}
public ArrayDocument(String id, List<String> values) {
this.id = id;
this.values = values;
}
public ArrayDocument() {
this("", List.of());
}
public static List<ArrayDocument> testDocuments =
List.of(
new ArrayDocument("first", List.of("a", "b", "c")),
new ArrayDocument("second", List.of("c", "d", "e")),
new ArrayDocument("third", List.of("x", "y", "z")));
}

View File

@ -1,16 +1,15 @@
package solutions.bitbadger.documents.java.jvm.integration.common; package solutions.bitbadger.documents.core.tests.java.integration;
import solutions.bitbadger.documents.DocumentException; import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.Field; import solutions.bitbadger.documents.Field;
import solutions.bitbadger.documents.java.support.JsonDocument; import solutions.bitbadger.documents.core.tests.integration.ThrowawayDatabase;
import solutions.bitbadger.documents.support.ThrowawayDatabase;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static solutions.bitbadger.documents.extensions.ConnExt.*; import static solutions.bitbadger.documents.core.tests.TypesKt.TEST_TABLE;
import static solutions.bitbadger.documents.support.TypesKt.TEST_TABLE; import static solutions.bitbadger.documents.java.extensions.ConnExt.*;
/** /**
* Integration tests for the `Count` object * Integration tests for the `Count` object

View File

@ -1,19 +1,18 @@
package solutions.bitbadger.documents.java.jvm.integration.common; package solutions.bitbadger.documents.core.tests.java.integration;
import solutions.bitbadger.documents.*; import solutions.bitbadger.documents.*;
import solutions.bitbadger.documents.java.support.JsonDocument; import solutions.bitbadger.documents.core.tests.integration.ThrowawayDatabase;
import solutions.bitbadger.documents.jvm.Results; import solutions.bitbadger.documents.java.Results;
import solutions.bitbadger.documents.query.CountQuery; import solutions.bitbadger.documents.query.CountQuery;
import solutions.bitbadger.documents.query.DeleteQuery; import solutions.bitbadger.documents.query.DeleteQuery;
import solutions.bitbadger.documents.query.FindQuery; import solutions.bitbadger.documents.query.FindQuery;
import solutions.bitbadger.documents.support.ThrowawayDatabase;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
import static solutions.bitbadger.documents.extensions.ConnExt.*; import static solutions.bitbadger.documents.core.tests.TypesKt.TEST_TABLE;
import static solutions.bitbadger.documents.support.TypesKt.TEST_TABLE; import static solutions.bitbadger.documents.java.extensions.ConnExt.*;
final public class CustomFunctions { final public class CustomFunctions {
@ -33,16 +32,18 @@ final public class CustomFunctions {
} }
public static void singleNone(ThrowawayDatabase db) throws DocumentException { public static void singleNone(ThrowawayDatabase db) throws DocumentException {
assertNull( assertFalse(
customSingle(db.getConn(), FindQuery.all(TEST_TABLE), List.of(), JsonDocument.class, Results::fromData), customSingle(db.getConn(), FindQuery.all(TEST_TABLE), List.of(), JsonDocument.class, Results::fromData)
.isPresent(),
"There should not have been a document returned"); "There should not have been a document returned");
} }
public static void singleOne(ThrowawayDatabase db) throws DocumentException { public static void singleOne(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db); JsonDocument.load(db);
assertNotNull( assertTrue(
customSingle(db.getConn(), FindQuery.all(TEST_TABLE), List.of(), JsonDocument.class, Results::fromData), customSingle(db.getConn(), FindQuery.all(TEST_TABLE), List.of(), JsonDocument.class, Results::fromData)
"There should not have been a document returned"); .isPresent(),
"There should have been a document returned");
} }
public static void nonQueryChanges(ThrowawayDatabase db) throws DocumentException { public static void nonQueryChanges(ThrowawayDatabase db) throws DocumentException {

View File

@ -0,0 +1,47 @@
package solutions.bitbadger.documents.core.tests.java.integration;
import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.DocumentIndex;
import solutions.bitbadger.documents.core.tests.integration.ThrowawayDatabase;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static solutions.bitbadger.documents.core.tests.TypesKt.TEST_TABLE;
import static solutions.bitbadger.documents.java.extensions.ConnExt.*;
final public class DefinitionFunctions {
public static void ensuresATable(ThrowawayDatabase db) throws DocumentException {
assertFalse(db.dbObjectExists("ensured"), "The 'ensured' table should not exist");
assertFalse(db.dbObjectExists("idx_ensured_key"), "The PK index for the 'ensured' table should not exist");
ensureTable(db.getConn(), "ensured");
assertTrue(db.dbObjectExists("ensured"), "The 'ensured' table should exist");
assertTrue(db.dbObjectExists("idx_ensured_key"), "The PK index for the 'ensured' table should now exist");
}
public static void ensuresAFieldIndex(ThrowawayDatabase db) throws DocumentException {
assertFalse(db.dbObjectExists(String.format("idx_%s_test", TEST_TABLE)), "The test index should not exist");
ensureFieldIndex(db.getConn(), TEST_TABLE, "test", List.of("id", "category"));
assertTrue(db.dbObjectExists(String.format("idx_%s_test", TEST_TABLE)), "The test index should now exist");
}
public static void ensureDocumentIndexFull(ThrowawayDatabase db) throws DocumentException {
assertFalse(db.dbObjectExists("doc_table"), "The 'doc_table' table should not exist");
ensureTable(db.getConn(), "doc_table");
assertTrue(db.dbObjectExists("doc_table"), "The 'doc_table' table should exist");
assertFalse(db.dbObjectExists("idx_doc_table_document"), "The document index should not exist");
ensureDocumentIndex(db.getConn(), "doc_table", DocumentIndex.FULL);
assertTrue(db.dbObjectExists("idx_doc_table_document"), "The document index should exist");
}
public static void ensureDocumentIndexOptimized(ThrowawayDatabase db) throws DocumentException {
assertFalse(db.dbObjectExists("doc_table"), "The 'doc_table' table should not exist");
ensureTable(db.getConn(), "doc_table");
assertTrue(db.dbObjectExists("doc_table"), "The 'doc_table' table should exist");
assertFalse(db.dbObjectExists("idx_doc_table_document"), "The document index should not exist");
ensureDocumentIndex(db.getConn(), "doc_table", DocumentIndex.OPTIMIZED);
assertTrue(db.dbObjectExists("idx_doc_table_document"), "The document index should exist");
}
}

View File

@ -0,0 +1,71 @@
package solutions.bitbadger.documents.core.tests.java.integration;
import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.Field;
import solutions.bitbadger.documents.core.tests.integration.ThrowawayDatabase;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static solutions.bitbadger.documents.core.tests.TypesKt.TEST_TABLE;
import static solutions.bitbadger.documents.java.extensions.ConnExt.*;
final public class DeleteFunctions {
public static void byIdMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertEquals(5L, countAll(db.getConn(), TEST_TABLE), "There should be 5 documents in the table");
deleteById(db.getConn(), TEST_TABLE, "four");
assertEquals(4L, countAll(db.getConn(), TEST_TABLE), "There should now be 4 documents in the table");
}
public static void byIdNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertEquals(5L, countAll(db.getConn(), TEST_TABLE), "There should be 5 documents in the table");
deleteById(db.getConn(), TEST_TABLE, "negative four");
assertEquals(5L, countAll(db.getConn(), TEST_TABLE), "There should still be 5 documents in the table");
}
public static void byFieldsMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertEquals(5L, countAll(db.getConn(), TEST_TABLE), "There should be 5 documents in the table");
deleteByFields( db.getConn(), TEST_TABLE, List.of(Field.notEqual("value", "purple")));
assertEquals(2L, countAll(db.getConn(), TEST_TABLE), "There should now be 2 documents in the table");
}
public static void byFieldsNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertEquals(5L, countAll(db.getConn(), TEST_TABLE), "There should be 5 documents in the table");
deleteByFields(db.getConn(), TEST_TABLE, List.of(Field.equal("value", "crimson")));
assertEquals(5L, countAll(db.getConn(), TEST_TABLE), "There should still be 5 documents in the table");
}
public static void byContainsMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertEquals(5L, countAll(db.getConn(), TEST_TABLE), "There should be 5 documents in the table");
deleteByContains(db.getConn(), TEST_TABLE, Map.of("value", "purple"));
assertEquals(3L, countAll(db.getConn(), TEST_TABLE), "There should now be 3 documents in the table");
}
public static void byContainsNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertEquals(5L, countAll(db.getConn(), TEST_TABLE), "There should be 5 documents in the table");
deleteByContains(db.getConn(), TEST_TABLE, Map.of("target", "acquired"));
assertEquals(5L, countAll(db.getConn(), TEST_TABLE), "There should still be 5 documents in the table");
}
public static void byJsonPathMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertEquals(5L, countAll(db.getConn(), TEST_TABLE), "There should be 5 documents in the table");
deleteByJsonPath(db.getConn(), TEST_TABLE, "$.value ? (@ == \"purple\")");
assertEquals(3L, countAll(db.getConn(), TEST_TABLE), "There should now be 3 documents in the table");
}
public static void byJsonPathNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertEquals(5L, countAll(db.getConn(), TEST_TABLE), "There should be 5 documents in the table");
deleteByJsonPath(db.getConn(), TEST_TABLE, "$.numValue ? (@ > 100)");
assertEquals(5L, countAll(db.getConn(), TEST_TABLE), "There should still be 5 documents in the table");
}
}

View File

@ -0,0 +1,138 @@
package solutions.bitbadger.documents.core.tests.java.integration;
import solutions.bitbadger.documents.AutoId;
import solutions.bitbadger.documents.Configuration;
import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.Field;
import solutions.bitbadger.documents.core.tests.integration.ThrowawayDatabase;
import java.util.List;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.*;
import static solutions.bitbadger.documents.core.tests.TypesKt.TEST_TABLE;
import static solutions.bitbadger.documents.java.extensions.ConnExt.*;
final public class DocumentFunctions {
public static void insertDefault(ThrowawayDatabase db) throws DocumentException {
assertEquals(0L, countAll(db.getConn(), TEST_TABLE), "There should be no documents in the table");
insert(db.getConn(), TEST_TABLE, new JsonDocument("turkey", "", 0, new SubDocument("gobble", "gobble!")));
final List<JsonDocument> after = findAll(db.getConn(), TEST_TABLE, JsonDocument.class);
assertEquals(1, after.size(), "There should be one document in the table");
final JsonDocument doc = after.get(0);
assertEquals("turkey", doc.getId(), "The inserted document's ID is incorrect");
assertEquals("", doc.getValue(), "The inserted document's value is incorrect");
assertEquals(0, doc.getNumValue(), "The document's numeric value is incorrect");
assertNotNull(doc.getSub(), "The inserted document's subdocument was not created");
assertEquals("gobble", doc.getSub().getFoo(), "The subdocument's \"foo\" property is incorrect");
assertEquals("gobble!", doc.getSub().getBar(), "The subdocument's \"bar\" property is incorrect");
}
public static void insertDupe(ThrowawayDatabase db) throws DocumentException {
insert(db.getConn(), TEST_TABLE, new JsonDocument("a", "", 0));
assertThrows(DocumentException.class, () -> insert(db.getConn(), TEST_TABLE, new JsonDocument("a", "b", 22)),
"Inserting a document with a duplicate key should have thrown an exception");
}
public static void insertNumAutoId(ThrowawayDatabase db) throws DocumentException {
try {
Configuration.autoIdStrategy = AutoId.NUMBER;
Configuration.idField = "key";
assertEquals(0L, countAll(db.getConn(), TEST_TABLE), "There should be no documents in the table");
insert(db.getConn(), TEST_TABLE, new NumIdDocument(0, "one"));
insert(db.getConn(), TEST_TABLE, new NumIdDocument(0, "two"));
insert(db.getConn(), TEST_TABLE, new NumIdDocument(77, "three"));
insert(db.getConn(), TEST_TABLE, new NumIdDocument(0, "four"));
final List<NumIdDocument> after = findAll(db.getConn(), TEST_TABLE, NumIdDocument.class,
List.of(Field.named("key")));
assertEquals(4, after.size(), "There should have been 4 documents returned");
assertEquals("1|2|77|78",
after.stream().map(doc -> String.valueOf(doc.getKey()))
.reduce((acc, item) -> String.format("%s|%s", acc, item)).get(),
"The IDs were not generated correctly");
} finally {
Configuration.autoIdStrategy = AutoId.DISABLED;
Configuration.idField = "id";
}
}
public static void insertUUIDAutoId(ThrowawayDatabase db) throws DocumentException {
try {
Configuration.autoIdStrategy = AutoId.UUID;
assertEquals(0L, countAll(db.getConn(), TEST_TABLE), "There should be no documents in the table");
insert(db.getConn(), TEST_TABLE, new JsonDocument(""));
final List<JsonDocument> after = findAll(db.getConn(), TEST_TABLE, JsonDocument.class);
assertEquals(1, after.size(), "There should have been 1 document returned");
assertEquals(32, after.get(0).getId().length(), "The ID was not generated correctly");
} finally {
Configuration.autoIdStrategy = AutoId.DISABLED;
}
}
public static void insertStringAutoId(ThrowawayDatabase db) throws DocumentException {
try {
Configuration.autoIdStrategy = AutoId.RANDOM_STRING;
assertEquals(0L, countAll(db.getConn(), TEST_TABLE), "There should be no documents in the table");
insert(db.getConn(), TEST_TABLE, new JsonDocument(""));
Configuration.idStringLength = 21;
insert(db.getConn(), TEST_TABLE, new JsonDocument(""));
final List<JsonDocument> after = findAll(db.getConn(), TEST_TABLE, JsonDocument.class);
assertEquals(2, after.size(), "There should have been 2 documents returned");
assertEquals(16, after.get(0).getId().length(), "The first document's ID was not generated correctly");
assertEquals(21, after.get(1).getId().length(), "The second document's ID was not generated correctly");
} finally {
Configuration.autoIdStrategy = AutoId.DISABLED;
Configuration.idStringLength = 16;
}
}
public static void saveMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
save(db.getConn(), TEST_TABLE, new JsonDocument("two", "", 44));
final Optional<JsonDocument> tryDoc = findById(db.getConn(), TEST_TABLE, "two", JsonDocument.class);
assertTrue(tryDoc.isPresent(), "There should have been a document returned");
final JsonDocument doc = tryDoc.get();
assertEquals("two", doc.getId(), "An incorrect document was returned");
assertEquals("", doc.getValue(), "The \"value\" field was not updated");
assertEquals(44, doc.getNumValue(), "The \"numValue\" field was not updated");
assertNull(doc.getSub(), "The \"sub\" field was not updated");
}
public static void saveNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final JsonDocument toSave = new JsonDocument("test");
toSave.setSub(new SubDocument("a", "b"));
save(db.getConn(), TEST_TABLE, toSave);
assertTrue(findById(db.getConn(), TEST_TABLE, "test", JsonDocument.class).isPresent(),
"The test document should have been saved");
}
public static void updateMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
update(db.getConn(), TEST_TABLE, "one", new JsonDocument("one", "howdy", 8, new SubDocument("y", "z")));
final Optional<JsonDocument> tryDoc = findById(db.getConn(), TEST_TABLE, "one", JsonDocument.class);
assertTrue(tryDoc.isPresent(), "There should have been a document returned");
final JsonDocument doc = tryDoc.get();
assertEquals("one", doc.getId(), "An incorrect document was returned");
assertEquals("howdy", doc.getValue(), "The \"value\" field was not updated");
assertEquals(8, doc.getNumValue(), "The \"numValue\" field was not updated");
assertNotNull(doc.getSub(), "The sub-document should not be null");
assertEquals("y", doc.getSub().getFoo(), "The sub-document \"foo\" field was not updated");
assertEquals("z", doc.getSub().getBar(), "The sub-document \"bar\" field was not updated");
}
public static void updateNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertFalse(existsById(db.getConn(), TEST_TABLE, "two-hundred"));
update(db.getConn(), TEST_TABLE, "two-hundred", new JsonDocument("two-hundred", "", 200));
assertFalse(existsById(db.getConn(), TEST_TABLE, "two-hundred"));
}
}

View File

@ -0,0 +1,62 @@
package solutions.bitbadger.documents.core.tests.java.integration;
import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.Field;
import solutions.bitbadger.documents.core.tests.integration.ThrowawayDatabase;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static solutions.bitbadger.documents.core.tests.TypesKt.TEST_TABLE;
import static solutions.bitbadger.documents.java.extensions.ConnExt.*;
final public class ExistsFunctions {
public static void byIdMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertTrue(existsById(db.getConn(), TEST_TABLE, "three"), "The document with ID \"three\" should exist");
}
public static void byIdNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertFalse(existsById(db.getConn(), TEST_TABLE, "seven"), "The document with ID \"seven\" should not exist");
}
public static void byFieldsMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertTrue(existsByFields(db.getConn(), TEST_TABLE, List.of(Field.equal("numValue", 10))),
"Matching documents should have been found");
}
public static void byFieldsNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertFalse(existsByFields(db.getConn(), TEST_TABLE, List.of(Field.equal("nothing", "none"))),
"No matching documents should have been found");
}
public static void byContainsMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertTrue(existsByContains(db.getConn(), TEST_TABLE, Map.of("value", "purple")),
"Matching documents should have been found");
}
public static void byContainsNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertFalse(existsByContains(db.getConn(), TEST_TABLE, Map.of("value", "violet")),
"Matching documents should not have been found");
}
public static void byJsonPathMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertTrue(existsByJsonPath(db.getConn(), TEST_TABLE, "$.numValue ? (@ == 10)"),
"Matching documents should have been found");
}
public static void byJsonPathNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertFalse(existsByJsonPath(db.getConn(), TEST_TABLE, "$.numValue ? (@ == 10.1)"),
"Matching documents should not have been found");
}
}

View File

@ -0,0 +1,279 @@
package solutions.bitbadger.documents.core.tests.java.integration;
import solutions.bitbadger.documents.Configuration;
import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.Field;
import solutions.bitbadger.documents.FieldMatch;
import solutions.bitbadger.documents.core.tests.integration.ThrowawayDatabase;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.*;
import static solutions.bitbadger.documents.core.tests.TypesKt.TEST_TABLE;
import static solutions.bitbadger.documents.java.extensions.ConnExt.*;
final public class FindFunctions {
private static String docIds(List<JsonDocument> docs) {
return docs.stream().map(JsonDocument::getId).reduce((acc, docId) -> String.format("%s|%s", acc, docId)).get();
}
public static void allDefault(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertEquals(5, findAll(db.getConn(), TEST_TABLE, JsonDocument.class).size(),
"There should have been 5 documents returned");
}
public static void allAscending(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final List<JsonDocument> docs = findAll(db.getConn(), TEST_TABLE, JsonDocument.class,
List.of(Field.named("id")));
assertEquals(5, docs.size(), "There should have been 5 documents returned");
assertEquals("five|four|one|three|two", docIds(docs), "The documents were not ordered correctly");
}
public static void allDescending(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final List<JsonDocument> docs = findAll(db.getConn(), TEST_TABLE, JsonDocument.class,
List.of(Field.named("id DESC")));
assertEquals(5, docs.size(), "There should have been 5 documents returned");
assertEquals("two|three|one|four|five", docIds(docs), "The documents were not ordered correctly");
}
public static void allNumOrder(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final List<JsonDocument> docs = findAll(db.getConn(), TEST_TABLE, JsonDocument.class,
List.of(Field.named("sub.foo NULLS LAST"), Field.named("n:numValue")));
assertEquals(5, docs.size(), "There should have been 5 documents returned");
assertEquals("two|four|one|three|five", docIds(docs), "The documents were not ordered correctly");
}
public static void allEmpty(ThrowawayDatabase db) throws DocumentException {
assertEquals(0, findAll(db.getConn(), TEST_TABLE, JsonDocument.class).size(),
"There should have been no documents returned");
}
public static void byIdString(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final Optional<JsonDocument> doc = findById(db.getConn(), TEST_TABLE, "two", JsonDocument.class);
assertTrue(doc.isPresent(), "The document should have been returned");
assertEquals("two", doc.get().getId(), "An incorrect document was returned");
}
public static void byIdNumber(ThrowawayDatabase db) throws DocumentException {
Configuration.idField = "key";
try {
insert(db.getConn(), TEST_TABLE, new NumIdDocument(18, "howdy"));
final Optional<NumIdDocument> doc = findById(db.getConn(), TEST_TABLE, 18, NumIdDocument.class);
assertTrue(doc.isPresent(), "The document should have been returned");
} finally {
Configuration.idField = "id";
}
}
public static void byIdNotFound(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertFalse(findById(db.getConn(), TEST_TABLE, "x", JsonDocument.class).isPresent(),
"There should have been no document returned");
}
public static void byFieldsMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final List<JsonDocument> docs = findByFields(db.getConn(), TEST_TABLE,
List.of(Field.any("value", List.of("blue", "purple")), Field.exists("sub")), JsonDocument.class,
FieldMatch.ALL);
assertEquals(1, docs.size(), "There should have been a document returned");
assertEquals("four", docs.get(0).getId(), "The incorrect document was returned");
}
public static void byFieldsMatchOrdered(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final List<JsonDocument> docs = findByFields(db.getConn(), TEST_TABLE, List.of(Field.equal("value", "purple")),
JsonDocument.class, null, List.of(Field.named("id")));
assertEquals(2, docs.size(), "There should have been 2 documents returned");
assertEquals("five|four", docIds(docs), "The documents were not ordered correctly");
}
public static void byFieldsMatchNumIn(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final List<JsonDocument> docs = findByFields(db.getConn(), TEST_TABLE,
List.of(Field.any("numValue", List.of(2, 4, 6, 8))), JsonDocument.class);
assertEquals(1, docs.size(), "There should have been a document returned");
assertEquals("three", docs.get(0).getId(), "The incorrect document was returned");
}
public static void byFieldsNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertEquals(0,
findByFields(db.getConn(), TEST_TABLE, List.of(Field.greater("numValue", 100)), JsonDocument.class)
.size(),
"There should have been no documents returned");
}
public static void byFieldsMatchInArray(ThrowawayDatabase db) throws DocumentException {
for (final ArrayDocument doc : ArrayDocument.testDocuments) { insert(db.getConn(), TEST_TABLE, doc); }
final List<ArrayDocument> docs = findByFields(db.getConn(), TEST_TABLE,
List.of(Field.inArray("values", TEST_TABLE, List.of("c"))), ArrayDocument.class);
assertEquals(2, docs.size(), "There should have been two documents returned");
assertTrue(List.of("first", "second").contains(docs.get(0).getId()),
String.format("An incorrect document was returned (%s)", docs.get(0).getId()));
assertTrue(List.of("first", "second").contains(docs.get(1).getId()),
String.format("An incorrect document was returned (%s)", docs.get(1).getId()));
}
public static void byFieldsNoMatchInArray(ThrowawayDatabase db) throws DocumentException {
for (final ArrayDocument doc : ArrayDocument.testDocuments) { insert(db.getConn(), TEST_TABLE, doc); }
assertEquals(0,
findByFields(db.getConn(), TEST_TABLE, List.of(Field.inArray("values", TEST_TABLE, List.of("j"))),
ArrayDocument.class).size(),
"There should have been no documents returned");
}
public static void byContainsMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final List<JsonDocument> docs = findByContains(db.getConn(), TEST_TABLE, Map.of("value", "purple"),
JsonDocument.class);
assertEquals(2, docs.size(), "There should have been 2 documents returned");
assertTrue(List.of("four", "five").contains(docs.get(0).getId()),
String.format("An incorrect document was returned (%s)", docs.get(0).getId()));
assertTrue(List.of("four", "five").contains(docs.get(1).getId()),
String.format("An incorrect document was returned (%s)", docs.get(1).getId()));
}
public static void byContainsMatchOrdered(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final List<JsonDocument> docs = findByContains(db.getConn(), TEST_TABLE, Map.of("sub", Map.of("foo", "green")),
JsonDocument.class, List.of(Field.named("value")));
assertEquals(2, docs.size(), "There should have been 2 documents returned");
assertEquals("two|four", docIds(docs), "The documents were not ordered correctly");
}
public static void byContainsNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertEquals(0, findByContains(db.getConn(), TEST_TABLE, Map.of("value", "indigo"), JsonDocument.class).size(),
"There should have been no documents returned");
}
public static void byJsonPathMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final List<JsonDocument> docs = findByJsonPath(db.getConn(), TEST_TABLE, "$.numValue ? (@ > 10)",
JsonDocument.class);
assertEquals(2, docs.size(), "There should have been 2 documents returned");
assertTrue(List.of("four", "five").contains(docs.get(0).getId()),
String.format("An incorrect document was returned (%s)", docs.get(0).getId()));
assertTrue(List.of("four", "five").contains(docs.get(1).getId()),
String.format("An incorrect document was returned (%s)", docs.get(1).getId())); }
public static void byJsonPathMatchOrdered(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final List<JsonDocument> docs = findByJsonPath(db.getConn(), TEST_TABLE, "$.numValue ? (@ > 10)",
JsonDocument.class, List.of(Field.named("id")));
assertEquals(2, docs.size(), "There should have been 2 documents returned");
assertEquals("five|four", docIds(docs), "The documents were not ordered correctly");
}
public static void byJsonPathNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertEquals(0, findByJsonPath(db.getConn(), TEST_TABLE, "$.numValue ? (@ > 100)", JsonDocument.class).size(),
"There should have been no documents returned");
}
public static void firstByFieldsMatchOne(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final Optional<JsonDocument> doc = findFirstByFields(db.getConn(), TEST_TABLE,
List.of(Field.equal("value", "another")), JsonDocument.class);
assertTrue(doc.isPresent(), "There should have been a document returned");
assertEquals("two", doc.get().getId(), "The incorrect document was returned");
}
public static void firstByFieldsMatchMany(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final Optional<JsonDocument> doc = findFirstByFields(db.getConn(), TEST_TABLE,
List.of(Field.equal("sub.foo", "green")), JsonDocument.class);
assertTrue(doc.isPresent(), "There should have been a document returned");
assertTrue(List.of("two", "four").contains(doc.get().getId()),
String.format("An incorrect document was returned (%s)", doc.get().getId()));
}
public static void firstByFieldsMatchOrdered(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final Optional<JsonDocument> doc = findFirstByFields(db.getConn(), TEST_TABLE,
List.of(Field.equal("sub.foo", "green")), JsonDocument.class, null,
List.of(Field.named("n:numValue DESC")));
assertTrue(doc.isPresent(), "There should have been a document returned");
assertEquals("four", doc.get().getId(), "An incorrect document was returned");
}
public static void firstByFieldsNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertFalse(findFirstByFields(db.getConn(), TEST_TABLE, List.of(Field.equal("value", "absent")),
JsonDocument.class).isPresent(),
"There should have been no document returned");
}
public static void firstByContainsMatchOne(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final Optional<JsonDocument> doc = findFirstByContains(db.getConn(), TEST_TABLE, Map.of("value", "FIRST!"),
JsonDocument.class);
assertTrue(doc.isPresent(), "There should have been a document returned");
assertEquals("one", doc.get().getId(), "An incorrect document was returned");
}
public static void firstByContainsMatchMany(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final Optional<JsonDocument> doc = findFirstByContains(db.getConn(), TEST_TABLE, Map.of("value", "purple"),
JsonDocument.class);
assertTrue(doc.isPresent(), "There should have been a document returned");
assertTrue(List.of("four", "five").contains(doc.get().getId()),
String.format("An incorrect document was returned (%s)", doc.get().getId()));
}
public static void firstByContainsMatchOrdered(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final Optional<JsonDocument> doc = findFirstByContains(db.getConn(), TEST_TABLE, Map.of("value", "purple"),
JsonDocument.class, List.of(Field.named("sub.bar NULLS FIRST")));
assertTrue(doc.isPresent(), "There should have been a document returned");
assertEquals("five", doc.get().getId(), "An incorrect document was returned");
}
public static void firstByContainsNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertFalse(findFirstByContains(db.getConn(), TEST_TABLE, Map.of("value", "indigo"), JsonDocument.class)
.isPresent(),
"There should have been no document returned");
}
public static void firstByJsonPathMatchOne(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final Optional<JsonDocument> doc = findFirstByJsonPath(db.getConn(), TEST_TABLE, "$.numValue ? (@ == 10)",
JsonDocument.class);
assertTrue(doc.isPresent(), "There should have been a document returned");
assertEquals("two", doc.get().getId(), "An incorrect document was returned");
}
public static void firstByJsonPathMatchMany(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final Optional<JsonDocument> doc = findFirstByJsonPath(db.getConn(), TEST_TABLE, "$.numValue ? (@ > 10)",
JsonDocument.class);
assertTrue(doc.isPresent(), "There should have been a document returned");
assertTrue(List.of("four", "five").contains(doc.get().getId()),
String.format("An incorrect document was returned (%s)", doc.get().getId()));
}
public static void firstByJsonPathMatchOrdered(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final Optional<JsonDocument> doc = findFirstByJsonPath(db.getConn(), TEST_TABLE, "$.numValue ? (@ > 10)",
JsonDocument.class, List.of(Field.named("id DESC")));
assertTrue(doc.isPresent(), "There should have been a document returned");
assertEquals("four", doc.get().getId(), "An incorrect document was returned");
}
public static void firstByJsonPathNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertFalse(findFirstByJsonPath(db.getConn(), TEST_TABLE, "$.numValue ? (@ > 100)", JsonDocument.class)
.isPresent(),
"There should have been no document returned");
}
}

View File

@ -1,13 +1,13 @@
package solutions.bitbadger.documents.java.support; package solutions.bitbadger.documents.core.tests.java.integration;
import solutions.bitbadger.documents.DocumentException; import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.jvm.Document; import solutions.bitbadger.documents.java.Document;
import solutions.bitbadger.documents.support.ThrowawayDatabase; import solutions.bitbadger.documents.core.tests.integration.ThrowawayDatabase;
import java.util.List; import java.util.List;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
import static solutions.bitbadger.documents.support.TypesKt.TEST_TABLE; import static solutions.bitbadger.documents.core.tests.TypesKt.TEST_TABLE;
public class JsonDocument { public class JsonDocument {

View File

@ -0,0 +1,32 @@
package solutions.bitbadger.documents.core.tests.java.integration;
public class NumIdDocument {
private int key;
private String value;
public int getKey() {
return key;
}
public void setKey(int key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public NumIdDocument(int key, String value) {
this.key = key;
this.value = value;
}
public NumIdDocument() {
this(0, "");
}
}

View File

@ -0,0 +1,85 @@
package solutions.bitbadger.documents.core.tests.java.integration;
import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.Field;
import solutions.bitbadger.documents.core.tests.integration.ThrowawayDatabase;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.*;
import static solutions.bitbadger.documents.core.tests.TypesKt.TEST_TABLE;
import static solutions.bitbadger.documents.java.extensions.ConnExt.*;
final public class PatchFunctions {
public static void byIdMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
patchById(db.getConn(), TEST_TABLE, "one", Map.of("numValue", 44));
final Optional<JsonDocument> doc = findById(db.getConn(), TEST_TABLE, "one", JsonDocument.class);
assertTrue(doc.isPresent(), "There should have been a document returned");
assertEquals("one", doc.get().getId(), "An incorrect document was returned");
assertEquals(44, doc.get().getNumValue(), "The document was not patched");
}
public static void byIdNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertFalse(existsById(db.getConn(), TEST_TABLE, "forty-seven"),
"Document with ID \"forty-seven\" should not exist");
patchById(db.getConn(), TEST_TABLE, "forty-seven", Map.of("foo", "green")); // no exception = pass
}
public static void byFieldsMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
patchByFields(db.getConn(), TEST_TABLE, List.of(Field.equal("value", "purple")), Map.of("numValue", 77));
assertEquals(2L, countByFields(db.getConn(), TEST_TABLE, List.of(Field.equal("numValue", 77))),
"There should have been 2 documents with numeric value 77");
}
public static void byFieldsNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final List<Field<?>> fields = List.of(Field.equal("value", "burgundy"));
assertFalse(existsByFields(db.getConn(), TEST_TABLE, fields),
"There should be no documents with value of \"burgundy\"");
patchByFields(db.getConn(), TEST_TABLE, fields, Map.of("foo", "green")); // no exception = pass
}
public static void byContainsMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final Map<String, String> contains = Map.of("value", "another");
patchByContains(db.getConn(), TEST_TABLE, contains, Map.of("numValue", 12));
final Optional<JsonDocument> doc = findFirstByContains(db.getConn(), TEST_TABLE, contains, JsonDocument.class);
assertTrue(doc.isPresent(), "There should have been a document returned");
assertEquals("two", doc.get().getId(), "The incorrect document was returned");
assertEquals(12, doc.get().getNumValue(), "The document was not updated");
}
public static void byContainsNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final Map<String, String> contains = Map.of("value", "updated");
assertFalse(existsByContains(db.getConn(), TEST_TABLE, contains), "There should be no matching documents");
patchByContains(db.getConn(), TEST_TABLE, contains, Map.of("sub.foo", "green")); // no exception = pass
}
public static void byJsonPathMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final String path = "$.numValue ? (@ > 10)";
patchByJsonPath(db.getConn(), TEST_TABLE, path, Map.of("value", "blue"));
final List<JsonDocument> docs = findByJsonPath(db.getConn(), TEST_TABLE, path, JsonDocument.class);
assertEquals(2, docs.size(), "There should have been two documents returned");
for (final JsonDocument doc : docs) {
assertTrue(List.of("four", "five").contains(doc.getId()),
String.format("An incorrect document was returned (%s)", doc.getId()));
assertEquals("blue", doc.getValue(), String.format("The value for ID %s was incorrect", doc.getId()));
}
}
public static void byJsonPathNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final String path = "$.numValue ? (@ > 100)";
assertFalse(existsByJsonPath(db.getConn(), TEST_TABLE, path),
"There should be no documents with numeric values over 100");
patchByJsonPath(db.getConn(), TEST_TABLE, path, Map.of("value", "blue")); // no exception = pass
}
}

View File

@ -1,16 +1,15 @@
package solutions.bitbadger.documents.java.jvm.integration.postgresql; package solutions.bitbadger.documents.core.tests.java.integration;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException; import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.java.jvm.integration.common.CountFunctions; import solutions.bitbadger.documents.core.tests.integration.PgDB;
import solutions.bitbadger.documents.jvm.integration.postgresql.PgDB;
/** /**
* PostgreSQL integration tests for the `Count` object / `count*` connection extension functions * PostgreSQL integration tests for the `Count` object / `count*` connection extension functions
*/ */
@DisplayName("JVM | Java | PostgreSQL: Count") @DisplayName("Core | Java | PostgreSQL: Count")
public class CountIT { public class PostgreSQLCountIT {
@Test @Test
@DisplayName("all counts all documents") @DisplayName("all counts all documents")

View File

@ -1,16 +1,15 @@
package solutions.bitbadger.documents.java.jvm.integration.postgresql; package solutions.bitbadger.documents.core.tests.java.integration;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException; import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.jvm.integration.postgresql.PgDB; import solutions.bitbadger.documents.core.tests.integration.PgDB;
import solutions.bitbadger.documents.java.jvm.integration.common.CustomFunctions;
/** /**
* PostgreSQL integration tests for the `Custom` object / `custom*` connection extension functions * PostgreSQL integration tests for the `Custom` object / `custom*` connection extension functions
*/ */
@DisplayName("JVM | Java | PostgreSQL: Custom") @DisplayName("Core | Java | PostgreSQL: Custom")
final public class CustomIT { final public class PostgreSQLCustomIT {
@Test @Test
@DisplayName("list succeeds with empty list") @DisplayName("list succeeds with empty list")

View File

@ -0,0 +1,45 @@
package solutions.bitbadger.documents.core.tests.java.integration;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.core.tests.integration.PgDB;
/**
* PostgreSQL integration tests for the `Definition` object / `ensure*` connection extension functions
*/
@DisplayName("Core | Java | PostgreSQL: Definition")
final public class PostgreSQLDefinitionIT {
@Test
@DisplayName("ensureTable creates table and index")
public void ensureTable() throws DocumentException {
try (PgDB db = new PgDB()) {
DefinitionFunctions.ensuresATable(db);
}
}
@Test
@DisplayName("ensureFieldIndex creates an index")
public void ensureFieldIndex() throws DocumentException {
try (PgDB db = new PgDB()) {
DefinitionFunctions.ensuresAFieldIndex(db);
}
}
@Test
@DisplayName("ensureDocumentIndex creates a full index")
public void ensureDocumentIndexFull() throws DocumentException {
try (PgDB db = new PgDB()) {
DefinitionFunctions.ensureDocumentIndexFull(db);
}
}
@Test
@DisplayName("ensureDocumentIndex creates an optimized index")
public void ensureDocumentIndexOptimized() throws DocumentException {
try (PgDB db = new PgDB()) {
DefinitionFunctions.ensureDocumentIndexOptimized(db);
}
}
}

View File

@ -0,0 +1,77 @@
package solutions.bitbadger.documents.core.tests.java.integration;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.core.tests.integration.PgDB;
/**
* PostgreSQL integration tests for the `Delete` object / `deleteBy*` connection extension functions
*/
@DisplayName("Core | Java | PostgreSQL: Delete")
final public class PostgreSQLDeleteIT {
@Test
@DisplayName("byId deletes a matching ID")
public void byIdMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
DeleteFunctions.byIdMatch(db);
}
}
@Test
@DisplayName("byId succeeds when no ID matches")
public void byIdNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
DeleteFunctions.byIdNoMatch(db);
}
}
@Test
@DisplayName("byFields deletes matching documents")
public void byFieldsMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
DeleteFunctions.byFieldsMatch(db);
}
}
@Test
@DisplayName("byFields succeeds when no documents match")
public void byFieldsNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
DeleteFunctions.byFieldsNoMatch(db);
}
}
@Test
@DisplayName("byContains deletes matching documents")
public void byContainsMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
DeleteFunctions.byContainsMatch(db);
}
}
@Test
@DisplayName("byContains succeeds when no documents match")
public void byContainsNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
DeleteFunctions.byContainsNoMatch(db);
}
}
@Test
@DisplayName("byJsonPath deletes matching documents")
public void byJsonPathMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
DeleteFunctions.byJsonPathMatch(db);
}
}
@Test
@DisplayName("byJsonPath succeeds when no documents match")
public void byJsonPathNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
DeleteFunctions.byJsonPathNoMatch(db);
}
}
}

View File

@ -0,0 +1,85 @@
package solutions.bitbadger.documents.core.tests.java.integration;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.core.tests.integration.PgDB;
/**
* PostgreSQL integration tests for the `Document` object / `insert`, `save`, `update` connection extension functions
*/
@DisplayName("Core | Java | PostgreSQL: Document")
final public class PostgreSQLDocumentIT {
@Test
@DisplayName("insert works with default values")
public void insertDefault() throws DocumentException {
try (PgDB db = new PgDB()) {
DocumentFunctions.insertDefault(db);
}
}
@Test
@DisplayName("insert fails with duplicate key")
public void insertDupe() throws DocumentException {
try (PgDB db = new PgDB()) {
DocumentFunctions.insertDupe(db);
}
}
@Test
@DisplayName("insert succeeds with numeric auto IDs")
public void insertNumAutoId() throws DocumentException {
try (PgDB db = new PgDB()) {
DocumentFunctions.insertNumAutoId(db);
}
}
@Test
@DisplayName("insert succeeds with UUID auto ID")
public void insertUUIDAutoId() throws DocumentException {
try (PgDB db = new PgDB()) {
DocumentFunctions.insertUUIDAutoId(db);
}
}
@Test
@DisplayName("insert succeeds with random string auto ID")
public void insertStringAutoId() throws DocumentException {
try (PgDB db = new PgDB()) {
DocumentFunctions.insertStringAutoId(db);
}
}
@Test
@DisplayName("save updates an existing document")
public void saveMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
DocumentFunctions.saveMatch(db);
}
}
@Test
@DisplayName("save inserts a new document")
public void saveNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
DocumentFunctions.saveNoMatch(db);
}
}
@Test
@DisplayName("update replaces an existing document")
public void updateMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
DocumentFunctions.updateMatch(db);
}
}
@Test
@DisplayName("update succeeds when no document exists")
public void updateNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
DocumentFunctions.updateNoMatch(db);
}
}
}

View File

@ -0,0 +1,77 @@
package solutions.bitbadger.documents.core.tests.java.integration;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.core.tests.integration.PgDB;
/**
* PostgreSQL integration tests for the `Exists` object / `existsBy*` connection extension functions
*/
@DisplayName("Core | Java | PostgreSQL: Exists")
final public class PostgreSQLExistsIT {
@Test
@DisplayName("byId returns true when a document matches the ID")
public void byIdMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
ExistsFunctions.byIdMatch(db);
}
}
@Test
@DisplayName("byId returns false when no document matches the ID")
public void byIdNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
ExistsFunctions.byIdNoMatch(db);
}
}
@Test
@DisplayName("byFields returns true when documents match")
public void byFieldsMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
ExistsFunctions.byFieldsMatch(db);
}
}
@Test
@DisplayName("byFields returns false when no documents match")
public void byFieldsNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
ExistsFunctions.byFieldsNoMatch(db);
}
}
@Test
@DisplayName("byContains returns true when documents match")
public void byContainsMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
ExistsFunctions.byContainsMatch(db);
}
}
@Test
@DisplayName("byContains returns false when no documents match")
public void byContainsNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
ExistsFunctions.byContainsNoMatch(db);
}
}
@Test
@DisplayName("byJsonPath returns true when documents match")
public void byJsonPathMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
ExistsFunctions.byJsonPathMatch(db);
}
}
@Test
@DisplayName("byJsonPath returns false when no documents match")
public void byJsonPathNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
ExistsFunctions.byJsonPathNoMatch(db);
}
}
}

View File

@ -0,0 +1,269 @@
package solutions.bitbadger.documents.core.tests.java.integration;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.core.tests.integration.PgDB;
/**
* PostgreSQL integration tests for the `Find` object / `find*` connection extension functions
*/
@DisplayName("Core | Java | PostgreSQL: Find")
final public class PostgreSQLFindIT {
@Test
@DisplayName("all retrieves all documents")
public void allDefault() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.allDefault(db);
}
}
@Test
@DisplayName("all sorts data ascending")
public void allAscending() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.allAscending(db);
}
}
@Test
@DisplayName("all sorts data descending")
public void allDescending() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.allDescending(db);
}
}
@Test
@DisplayName("all sorts data numerically")
public void allNumOrder() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.allNumOrder(db);
}
}
@Test
@DisplayName("all succeeds with an empty table")
public void allEmpty() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.allEmpty(db);
}
}
@Test
@DisplayName("byId retrieves a document via a string ID")
public void byIdString() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.byIdString(db);
}
}
@Test
@DisplayName("byId retrieves a document via a numeric ID")
public void byIdNumber() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.byIdNumber(db);
}
}
@Test
@DisplayName("byId returns null when a matching ID is not found")
public void byIdNotFound() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.byIdNotFound(db);
}
}
@Test
@DisplayName("byFields retrieves matching documents")
public void byFieldsMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.byFieldsMatch(db);
}
}
@Test
@DisplayName("byFields retrieves ordered matching documents")
public void byFieldsMatchOrdered() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.byFieldsMatchOrdered(db);
}
}
@Test
@DisplayName("byFields retrieves matching documents with a numeric IN clause")
public void byFieldsMatchNumIn() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.byFieldsMatchNumIn(db);
}
}
@Test
@DisplayName("byFields succeeds when no documents match")
public void byFieldsNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.byFieldsNoMatch(db);
}
}
@Test
@DisplayName("byFields retrieves matching documents with an IN_ARRAY comparison")
public void byFieldsMatchInArray() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.byFieldsMatchInArray(db);
}
}
@Test
@DisplayName("byFields succeeds when no documents match an IN_ARRAY comparison")
public void byFieldsNoMatchInArray() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.byFieldsNoMatchInArray(db);
}
}
@Test
@DisplayName("byContains retrieves matching documents")
public void byContainsMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.byContainsMatch(db);
}
}
@Test
@DisplayName("byContains retrieves ordered matching documents")
public void byContainsMatchOrdered() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.byContainsMatchOrdered(db);
}
}
@Test
@DisplayName("byContains succeeds when no documents match")
public void byContainsNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.byContainsNoMatch(db);
}
}
@Test
@DisplayName("byJsonPath retrieves matching documents")
public void byJsonPathMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.byJsonPathMatch(db);
}
}
@Test
@DisplayName("byJsonPath retrieves ordered matching documents")
public void byJsonPathMatchOrdered() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.byJsonPathMatchOrdered(db);
}
}
@Test
@DisplayName("byJsonPath succeeds when no documents match")
public void byJsonPathNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.byJsonPathNoMatch(db);
}
}
@Test
@DisplayName("firstByFields retrieves a matching document")
public void firstByFieldsMatchOne() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.firstByFieldsMatchOne(db);
}
}
@Test
@DisplayName("firstByFields retrieves a matching document among many")
public void firstByFieldsMatchMany() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.firstByFieldsMatchMany(db);
}
}
@Test
@DisplayName("firstByFields retrieves a matching document among many (ordered)")
public void firstByFieldsMatchOrdered() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.firstByFieldsMatchOrdered(db);
}
}
@Test
@DisplayName("firstByFields returns null when no document matches")
public void firstByFieldsNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.firstByFieldsNoMatch(db);
}
}
@Test
@DisplayName("firstByContains retrieves a matching document")
public void firstByContainsMatchOne() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.firstByContainsMatchOne(db);
}
}
@Test
@DisplayName("firstByContains retrieves a matching document among many")
public void firstByContainsMatchMany() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.firstByContainsMatchMany(db);
}
}
@Test
@DisplayName("firstByContains retrieves a matching document among many (ordered)")
public void firstByContainsMatchOrdered() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.firstByContainsMatchOrdered(db);
}
}
@Test
@DisplayName("firstByContains returns null when no document matches")
public void firstByContainsNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.firstByContainsNoMatch(db);
}
}
@Test
@DisplayName("firstByJsonPath retrieves a matching document")
public void firstByJsonPathMatchOne() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.firstByJsonPathMatchOne(db);
}
}
@Test
@DisplayName("firstByJsonPath retrieves a matching document among many")
public void firstByJsonPathMatchMany() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.firstByJsonPathMatchMany(db);
}
}
@Test
@DisplayName("firstByJsonPath retrieves a matching document among many (ordered)")
public void firstByJsonPathMatchOrdered() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.firstByJsonPathMatchOrdered(db);
}
}
@Test
@DisplayName("firstByJsonPath returns null when no document matches")
public void firstByJsonPathNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
FindFunctions.firstByJsonPathNoMatch(db);
}
}
}

View File

@ -0,0 +1,77 @@
package solutions.bitbadger.documents.core.tests.java.integration;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.core.tests.integration.PgDB;
/**
* PostgreSQL integration tests for the `Patch` object / `patchBy*` connection extension functions
*/
@DisplayName("Core | Java | PostgreSQL: Patch")
final public class PostgreSQLPatchIT {
@Test
@DisplayName("byId patches an existing document")
public void byIdMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
PatchFunctions.byIdMatch(db);
}
}
@Test
@DisplayName("byId succeeds for a non-existent document")
public void byIdNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
PatchFunctions.byIdNoMatch(db);
}
}
@Test
@DisplayName("byFields patches matching document")
public void byFieldsMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
PatchFunctions.byFieldsMatch(db);
}
}
@Test
@DisplayName("byFields succeeds when no documents match")
public void byFieldsNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
PatchFunctions.byFieldsNoMatch(db);
}
}
@Test
@DisplayName("byContains patches matching document")
public void byContainsMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
PatchFunctions.byContainsMatch(db);
}
}
@Test
@DisplayName("byContains succeeds when no documents match")
public void byContainsNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
PatchFunctions.byContainsNoMatch(db);
}
}
@Test
@DisplayName("byJsonPath patches matching document")
public void byJsonPathMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
PatchFunctions.byJsonPathMatch(db);
}
}
@Test
@DisplayName("byJsonPath succeeds when no documents match")
public void byJsonPathNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
PatchFunctions.byJsonPathNoMatch(db);
}
}
}

View File

@ -0,0 +1,109 @@
package solutions.bitbadger.documents.core.tests.java.integration;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.core.tests.integration.PgDB;
/**
* PostgreSQL integration tests for the `RemoveFields` object / `removeFieldsBy*` connection extension functions
*/
@DisplayName("Core | Java | PostgreSQL: RemoveFields")
final public class PostgreSQLRemoveFieldsIT {
@Test
@DisplayName("byId removes fields from an existing document")
public void byIdMatchFields() throws DocumentException {
try (PgDB db = new PgDB()) {
RemoveFieldsFunctions.byIdMatchFields(db);
}
}
@Test
@DisplayName("byId succeeds when fields do not exist on an existing document")
public void byIdMatchNoFields() throws DocumentException {
try (PgDB db = new PgDB()) {
RemoveFieldsFunctions.byIdMatchNoFields(db);
}
}
@Test
@DisplayName("byId succeeds when no document exists")
public void byIdNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
RemoveFieldsFunctions.byIdNoMatch(db);
}
}
@Test
@DisplayName("byFields removes fields from matching documents")
public void byFieldsMatchFields() throws DocumentException {
try (PgDB db = new PgDB()) {
RemoveFieldsFunctions.byFieldsMatchFields(db);
}
}
@Test
@DisplayName("byFields succeeds when fields do not exist on matching documents")
public void byFieldsMatchNoFields() throws DocumentException {
try (PgDB db = new PgDB()) {
RemoveFieldsFunctions.byFieldsMatchNoFields(db);
}
}
@Test
@DisplayName("byFields succeeds when no matching documents exist")
public void byFieldsNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
RemoveFieldsFunctions.byFieldsNoMatch(db);
}
}
@Test
@DisplayName("byContains removes fields from matching documents")
public void byContainsMatchFields() throws DocumentException {
try (PgDB db = new PgDB()) {
RemoveFieldsFunctions.byContainsMatchFields(db);
}
}
@Test
@DisplayName("byContains succeeds when fields do not exist on matching documents")
public void byContainsMatchNoFields() throws DocumentException {
try (PgDB db = new PgDB()) {
RemoveFieldsFunctions.byContainsMatchNoFields(db);
}
}
@Test
@DisplayName("byContains succeeds when no matching documents exist")
public void byContainsNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
RemoveFieldsFunctions.byContainsNoMatch(db);
}
}
@Test
@DisplayName("byJsonPath removes fields from matching documents")
public void byJsonPathMatchFields() throws DocumentException {
try (PgDB db = new PgDB()) {
RemoveFieldsFunctions.byJsonPathMatchFields(db);
}
}
@Test
@DisplayName("byJsonPath succeeds when fields do not exist on matching documents")
public void byJsonPathMatchNoFields() throws DocumentException {
try (PgDB db = new PgDB()) {
RemoveFieldsFunctions.byJsonPathMatchNoFields(db);
}
}
@Test
@DisplayName("byJsonPath succeeds when no matching documents exist")
public void byJsonPathNoMatch() throws DocumentException {
try (PgDB db = new PgDB()) {
RemoveFieldsFunctions.byJsonPathNoMatch(db);
}
}
}

View File

@ -0,0 +1,115 @@
package solutions.bitbadger.documents.core.tests.java.integration;
import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.Field;
import solutions.bitbadger.documents.core.tests.integration.ThrowawayDatabase;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.*;
import static solutions.bitbadger.documents.core.tests.TypesKt.TEST_TABLE;
import static solutions.bitbadger.documents.java.extensions.ConnExt.*;
final public class RemoveFieldsFunctions {
public static void byIdMatchFields(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
removeFieldsById(db.getConn(), TEST_TABLE, "two", List.of("sub", "value"));
final Optional<JsonDocument> doc = findById(db.getConn(), TEST_TABLE, "two", JsonDocument.class);
assertTrue(doc.isPresent(), "There should have been a document returned");
assertEquals("", doc.get().getValue(), "The value should have been empty");
assertNull(doc.get().getSub(), "The sub-document should have been removed");
}
public static void byIdMatchNoFields(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertFalse(existsByFields(db.getConn(), TEST_TABLE, List.of(Field.exists("a_field_that_does_not_exist"))));
removeFieldsById(db.getConn(), TEST_TABLE, "one", List.of("a_field_that_does_not_exist")); // no exn = pass
}
public static void byIdNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertFalse(existsById(db.getConn(), TEST_TABLE, "fifty"));
removeFieldsById(db.getConn(), TEST_TABLE, "fifty", List.of("sub")); // no exception = pass
}
public static void byFieldsMatchFields(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final List<Field<?>> fields = List.of(Field.equal("numValue", 17));
removeFieldsByFields(db.getConn(), TEST_TABLE, fields, List.of("sub"));
final Optional<JsonDocument> doc = findFirstByFields(db.getConn(), TEST_TABLE, fields, JsonDocument.class);
assertTrue(doc.isPresent(), "The document should have been returned");
assertEquals("four", doc.get().getId(), "An incorrect document was returned");
assertNull(doc.get().getSub(), "The sub-document should have been removed");
}
public static void byFieldsMatchNoFields(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertFalse(existsByFields(db.getConn(), TEST_TABLE, List.of(Field.exists("nada"))));
removeFieldsByFields(db.getConn(), TEST_TABLE, List.of(Field.equal("numValue", 17)), List.of("nada"));
// no exception = pass
}
public static void byFieldsNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final List<Field<?>> fields = List.of(Field.notEqual("missing", "nope"));
assertFalse(existsByFields(db.getConn(), TEST_TABLE, fields));
removeFieldsByFields(db.getConn(), TEST_TABLE, fields, List.of("value")); // no exception = pass
}
public static void byContainsMatchFields(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final Map<String, Map<String, String>> criteria = Map.of("sub", Map.of("foo", "green"));
removeFieldsByContains(db.getConn(), TEST_TABLE, criteria, List.of("value"));
final List<JsonDocument> docs = findByContains(db.getConn(), TEST_TABLE, criteria, JsonDocument.class);
assertEquals(2, docs.size(), "There should have been 2 documents returned");
for (final JsonDocument doc : docs) {
assertTrue(List.of("two", "four").contains(doc.getId()),
String.format("An incorrect document was returned (%s)", doc.getId()));
assertEquals("", doc.getValue(), "The value should have been empty");
}
}
public static void byContainsMatchNoFields(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertFalse(existsByFields(db.getConn(), TEST_TABLE, List.of(Field.exists("invalid_field"))));
removeFieldsByContains(db.getConn(), TEST_TABLE, Map.of("sub", Map.of("foo", "green")),
List.of("invalid_field")); // no exception = pass
}
public static void byContainsNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final Map<String, String> contains = Map.of("value", "substantial");
assertFalse(existsByContains(db.getConn(), TEST_TABLE, contains));
removeFieldsByContains(db.getConn(), TEST_TABLE, contains, List.of("numValue")); // no exception = pass
}
public static void byJsonPathMatchFields(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final String path = "$.value ? (@ == \"purple\")";
removeFieldsByJsonPath(db.getConn(), TEST_TABLE, path, List.of("sub"));
final List<JsonDocument> docs = findByJsonPath(db.getConn(), TEST_TABLE, path, JsonDocument.class);
assertEquals(2, docs.size(), "There should have been 2 documents returned");
for (final JsonDocument doc : docs) {
assertTrue(List.of("four", "five").contains(doc.getId()),
String.format("An incorrect document was returned (%s)", doc.getId()));
assertNull(doc.getSub(), "The sub-document should have been removed");
}
}
public static void byJsonPathMatchNoFields(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
assertFalse(existsByFields(db.getConn(), TEST_TABLE, List.of(Field.exists("submarine"))));
removeFieldsByJsonPath(db.getConn(), TEST_TABLE, "$.value ? (@ == \"purple\")", List.of("submarine"));
// no exception = pass
}
public static void byJsonPathNoMatch(ThrowawayDatabase db) throws DocumentException {
JsonDocument.load(db);
final String path = "$.value ? (@ == \"mauve\")";
assertFalse(existsByJsonPath(db.getConn(), TEST_TABLE, path));
removeFieldsByJsonPath(db.getConn(), TEST_TABLE, path, List.of("value")); // no exception = pass
}
}

View File

@ -1,18 +1,17 @@
package solutions.bitbadger.documents.java.jvm.integration.sqlite; package solutions.bitbadger.documents.core.tests.java.integration;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException; import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.java.jvm.integration.common.CountFunctions; import solutions.bitbadger.documents.core.tests.integration.SQLiteDB;
import solutions.bitbadger.documents.jvm.integration.sqlite.SQLiteDB;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
/** /**
* SQLite integration tests for the `Count` object / `count*` connection extension functions * SQLite integration tests for the `Count` object / `count*` connection extension functions
*/ */
@DisplayName("JVM | Java | SQLite: Count") @DisplayName("Core | Java | SQLite: Count")
public class CountIT { public class SQLiteCountIT {
@Test @Test
@DisplayName("all counts all documents") @DisplayName("all counts all documents")

View File

@ -1,16 +1,15 @@
package solutions.bitbadger.documents.java.jvm.integration.sqlite; package solutions.bitbadger.documents.core.tests.java.integration;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException; import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.java.jvm.integration.common.CustomFunctions; import solutions.bitbadger.documents.core.tests.integration.SQLiteDB;
import solutions.bitbadger.documents.jvm.integration.sqlite.SQLiteDB;
/** /**
* SQLite integration tests for the `Custom` object / `custom*` connection extension functions * SQLite integration tests for the `Custom` object / `custom*` connection extension functions
*/ */
@DisplayName("JVM | Java | SQLite: Custom") @DisplayName("Core | Java | SQLite: Custom")
final public class CustomIT { final public class SQLiteCustomIT {
@Test @Test
@DisplayName("list succeeds with empty list") @DisplayName("list succeeds with empty list")

View File

@ -0,0 +1,47 @@
package solutions.bitbadger.documents.core.tests.java.integration;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.core.tests.integration.SQLiteDB;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* SQLite integration tests for the `Definition` object / `ensure*` connection extension functions
*/
@DisplayName("Core | Java | SQLite: Definition")
final public class SQLiteDefinitionIT {
@Test
@DisplayName("ensureTable creates table and index")
public void ensureTable() throws DocumentException {
try (SQLiteDB db = new SQLiteDB()) {
DefinitionFunctions.ensuresATable(db);
}
}
@Test
@DisplayName("ensureFieldIndex creates an index")
public void ensureFieldIndex() throws DocumentException {
try (SQLiteDB db = new SQLiteDB()) {
DefinitionFunctions.ensuresAFieldIndex(db);
}
}
@Test
@DisplayName("ensureDocumentIndex fails for full index")
public void ensureDocumentIndexFull() {
try (SQLiteDB db = new SQLiteDB()) {
assertThrows(DocumentException.class, () -> DefinitionFunctions.ensureDocumentIndexFull(db));
}
}
@Test
@DisplayName("ensureDocumentIndex fails for optimized index")
public void ensureDocumentIndexOptimized() {
try (SQLiteDB db = new SQLiteDB()) {
assertThrows(DocumentException.class, () -> DefinitionFunctions.ensureDocumentIndexOptimized(db));
}
}
}

View File

@ -0,0 +1,63 @@
package solutions.bitbadger.documents.core.tests.java.integration;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.core.tests.integration.SQLiteDB;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* SQLite integration tests for the `Delete` object / `deleteBy*` connection extension functions
*/
@DisplayName("Core | Java | SQLite: Delete")
final public class SQLiteDeleteIT {
@Test
@DisplayName("byId deletes a matching ID")
public void byIdMatch() throws DocumentException {
try (SQLiteDB db = new SQLiteDB()) {
DeleteFunctions.byIdMatch(db);
}
}
@Test
@DisplayName("byId succeeds when no ID matches")
public void byIdNoMatch() throws DocumentException {
try (SQLiteDB db = new SQLiteDB()) {
DeleteFunctions.byIdNoMatch(db);
}
}
@Test
@DisplayName("byFields deletes matching documents")
public void byFieldsMatch() throws DocumentException {
try (SQLiteDB db = new SQLiteDB()) {
DeleteFunctions.byFieldsMatch(db);
}
}
@Test
@DisplayName("byFields succeeds when no documents match")
public void byFieldsNoMatch() throws DocumentException {
try (SQLiteDB db = new SQLiteDB()) {
DeleteFunctions.byFieldsNoMatch(db);
}
}
@Test
@DisplayName("byContains fails")
public void byContainsMatch() {
try (SQLiteDB db = new SQLiteDB()) {
assertThrows(DocumentException.class, () -> DeleteFunctions.byContainsMatch(db));
}
}
@Test
@DisplayName("byJsonPath fails")
public void byJsonPathMatch() {
try (SQLiteDB db = new SQLiteDB()) {
assertThrows(DocumentException.class, () -> DeleteFunctions.byJsonPathMatch(db));
}
}
}

View File

@ -0,0 +1,84 @@
package solutions.bitbadger.documents.core.tests.java.integration;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import solutions.bitbadger.documents.DocumentException;
import solutions.bitbadger.documents.core.tests.integration.SQLiteDB;
/**
* SQLite integration tests for the `Document` object / `insert`, `save`, `update` connection extension functions
*/
@DisplayName("Core | Java | SQLite: Document")
final public class SQLiteDocumentIT {
@Test
@DisplayName("insert works with default values")
public void insertDefault() throws DocumentException {
try (SQLiteDB db = new SQLiteDB()) {
DocumentFunctions.insertDefault(db);
}
}
@Test
@DisplayName("insert fails with duplicate key")
public void insertDupe() throws DocumentException {
try (SQLiteDB db = new SQLiteDB()) {
DocumentFunctions.insertDupe(db);
}
}
@Test
@DisplayName("insert succeeds with numeric auto IDs")
public void insertNumAutoId() throws DocumentException {
try (SQLiteDB db = new SQLiteDB()) {
DocumentFunctions.insertNumAutoId(db);
}
}
@Test
@DisplayName("insert succeeds with UUID auto ID")
public void insertUUIDAutoId() throws DocumentException {
try (SQLiteDB db = new SQLiteDB()) {
DocumentFunctions.insertUUIDAutoId(db);
}
}
@Test
@DisplayName("insert succeeds with random string auto ID")
public void insertStringAutoId() throws DocumentException {
try (SQLiteDB db = new SQLiteDB()) {
DocumentFunctions.insertStringAutoId(db);
}
}
@Test
@DisplayName("save updates an existing document")
public void saveMatch() throws DocumentException {
try (SQLiteDB db = new SQLiteDB()) {
DocumentFunctions.saveMatch(db);
}
}
@Test
@DisplayName("save inserts a new document")
public void saveNoMatch() throws DocumentException {
try (SQLiteDB db = new SQLiteDB()) {
DocumentFunctions.saveNoMatch(db);
}
}
@Test
@DisplayName("update replaces an existing document")
public void updateMatch() throws DocumentException {
try (SQLiteDB db = new SQLiteDB()) {
DocumentFunctions.updateMatch(db);
}
}
@Test
@DisplayName("update succeeds when no document exists")
public void updateNoMatch() throws DocumentException {
try (SQLiteDB db = new SQLiteDB()) {
DocumentFunctions.updateNoMatch(db);
}
}
}

Some files were not shown because too many files have changed in this diff Show More