mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-26 20:44:23 +01:00
Implement JDBC so that DriverManager can detect limbo connection
This commit is contained in:
@@ -7,9 +7,16 @@ import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class JDBC implements Driver {
|
||||
|
||||
private static final String VALID_URL_PREFIX = "jdbc:limbo:";
|
||||
|
||||
static {
|
||||
try {
|
||||
DriverManager.registerDriver(new JDBC());
|
||||
} catch (Exception e) {
|
||||
// TODO: log
|
||||
}
|
||||
}
|
||||
|
||||
public static LimboConnection createConnection(String url, Properties properties) throws SQLException {
|
||||
if (!isValidURL(url)) return null;
|
||||
|
||||
@@ -27,26 +34,28 @@ public class JDBC implements Driver {
|
||||
|
||||
@Override
|
||||
public Connection connect(String url, Properties info) throws SQLException {
|
||||
return null;
|
||||
return createConnection(url, info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsURL(String url) throws SQLException {
|
||||
return false;
|
||||
return isValidURL(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) throws SQLException {
|
||||
return new DriverPropertyInfo[0];
|
||||
return LimboConfig.getDriverPropertyInfo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMajorVersion() {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinorVersion() {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -57,6 +66,7 @@ public class JDBC implements Driver {
|
||||
|
||||
@Override
|
||||
public Logger getParentLogger() throws SQLFeatureNotSupportedException {
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.github.tursodatabase;
|
||||
|
||||
import java.sql.DriverPropertyInfo;
|
||||
import java.util.Arrays;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
@@ -12,9 +14,38 @@ public class LimboConfig {
|
||||
this.pragma = properties;
|
||||
}
|
||||
|
||||
public static DriverPropertyInfo[] getDriverPropertyInfo() {
|
||||
return Arrays.stream(Pragma.values())
|
||||
.map(p -> {
|
||||
DriverPropertyInfo info = new DriverPropertyInfo(p.pragmaName, null);
|
||||
info.description = p.description;
|
||||
info.choices = p.choices;
|
||||
info.required = false;
|
||||
return info;
|
||||
})
|
||||
.toArray(DriverPropertyInfo[]::new);
|
||||
}
|
||||
|
||||
public Properties toProperties() {
|
||||
Properties copy = new Properties();
|
||||
copy.putAll(pragma);
|
||||
return copy;
|
||||
}
|
||||
|
||||
public enum Pragma {
|
||||
;
|
||||
private final String pragmaName;
|
||||
private final String description;
|
||||
private final String[] choices;
|
||||
|
||||
Pragma(String pragmaName, String description, String[] choices) {
|
||||
this.pragmaName = pragmaName;
|
||||
this.description = description;
|
||||
this.choices = choices;
|
||||
}
|
||||
|
||||
public String getPragmaName() {
|
||||
return pragmaName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user