Fix MultiTenantConnectionProvider implementations in Hibernate examples.

This commit is contained in:
Oliver Drotbohm
2024-08-15 15:33:46 +02:00
parent 6e06bf6a17
commit cb50e716b6
2 changed files with 23 additions and 14 deletions

View File

@@ -42,17 +42,6 @@ public class NoOpConnectionProvider implements MultiTenantConnectionProvider, Hi
connection.close();
}
@Override
public Connection getConnection(String schema) throws SQLException {
return dataSource.getConnection();
}
@Override
public void releaseConnection(String s, Connection connection) throws SQLException {
connection.close();
}
@Override
public boolean supportsAggressiveRelease() {
return false;
@@ -72,4 +61,18 @@ public class NoOpConnectionProvider implements MultiTenantConnectionProvider, Hi
public void customize(Map<String, Object> hibernateProperties) {
hibernateProperties.put(AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER, this);
}
@Override
public Connection getConnection(Object tenantIdentifier) throws SQLException {
return dataSource.getConnection();
}
/*
* (non-Javadoc)
* @see org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider#releaseConnection(java.lang.Object, java.sql.Connection)
*/
@Override
public void releaseConnection(Object tenantIdentifier, Connection connection) throws SQLException {
connection.close();
}
}

View File

@@ -43,14 +43,20 @@ public class ExampleConnectionProvider implements MultiTenantConnectionProvider,
}
@Override
public Connection getConnection(String schema) throws SQLException {
public Connection getConnection(Object tenantIdentifier) throws SQLException {
final Connection connection = dataSource.getConnection();
connection.setSchema(schema);
connection.setSchema(tenantIdentifier.toString());
return connection;
}
/*
* (non-Javadoc)
* @see org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider#releaseConnection(java.lang.Object, java.sql.Connection)
*/
@Override
public void releaseConnection(String s, Connection connection) throws SQLException {
public void releaseConnection(Object tenantIdentifier, Connection connection) throws SQLException {
connection.setSchema("PUBLIC");
connection.close();
}