diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/EntityDelete.java b/src/main/java/ortus/boxlang/modules/orm/bifs/EntityDelete.java index 3028af6..6972b39 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/EntityDelete.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/EntityDelete.java @@ -2,6 +2,9 @@ import org.apache.commons.lang3.NotImplementedException; +import ortus.boxlang.modules.orm.ORMService; +import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -10,6 +13,11 @@ @BoxBIF public class EntityDelete extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * ExampleBIF * @@ -18,6 +26,7 @@ public class EntityDelete extends BIF { */ public String _invoke( IBoxContext context, ArgumentsScope arguments ) { // TODO implement BIF + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); throw new NotImplementedException(); } diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/EntityLoad.java b/src/main/java/ortus/boxlang/modules/orm/bifs/EntityLoad.java index e06439a..2bf393e 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/EntityLoad.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/EntityLoad.java @@ -2,6 +2,9 @@ import org.apache.commons.lang3.NotImplementedException; +import ortus.boxlang.modules.orm.ORMService; +import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -10,6 +13,11 @@ @BoxBIF public class EntityLoad extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * ExampleBIF * @@ -18,6 +26,7 @@ public class EntityLoad extends BIF { */ public String _invoke( IBoxContext context, ArgumentsScope arguments ) { // TODO implement BIF + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); throw new NotImplementedException(); } diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/EntityLoadByExample.java b/src/main/java/ortus/boxlang/modules/orm/bifs/EntityLoadByExample.java index dc60b59..f25390c 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/EntityLoadByExample.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/EntityLoadByExample.java @@ -2,6 +2,9 @@ import org.apache.commons.lang3.NotImplementedException; +import ortus.boxlang.modules.orm.ORMService; +import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -10,6 +13,11 @@ @BoxBIF public class EntityLoadByExample extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * ExampleBIF * @@ -18,6 +26,7 @@ public class EntityLoadByExample extends BIF { */ public String _invoke( IBoxContext context, ArgumentsScope arguments ) { // TODO implement BIF + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); throw new NotImplementedException(); } diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/EntityLoadByPK.java b/src/main/java/ortus/boxlang/modules/orm/bifs/EntityLoadByPK.java index 1f3a468..c61f3d9 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/EntityLoadByPK.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/EntityLoadByPK.java @@ -7,6 +7,7 @@ import ortus.boxlang.modules.orm.ORMService; import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -19,12 +20,19 @@ @BoxBIF public class EntityLoadByPK extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * Constructor */ public EntityLoadByPK() { + super(); - declaredArguments = new Argument[] { + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); + declaredArguments = new Argument[] { new Argument( true, "String", ORMKeys.entity, Set.of( Validator.REQUIRED, Validator.NON_EMPTY ) ), new Argument( true, "String", Key.id, Set.of( Validator.REQUIRED, Validator.NON_EMPTY ) ), new Argument( false, "String", ORMKeys.unique, Set.of( Validator.NOT_IMPLEMENTED ) ) @@ -51,7 +59,7 @@ public EntityLoadByPK() { * @param arguments Argument scope for the BIF. */ public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { - Session session = ORMService.getInstance().getORMApp( context ).getSession( context ); + Session session = this.ormService.getORMApp( context ).getSession( context ); // @TODO: Move this to a more sensible location. if ( session.getTransaction() == null ) { diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/EntityMerge.java b/src/main/java/ortus/boxlang/modules/orm/bifs/EntityMerge.java index 3851c68..6e25336 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/EntityMerge.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/EntityMerge.java @@ -2,6 +2,9 @@ import org.apache.commons.lang3.NotImplementedException; +import ortus.boxlang.modules.orm.ORMService; +import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -10,6 +13,11 @@ @BoxBIF public class EntityMerge extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * ExampleBIF * @@ -18,6 +26,7 @@ public class EntityMerge extends BIF { */ public String _invoke( IBoxContext context, ArgumentsScope arguments ) { // TODO implement BIF + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); throw new NotImplementedException(); } diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/EntityNameArray.java b/src/main/java/ortus/boxlang/modules/orm/bifs/EntityNameArray.java index 2375db2..8da0103 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/EntityNameArray.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/EntityNameArray.java @@ -7,6 +7,7 @@ import ortus.boxlang.modules.orm.ORMService; import ortus.boxlang.modules.orm.config.ORMKeys; import ortus.boxlang.modules.orm.mapping.EntityRecord; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -22,12 +23,19 @@ @BoxBIF( alias = "EntityNameList" ) public class EntityNameArray extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * Constructor */ public EntityNameArray() { + super(); - declaredArguments = new Argument[] { + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); + declaredArguments = new Argument[] { new Argument( false, "String", Key.delimiter, Set.of( Validator.NON_EMPTY ) ), new Argument( false, "String", Key.datasource, Set.of( Validator.NON_EMPTY ) ), }; @@ -51,7 +59,7 @@ public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { } String datasourceName = ( String ) arguments.getAsString( Key.datasource ); - ORMApp ormApp = ORMService.getInstance().getORMApp( context ); + ORMApp ormApp = this.ormService.getORMApp( context ); List entityList = datasourceName != null ? ormApp.getEntityRecords( datasourceName ) : ormApp.getEntityRecords(); diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/EntityNew.java b/src/main/java/ortus/boxlang/modules/orm/bifs/EntityNew.java index ccfd3ec..e99cd37 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/EntityNew.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/EntityNew.java @@ -9,6 +9,7 @@ import ortus.boxlang.modules.orm.config.ORMKeys; import ortus.boxlang.modules.orm.hibernate.BoxClassInstantiator; import ortus.boxlang.modules.orm.mapping.EntityRecord; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.ApplicationBoxContext; @@ -23,12 +24,19 @@ @BoxBIF public class EntityNew extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * Constructor */ public EntityNew() { + super(); - declaredArguments = new Argument[] { + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); + declaredArguments = new Argument[] { new Argument( true, "String", ORMKeys.entityName, Set.of( Validator.REQUIRED, Validator.NON_EMPTY ) ), new Argument( false, "Struct", Key.properties ) }; @@ -41,7 +49,7 @@ public EntityNew() { * @param arguments Argument scope for the BIF. */ public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { - Session session = ORMService.getInstance().getORMApp( context ).getSession( context ); + Session session = this.ormService.getORMApp( context ).getSession( context ); EntityRecord entityRecord = SessionFactoryBuilder.lookupEntity( session, arguments.getAsString( ORMKeys.entityName ) ); IStruct properties = arguments.containsKey( Key.properties ) ? arguments.getAsStruct( Key.properties ) : Struct.EMPTY; diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/EntityReload.java b/src/main/java/ortus/boxlang/modules/orm/bifs/EntityReload.java index 736e438..2adf711 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/EntityReload.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/EntityReload.java @@ -2,6 +2,9 @@ import org.apache.commons.lang3.NotImplementedException; +import ortus.boxlang.modules.orm.ORMService; +import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -10,6 +13,11 @@ @BoxBIF public class EntityReload extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * ExampleBIF * @@ -18,6 +26,7 @@ public class EntityReload extends BIF { */ public String _invoke( IBoxContext context, ArgumentsScope arguments ) { // TODO implement BIF + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); throw new NotImplementedException(); } diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/EntitySave.java b/src/main/java/ortus/boxlang/modules/orm/bifs/EntitySave.java index ced31ab..8f4fee6 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/EntitySave.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/EntitySave.java @@ -8,6 +8,7 @@ import ortus.boxlang.modules.orm.ORMService; import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -20,14 +21,21 @@ @BoxBIF public class EntitySave extends BIF { - Logger logger = LoggerFactory.getLogger( EntitySave.class ); + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + + Logger logger = LoggerFactory.getLogger( EntitySave.class ); /** * Constructor */ public EntitySave() { + super(); - declaredArguments = new Argument[] { + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); + declaredArguments = new Argument[] { new Argument( true, "Any", ORMKeys.entity, Set.of( Validator.REQUIRED, Validator.NON_EMPTY ) ), new Argument( false, "Boolean", ORMKeys.forceinsert ) }; @@ -42,7 +50,7 @@ public EntitySave() { * @return */ public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { - Session session = ORMService.getInstance().getORMApp( context ).getSession( context ); + Session session = this.ormService.getORMApp( context ).getSession( context ); // @TODO: Implement forceinsert IClassRunnable entity = ( IClassRunnable ) arguments.get( ORMKeys.entity ); // @TODO: Should we look up the EntityRecord and use that to grab the class name? diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/EntityToQuery.java b/src/main/java/ortus/boxlang/modules/orm/bifs/EntityToQuery.java index 5c0c7bf..15f50d5 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/EntityToQuery.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/EntityToQuery.java @@ -2,6 +2,9 @@ import org.apache.commons.lang3.NotImplementedException; +import ortus.boxlang.modules.orm.ORMService; +import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -10,6 +13,11 @@ @BoxBIF public class EntityToQuery extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * ExampleBIF * @@ -18,6 +26,7 @@ public class EntityToQuery extends BIF { */ public String _invoke( IBoxContext context, ArgumentsScope arguments ) { // TODO implement BIF + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); throw new NotImplementedException(); } diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/GetHibernateVersion.java b/src/main/java/ortus/boxlang/modules/orm/bifs/GetHibernateVersion.java index ae6a212..824f434 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/GetHibernateVersion.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/GetHibernateVersion.java @@ -1,5 +1,6 @@ package ortus.boxlang.modules.orm.bifs; +import ortus.boxlang.modules.orm.ORMService; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -8,6 +9,11 @@ @BoxBIF public class GetHibernateVersion extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * Retrieve the installed Hibernate version. * diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMClearSession.java b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMClearSession.java index 48f8ea3..7979e2f 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMClearSession.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMClearSession.java @@ -6,6 +6,7 @@ import ortus.boxlang.modules.orm.ORMService; import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -18,12 +19,19 @@ @BoxBIF public class ORMClearSession extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * Constructor */ public ORMClearSession() { + super(); - declaredArguments = new Argument[] { + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); + declaredArguments = new Argument[] { new Argument( false, "String", ORMKeys.datasource, Set.of( Validator.NON_EMPTY ) ) }; } @@ -42,9 +50,9 @@ public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { Session session; String datasourceName = StringCaster.attempt( arguments.get( ORMKeys.datasource ) ).getOrDefault( "" ); if ( !datasourceName.isBlank() ) { - session = ORMService.getInstance().getORMApp( context ).getSession( context, Key.of( datasourceName ) ); + session = this.ormService.getORMApp( context ).getSession( context, Key.of( datasourceName ) ); } else { - session = ORMService.getInstance().getORMApp( context ).getSession( context ); + session = this.ormService.getORMApp( context ).getSession( context ); } session.clear(); diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMCloseAllSessions.java b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMCloseAllSessions.java index ac822c3..7f0036e 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMCloseAllSessions.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMCloseAllSessions.java @@ -2,6 +2,9 @@ import org.apache.commons.lang3.NotImplementedException; +import ortus.boxlang.modules.orm.ORMService; +import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -10,6 +13,11 @@ @BoxBIF public class ORMCloseAllSessions extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * ExampleBIF * @@ -18,6 +26,7 @@ public class ORMCloseAllSessions extends BIF { */ public String _invoke( IBoxContext context, ArgumentsScope arguments ) { // TODO implement BIF + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); throw new NotImplementedException(); } diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMCloseSession.java b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMCloseSession.java index a04fb5b..b0b1210 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMCloseSession.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMCloseSession.java @@ -6,6 +6,7 @@ import ortus.boxlang.modules.orm.ORMService; import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -18,12 +19,19 @@ @BoxBIF public class ORMCloseSession extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * Constructor */ public ORMCloseSession() { + super(); - declaredArguments = new Argument[] { + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); + declaredArguments = new Argument[] { new Argument( false, "String", ORMKeys.datasource, Set.of( Validator.NON_EMPTY ) ) }; } @@ -42,9 +50,9 @@ public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { Session session; String datasourceName = StringCaster.attempt( arguments.get( ORMKeys.datasource ) ).getOrDefault( "" ); if ( !datasourceName.isBlank() ) { - session = ORMService.getInstance().getORMApp( context ).getSession( context, Key.of( datasourceName ) ); + session = this.ormService.getORMApp( context ).getSession( context, Key.of( datasourceName ) ); } else { - session = ORMService.getInstance().getORMApp( context ).getSession( context ); + session = this.ormService.getORMApp( context ).getSession( context ); } session.close(); diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMEvictCollection.java b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMEvictCollection.java index d414c61..9258cf2 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMEvictCollection.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMEvictCollection.java @@ -2,6 +2,9 @@ import org.apache.commons.lang3.NotImplementedException; +import ortus.boxlang.modules.orm.ORMService; +import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -10,6 +13,11 @@ @BoxBIF public class ORMEvictCollection extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * ExampleBIF * @@ -18,6 +26,7 @@ public class ORMEvictCollection extends BIF { */ public String _invoke( IBoxContext context, ArgumentsScope arguments ) { // TODO implement BIF + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); throw new NotImplementedException(); } diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMEvictEntity.java b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMEvictEntity.java index 7109529..ee6a2d6 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMEvictEntity.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMEvictEntity.java @@ -2,6 +2,9 @@ import org.apache.commons.lang3.NotImplementedException; +import ortus.boxlang.modules.orm.ORMService; +import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -10,6 +13,11 @@ @BoxBIF public class ORMEvictEntity extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * ExampleBIF * @@ -18,6 +26,7 @@ public class ORMEvictEntity extends BIF { */ public String _invoke( IBoxContext context, ArgumentsScope arguments ) { // TODO implement BIF + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); throw new NotImplementedException(); } diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMExecuteQuery.java b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMExecuteQuery.java index ff24a22..4fad651 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMExecuteQuery.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMExecuteQuery.java @@ -2,6 +2,9 @@ import org.apache.commons.lang3.NotImplementedException; +import ortus.boxlang.modules.orm.ORMService; +import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -10,6 +13,11 @@ @BoxBIF public class ORMExecuteQuery extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * ExampleBIF * @@ -18,6 +26,7 @@ public class ORMExecuteQuery extends BIF { */ public String _invoke( IBoxContext context, ArgumentsScope arguments ) { // TODO implement BIF + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); throw new NotImplementedException(); } diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMFlush.java b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMFlush.java index 3edfd1b..8ed9ecd 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMFlush.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMFlush.java @@ -1,9 +1,12 @@ package ortus.boxlang.modules.orm.bifs; import org.hibernate.Session; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import ortus.boxlang.modules.orm.ORMService; import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -13,12 +16,21 @@ @BoxBIF public class ORMFlush extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + + private static final Logger logger = LoggerFactory.getLogger( ORMFlush.class ); + /** * Constructor */ public ORMFlush() { + super(); - declaredArguments = new Argument[] { + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); + declaredArguments = new Argument[] { new Argument( false, "String", ORMKeys.datasource ) }; } @@ -32,7 +44,8 @@ public ORMFlush() { * @param arguments Argument scope for the BIF. */ public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { - Session session = ORMService.getInstance().getORMApp( context ).getSession( context ); + Session session = this.ormService.getORMApp( context ).getSession( context ); + logger.debug( "Flushing session: {}", session ); session.flush(); return null; diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMFlushAll.java b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMFlushAll.java index f906ae0..06d272a 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMFlushAll.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMFlushAll.java @@ -2,6 +2,9 @@ import org.apache.commons.lang3.NotImplementedException; +import ortus.boxlang.modules.orm.ORMService; +import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -10,6 +13,11 @@ @BoxBIF public class ORMFlushAll extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * ExampleBIF * @@ -18,6 +26,7 @@ public class ORMFlushAll extends BIF { */ public String _invoke( IBoxContext context, ArgumentsScope arguments ) { // TODO implement BIF + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); throw new NotImplementedException(); } diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMGetSession.java b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMGetSession.java index d8a5798..c10f087 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMGetSession.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMGetSession.java @@ -6,6 +6,7 @@ import ortus.boxlang.modules.orm.ORMService; import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -18,12 +19,18 @@ @BoxBIF public class ORMGetSession extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * Constructor */ public ORMGetSession() { super(); - declaredArguments = new Argument[] { + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); + declaredArguments = new Argument[] { new Argument( false, "String", ORMKeys.datasource, Set.of( Validator.NON_EMPTY ) ) }; } @@ -39,9 +46,9 @@ public ORMGetSession() { public Session _invoke( IBoxContext context, ArgumentsScope arguments ) { String datasourceName = StringCaster.attempt( arguments.get( ORMKeys.datasource ) ).getOrDefault( "" ); if ( !datasourceName.isBlank() ) { - return ORMService.getInstance().getORMApp( context ).getSession( context, Key.of( datasourceName ) ); + return this.ormService.getORMApp( context ).getSession( context, Key.of( datasourceName ) ); } - return ORMService.getInstance().getORMApp( context ).getSession( context ); + return this.ormService.getORMApp( context ).getSession( context ); } } diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMGetSessionFactory.java b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMGetSessionFactory.java index c7b40a0..3c849c0 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMGetSessionFactory.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMGetSessionFactory.java @@ -6,6 +6,7 @@ import ortus.boxlang.modules.orm.ORMService; import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -18,12 +19,19 @@ @BoxBIF public class ORMGetSessionFactory extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * Constructor */ public ORMGetSessionFactory() { + super(); - declaredArguments = new Argument[] { + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); + declaredArguments = new Argument[] { new Argument( false, "String", ORMKeys.datasource, Set.of( Validator.NON_EMPTY ) ) }; } @@ -39,9 +47,9 @@ public ORMGetSessionFactory() { public SessionFactory _invoke( IBoxContext context, ArgumentsScope arguments ) { String datasourceName = StringCaster.attempt( arguments.get( ORMKeys.datasource ) ).getOrDefault( "" ); if ( !datasourceName.isBlank() ) { - return ORMService.getInstance().getORMApp( context ).getSessionFactoryOrThrow( Key.of( datasourceName ) ); + return this.ormService.getORMApp( context ).getSessionFactoryOrThrow( Key.of( datasourceName ) ); } - return ORMService.getInstance().getORMApp( context ).getDefaultSessionFactoryOrThrow(); + return this.ormService.getORMApp( context ).getDefaultSessionFactoryOrThrow(); } } diff --git a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMReload.java b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMReload.java index b7a984a..1ee73e3 100644 --- a/src/main/java/ortus/boxlang/modules/orm/bifs/ORMReload.java +++ b/src/main/java/ortus/boxlang/modules/orm/bifs/ORMReload.java @@ -2,6 +2,9 @@ import org.apache.commons.lang3.NotImplementedException; +import ortus.boxlang.modules.orm.ORMService; +import ortus.boxlang.modules.orm.config.ORMKeys; +import ortus.boxlang.runtime.BoxRuntime; import ortus.boxlang.runtime.bifs.BIF; import ortus.boxlang.runtime.bifs.BoxBIF; import ortus.boxlang.runtime.context.IBoxContext; @@ -10,6 +13,11 @@ @BoxBIF public class ORMReload extends BIF { + /** + * ORM Service, responsible for managing ORM applications. + */ + private ORMService ormService; + /** * ExampleBIF * @@ -18,6 +26,7 @@ public class ORMReload extends BIF { */ public String _invoke( IBoxContext context, ArgumentsScope arguments ) { // TODO implement BIF + this.ormService = ( ORMService ) BoxRuntime.getInstance().getGlobalService( ORMKeys.ORMService ); throw new NotImplementedException(); }