Skip to content

Commit

Permalink
Fix ORMEnabled config check
Browse files Browse the repository at this point in the history
... as well as error in ORMContext retrieval if the current request is not ORM-enabled.
  • Loading branch information
michaelborn committed Nov 13, 2024
1 parent 70fbbfa commit deb43fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
import ortus.boxlang.runtime.context.IBoxContext;
import ortus.boxlang.runtime.context.IJDBCCapableContext;
import ortus.boxlang.runtime.context.RequestBoxContext;
import ortus.boxlang.runtime.dynamic.casters.BooleanCaster;
import ortus.boxlang.runtime.jdbc.ConnectionManager;
import ortus.boxlang.runtime.jdbc.DataSource;
import ortus.boxlang.runtime.scopes.Key;
import ortus.boxlang.runtime.types.IStruct;
import ortus.boxlang.runtime.types.exceptions.BoxRuntimeException;

/**
* Transient context for ORM requests.
Expand Down Expand Up @@ -53,6 +56,12 @@ public class ORMRequestContext {
* @return The ORMRequestContext for the given context.
*/
public static ORMRequestContext getForContext( IBoxContext context ) {
IStruct appSettings = ( IStruct ) context.getConfigItem( Key.applicationSettings );
logger.debug( "application settings: {}", appSettings );
if ( !appSettings.containsKey( ORMKeys.ORMEnabled )
|| !BooleanCaster.cast( appSettings.getOrDefault( ORMKeys.ORMEnabled, false ) ) ) {
throw new BoxRuntimeException( "Could not acquire ORM context; ORMEnabled is false or not specified. Is this application ORM-enabled?" );
}
return context.getAttachment( ORMKeys.ORMRequestContext );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class BaseListener extends BaseInterceptor {
protected static ORMConfig getORMConfig( RequestBoxContext context ) {
IStruct appSettings = ( IStruct ) context.getConfigItem( Key.applicationSettings );
if ( !appSettings.containsKey( ORMKeys.ORMEnabled )
|| BooleanCaster.cast( appSettings.getOrDefault( ORMKeys.ORMEnabled, false ) ) ) {
|| !BooleanCaster.cast( appSettings.getOrDefault( ORMKeys.ORMEnabled, false ) ) ) {
logger.info( "ORMEnabled is false or not specified;" );
return null;
}
Expand Down

0 comments on commit deb43fe

Please sign in to comment.