TWiki
>
WebXEO Web
>
XeoPrimer
>
XeoPrimerJavaAPI
>
XeoPrimerJavaAPISessionEboContext
(2012-01-16,
PedroRio
)
(raw view)
E
dit
A
ttach
Tags:
tag this topic
create new tag
,
view all tags
-- Main.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 ---+++ boSession The boSession instance | *Method Name* | *Description* | *Parameters* | *Return type* | *Notes* | | createRequestContext | Creates a new EboContext | HttpServletRequest request, HttpServletResponse response, PageContext pagecontext | EboContext | [[#safeContext][See note*]] | | createRequestContext | Creates a new EboContext | HttpServletRequest request, HttpServletResponse response, ServletContext servletContext | EboContext | [[#safeContext][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 | <p>String key<br />Object value</p> | 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. ---+++ EboContext<a name="eboCtx"></a> Every request made to a XEO Application to load/create <em>boObject </em>instances must be contained in a context. <em>EboContext </em>is the class that implements that "context" and is where instances of <em>boObjects </em>are stored wheneved they are created/loaded. _EboContext_ is also the place where transactional control can happen (there's another alternative in [[WebXEO.XeoPrimerJavaAPIboObject#lifeCycle][ _boObject_ (getUpdateQueue)]].Transactions created by using EboContext methods are JTA ( [[http://www.oracle.com/technetwork/java/javaee/tech/jta-138684.html][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 [[#jta][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<a name="safeContext"></a> <verbatim> 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(); }</verbatim> ---++++++ Using JTA Transactions Example <a name="jta"></a> ___ <pre> <verbatim>//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(); }</verbatim> </pre> ___ <div style="position: absolute; left: -10000px; top: 12px; width: 1px; height: 1px; overflow: hidden;" id="_mcePaste">getPerformerIProfileBoui</div>
E
dit
|
A
ttach
|
P
rint version
|
H
istory
: r6
<
r5
<
r4
<
r3
<
r2
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r6 - 2012-01-16
-
PedroRio
WebXEO
XEO Primer
-
Instalation
-
Introduction
-
Concepts
-
Architecture
-
XEO Library
-
Deploy to EAR
-
PreferenceStore
XEO - Core
-
XEO Model Reference
-
Security
-
Java API
-
BOL
-
XEOQL (BOQL)
-
Administrating
-
Background Tasks
-
boConfig.xml
-
Web.xml
-
Known Issues
-
XEO Flags
XEO - XWC
- Web Components
- Java Samples
- Custom Components
- Component Plugins
- Internationalization
- Viewer Events
- Value Change Listeners
- XUIServlet
- XeoLocalization
- XvwTemplates
Create New Topic
WebXEO Web
No permission to view
TWiki.WebTopBar
No permission to view
TWiki.WebBottomBar