mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-14 06:45:21 +00:00
#2623 - CurrentTenantProvider called even when table has no tenantId column specified
This commit is contained in:
1 parent
585fb9d849
commit
c4a3f43e0d
9 files changed
+81
-15
No files matched your search
+7
@@ -17,12 +17,14 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
final class MultiTenantDbCatalogSupplier implements DataSourceSupplier {
|
||||
|
||||
private final CurrentTenantProvider tenantProvider;
|
||||
private final DataSource dataSource;
|
||||
private final DataSource readOnlyDataSource;
|
||||
private final CatalogDataSource catalogDataSource;
|
||||
private final CatalogDataSource readOnly;
|
||||
|
||||
MultiTenantDbCatalogSupplier(CurrentTenantProvider tenantProvider, DataSource dataSource, DataSource readOnlyDataSource, TenantCatalogProvider catalogProvider) {
|
||||
this.tenantProvider = tenantProvider;
|
||||
this.dataSource = dataSource;
|
||||
this.readOnlyDataSource = readOnlyDataSource;
|
||||
this.catalogDataSource = new CatalogDataSource(dataSource, tenantProvider, catalogProvider);
|
||||
@@ -33,6 +35,11 @@ final class MultiTenantDbCatalogSupplier implements DataSourceSupplier {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object currentTenantId() {
|
||||
return tenantProvider.currentId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSource getDataSource() {
|
||||
return catalogDataSource;
|
||||
|
||||
@@ -17,12 +17,14 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
final class MultiTenantDbSchemaSupplier implements DataSourceSupplier {
|
||||
|
||||
private final CurrentTenantProvider tenantProvider;
|
||||
private final DataSource dataSource;
|
||||
private final DataSource readOnlyDataSource;
|
||||
private final SchemaDataSource schemaDataSource;
|
||||
private final SchemaDataSource readOnly;
|
||||
|
||||
MultiTenantDbSchemaSupplier(CurrentTenantProvider tenantProvider, DataSource dataSource, DataSource readOnlyDataSource, TenantSchemaProvider schemaProvider) {
|
||||
this.tenantProvider = tenantProvider;
|
||||
this.dataSource = dataSource;
|
||||
this.readOnlyDataSource = readOnlyDataSource;
|
||||
this.schemaDataSource = new SchemaDataSource(dataSource, schemaProvider, tenantProvider);
|
||||
@@ -33,6 +35,11 @@ final class MultiTenantDbSchemaSupplier implements DataSourceSupplier {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object currentTenantId() {
|
||||
return tenantProvider.currentId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSource getDataSource() {
|
||||
return schemaDataSource;
|
||||
|
||||
@@ -21,6 +21,11 @@ final class MultiTenantDbSupplier implements DataSourceSupplier {
|
||||
this.dataSourceProvider = dataSourceProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object currentTenantId() {
|
||||
return tenantProvider.currentId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSource getReadOnlyDataSource() {
|
||||
// read only datasource not supported with DB per tenant at this stage
|
||||
|
||||
@@ -20,6 +20,11 @@ final class SimpleDataSourceProvider implements DataSourceSupplier {
|
||||
this.readOnlyDataSource = readOnlyDataSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object currentTenantId() {
|
||||
return null; // not required here
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataSource getDataSource() {
|
||||
return dataSource;
|
||||
|
||||
+5
-2
@@ -16,7 +16,6 @@ public interface DataSourceSupplier {
|
||||
* Return the DataSource to use for the current request.
|
||||
* <p>
|
||||
* This should take into account multi-tenancy and the current tenantId.
|
||||
* </p>
|
||||
*/
|
||||
DataSource getDataSource();
|
||||
|
||||
@@ -25,10 +24,14 @@ public interface DataSourceSupplier {
|
||||
* <p>
|
||||
* This can return null meaning that no read only DataSource (with autoCommit)
|
||||
* is available for use so normal transactions with explicit commit should be used.
|
||||
* </p>
|
||||
*/
|
||||
DataSource getReadOnlyDataSource();
|
||||
|
||||
/**
|
||||
* Obtain the current TenantId *IF* it is required for the DataSource.
|
||||
*/
|
||||
Object currentTenantId();
|
||||
|
||||
/**
|
||||
* Return a connection from the DataSource taking into account a tenantId for multi-tenant lazy loading.
|
||||
*
|
||||
|
||||
+2
-2
@@ -27,8 +27,8 @@ final class TransactionFactoryTenantWithRead extends TransactionFactoryTenant {
|
||||
Connection connection = null;
|
||||
try {
|
||||
if (tenantId == null) {
|
||||
// tenantId not set (by lazy loading) so get current tenantId
|
||||
tenantId = tenantProvider.currentId();
|
||||
// obtain the tenantId if the DataSource requires it
|
||||
tenantId = dataSourceSupplier.currentTenantId();
|
||||
}
|
||||
connection = dataSourceSupplier.getReadOnlyConnection(tenantId);
|
||||
return new ImplicitReadOnlyTransaction(manager, connection, tenantId);
|
||||
|
||||
Reference in new issue
Block a user