update to gradle 7.4.2, add metadata column length API
This commit is contained in:
parent
81a0bd8bc9
commit
aec2061f68
14 changed files with 97 additions and 30 deletions
|
@ -4,7 +4,7 @@ plugins {
|
|||
}
|
||||
|
||||
wrapper {
|
||||
gradleVersion = "${project.property('gradle.wrapper.version')}"
|
||||
gradleVersion = libs.versions.gradle.get()
|
||||
distributionType = Wrapper.DistributionType.ALL
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
group = org.xbib
|
||||
name = database
|
||||
version = 0.0.1
|
||||
version = 0.0.2
|
||||
|
||||
org.gradle.warning.mode = ALL
|
||||
gradle.wrapper.version = 7.3.2
|
||||
h2.version = 1.4.200
|
||||
mockito.version = 3.3.3
|
||||
testcontainers.version = 1.16.2
|
||||
derby.version = 10.15.2.0
|
||||
oracle-client.version = 21.4.0.0
|
||||
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
|
||||
def junitVersion = project.hasProperty('junit.version')?project.property('junit.version'):'5.6.2'
|
||||
def hamcrestVersion = project.hasProperty('hamcrest.version')?project.property('hamcrest.version'):'2.2'
|
||||
|
||||
dependencies {
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
|
||||
testImplementation "org.junit.jupiter:junit-jupiter-params:${junitVersion}"
|
||||
testImplementation "org.hamcrest:hamcrest-library:${hamcrestVersion}"
|
||||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
|
||||
testImplementation libs.junit.jupiter.api
|
||||
testImplementation libs.junit.jupiter.params
|
||||
testImplementation libs.hamcrest
|
||||
testRuntimeOnly libs.junit.jupiter.engine
|
||||
}
|
||||
|
||||
test {
|
||||
|
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,5 +1,5 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
dependencies {
|
||||
testImplementation "com.h2database:h2:${project.property('h2.version')}"
|
||||
testImplementation "org.mockito:mockito-core:${project.property('mockito.version')}"
|
||||
testImplementation libs.h2
|
||||
testImplementation libs.mockito.core
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
dependencies {
|
||||
api project(":jdbc-connection-pool")
|
||||
testImplementation "org.apache.derby:derby:${project.property('derby.version')}"
|
||||
testImplementation "org.testcontainers:testcontainers:${project.property('testcontainers.version')}"
|
||||
testImplementation "org.testcontainers:junit-jupiter:${project.property('testcontainers.version')}"
|
||||
testImplementation "org.testcontainers:oracle-xe:${project.property('testcontainers.version')}"
|
||||
testImplementation libs.derby
|
||||
testImplementation libs.testcontainers
|
||||
testImplementation libs.testcontainers.junit.jupiter
|
||||
testImplementation libs.testcontainers.oracle.xe
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.xbib.jdbc.query;
|
|||
|
||||
import java.sql.Connection;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
|
@ -176,6 +177,13 @@ public interface Database extends Supplier<Database> {
|
|||
*/
|
||||
boolean tableExists( String tableName, String schemaName);
|
||||
|
||||
/**
|
||||
* Convenience method to get all column sizes from a table.
|
||||
* @param tableName the table to be checked
|
||||
* @return a map of columns names with size
|
||||
*/
|
||||
Map<String, Integer> getColumnSizesOfTable(String tableName);
|
||||
|
||||
/**
|
||||
* Return the DB table name in the normalized form in which it is stored.
|
||||
* Databases like Oracle, Derby, HSQL store their tables in upper case.
|
||||
|
|
|
@ -4,10 +4,15 @@ import java.lang.reflect.Method;
|
|||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
|
@ -200,16 +205,13 @@ public class DatabaseImpl implements Database {
|
|||
return tableExists(tableName, schemaName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean tableExists(String tableName, String schemaName) throws DatabaseException {
|
||||
if (tableName != null) {
|
||||
if (tableName != null && connection != null) {
|
||||
try {
|
||||
DatabaseMetaData metadata = connection.getMetaData();
|
||||
String normalizedTable = normalizeTableName(tableName);
|
||||
ResultSet resultSet =
|
||||
metadata.getTables(connection.getCatalog(), schemaName, normalizedTable, new String[]{"TABLE", "VIEW"});
|
||||
|
||||
ResultSet resultSet = metadata.getTables(connection.getCatalog(), schemaName, normalizedTable, new String[]{"TABLE", "VIEW"});
|
||||
while (resultSet.next()) {
|
||||
if (normalizedTable.equals(resultSet.getString("TABLE_NAME"))) {
|
||||
return true;
|
||||
|
@ -221,10 +223,42 @@ public class DatabaseImpl implements Database {
|
|||
exc);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> getColumnSizesOfTable(String tableName) {
|
||||
Map<String, Integer> map = new HashMap<>();
|
||||
if (tableName != null && connection != null) {
|
||||
try {
|
||||
DatabaseMetaData metaData = connection.getMetaData();
|
||||
String normalizedTable = normalizeTableName(tableName);
|
||||
ResultSet rs = metaData.getColumns(null, null, normalizedTable, "%");
|
||||
ResultSetMetaData rsmd = rs.getMetaData();
|
||||
int cols = rsmd.getColumnCount();
|
||||
while (rs.next()) {
|
||||
String name = "";
|
||||
Integer size = 0;
|
||||
for (int i = 1; i <= cols; i++) {
|
||||
String label = rsmd.getColumnName(i);
|
||||
Object v = rs.getObject(i);
|
||||
if (label.equals("COLUMN_NAME")) {
|
||||
name = (String) v;
|
||||
}
|
||||
if (label.equals("COLUMN_SIZE")) {
|
||||
size = (Integer) v;
|
||||
}
|
||||
}
|
||||
map.put(name, size);
|
||||
}
|
||||
rs.close();
|
||||
} catch (SQLException exc) {
|
||||
throw new DatabaseException("Unable to look up table " + tableName + " : " + exc.getMessage(), exc);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String normalizeTableName(String tableName) {
|
||||
if (tableName == null) {
|
||||
|
|
|
@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
/**
|
||||
* Exercise database functionality with a real HyperSQL database.
|
||||
*/
|
||||
@Disabled
|
||||
public class HsqldbTest extends CommonTest {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(HsqldbTest.class.getName());
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.Properties;
|
|||
/**
|
||||
* Exercise Database functionality with a real Oracle database.
|
||||
*/
|
||||
@Disabled
|
||||
public class OracleTest extends CommonTest {
|
||||
|
||||
@Container
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.xbib.jdbc.query.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.xbib.jdbc.query.DatabaseProvider;
|
||||
import org.xbib.jdbc.query.OptionsOverride;
|
||||
|
@ -14,6 +15,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
|||
/**
|
||||
* Exercise Database functionality with a real PostgreSQL database.
|
||||
*/
|
||||
@Disabled
|
||||
public class PostgreSqlTest extends CommonTest {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,8 +11,9 @@ import org.xbib.jdbc.query.Schema;
|
|||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
|
||||
/**
|
||||
* Exercise Database functionality with a real Oracle database.
|
||||
* Exercise Database functionality with a real SQL server database.
|
||||
*/
|
||||
@Disabled
|
||||
public class SqlServerTest extends CommonTest {
|
||||
@Override
|
||||
protected DatabaseProvider createDatabaseProvider(OptionsOverride options) throws Exception {
|
||||
|
|
|
@ -1,2 +1,31 @@
|
|||
dependencyResolutionManagement {
|
||||
versionCatalogs {
|
||||
libs {
|
||||
version('gradle', '7.4.2')
|
||||
version('junit', '5.8.2')
|
||||
version('testcontainers', '1.16.2')
|
||||
library('junit-jupiter-api', 'org.junit.jupiter', 'junit-jupiter-api').versionRef('junit')
|
||||
library('junit-jupiter-params', 'org.junit.jupiter', 'junit-jupiter-params').versionRef('junit')
|
||||
library('junit-jupiter-engine', 'org.junit.jupiter', 'junit-jupiter-engine').versionRef('junit')
|
||||
library('hamcrest', 'org.hamcrest:hamcrest-library:2.2')
|
||||
library('junit4', 'junit:junit:4.13.2')
|
||||
library('derby', 'org.apache.derby', 'derby').version('10.15.2.0')
|
||||
library('testcontainers', 'org.testcontainers', 'testcontainers').versionRef('testcontainers')
|
||||
library('testcontainers-junit-jupiter', 'org.testcontainers', 'junit-jupiter').versionRef('testcontainers')
|
||||
library('testcontainers-oracle-xe', 'org.testcontainers', 'oracle-xe').versionRef('testcontainers')
|
||||
library('h2', 'com.h2database', 'h2').version('1.4.200')
|
||||
library('mockito-core', 'org.mockito', 'mockito-core').version('3.3.3')
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
gradle.wrapper.version = 7.4.2
|
||||
h2.version = 1.4.200
|
||||
mockito.version = 3.3.3
|
||||
testcontainers.version = 1.16.2
|
||||
derby.version = 10.15.2.0
|
||||
oracle-client.version = 21.4.0.0
|
||||
*/
|
||||
|
||||
include 'jdbc-connection-pool'
|
||||
include 'jdbc-query'
|
||||
|
|
Loading…
Reference in a new issue