create new tag
, view all tags
-- PedroRio - 30 Dec 2010

boSession & EboContext

Each time a user logs to a XEO application a boSession instance is created to represent the session of the user whithin the application


The boSession instance

Method Name Description Parameters Return type Notes
createRequestContext Creates a new EboContext HttpServletRequest request, HttpServletResponse response, PageContext pagecontext EboContext See note*
createRequestContext Creates a new EboContext HttpServletRequest request, HttpServletResponse response, ServletContext servletContext EboContext See note*
getPerformerBoui Returns the boui of XEO Model instance representing the user who created the session (tipically it's an instance of a XEO Model which extends the system XEO Model Ebo_Perf or the system XEO Model Interface iXEOUser) - long  
getPerformerIProfileName Retrieves the name of the current profile associated to the user who created the session - String  
getPerformerIProfileBoui Retrieves the boui of the current profile instance associated to the user who created the session - long  
closeSession Closes the current session (does not destroy contexts created whithin the session) - void  
setProperty Sets a propery withthin the session

String key
Object value

void Property can later be retrieved with getProperty(String key)
getProperty Retrieves an existing property (or null if it does not exits) String key Object  
removeProperty Removes an existing property identified by the key parameter String key void  
getProperties Retrieves an enumeration of all properties of this session - Enumeration  

When using XEO's Web Component Layer, the login is made through a web form which will automatically create a boSession instance for the user (and EboContext instances as well), so there's usually no need to explicitely create boSession instances, unless you're creating a custom JSP/Servlet and need to programatically connect to the XEO Application.


Every request made to a XEO Application to load/create boObject instances must be contained in a context. EboContext is the class that implements that "context" and is where instances of boObjects are stored wheneved they are created/loaded. EboContext is also the place where transactional control can happen (there's another alternative in boObject (getUpdateQueue).Transactions created by using EboContext methods are JTA ( Java Transactional API) transactions which means you can mix DML statements with your object creation and update inside a transaction and commit on success/rollback on failure, see an example bellow.

EboContext instances are generally created by the XEO Runtime and can be accessed from several places, such as from any instance of a boObject throught the getEboContext() method. If you recall from the methods generated by XEO Studio for the required/defaultValue and such methods, one of the parameters was the boObject instance. Bellow, see the table of important methods in the EboContext class.

Method Name Description Parameters Return type Notes
beginContainterTransaction Initiates a JTA Transaction, this is the prefered method if you want to mix database DML statements with Object updates - void  
commitContainerTransaction Commits a previously created JTA transaction (initiated with beginContainerTransaction) - void  
rollbackContainerTransaction Rollback of a previously created JTA transaction (initiated with beginContainerTransaction) - void  
close Closes the current context - void It's very important to close an open context whenever you don't need one as each context has an open data conection associated.
getConnection Retrieves a JDBC database connection (allows to make queries to the database) - java.sql.Connection  
setModeBatch Sets the context to operate in batch mode (turns events and validations off) - void Can be usefull to process large batches of instances, since it disables events and validations
setModeBatch Sets the context to operate in batch mode, acceppts a parameter to indicate the type of batch being used (validate objects, execute certain events, etc...) int mode void See above


Safe Ebo Context Usage Example
        boSession session = null;
        EboContext context = null;
        boApplication xeoApp = boApplication.getDefaultApplication();
        try {
                session = xeoApp.boLogin("USERNAME", "PASSWORD");        
                context = xeoApp.createContext(session);
                //Your code in here

        } catch (Exception e) {
                 //Process the exception in case of error
        } finally {
            if (context!=null)
            if (session!=null)
Using JTA Transactions Example


//Declare variables
        boApplication app = null;
        boSession session = null;
        EboContext ctx = null;
                //Get the application instance
                app = boApplication.getDefaultApplication();
                //Login a user
                session = app.boLogin("SYSUSER", "ABC");
                //Create a context
                ctx = app.createContext(session);
                //Start Transaction 
                    //Create Object, set an attribute and save
                    boObject obj = app.getObjectManager().createObject(ctx, "MyObj");
                    //Make a DML statement to insert some values in database
                    Connection conn = null;
                    Statement stmt = null;
                    //Retrieve the connection and execute the query
                    conn = ctx.getConnectionData();
                    stmt = conn.createStatement(
                    stmt.executeQuery("INSERT INTO MY_TABLE VALUES('foo','bar')");
                    //Commit the changes
                catch (Exception e){
                    //If anything goes wrong roll back the transaction
        catch (boRuntimeException e ){
            //Deal with the exception during execution
        } catch (boLoginException e) {
            // Deal with login exception 
            //Close all used resources
            if (ctx != null) ctx.close();
            if (session != null) session.closeSession();


Topic revision: r6 - 2012-01-16 - PedroRio

No permission to view TWiki.WebTopBar

This site is powered by the TWiki collaboration platform Powered by Perl

No permission to view TWiki.WebBottomBar