Skip to content

Commit

Permalink
dbeaver/dbeaver#23361 Metadata and refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-rider committed Oct 29, 2024
1 parent 8a21ef2 commit 803da95
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@
import java.sql.Statement;
import java.util.Map;

public class LSqlConnection extends AbstractJdbcConnection {
public class LibSqlConnection extends AbstractJdbcConnection {

@NotNull
private final LSqlDriver driver;
private final LibSqlDriver driver;
private final LSqlClient client;
@NotNull
private String url;
@NotNull
private Map<String, Object> driverProperties;

public LSqlConnection(
@NotNull LSqlDriver driver,
public LibSqlConnection(
@NotNull LibSqlDriver driver,
@NotNull String url,
@NotNull Map<String, Object> driverProperties
) throws SQLException {
Expand Down Expand Up @@ -71,13 +71,13 @@ public Map<String, Object> getDriverProperties() {
}

@NotNull
public LSqlDriver getDriver() {
public LibSqlDriver getDriver() {
return driver;
}

@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
return new LSqlStatement(this);
return new LibSqlStatement(this);
}

@Override
Expand All @@ -86,8 +86,8 @@ public PreparedStatement prepareStatement(String sql, int resultSetType, int res
}

@NotNull
private LSqlPreparedStatement prepareStatementImpl(String sql) throws SQLException {
return new LSqlPreparedStatement(this, sql);
private LibSqlPreparedStatement prepareStatementImpl(String sql) throws SQLException {
return new LibSqlPreparedStatement(this, sql);
}

@Override
Expand All @@ -101,7 +101,7 @@ public boolean isClosed() {

@Override
public DatabaseMetaData getMetaData() throws SQLException {
return new LSqlDatabaseMetaData(this);
return new LibSqlDatabaseMetaData(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.util.regex.Pattern;

public class LSqlConstants {
public class LibSqlConstants {

public static final Pattern CONNECTION_URL_EXAMPLE = Pattern.compile("jdbc:dbeaver:libsql:<server-url>");
public static final Pattern CONNECTION_URL_PATTERN = Pattern.compile("jdbc:dbeaver:libsql:(.+)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class LSqlDatabaseMetaData extends AbstractJdbcDatabaseMetaData<LSqlConnection> {
public class LibSqlDatabaseMetaData extends AbstractJdbcDatabaseMetaData<LibSqlConnection> {

private static Pattern VERSION_PATTERN = Pattern.compile("(\\w+)\\s+([0-9.]+)\\s+(.+)");
private String serverVersion;

public LSqlDatabaseMetaData(@NotNull LSqlConnection connection) {
public LibSqlDatabaseMetaData(@NotNull LibSqlConnection connection) {
super(connection, connection.getUrl());
}

Expand Down Expand Up @@ -107,7 +107,7 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam
"SELECT NULL as TABLE_CAT, NULL AS TABLE_SCHEM," +
"name AS TABLE_NAME,type as TABLE_TYPE, " +
"NULL AS REMARKS, NULL AS TYPE_CAT, NULL AS TYPE_SCHEM, NULL AS TYPE_NAME " +
"FROM sqlite_master")
"FROM sqlite_master WHERE type='table'")
) {
return dbStat.executeQuery();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@
import java.util.logging.Logger;
import java.util.regex.Matcher;

public class LSqlDriver implements Driver {
public class LibSqlDriver implements Driver {

static final java.util.logging.Logger parentLogger = java.util.logging.Logger.getLogger("com.dbeaver.jdbc.upd.driver.driver");

@Override
public Connection connect(String url, Properties info) throws SQLException {
Matcher matcher = LSqlConstants.CONNECTION_URL_PATTERN.matcher(url);
Matcher matcher = LibSqlConstants.CONNECTION_URL_PATTERN.matcher(url);
if (!matcher.matches()) {
throw new LSqlException(
throw new LibSqlException(
"Invalid connection URL: " + url +
".\nExpected URL format: " + LSqlConstants.CONNECTION_URL_EXAMPLE);
".\nExpected URL format: " + LibSqlConstants.CONNECTION_URL_EXAMPLE);
}
String targetUrl = matcher.group(1);

Expand All @@ -44,7 +44,7 @@ public Connection connect(String url, Properties info) throws SQLException {
String propName = pne.toString();
props.put(propName, info.get(propName));
}
return new LSqlConnection(this, targetUrl, props);
return new LibSqlConnection(this, targetUrl, props);
/*
UPDEndpoint endpoint = new UPDEndpoint();
endpoint.setServerAddress(matcher.group(1));
Expand Down Expand Up @@ -122,7 +122,7 @@ private UPDProtocol openServerConnection(

@Override
public boolean acceptsURL(String url) {
return LSqlConstants.CONNECTION_URL_PATTERN.matcher(url).matches();
return LibSqlConstants.CONNECTION_URL_PATTERN.matcher(url).matches();
}

@Override
Expand All @@ -134,12 +134,12 @@ public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws

@Override
public int getMajorVersion() {
return LSqlConstants.DRIVER_VERSION_MAJOR;
return LibSqlConstants.DRIVER_VERSION_MAJOR;
}

@Override
public int getMinorVersion() {
return LSqlConstants.DRIVER_VERSION_MINOR;
return LibSqlConstants.DRIVER_VERSION_MINOR;
}

@Override
Expand All @@ -153,10 +153,10 @@ public Logger getParentLogger() throws SQLFeatureNotSupportedException {
}

public String getDriverName() {
return LSqlConstants.DRIVER_NAME;
return LibSqlConstants.DRIVER_NAME;
}

public String getFullVersion() {
return getMajorVersion() + "." + getMinorVersion() + " (" + LSqlConstants.DRIVER_INFO + ")";
return getMajorVersion() + "." + getMinorVersion() + " (" + LibSqlConstants.DRIVER_INFO + ")";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,35 @@

import java.sql.SQLException;

public class LSqlException extends SQLException {
public LSqlException(String reason, String SQLState, int vendorCode) {
public class LibSqlException extends SQLException {
public LibSqlException(String reason, String SQLState, int vendorCode) {
super(reason, SQLState, vendorCode);
}

public LSqlException(String reason, String SQLState) {
public LibSqlException(String reason, String SQLState) {
super(reason, SQLState);
}

public LSqlException(String reason) {
public LibSqlException(String reason) {
super(reason);
}

public LSqlException() {
public LibSqlException() {
}

public LSqlException(Throwable cause) {
public LibSqlException(Throwable cause) {
super(cause);
}

public LSqlException(String reason, Throwable cause) {
public LibSqlException(String reason, Throwable cause) {
super(reason, cause);
}

public LSqlException(String reason, String sqlState, Throwable cause) {
public LibSqlException(String reason, String sqlState, Throwable cause) {
super(reason, sqlState, cause);
}

public LSqlException(String reason, String sqlState, int vendorCode, Throwable cause) {
public LibSqlException(String reason, String sqlState, int vendorCode, Throwable cause) {
super(reason, sqlState, vendorCode, cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/
package com.dbeaver.jdbc.driver.libsql;

import com.dbeaver.jdbc.driver.libsql.client.LSqlReaderInput;
import com.dbeaver.jdbc.driver.libsql.client.LSqlStreamInput;
import com.dbeaver.jdbc.driver.libsql.client.LibSqlReaderInput;
import com.dbeaver.jdbc.driver.libsql.client.LibSqlStreamInput;
import org.jkiss.code.NotNull;

import java.io.InputStream;
Expand All @@ -27,10 +27,10 @@
import java.sql.*;
import java.util.Calendar;

public class LSqlPreparedStatement extends LSqlStatement implements PreparedStatement {
public class LibSqlPreparedStatement extends LibSqlStatement implements PreparedStatement {

public LSqlPreparedStatement(
@NotNull LSqlConnection connection, String sql) throws SQLException {
public LibSqlPreparedStatement(
@NotNull LibSqlConnection connection, String sql) throws SQLException {
super(connection);
this.queryText = sql;
}
Expand Down Expand Up @@ -115,17 +115,17 @@ public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {

@Override
public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
this.addParameter(parameterIndex, new LSqlStreamInput(x, length));
this.addParameter(parameterIndex, new LibSqlStreamInput(x, length));
}

@Override
public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException {
this.addParameter(parameterIndex, new LSqlStreamInput(x, length));
this.addParameter(parameterIndex, new LibSqlStreamInput(x, length));
}

@Override
public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
this.addParameter(parameterIndex, new LSqlStreamInput(x, length));
this.addParameter(parameterIndex, new LibSqlStreamInput(x, length));
}

@Override
Expand All @@ -150,7 +150,7 @@ public void addBatch() throws SQLException {

@Override
public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException {
this.addParameter(parameterIndex, new LSqlReaderInput(reader, length));
this.addParameter(parameterIndex, new LibSqlReaderInput(reader, length));
}

@Override
Expand Down Expand Up @@ -220,7 +220,7 @@ public void setNString(int parameterIndex, String value) throws SQLException {

@Override
public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException {
this.addParameter(parameterIndex, new LSqlReaderInput(value, length));
this.addParameter(parameterIndex, new LibSqlReaderInput(value, length));
}

@Override
Expand All @@ -230,17 +230,17 @@ public void setNClob(int parameterIndex, NClob value) throws SQLException {

@Override
public void setClob(int parameterIndex, Reader reader, long length) throws SQLException {
this.addParameter(parameterIndex, new LSqlReaderInput(reader, length));
this.addParameter(parameterIndex, new LibSqlReaderInput(reader, length));
}

@Override
public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException {
this.addParameter(parameterIndex, new LSqlStreamInput(inputStream, length));
this.addParameter(parameterIndex, new LibSqlStreamInput(inputStream, length));
}

@Override
public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {
this.addParameter(parameterIndex, new LSqlReaderInput(reader, length));
this.addParameter(parameterIndex, new LibSqlReaderInput(reader, length));
}

@Override
Expand All @@ -255,51 +255,51 @@ public void setObject(int parameterIndex, Object x, int targetSqlType, int scale

@Override
public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
this.addParameter(parameterIndex, new LSqlStreamInput(x, length));
this.addParameter(parameterIndex, new LibSqlStreamInput(x, length));
}

@Override
public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException {
this.addParameter(parameterIndex, new LSqlStreamInput(x, length));
this.addParameter(parameterIndex, new LibSqlStreamInput(x, length));
}

@Override
public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException {
this.addParameter(parameterIndex, new LSqlReaderInput(reader, length));
this.addParameter(parameterIndex, new LibSqlReaderInput(reader, length));
}

@Override
public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
this.addParameter(parameterIndex, new LSqlStreamInput(x, -1));
this.addParameter(parameterIndex, new LibSqlStreamInput(x, -1));
}

@Override
public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
this.addParameter(parameterIndex, new LSqlStreamInput(x, -1));
this.addParameter(parameterIndex, new LibSqlStreamInput(x, -1));
}

@Override
public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
this.addParameter(parameterIndex, new LSqlReaderInput(reader, -1));
this.addParameter(parameterIndex, new LibSqlReaderInput(reader, -1));
}

@Override
public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
this.addParameter(parameterIndex, new LSqlReaderInput(value, -1));
this.addParameter(parameterIndex, new LibSqlReaderInput(value, -1));
}

@Override
public void setClob(int parameterIndex, Reader reader) throws SQLException {
this.addParameter(parameterIndex, new LSqlReaderInput(reader, -1));
this.addParameter(parameterIndex, new LibSqlReaderInput(reader, -1));
}

@Override
public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
this.addParameter(parameterIndex, new LSqlStreamInput(inputStream, -1));
this.addParameter(parameterIndex, new LibSqlStreamInput(inputStream, -1));
}

@Override
public void setNClob(int parameterIndex, Reader reader) throws SQLException {
this.addParameter(parameterIndex, new LSqlReaderInput(reader, -1));
this.addParameter(parameterIndex, new LibSqlReaderInput(reader, -1));
}
}
Loading

0 comments on commit 803da95

Please sign in to comment.