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 |
---|---|---|---|---|
setProperty | Sets a propery withthin the session | String key |
void | Property can later be retrieved with getProperty(String key) |
removeProperty | Removes an existing property identified by the key parameter | String key | void | |
getProperty | Retrieves an existing property (or null if it does not exits) | String key | Object | |
getProperties | Retrieves an enumeration of all properties of this session | - | Enumeration | |
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 | |
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 | |
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* |
closeSession | Closes the current session (does not destroy contexts created whithin the session) | - | void |
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 |
_
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) context.close(); if (session!=null) session.closeSession(); }
_
//Declare variables boApplication app = null; boSession session = null; EboContext ctx = null; try{ //Get the application instance app = boApplication.getDefaultApplication(); //Login a user session = app.boLogin("SYSUSER", "ABC"); //Create a context ctx = app.createContext(session); //Start Transaction ctx.beginContainerTransaction(); try{ //Create Object, set an attribute and save boObject obj = app.getObjectManager().createObject(ctx, "MyObj"); obj.getAttribute("att").setValueString("foo"); obj.update(); //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( ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); stmt.executeQuery("INSERT INTO MY_TABLE VALUES('foo','bar')"); //Commit the changes ctx.commitContainerTransaction(); } catch (Exception e){ //If anything goes wrong roll back the transaction ctx.rollbackContainerTransaction(); } } catch (boRuntimeException e ){ //Deal with the exception during execution } catch (boLoginException e) { // Deal with login exception }finally{ //Close all used resources if (ctx != null) ctx.close(); if (session != null) session.closeSession(); }
_
No permission to view TWiki.WebTopBar