mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-26 12:34:22 +01:00
Implement driver name and version related methods
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package org.github.tursodatabase.jdbc4;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.PreparedStatement;
|
||||
@@ -7,29 +9,53 @@ import java.sql.ResultSet;
|
||||
import java.sql.RowIdLifetime;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.SQLFeatureNotSupportedException;
|
||||
import java.util.Properties;
|
||||
import org.github.tursodatabase.annotations.Nullable;
|
||||
import org.github.tursodatabase.annotations.SkipNullableCheck;
|
||||
import org.github.tursodatabase.utils.Logger;
|
||||
import org.github.tursodatabase.utils.LoggerFactory;
|
||||
|
||||
public class JDBC4DatabaseMetaData implements DatabaseMetaData {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(JDBC4DatabaseMetaData.class);
|
||||
|
||||
private static String driverName = "";
|
||||
private static String driverVersion = "";
|
||||
|
||||
private final JDBC4Connection connection;
|
||||
private PreparedStatement getTables = null,
|
||||
getTableTypes = null,
|
||||
getTypeInfo = null,
|
||||
getCatalogs = null,
|
||||
getSchemas = null,
|
||||
getUDTs = null,
|
||||
getColumnsTblName = null,
|
||||
getSuperTypes = null,
|
||||
getSuperTables = null,
|
||||
getTablePrivileges = null,
|
||||
getIndexInfo = null,
|
||||
getProcedures = null,
|
||||
getProcedureColumns = null,
|
||||
getAttributes = null,
|
||||
getBestRowIdentifier = null,
|
||||
getVersionColumns = null,
|
||||
getColumnPrivileges = null;
|
||||
@Nullable private PreparedStatement getTables = null;
|
||||
@Nullable private PreparedStatement getTableTypes = null;
|
||||
@Nullable private PreparedStatement getTypeInfo = null;
|
||||
@Nullable private PreparedStatement getCatalogs = null;
|
||||
@Nullable private PreparedStatement getSchemas = null;
|
||||
@Nullable private PreparedStatement getUDTs = null;
|
||||
@Nullable private PreparedStatement getColumnsTblName = null;
|
||||
@Nullable private PreparedStatement getSuperTypes = null;
|
||||
@Nullable private PreparedStatement getSuperTables = null;
|
||||
@Nullable private PreparedStatement getTablePrivileges = null;
|
||||
@Nullable private PreparedStatement getIndexInfo = null;
|
||||
@Nullable private PreparedStatement getProcedures = null;
|
||||
@Nullable private PreparedStatement getProcedureColumns = null;
|
||||
@Nullable private PreparedStatement getAttributes = null;
|
||||
@Nullable private PreparedStatement getBestRowIdentifier = null;
|
||||
@Nullable private PreparedStatement getVersionColumns = null;
|
||||
@Nullable private PreparedStatement getColumnPrivileges = null;
|
||||
|
||||
static {
|
||||
try (InputStream limboJdbcPropStream =
|
||||
JDBC4DatabaseMetaData.class.getClassLoader().getResourceAsStream("limbo-jdbc.properties")) {
|
||||
if (limboJdbcPropStream == null) {
|
||||
throw new IOException("Cannot load limbo-jdbc.properties from jar");
|
||||
}
|
||||
|
||||
final Properties properties = new Properties();
|
||||
properties.load(limboJdbcPropStream);
|
||||
driverName = properties.getProperty("driverName");
|
||||
driverVersion = properties.getProperty("driverVersion");
|
||||
} catch (IOException e) {
|
||||
logger.error("Failed to load driverName and driverVersion");
|
||||
}
|
||||
}
|
||||
|
||||
public JDBC4DatabaseMetaData(JDBC4Connection connection) {
|
||||
this.connection = connection;
|
||||
@@ -94,24 +120,22 @@ public class JDBC4DatabaseMetaData implements DatabaseMetaData {
|
||||
|
||||
@Override
|
||||
public String getDriverName() {
|
||||
// TODO - important
|
||||
return "";
|
||||
return driverName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDriverVersion() {
|
||||
// TODO - important
|
||||
return "";
|
||||
return driverVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDriverMajorVersion() {
|
||||
return 0;
|
||||
return Integer.parseInt(driverVersion.split("\\.")[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDriverMinorVersion() {
|
||||
return 0;
|
||||
return Integer.parseInt(driverVersion.split("\\.")[1]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
3
bindings/java/src/main/resources/limbo-jdbc.properties
Normal file
3
bindings/java/src/main/resources/limbo-jdbc.properties
Normal file
@@ -0,0 +1,3 @@
|
||||
driverName=limbo-jdbc
|
||||
# find a way to relate driverVersion with project.version defined in gradle.properties
|
||||
driverVersion=0.0.1-SNAPSHOT
|
||||
@@ -1,28 +1,47 @@
|
||||
package org.github.tursodatabase.jdbc4;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.github.tursodatabase.TestUtils;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class JDBC4DatabaseMetaDataTest {
|
||||
|
||||
private JDBC4Connection connection;
|
||||
private JDBC4DatabaseMetaData metaData;
|
||||
private JDBC4Connection connection;
|
||||
private JDBC4DatabaseMetaData metaData;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
String filePath = TestUtils.createTempFile();
|
||||
String url = "jdbc:sqlite:" + filePath;
|
||||
connection = new JDBC4Connection(url, filePath, new Properties());
|
||||
metaData = new JDBC4DatabaseMetaData(connection);
|
||||
}
|
||||
@BeforeEach
|
||||
void set_up() throws Exception {
|
||||
String filePath = TestUtils.createTempFile();
|
||||
String url = "jdbc:sqlite:" + filePath;
|
||||
connection = new JDBC4Connection(url, filePath, new Properties());
|
||||
metaData = new JDBC4DatabaseMetaData(connection);
|
||||
}
|
||||
|
||||
@Test
|
||||
void getURLShouldReturnNonEmptyString() throws Exception{
|
||||
assertFalse(metaData.getURL().isEmpty());
|
||||
}
|
||||
@Test
|
||||
void getURL_should_return_non_empty_string() {
|
||||
assertFalse(metaData.getURL().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getDriverName_should_not_return_empty_string() {
|
||||
assertFalse(metaData.getDriverName().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_getDriverMajorVersion() {
|
||||
metaData.getDriverMajorVersion();
|
||||
}
|
||||
|
||||
@Test
|
||||
void test_getDriverMinorVersion() {
|
||||
metaData.getDriverMinorVersion();
|
||||
}
|
||||
|
||||
@Test
|
||||
void getDriverVersion_should_not_return_empty_string() {
|
||||
assertFalse(metaData.getDriverVersion().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user