177177import org .eclipse .daanse .xmla .model .record .mddataset .RowSetR ;
178178import org .eclipse .daanse .xmla .model .record .mddataset .RowSetRowR ;
179179import org .eclipse .daanse .xmla .model .record .xmla_empty .EmptyresultR ;
180+ import org .slf4j .Logger ;
180181
181182public class OlapExecuteService implements ExecuteService {
182183
184+ private static final Logger LOGGER = org .slf4j .LoggerFactory .getLogger (OlapExecuteService .class );
183185 private static final String MDX_CUBE_0_NOT_FOUND = "MDX cube ''{0}'' not found" ;
184186 public static final String SESSION_ID = "sessionId" ;
185187 public static final String CODE3238658121 = "3238658121" ;
@@ -247,14 +249,19 @@ public ClearCacheResponse clearCache(ClearCacheRequest clearCacheRequest, Reques
247249 public StatementResponse statement (StatementRequest statementRequest , RequestMetaData metaData ,
248250 UserRolePrincipal userRolePrincipal ) {
249251
252+ String statement = statementRequest .command ().statement ();
253+ if (statement == null || statement .isBlank ()) {
254+ LOGGER .warn ("Empty statement received" );
255+ return new StatementResponseR (null , null );
256+ }
257+
250258 Optional <String > oCatalog = statementRequest .properties ().catalog ();
259+
251260 if (oCatalog .isPresent ()) {
252261 String catalogName = oCatalog .get ();
253262 Optional <Context <?>> oContext = contextsListSupplyer .getContexts ().stream ()
254263 .filter (ctx -> catalogName .equals (ctx .getName ())).findAny ();
255264 Context context = oContext .get ();
256- String statement = statementRequest .command ().statement ();
257- if (statement != null && statement .length () > 0 ) {
258265 Locale locale = getLocale (statementRequest .properties ());
259266 Connection connection = context .getConnection (new ConnectionProps (RoleUtils .getRoles (contextsListSupplyer , r -> userRolePrincipal .hasRole (r )), locale ));
260267 QueryComponent queryComponent = connection .parseStatement (statement );
@@ -278,11 +285,11 @@ public StatementResponse statement(StatementRequest statementRequest, RequestMet
278285 } else if (queryComponent instanceof SqlQuery sqlQuery ) {
279286 return executeSqlQuery (sqlQuery );
280287 }
281- }
288+
282289 } else {
283- String statement = statementRequest . command ().statement ();
284- if ( statement != null && statement . length () > 0 && contextsListSupplyer . getContexts () != null
285- && ! contextsListSupplyer . getContexts (). isEmpty ()) {
290+ if ( contextsListSupplyer . getContexts () != null && ! contextsListSupplyer . getContexts ().isEmpty ()) {
291+ //TODO: aggregate word from all statements?
292+ //or do we have a default context?
286293 Connection connection = contextsListSupplyer .getContexts ().get (0 ).getConnection (new ConnectionProps (RoleUtils .getRoles (contextsListSupplyer , r -> userRolePrincipal .hasRole (r ))));
287294 QueryComponent queryComponent = connection .parseStatement (statement );
288295 if (queryComponent instanceof DmvQuery dmvQuery ) {
@@ -321,10 +328,10 @@ public StatementResponse statement(StatementRequest statementRequest, RequestMet
321328
322329 }
323330// here
324- }
325331 }
326-
332+ }
327333 return new StatementResponseR (null , null );
334+
328335 }
329336
330337 private Locale getLocale (Properties properties ) {
0 commit comments