Skip to content

Commit 4c3760d

Browse files
committed
Sample implementation of DB2 trusted context
1 parent 234e432 commit 4c3760d

File tree

6 files changed

+1021
-0
lines changed

6 files changed

+1021
-0
lines changed

ebean-datasource/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
<scope>test</scope>
2727
</dependency>
2828

29+
<dependency>
30+
<groupId>org.junit.jupiter</groupId>
31+
<artifactId>junit-jupiter-params</artifactId>
32+
<version>5.10.2</version>
33+
<scope>test</scope>
34+
</dependency>
35+
2936
<dependency>
3037
<groupId>io.ebean</groupId>
3138
<artifactId>ebean-test-containers</artifactId>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.ebean.datasource.tcdriver;
2+
3+
import io.ebean.datasource.DataSourceConnection;
4+
import io.ebean.datasource.DataSourcePool;
5+
import io.ebean.datasource.DataSourcePoolListener;
6+
7+
import java.sql.SQLException;
8+
9+
/**
10+
* Listener, that sets up TrustedConnection properly
11+
*
12+
* @author Roland Praml, Foconis Analytics GmbH
13+
*/
14+
public class TrustedContextListener implements DataSourcePoolListener {
15+
16+
@Override
17+
public void onAfterBorrowConnection(DataSourcePool pool, DataSourceConnection connection) throws SQLException {
18+
TrustedContextTenant tenant = (TrustedContextTenant) connection.affinityId();
19+
TrustedDb2Connection trustedDb2Connection = connection.unwrap(TrustedDb2Connection.class);
20+
if (trustedDb2Connection.switchUser(tenant.user(), tenant.password())) {
21+
trustedDb2Connection.setSchema(tenant.schema());
22+
connection.clearPreparedStatementCache();
23+
}
24+
}
25+
26+
27+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package io.ebean.datasource.tcdriver;
2+
3+
/**
4+
* @author Roland Praml, Foconis Analytics GmbH
5+
*/
6+
public class TrustedContextTenant {
7+
private final int id;
8+
private final String user;
9+
private final String password;
10+
private final String schema;
11+
12+
public TrustedContextTenant(int id, String user, String password, String schema) {
13+
this.id = id;
14+
this.user = user;
15+
this.password = password;
16+
this.schema = schema;
17+
}
18+
19+
public int id() {
20+
return id;
21+
}
22+
23+
public String user() {
24+
return user;
25+
}
26+
27+
public String password() {
28+
return password;
29+
}
30+
31+
public String schema() {
32+
return schema;
33+
}
34+
35+
}

0 commit comments

Comments
 (0)