File tree Expand file tree Collapse file tree 2 files changed +23
-14
lines changed Top Open diff view settings
db/src/main/java/example/springdata/jpa/hibernatemultitenant/db
schema/src/main/java/example/springdata/jpa/hibernatemultitenant/schema Expand file tree Collapse file tree 2 files changed +23
-14
lines changed Top Open diff view settings Original file line number Diff line number Diff line change @@ -42,17 +42,6 @@ public void releaseAnyConnection(Connection connection) throws SQLException {
4242 connection .close ();
4343 }
4444
45- @ Override
46- public Connection getConnection (String schema ) throws SQLException {
47-
48- return dataSource .getConnection ();
49- }
50-
51- @ Override
52- public void releaseConnection (String s , Connection connection ) throws SQLException {
53- connection .close ();
54- }
55-
5645 @ Override
5746 public boolean supportsAggressiveRelease () {
5847 return false ;
@@ -72,4 +61,18 @@ public <T> T unwrap(Class<T> aClass) {
7261 public void customize (Map <String , Object > hibernateProperties ) {
7362 hibernateProperties .put (AvailableSettings .MULTI_TENANT_CONNECTION_PROVIDER , this );
7463 }
64+
65+ @ Override
66+ public Connection getConnection (Object tenantIdentifier ) throws SQLException {
67+ return dataSource .getConnection ();
68+ }
69+
70+ /*
71+ * (non-Javadoc)
72+ * @see org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider#releaseConnection(java.lang.Object, java.sql.Connection)
73+ */
74+ @ Override
75+ public void releaseConnection (Object tenantIdentifier , Connection connection ) throws SQLException {
76+ connection .close ();
77+ }
7578}
Original file line number Diff line number Diff line change @@ -43,14 +43,20 @@ public void releaseAnyConnection(Connection connection) throws SQLException {
4343 }
4444
4545 @ Override
46- public Connection getConnection (String schema ) throws SQLException {
46+ public Connection getConnection (Object tenantIdentifier ) throws SQLException {
47+
4748 final Connection connection = dataSource .getConnection ();
48- connection .setSchema (schema );
49+ connection .setSchema (tenantIdentifier . toString () );
4950 return connection ;
5051 }
5152
53+ /*
54+ * (non-Javadoc)
55+ * @see org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider#releaseConnection(java.lang.Object, java.sql.Connection)
56+ */
5257 @ Override
53- public void releaseConnection (String s , Connection connection ) throws SQLException {
58+ public void releaseConnection (Object tenantIdentifier , Connection connection ) throws SQLException {
59+
5460 connection .setSchema ("PUBLIC" );
5561 connection .close ();
5662 }
You can’t perform that action at this time.
0 commit comments