Skip to content

Commit

Permalink
- Added sqlLeast and sqlGreatest functions to `com.senzing.sql.Da…
Browse files Browse the repository at this point in the history
…tabaseType` (#85)

- Updated depdendncies to newer versions:
  - Upgraded `junit-jupiter` from version `5.10.1` to `5.10.2`
  - Upgraded `maven-surefire-plugin` from version `3.2.3` to version `3.2.5`
  • Loading branch information
barrycaceres authored Feb 29, 2024
1 parent 7b3afd5 commit d2a434f
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
[markdownlint](https://dlaa.me/markdownlint/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.2.0] - 2024-02-29

### Changed in 3.2.0

- Added `sqlLeast` and `sqlGreatest` functions to `com.senzing.sql.DatabaseType`
- Updated depdendncies to newer versions:

## [3.1.5] - 2024-01-10

### Changed in 3.1.5
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.senzing</groupId>
<artifactId>senzing-commons</artifactId>
<packaging>jar</packaging>
<version>3.1.5</version>
<version>3.2.0</version>
<name>Senzing Commons</name>
<description>Utility classes and functions common to multiple Senzing projects.</description>
<url>http://github.com/senzing-garage/senzing-commons-java</url>
Expand Down Expand Up @@ -71,7 +71,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.1</version>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -107,7 +107,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.3</version>
<version>3.2.5</version>
<configuration>
<systemPropertyVariables>
<project.build.directory>${project.build.directory}</project.build.directory>
Expand Down
77 changes: 77 additions & 0 deletions src/main/java/com/senzing/sql/DatabaseType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.senzing.sql;

import java.util.Objects;
import java.sql.*;
import java.time.Instant;
import java.time.ZoneId;
Expand Down Expand Up @@ -148,6 +149,82 @@ public void setTimestamp(CallableStatement cs, int index, Timestamp value)
}
}

/**
* Provides a generic way to format the equivalent of the SQL
* "least" function for the database type.
*
* @param first The first parameter to the LEAST function.
* @param second The second parameter to the LEAST function.
* @param other The optional other parameters to the LEAST
* function for variable length parameters.
* @return The formatted SQL "least" function for the respective
* database.
* @throws NullPointerException If either the first or second
* parameters is <code>null</code>.
*/
public String sqlLeast(String first, String second, String... other)
throws NullPointerException
{
Objects.requireNonNull(first,
"The first parameter to LEAST cannot be null");
Objects.requireNonNull(first,
"The second parameter to LEAST cannot be null");
StringBuilder sb = new StringBuilder();
switch (this) {
case SQLITE:
sb.append("MIN");
break;
default:
sb.append("LEAST");
}
sb.append("(").append(first).append(", ").append(second);
if (other != null) {
for (String param: other) {
sb.append(", ").append(param);
}
}
sb.append(")");
return sb.toString();
}

/**
* Provides a generic way to format the equivalent of the SQL
* "least" function for the database type.
*
* @param first The first parameter to the LEAST function.
* @param second The second parameter to the LEAST function.
* @param other The optional other parameters to the LEAST
* function for variable length parameters.
* @return The formatted SQL "least" function for the respective
* database.
* @throws NullPointerException If either the first or second
* parameters is <code>null</code>.
*/
public String sqlGreatest(String first, String second, String... other)
throws NullPointerException
{
Objects.requireNonNull(first,
"The first parameter to GREATEST cannot be null");
Objects.requireNonNull(first,
"The second parameter to GREATEST cannot be null");
StringBuilder sb = new StringBuilder();
switch (this) {
case SQLITE:
sb.append("MAX");
break;
default:
sb.append("GREATEST");
}
sb.append("(").append(first).append(", ").append(second);
if (other != null) {
for (String param: other) {
sb.append(", ").append(param);
}
}
sb.append(")");
return sb.toString();
}

/**
* The {@link Calendar} to use for retrieving timestamps from the database.
*/
Expand Down

0 comments on commit d2a434f

Please sign in to comment.