JSF DB Connection Best Practices

During the life of a JavaServer Faces request, what are some best practices for storing a db connection?
For the duration of the transaction, a single connection should be created before db updates, made available to (possibly) multiple model objects, and closed at the conclusion of the request. The connection would only live during the request.
Right now each model object gets and releases it's own dbCon but that doesn't satisfy the (logical unit of work) requirements of a transaction when multiple objects are required for updating the database.
What is a good technique to get a dbCon and release it, and, where should it be stored?
TIA,
Al Malin

Hi,
I'd like to ask a follow-up question.
How do I close the connection after the session timed out or the user leaves the application by closing the browser?
Thanks,
Achim

Similar Messages

  • External connectivity best practice

    Hi,
    I would like to know what are the best practices to have external users using Excel to connect to SSAS cube. I understand the general concept that a cube user must be in a domain AD andthat same user is a member of a SSAS cube.
    How can I ensure the excel connection is secure and each external user is only able to view their own data? I know the workbook can be password protected but can the connection be also password protected ?
    BTW, I am not sure if this is the right forum for this question
    Regards

    Most modern external drives will typically go into a standby mode shortly after they're unmounted or disconnected which will spin down the drive. They'll still use some power, but your drive won't be doing anything so you don't need to worry about wearing it out. I'm a bit anal about stuff. I usually go so far as to unplug my external drives when I'm not using them as the power supply still consumes some juice... but, in your case, as it seems like you probably go back and forth quite a bit... just powering it down would be the best thing. It really doesn't take any extra effort when connecting your MacBook Pro to just switch it back on again.

  • How to establish the connection - Best Practice

    Following is my code for database connection
    import java.sql.Connection;
    import java.sql.DriverManager;
    import oracle.jdbc.driver.OracleDriver;
    public class DBConnect
         private static Connection connection = null;
         static
              try
                   DriverManager.registerDriver( new OracleDriver() );
                   String url = "jdbc:oracle:thin:@dbserver:1521:ORCL";
                   connection = DriverManager.getConnection( url, "user", "password" );
              catch ( Exception e )
         private DBConnect()
         public static synchronized Connection getConnection()
              return connection;
    }Tell me the Best Practice to establish the connection.
    Edited by: shashiwagh on Feb 1, 2010 11:25 AM
    Edited by: shashiwagh on Feb 1, 2010 11:26 AM

    First, handle your exceptions properly.
    Second, you should not normally create static database connections.
    Third, hardcoding connection data like that is not a good idea.

  • Access Connections best practice

    I like the idea of having Lenovo Access Connection change the appropriate settings depending on you network location. Like turning off wifi when you are cabled.
    Althoguh I often find it to be creating more problems than gains.
    Any generel best practice using this tool?
    Regards, Lars.

    Hi!
    Use non overlapping channel 1-6-11 on 3
    consecutive AP's.
    eg.
    AP1-Channel 1
    AP2-Channel 6
    AP3-Channel 11
    AP4-Channel 1
    AP5-Channel 6
    plzz take a look:
    http://www.cisco.com/en/US/products/hw/wirele
    ss/ps441/products_tech_note09186a00800a86d7.shtml#nonover
    HTH
    -Jai

  • Physical Connection Best Practices

    Hi;
    I hope someone can help us.
    We already have 4 SG300 52 ports Switches: (L2 mode)
    We need to know the best way to connect the Switches and the router due to:
    - Do not get excesive latency in the internal network.
    - Do not get SPF problems.
    - Do not get duplicated pings
    - Get the maximum bandwith in the internal network.
    - Get the best router link.
    My thougts are:
    Option 1:
    Connect one uplink port to another uplink port at the next SW
    Connect the other uplink port (of all Switches) to the internal SW port on the router/Firewall. (4 integrated ports 10/100)
    Option 2
    Connect two uplink ports to the two uplink ports at the next SW
    Connect the number 1 port (of all Switches) to the internal SW port on the router/Firewall. (4 integrated ports 10/100)
    Option 3 
    Connect two uplink ports to the number 1 and 2 port at the next SW
    Connect the uplink port (of all Switches) to the internal SW port on the router/Firewall. (4 integrated ports 10/100)
    Any suggestions?
    Thanks.
    Regards.

    If you have a multi-threaded server then before long you will have two "simultaneous" requests for a database connection. These requests will want to use different connections, since as you can see if they both use it at the same time, bad things will happen. You could synchronize so they wait in line to use the single connection but I think you can see that doesn't scale well to higher load.
    So you need to have access to more than one connection. What's commonly done in multi-threaded servers is to use a connection pool. You can get open-source connection pools, so don't spend any time writing your own. (They aren't easy to get right.)

  • Managing connections best practices

    Hi,
    I have a web application that uses JDBC to retrieve information and display it. My question is: What is the best way to manage your connection objects? I know using a connection pool is probably best, but I'm curious to hear good alternatives? If I need a connection in several places in my web-app, then storing one Connection object in the session seems like a good idea. This way I don't have to create and close my connections each time and slow down performance. But what happens to the connection when the user is no longer in the session. Does the database close the connection implicitly and is there any cons to doing it this way?
    Thanks

    Hi,
    I have a web application that uses JDBC to retrieve
    information and display it. My question is: What is
    the best way to manage your connection objects? I know
    using a connection pool is probably best, but I'm
    curious to hear good alternatives? If I need a
    connection in several places in my web-app, then
    storing one Connection object in the session seems
    like a good idea. The term "session" usually refers to a 'space' that exists both on a client and a server.
    Connections never exist on more than one machine or even more than one application.
    This way I don't have to create and
    close my connections each time and slow down
    performance. But what happens to the connection when
    the user is no longer in the session. Does the
    database close the connection implicitly and is there
    any cons to doing it this way?
    Well one con is that in general you have no control over when the "session" is closed. Thus you must rely on finalize in a java class to close your connections via the GC. And unless you have a really unusual database, or you only use a couple of "sessions" an hour, you are going to run out of connections. This is because GC is optimized for memory handling and not any other resource (a connection is a resource.)

  • Closing DB Connection-Best Practice

    Currently I am opening and closing my connection to the database on each event that warrants a database connection. Is this the way I should handle it, or should I open the connection at the beginning and close it at the end, leaving it open in between?
    I have a certain panel that has numerous, separate inputs to a database that are isolated from each other, and if I happen to use all of these inputs, I open and close the connection 3 or 4 times.
    Thanks

    Hi,
    As far as an application is concerned we usually wont advice opening and closing connection as and when necessary. But if the connection is open for a long time there are some possible problems. One is that if the server goes down the user wont be aware of that till he executes the next query and also the error wont will be a valid one.Next is the amount of time ther server holds the connection and this has its significance if max. number of connections is specified.
    So again, its upto you to decide what all conditions are applicable to you. Its actually a trade-off between reliability and performance. :-)..
    regards Stallon

  • Sql connection best practices

    Can someone discuss the pros and cons of setting your db connection in the web.xml and then using the following in a jsp;
    <sql:query var="myQuery">
         SELECT * FROM mytable
    </sql:query>I find that it is quick and easy, but would I want to give this kind of code to my supervisor? From 20,000 ft up. :)
    Edited by: Reme on Aug 2, 2008 5:12 AM

    [http://java.sun.com/javaee/5/docs/tutorial/doc/bnald.html]
    The JSTL SQL tags for accessing databases listed in Table 7-7 are designed for quick prototyping and simple applications. For production applications, database operations are normally encapsulated in JavaBeans components.I wouldn't use it. Layer your application properly. Make use of a DAO class.

  • What is the best practice to connect 2 sites and replicate ADDS between 2 different sites using windows server 2012 r2?

    I found that there is new features remote access inside windows server 2012 r2 which is much more easier. Is there anybody can suggest me how to connect 2 different sites and it will be the tunnel to replicate ADDS (RW) between both sites.

    See this
    https://social.technet.microsoft.com/Forums/windowsserver/en-US/133e7780-6a59-4bd7-906b-70830bea48d0/sites-connections-best-practice?forum=winserverDS
    Regards,
    Biswajit
    MCTS, MCP 2003,MCSA 2003, MCSA:M 2003, CCNA, Enterprise Admin, ITIL F 2011
    Blog:
      Script Gallary:
      LinkedIn:
    Note: Disclaimer: This posting is provided & with no warranties or guarantees and confers no rights..

  • JSF CDI : Conversation scope bean[s] best practice

    *JSF CDI : Conversation scope bean[s] best practice*
    Hello, im currently learning about JSF 2.0 and im so glad for the existence of this conversation scope feature, which is very helpful in opening a new tab or a new window on the same page and having separate resources, not overriding one another.
    But im curious on how to implement this in a good way, about when to start the conversation and when to close it.
    In my case, i have each CDI bean for each JSF page. And let's say that i have a menu, and when it's clicked, this will lead to page A, and from A, could lead to B, B could lead to C, C could lead to D, all these 4 pages are connected in one chain.
    Accessing A's bean properties from B or C or D beans is possible, accessing B's properties is also possible from C or D beans and so forth.
    Now im quite confused about :
    * whether all these A B C D should be in conversation scope or not, or perhaps just A ? Because i think sometimes from another page that is outside the ABCD chain, like a page F, it could navigate to page B, although i dont know how to supply the data to the bean B yet.
    * whether all these A B C D should be combined into one bean
    * where and when to start the conversation, im thinking about the constructor, but i dont think it's a good idea, because i prefer starting the conversation when first accessing the page, not the bean
    * where and when to stop the conversation, so that there wont be unused resources hanging around
    Regards,
    Albert Kam

    There are also some commandButtons on the view page, which performs actions on Product object, fetched by passed ID.

  • Error while Connecting report Best Practices v1.31 with SAP

    Hello experts,
    I'm facing an issue while trying to connect some of my reports from Best Practices for BI with SAP.
    It only happens when it's about info sets, the other ones that are with SAP tables go smoothly without a problem.
    The most interesting is I have already one of the reports connected to SAP info sets.
    I have already verified the document of steps of creation of additional database that comes with BP pack. They seem ok.
    Here goes what Crystal Reports throws to me after changing the data source to SAP:
    For report "GL Statement" one of the Financial Analysis one which uses InfoSet: /KYK/IS_FIGL_I3:
    - Failed to retrieve data from the database; - click ok then...
    - Database connector error: It wasn't indicated any variant for exercise (something like this after translating) - click ok then
    - Database connector error: RFC_INVALID_HANDLE
    For report "Cost Analysis: Planned vs. Actual Order Costs" one of the Financial Analysis one which uses InfoSet: ZBPBI131_INFO_ODVR and ZBPBI131_INFO_COAS; and also the Query CO_OM_OP_20_Q1:
    - Failed to retrieve data from the database; - click ok then...
    - Database connector error: check class for selections raised errors - click ok then
    - Database connector error: RFC_INVALID_HANDLE
    Obs.: Those "Z" infosets are already created in SAP environment.
    The one that works fine is one of the Purchasing Analysis reports:
    - Purchasing Group Analysis -> InfoSet: /KYK/IS_MCE1
    I'm kind of lost to solve this, because I'm not sure if it can be in the SAP JCO or some parameter that was done wrongly in SAP and I have already check possible solutions for both.
    Thanks in advance,
    Carlos Henrique Matos da Silva - SAP BusinessObjects BI - Brazil.

    I re-checked step 3.2.3 - Uploading Crystal User Roles (transaction PFCG) - of the manual where it talks about CRYSTAL_ENTITLEMENT and CRYSTAL_DESIGNER roles, I noticed in the Authorizations tab that the status was saying it hadn't been generated and I had a yellow sign, so then that was what I did (I generated) as it says in the manual.
    Both statuses are now saying "Authorization profile is generated" and the sign is now green on the tab.
    I had another issue in the User tab (it was yellow as Authorizations one before generating)....all I needed to do to change to green was comparing user (User Comparison button).
    After all that, I tried once more to refresh the Crystal report and I still have the error messages being thrown.
    There's one more issue in one of the tabs of PFCG transaction, it is on the Menu one where it is with a red sign, but there's nothing talking about it in the manual. I just have a folder called "Role menu" without anything in it.
    Can it be the reason why I'm facing errors when connecting the report to SAP infoSets? (remember one of my reports which is connected to an infoSet works good)
    Thanks in advance,
    Carlos Henrique Matos da Silva - SAP BusinessObjects BI - Brazil.

  • BEST PRACTICES FOR CREATING DISCOVERER DATABASE CONNECTION -PUBLIC VS. PRIV

    I have enabled SSO for Discoverer. So when you browse to http://host:port/discoverer/viewer you get prompted for your SSO
    username/password. I have enabled users to create their own private
    connections. I log in as portal and created a private connection. I then from
    Oracle Portal create a portlet and add a discoverer worksheet using the private
    connection that I created as the portal user. This works fine...users access
    the portal they can see the worksheet. When they click the analyze link, the
    users are prompted to enter a password for the private connection. The
    following message is displayed:
    The item you are requesting requires you to enter a password. This could occur because this is a private connection or
    because the public connection password was invalid. Please enter the correct
    password now to continue.
    I originally created a public connection...and then follow the same steps from Oracle portal to create the portlet and display the
    worksheet. Worksheet is displayed properly from Portal, when users click the
    analyze link they are taken to Discoverer Viewer without having to enter a
    password. The problem with this is that when a user browses to
    http://host:port/discoverer/viewer they enter their SSO information and then
    any user with an SSO account can see the public connection...very insecure!
    When private connections are used, no connection information is displayed to
    SSO users when logging into Discoverer Viewer.
    For the very first step, when editing the Worksheet portlet from Portal, I enter the following for Database
    Connections:
    Publisher: I choose either the private or public connection that I created
    Users Logged In: Display same data to all users using connection (Publisher's Connection)
    Users Not Logged In: Do no display data
    My question is what are the best practices for creating Discoverer Database
    Connections.
    Is there a way to create a public connection, but not display it in at http://host:port/discoverer/viewer?
    Can I restrict access to http://host:port/discoverer/viewer to specific SSO users?
    So overall, I want roughly 40 users to have access to my Portal Page Group. I then want to
    display portlets with Discoverer worksheets. Certain worksheets I want to have
    the ability to display the analyze link. When the SSO user clicks on this they
    will be taken to Discoverer Viewer and prompted for no logon information. All
    SSO users will see the same data...there is no need to restrict access based on
    SSO username...1 database user will be set up in either the public or private
    connection.

    You can make it happen by creating a private connection for 40 users by capi script and when creating portlet select 2nd option in Users Logged in section. In this the portlet uses there own private connection every time user logs in.
    So that it won't ask for password.
    Another thing is there is an option of entering password or not in ASC in discoverer section, if your version 10.1.2.2. Let me know if you need more information
    thnaks
    kiran

  • What are the best practices to connect 30-40 iPads to Wi-Fi in a single room?

    What are the best practices to connect 30-40 iPads to Wi-Fi in a single room?

    I don't use it but it does say this in the help section...

  • JSF - Best Practice For Using Managed Bean

    I want to discuss what is the best practice for managed bean usage, especially using session scope or request scope to build database driven pages
    ---- Session Bean ----
    - In the book Core Java Server Faces, the author mentioned that most of the cases session bean should be used, unless the processing is passed on to other handler. Since JSF can store the state on client side, i think storing everything in session is not a big memory concern. (can some expert confirm this is true?) Session objects are easy to manage and states can be shared across the pages. It can make programming easy.
    In the case of a page binded to a resultset, the bean usually helds a java.util.List object for the result, which is intialized in the constructor by query the database first. However, this approach has a problem: when user navigates to other page and comes back, the data is not refreshed. You can of course solve the problem by issuing query everytime in your getXXX method. But you need to be very careful that you don't bind this XXX property too many times. In the case of querying in getXXX, setXXX is also tricky as you don't have a member to set. You usually don't want to persist the resultset changes in the setXXX as the changes may not be final, in stead, you want to handle in the actionlistener (like a save(actionevent)).
    I would glad to see your thought on this.
    --- Request Bean ---
    request bean is initialized everytime a reuqest is made. It sometimes drove me nuts because JSF seems not to be every consistent in updating model values. Suppose you have a page showing parent-children a list of records from database, and you also allow user to change directly on the children. if I hbind the parent to a bean called #{Parent} and you bind the children to ADF table (value="#{Parent.children}" var="rowValue". If I set Parent as a request scope, the setChildren method is never called when I submit the form. Not sure if this is just for ADF or it is JSF problem. But if you change the bean to session scope, everything works fine.
    I believe JSF doesn't update the bindings for all component attributes. It only update the input component value binding. Some one please verify this is true.
    In many cases, i found request bean is very hard to work with if there are lots of updates. (I have lots of trouble with update the binding value for rendered attributes).
    However, request bean is working fine for read only pages and simple binded forms. It definitely frees up memory quicker than session bean.
    ----- any comments or opinions are welcome!!! ------

    I think it should be either Option 2 or Option 3.
    Option 2 would be necessary if the bean data depends on some request parameters.
    (Example: Getting customer bean for a particular customer id)
    Otherwise Option 3 seems the reasonable approach.
    But, I am also pondering on this issue. The above are just my initial thoughts.

  • [XI 3.1] BEST PRACTICE method of Oracle connection for RPTs on Linux

    Business Objects XI (3.1) - SP3.
    Running on Red Hat Enterprise Linux OS.
    7,000+ Crystal Reports 2008 *.rpt objects ONLY (No Universe / No WebI).
    All reports connecting to Oracle 10g databases.
    ==================
    In the past, all of this infrastructure was running on Windows Server OS and providing the database access via a Named ODBC connection (eg. "APP_DATA".)
    This made it easy to manage as all the Report Developers had a standard System DSN called "APP_DATA" which was the same as the System DSN name on all of our DEV, TEST/UAT, and PROD servers for Business Objects.
    When we wanted to move/promote a *.rpt file from DEV to PROD we did not have to change any "Database Connection" info as it was all taken care of by pointing the System DSN called "APP_DATA" a a different physical Oracle server at the ODBC level.
    Now, that hardware is moving from Windows OS to Red Hat Linux and we are trying to determine the Best Practices (and Pros/Cons) of using one of the three methods below to access the Oracle database for our *.rpts....
    1.) Oracle Native connection
    2.) ODBC connection
    3.) JDBC connection
    Here's what we have determined so far -
    1a.) Oracle Native connection should be the most efficient method of passing SQL-query to the DB with the fewest issues and best speed [PRO]
    1b.) Oracle Native connection may not be supported on Linux - http://www.forumtopics.com/busobj/viewtopic.php?t=118770&view=previous&sid=9cca754b468fc67888ab2553c0fbe448 [CON]
    1c.) Using Oracle Native would require special-handling on the *.rpts at either the source-file or the CMC level to change them from DEV -> TEST -> PROD connection. This would result in a lot more Developer / Admin overhead than they are currently used to. [CON]
    2a.) A 3rd-Party Linux ODBC option may be available from EasySoft - http://www.easysoft.com/products/data_access/odbc_oracle_driver/index.html - which would allow us to use a similar Developer / Admin overhead to what we are used to. [PRO]
    2b.) Adding a 3rd-Party Vendor into the mix may lead to support issues is we have problems with results or speeds of our queries. [CON]
    3a.) JDBC appears to be the "defacto standard" when running Oracle SQL queries from Linux. [PRO]
    3b.) There may be issues with results or speeds of our queries when using JDBC. [CON]
    3c.) Using JDBC requires the explicit-IP of the Oracle server to be defined for each connection. This would require special-handling on the *.rpts at either the source-file (and NOT the CMC level) to change them from DEV -> TEST -> PROD connection. This would result in a lot more Developer / Admin overhead than they are currently used to. [CON]
    ==================
    We would appreciate some advice from anyone who has been down this road before.
    What were your Best Practices?
    What can you add to the Pros and Cons listed above?
    How do we find the "sweet spot" between quality/performance/speed of reports and easy-overhead for the Admins and Developers?
    As always, thanks in advance for your comments.

    Hi,
    I just saw this article and I would like to add some infos.
    First you can quite easely reproduce the same way of working with the odbc entries by playing with the oracle name resolution on the server. By changing some files (sqlnet, tnsnames.ora,..) you can define a different oracle server for a specific name that will be the same accross all environments.
    Database name will be resolved differently regarding to the environment and therefore will access a different database.
    Second option is the possibility to change the connection in .rpt files by an automated way like the schedule manager. This tool is a additional web application to deploy that can change the connection settings of rpt reports on thousands of reports in a few clicks. you can find it here :
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/80af7965-8bdf-2b10-fa94-bb21833f3db8
    The last option is to do it with a small sdk script, for this purpose, a few lines of codes can change all the reports in a row.
    After some implementations on linux to oracle database I would prefer also the native connection. ODBC and JDBC are deprecated ways to connect to database. You can use DATADIRECT connectors that are quite good but for volumes you will see the difference.

Maybe you are looking for