Skip to content

Commit 0b1687a

Browse files
committed
add sessionCache to Context Supplier
Signed-off-by: dbulahov <[email protected]>
1 parent e63b73a commit 0b1687a

File tree

15 files changed

+257
-267
lines changed

15 files changed

+257
-267
lines changed

xmla/bridge/src/main/java/org/eclipse/daanse/olap/xmla/bridge/ActionService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ public interface ActionService {
3030
List<MdSchemaActionsResponseRow> getResponses(List<Catalog> catalogs, Optional<String> schemaName, String cubeName,
3131
Optional<String> actionName, Optional<ActionTypeEnum> actionType, Optional<String> coordinate,
3232
CoordinateTypeEnum coordinateType, InvocationEnum invocation, Optional<CubeSourceEnum> cubeSource,
33-
RequestMetaData metaData, UserRolePrincipal userPrincipal);
33+
RequestMetaData metaData);
3434
}

xmla/bridge/src/main/java/org/eclipse/daanse/olap/xmla/bridge/ActionServiceImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ public void unbindDrillThroughAction(org.eclipse.daanse.olap.api.action.DrillThr
8282
public List<MdSchemaActionsResponseRow> getResponses(List<Catalog> catalogs, Optional<String> schemaName,
8383
String cubeName, Optional<String> actionName, Optional<ActionTypeEnum> actionType,
8484
Optional<String> coordinate, CoordinateTypeEnum coordinateType, InvocationEnum invocation,
85-
Optional<CubeSourceEnum> cubeSource, RequestMetaData metaData, UserRolePrincipal userRolePrincipal) {
85+
Optional<CubeSourceEnum> cubeSource, RequestMetaData metaData) {
8686
// TODO: one connection per context not each row
8787
List<MdSchemaActionsResponseRow> result = new ArrayList<>();
8888
result.addAll(catalogs.stream()
8989
.map(c -> getMdSchemaActionsResponseRow(c, schemaName, cubeName, actionName, actionType, coordinate,
90-
coordinateType, invocation, cubeSource, metaData, userRolePrincipal))
90+
coordinateType, invocation, cubeSource, metaData))
9191
.flatMap(Collection::stream).toList());
9292

9393
if (CoordinateTypeEnum.CELL.equals(coordinateType)) {
@@ -165,8 +165,7 @@ private ActionTypeEnum getActionType(Action xmlaAcriton) {
165165
private List<MdSchemaActionsResponseRow> getMdSchemaActionsResponseRow(Catalog catalog,
166166
Optional<String> oSchemaName, String cubeName, Optional<String> oActionName,
167167
Optional<ActionTypeEnum> oActionType, Optional<String> oCoordinate, CoordinateTypeEnum coordinateType,
168-
InvocationEnum invocation, Optional<CubeSourceEnum> oCubeSource, RequestMetaData metaData,
169-
UserRolePrincipal userPrincipal) {
168+
InvocationEnum invocation, Optional<CubeSourceEnum> oCubeSource, RequestMetaData metaData) {
170169
if (catalog != null) {
171170
return getMdSchemaActionsResponseRow(catalog.getName(), catalog, cubeName, oActionName, oActionType,
172171
oCoordinate, coordinateType, invocation, oCubeSource);

xmla/bridge/src/main/java/org/eclipse/daanse/olap/xmla/bridge/ContextGroupXmlaService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void activate(ContextGroupXmlaServiceConfig config, Map<String, Object> props) {
5757
ContextListSupplyer contextsListSupplyer = new ContextsSupplyerImpl(contextGroup);
5858
executeService = new OlapExecuteService(contextsListSupplyer, actionService, lcidService, config);
5959
discoverService = new DelegatingDiscoverService(contextsListSupplyer, actionService, config);
60-
sessionService = new SessionServiceImpl();
60+
sessionService = new SessionServiceImpl(contextsListSupplyer);
6161
}
6262

6363
private ExecuteService executeService;

xmla/bridge/src/main/java/org/eclipse/daanse/olap/xmla/bridge/ContextListSupplyer.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,18 @@
1717
import java.util.Optional;
1818

1919
import org.eclipse.daanse.olap.api.Context;
20+
import org.eclipse.daanse.olap.api.connection.Connection;
2021
import org.eclipse.daanse.olap.api.element.Catalog;
2122

2223
public interface ContextListSupplyer {
2324

2425
List<Context<?>> getContexts();
2526

26-
List<Catalog> get(List<String> roles);
27+
List<Catalog> get(Optional<String> sessionId);
2728

28-
Optional<Catalog> tryGetFirstByName(String catalogName, List<String> roles);
29+
Optional<Catalog> tryGetFirstByName(String catalogName, Optional<String> sessionId);
2930

3031
Optional<Context<?>> getContext(String name);
31-
32+
33+
Connection getConnection(Optional<String> sessionId, String catalogName);
3234
}

xmla/bridge/src/main/java/org/eclipse/daanse/olap/xmla/bridge/ContextsSupplyerImpl.java

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
*/
1414
package org.eclipse.daanse.olap.xmla.bridge;
1515

16+
import java.util.HashMap;
1617
import java.util.List;
18+
import java.util.Map;
1719
import java.util.Optional;
1820

1921
import org.eclipse.daanse.olap.api.Context;
@@ -25,6 +27,7 @@
2527
public class ContextsSupplyerImpl implements ContextListSupplyer {
2628

2729
private final ContextGroup contextsGroup;
30+
private Map<String, Map<String, Connection>> sessionCache = new HashMap<String, Map<String, Connection>>();
2831

2932
// Accepts Null as Empty List
3033
public ContextsSupplyerImpl(ContextGroup contextsGroup) {
@@ -33,13 +36,13 @@ public ContextsSupplyerImpl(ContextGroup contextsGroup) {
3336
}
3437

3538
@Override
36-
public List<Catalog> get(List<String> roles) {
37-
return getContexts().stream().map(context -> context.getConnection(new ConnectionProps(roles))).map(Connection::getCatalog).toList();
39+
public List<Catalog> get(Optional<String> sessionId) {
40+
return getContexts().stream().map(context -> getConnection(sessionId, context.getName())).map(Connection::getCatalog).toList();
3841
}
3942

4043
@Override
41-
public Optional<Catalog> tryGetFirstByName(String catalogName, List<String> roles) {
42-
return getContext(catalogName).map(co -> co.getConnection(new ConnectionProps(roles)).getCatalog());
44+
public Optional<Catalog> tryGetFirstByName(String catalogName, Optional<String> sessionId) {
45+
return Optional.of(getConnection(sessionId, catalogName).getCatalog());
4346
}
4447

4548
@Override
@@ -53,4 +56,20 @@ public Optional<Context<?>> getContext(String name) {
5356

5457
}
5558

59+
public Map<String, Map<String, Connection>> getSessionCache() {
60+
return this.sessionCache;
61+
62+
}
63+
64+
@Override
65+
public Connection getConnection(Optional<String> sessionId, String catalogName) {
66+
if (sessionId.isPresent() && sessionCache.containsKey(sessionId.get())) {
67+
Map<String, Connection> connectionMap = sessionCache.get(sessionId.get());
68+
if (connectionMap.containsKey(catalogName)) {
69+
return connectionMap.get(catalogName);
70+
}
71+
}
72+
throw new RuntimeException("Connection is absent in cache for session " + sessionId + " for catalog " + catalogName);
73+
}
74+
5675
}

xmla/bridge/src/main/java/org/eclipse/daanse/olap/xmla/bridge/discover/DBSchemaDiscoverService.java

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,11 @@
2525
import java.util.Collection;
2626
import java.util.List;
2727
import java.util.Optional;
28-
import java.util.function.Function;
2928

3029
import org.eclipse.daanse.olap.api.Context;
3130
import org.eclipse.daanse.olap.api.element.Catalog;
3231
import org.eclipse.daanse.olap.xmla.bridge.ContextListSupplyer;
33-
import org.eclipse.daanse.olap.xmla.bridge.RoleUtils;
3432
import org.eclipse.daanse.xmla.api.RequestMetaData;
35-
import org.eclipse.daanse.xmla.api.UserRolePrincipal;
3633
import org.eclipse.daanse.xmla.api.XmlaConstants;
3734
import org.eclipse.daanse.xmla.api.common.enums.ColumnOlapTypeEnum;
3835
import org.eclipse.daanse.xmla.api.common.enums.LevelDbTypeEnum;
@@ -62,8 +59,7 @@ public DBSchemaDiscoverService(ContextListSupplyer contextsListSupplyer) {
6259
this.contextsListSupplyer = contextsListSupplyer;
6360
}
6461

65-
public List<DbSchemaCatalogsResponseRow> dbSchemaCatalogs(DbSchemaCatalogsRequest request, RequestMetaData metaData,
66-
UserRolePrincipal userRolePrincipal) {
62+
public List<DbSchemaCatalogsResponseRow> dbSchemaCatalogs(DbSchemaCatalogsRequest request, RequestMetaData metaData) {
6763

6864
Optional<String> oCatalogName = request.restrictions().catalogName();
6965
if (oCatalogName.isPresent()) {
@@ -85,8 +81,7 @@ public DbSchemaCatalogsResponseRow dbSchemaCatalogsRow(Context catalog) {
8581
Optional.empty(), Optional.empty(), Optional.empty());
8682
}
8783

88-
public List<DbSchemaColumnsResponseRow> dbSchemaColumns(DbSchemaColumnsRequest request, RequestMetaData metaData,
89-
UserRolePrincipal userRolePrincipal) {
84+
public List<DbSchemaColumnsResponseRow> dbSchemaColumns(DbSchemaColumnsRequest request, RequestMetaData metaData) {
9085
Optional<String> oCatalog = request.restrictions().tableCatalog();
9186
Optional<String> oTableSchema = request.restrictions().tableSchema();
9287
Optional<String> oTableName = request.restrictions().tableName();
@@ -95,22 +90,22 @@ public List<DbSchemaColumnsResponseRow> dbSchemaColumns(DbSchemaColumnsRequest r
9590
List<DbSchemaColumnsResponseRow> result = new ArrayList<>();
9691
if (oCatalog.isPresent()) {
9792
Optional<Catalog> oContext = oCatalog
98-
.flatMap(name -> contextsListSupplyer.tryGetFirstByName(name, RoleUtils.getRoles(contextsListSupplyer, r -> userRolePrincipal.hasRole(r))));
93+
.flatMap(name -> contextsListSupplyer.tryGetFirstByName(name, metaData.sessionId()));
9994
if (oContext.isPresent()) {
10095
Catalog catalog = oContext.get();
10196
result.addAll(
10297
getDbSchemaColumnsResponseRow(catalog, oTableSchema, oTableName, oColumnName, oColumnOlapType));
10398
}
10499
} else {
105-
result.addAll(contextsListSupplyer.get(RoleUtils.getRoles(contextsListSupplyer, r -> userRolePrincipal.hasRole(r))).stream()
100+
result.addAll(contextsListSupplyer.get(metaData.sessionId()).stream()
106101
.map(c -> getDbSchemaColumnsResponseRow(c, oTableSchema, oTableName, oColumnName, oColumnOlapType))
107102
.flatMap(Collection::stream).toList());
108103
}
109104
return result;
110105
}
111106

112107
public List<DbSchemaProviderTypesResponseRow> dbSchemaProviderTypes(DbSchemaProviderTypesRequest request,
113-
RequestMetaData metaData, UserRolePrincipal userRolePrincipal) {
108+
RequestMetaData metaData) {
114109
List<DbSchemaProviderTypesResponseRow> result = new ArrayList<>();
115110
Optional<LevelDbTypeEnum> oLevelDbType = request.restrictions().dataType();
116111

@@ -177,48 +172,46 @@ public List<DbSchemaProviderTypesResponseRow> dbSchemaProviderTypes(DbSchemaProv
177172
return result;
178173
}
179174

180-
public List<DbSchemaSchemataResponseRow> dbSchemaSchemata(DbSchemaSchemataRequest request, RequestMetaData metaData,
181-
UserRolePrincipal userRolePrincipal) {
175+
public List<DbSchemaSchemataResponseRow> dbSchemaSchemata(DbSchemaSchemataRequest request, RequestMetaData metaData) {
182176
String catalogName = request.restrictions().catalogName();
183177
String schemaName = request.restrictions().schemaName();
184178
String schemaOwner = request.restrictions().schemaOwner();
185179
List<DbSchemaSchemataResponseRow> result = new ArrayList<>();
186180
if (catalogName != null) {
187-
Optional<Catalog> oCatalog = contextsListSupplyer.tryGetFirstByName(catalogName, RoleUtils.getRoles(contextsListSupplyer, r -> userRolePrincipal.hasRole(r)));
181+
Optional<Catalog> oCatalog = contextsListSupplyer.tryGetFirstByName(catalogName, metaData.sessionId());
188182
if (oCatalog.isPresent()) {
189183
result.addAll(getDbSchemaSchemataResponseRow(oCatalog.get(), schemaName, schemaOwner));
190184
}
191185
} else {
192-
result.addAll(contextsListSupplyer.get(RoleUtils.getRoles(contextsListSupplyer, r -> userRolePrincipal.hasRole(r))).stream()
186+
result.addAll(contextsListSupplyer.get(metaData.sessionId()).stream()
193187
.map(c -> getDbSchemaSchemataResponseRow(c, schemaName, schemaOwner)).flatMap(Collection::stream)
194188
.toList());
195189
}
196190
return result;
197191
}
198192

199193
public List<DbSchemaSourceTablesResponseRow> dbSchemaSourceTables(DbSchemaSourceTablesRequest request,
200-
RequestMetaData metaData, UserRolePrincipal userRolePrincipal) {
194+
RequestMetaData metaData) {
201195
Optional<String> oCatalogName = request.restrictions().catalogName();
202196
Optional<String> oSchemaName = request.restrictions().schemaName();
203197
String tableName = request.restrictions().tableName();
204198
TableTypeEnum tableType = request.restrictions().tableType();
205199

206200
if (oCatalogName.isPresent()) {
207201
Optional<Catalog> oCatalog = oCatalogName
208-
.flatMap(name -> contextsListSupplyer.tryGetFirstByName(name, RoleUtils.getRoles(contextsListSupplyer, r -> userRolePrincipal.hasRole(r))));
202+
.flatMap(name -> contextsListSupplyer.tryGetFirstByName(name, metaData.sessionId()));
209203
if (oCatalog.isPresent()) {
210204
return getDbSchemaSourceTablesResponseRow(oCatalog.get(), List.of(tableType.getValue()));
211205
}
212206
} else {
213-
return contextsListSupplyer.get(RoleUtils.getRoles(contextsListSupplyer, r -> userRolePrincipal.hasRole(r))).stream()
207+
return contextsListSupplyer.get(metaData.sessionId()).stream()
214208
.map(c -> getDbSchemaSourceTablesResponseRow(c, List.of(tableType.getValue())))
215209
.flatMap(Collection::stream).toList();
216210
}
217211
return List.of();
218212
}
219213

220-
public List<DbSchemaTablesResponseRow> dbSchemaTables(DbSchemaTablesRequest request, RequestMetaData metaData,
221-
UserRolePrincipal userRolePrincipal) {
214+
public List<DbSchemaTablesResponseRow> dbSchemaTables(DbSchemaTablesRequest request, RequestMetaData metaData) {
222215
Optional<String> oTableCatalog = request.restrictions().tableCatalog();
223216
Optional<String> oTableSchema = request.restrictions().tableSchema();
224217
Optional<String> oTableName = request.restrictions().tableName();
@@ -230,32 +223,32 @@ public List<DbSchemaTablesResponseRow> dbSchemaTables(DbSchemaTablesRequest requ
230223

231224
if (oTableCatalog.isPresent()) {
232225
Optional<Catalog> oCatalog = oTableCatalog
233-
.flatMap(name -> contextsListSupplyer.tryGetFirstByName(name, RoleUtils.getRoles(contextsListSupplyer, r -> userRolePrincipal.hasRole(r))));
226+
.flatMap(name -> contextsListSupplyer.tryGetFirstByName(name, metaData.sessionId()));
234227
if (oCatalog.isPresent()) {
235228
return Utils.getDbSchemaTablesResponseRow(oCatalog.get(), oTableSchema, oTableName, oTableType);
236229
}
237230
} else {
238-
return contextsListSupplyer.get(RoleUtils.getRoles(contextsListSupplyer, r -> userRolePrincipal.hasRole(r))).stream()
231+
return contextsListSupplyer.get(metaData.sessionId()).stream()
239232
.map(c -> Utils.getDbSchemaTablesResponseRow(c, oTableSchema, oTableName, oTableType))
240233
.flatMap(Collection::stream).toList();
241234
}
242235
return List.of();
243236
}
244237

245238
public List<DbSchemaTablesInfoResponseRow> dbSchemaTablesInfo(DbSchemaTablesInfoRequest request,
246-
RequestMetaData metaData, UserRolePrincipal userRolePrincipal) {
239+
RequestMetaData metaData) {
247240
Optional<String> oCatalogName = request.restrictions().catalogName();
248241
Optional<String> oSchemaName = request.restrictions().schemaName();
249242
String tableName = request.restrictions().tableName();
250243
TableTypeEnum tableType = request.restrictions().tableType();
251244
if (oCatalogName.isPresent()) {
252245
Optional<Catalog> oCatalog = oCatalogName
253-
.flatMap(name -> contextsListSupplyer.tryGetFirstByName(name, RoleUtils.getRoles(contextsListSupplyer, r -> userRolePrincipal.hasRole(r))));
246+
.flatMap(name -> contextsListSupplyer.tryGetFirstByName(name, metaData.sessionId()));
254247
if (oCatalog.isPresent()) {
255248
return getDbSchemaTablesInfoResponseRow(oCatalog.get(), oSchemaName, tableName, tableType);
256249
}
257250
} else {
258-
return contextsListSupplyer.get(RoleUtils.getRoles(contextsListSupplyer, r -> userRolePrincipal.hasRole(r))).stream()
251+
return contextsListSupplyer.get(metaData.sessionId()).stream()
259252
.map(c -> getDbSchemaTablesInfoResponseRow(c, oSchemaName, tableName, tableType))
260253
.flatMap(Collection::stream).toList();
261254
}

0 commit comments

Comments
 (0)