Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class LibsqlConnection implements Connection {
private int transactionIsolation = TRANSACTION_SERIALIZABLE;
private boolean closed = false;
private TransactionMode transactionMode = TransactionMode.DEFERRED;
private LibsqlDatabaseMetaData meta;

/**
* Transaction begin mode, matching xerial sqlite-jdbc's
Expand Down Expand Up @@ -389,10 +390,19 @@ public boolean isClosed() throws SQLException {
return closed;
}

/**
* Returns the metadata for this connection, creating it on first use and reusing it afterwards,
* matching xerial sqlite-jdbc 3.53.4.0. The instance is cached for the lifetime of the
* connection, so repeated calls return the same object and separate connections get separate
* instances. Calling this on a closed connection throws.
*/
@Override
public DatabaseMetaData getMetaData() throws SQLException {
checkClosed();
return new LibsqlDatabaseMetaData(this);
if (meta == null) {
meta = new LibsqlDatabaseMetaData(this);
}
return meta;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ class LibsqlConnectionTest {
private static final String SERVER_ERROR = "transaction end failed on server";
private static final String TRANSPORT_ERROR = "Connection reset by peer";

@Test
void getMetaDataIsCachedPerConnection() throws SQLException {
LibsqlConnection connection = new LibsqlConnection(
CONFIG, new ScriptedClient((request, index) -> successResponse(request)));
LibsqlConnection other = new LibsqlConnection(
CONFIG, new ScriptedClient((request, index) -> successResponse(request)));

assertThat(connection.getMetaData()).isSameAs(connection.getMetaData());
assertThat(other.getMetaData()).isNotSameAs(connection.getMetaData());
}

@Test
void disablingAutoCommitBeginsTransactionImmediately() throws SQLException {
ScriptedClient client = new ScriptedClient((request, index) -> successResponse(request));
Expand Down
Loading