Skip to content

Commit

Permalink
#3 DriverManager support added. (#5)
Browse files Browse the repository at this point in the history
* #3 DriverManager support added.
- ResultSet metadata read fix.
- Connection close fix.
- 1.0.2 version bump.

* #3 Code style fixes
  • Loading branch information
serge-rider authored Nov 7, 2024
1 parent f0aaaec commit a4a2326
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Download from Maven Central or from the releases page.
<dependency>
<groupId>com.dbeaver.jdbc</groupId>
<artifactId>com.dbeaver.jdbc.driver.libsql</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
</dependency>
</dependencies>
```
2 changes: 1 addition & 1 deletion com.dbeaver.jdbc.driver.libsql/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: DBeaver LibSQL JDBC Driver
Bundle-SymbolicName: com.dbeaver.jdbc.driver.libsql
Bundle-Version: 1.1.0.qualifier
Bundle-Version: 1.0.2.qualifier
Bundle-Release-Date: 20230522
Bundle-RequiredExecutionEnvironment: JavaSE-17
Export-Package: com.dbeaver.jdbc.driver.libsql,
Expand Down
2 changes: 1 addition & 1 deletion com.dbeaver.jdbc.driver.libsql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.dbeaver.jdbc</groupId>
<artifactId>jdbc-libsql</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.0.2-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>com.dbeaver.jdbc.driver.libsql</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ private LibSqlPreparedStatement prepareStatementImpl(String sql) throws SQLExcep

@Override
public void close() throws SQLException {
client.close();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class LibSqlConstants {

public static final int DRIVER_VERSION_MAJOR = 1;
public static final int DRIVER_VERSION_MINOR = 0;
public static final int DRIVER_VERSION_MICRO = 1;
public static final int DRIVER_VERSION_MICRO = 2;

public static final String DRIVER_NAME = "LibSQL";
public static final String DRIVER_INFO = "DBeaver LibSQL JDBC driver";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,28 @@
package com.dbeaver.jdbc.driver.libsql;


import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.sql.*;
import java.util.Enumeration;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;

public class LibSqlDriver implements Driver {

static final java.util.logging.Logger parentLogger = java.util.logging.Logger.getLogger("com.dbeaver.jdbc.upd.driver.driver");
static {
Logger logger = Logger.getLogger("com.dbeaver.jdbc.upd.driver.driver");
parentLogger = logger;
try {
DriverManager.registerDriver(new LibSqlDriver());
} catch (Exception e) {
logger.log(Level.SEVERE, "Could not register driver", e);
}
}

private static final java.util.logging.Logger parentLogger;

@Override
public Connection connect(String url, Properties info) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public LibSqlResultSetMetaData(@NotNull LibSqlResultSet resultSet) throws SQLExc
private ResultColumnDataType getDataTypeFromData(int column) {
LibSqlExecutionResult result = resultSet.getResult();
if (result != null && !CommonUtils.isEmpty(result.getRows())) {
Object columnValue = result.getRows().get(0)[column];
Object columnValue = result.getRows().get(0)[column - 1];
if (columnValue instanceof Boolean) {
return ResultColumnDataType.BOOLEAN;
} else if (columnValue instanceof Number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.sql.SQLException;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
Expand All @@ -52,15 +53,20 @@ public class LibSqlClient {

private final URL url;
private final String authToken;
private String userAgent = LibSqlConstants.DRIVER_INFO + " " + LibSqlConstants.DRIVER_VERSION_MAJOR + "." + LibSqlConstants.DRIVER_VERSION_MAJOR;
private final ExecutorService clientExecutor;
private String userAgent = LibSqlConstants.DRIVER_INFO + " " +
LibSqlConstants.DRIVER_VERSION_MAJOR +
"." + LibSqlConstants.DRIVER_VERSION_MAJOR +
"." + LibSqlConstants.DRIVER_VERSION_MICRO;
private final HttpClient client;

public LibSqlClient(URL url, String authToken) {
this.url = url;
this.authToken = authToken;

this.clientExecutor = Executors.newSingleThreadExecutor();
HttpClient.Builder builder = HttpClient.newBuilder()
.executor(Executors.newSingleThreadExecutor())
.executor(this.clientExecutor)
.cookieHandler(new CookieManager());
this.client = builder.build();
}
Expand Down Expand Up @@ -222,6 +228,13 @@ private static void serializeParameterValue(Object value, JsonWriter jsonWriter)
}
}

/**
* Closes client. Terminates client executor.
*/
public void close() {
clientExecutor.shutdown();
}

private static class Response {
public String error;
public LibSqlExecutionResult results;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package com.dbeaver.jdbc.upd.driver.test;

import com.dbeaver.jdbc.driver.libsql.LibSqlDriver;

import java.sql.*;
import java.util.Properties;

Expand All @@ -26,9 +24,8 @@ public static void main(String[] args) throws Exception {
long startTime = System.currentTimeMillis();

try {
LibSqlDriver driver = new LibSqlDriver();
Properties props = new Properties();
try (Connection connection = driver.connect("jdbc:dbeaver:libsql:" + args[0], props)) {
try (Connection connection = DriverManager.getConnection("jdbc:dbeaver:libsql:" + args[0], props)) {
DatabaseMetaData metaData = connection.getMetaData();
System.out.println("Driver: " + metaData.getDriverName());
System.out.println("Database: " + metaData.getDatabaseProductName() + " " + metaData.getDatabaseProductVersion());
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.dbeaver.jdbc</groupId>
<artifactId>jdbc-libsql</artifactId>
<version>1.1.0-SNAPSHOT</version>
<version>1.0.2-SNAPSHOT</version>

<packaging>pom</packaging>
<name>DBeaver LibSQL JDBC Project</name>
Expand Down

0 comments on commit a4a2326

Please sign in to comment.