AD 112: Real World Experience: Integrating DB2 with XPages Steve Zavocki Navy Federal Credit Union Consultant Dwain Wuerfel Navy Federal Credit Union Real World Experience: Integrating DB2 with XPages About Steve Notes Developer since 1996 Exclusively XPages since 2012 Fluent in Java, and use it whenever possible Have been a consultant with Navy Federal since April 2014 working out of Milton, Florida Real World Experience: Integrating DB2 with XPages About Dwain Notes Developer since 1997 XPages since 2011 Have been an employee with Navy Federal since July 2014 working out of Milton, Florida Real World Experience: Integrating DB2 with XPages About Navy Federal Credit Union The world’s largest credit union $69 billion in assets and over 5.5 million members Approximately 12,000 employees worldwide Member-owned and not-for-profit We offer credit cards, auto loans, mortgages, checking and savings, CDs, IRAs and our subsidiary Navy Federal Financial Group offers investments & insurance Navy Federal: Field of Membership •We serve all Department of Defense and Coast Guard active duty, civilian and contractor personnel and their families •We have 270 branches worldwide; online, mobile account access, and call center 24/7 FORTUNE's 100 Best Companies to Work For in 2015 Fifth time selected ComputerWorld’s 2015 Best Place to Work in IT Real World Experience: Integrating DB2 with XPages Agenda Why use DB2? Application Overview Application Design DB2 configuration Lessons Learned What your DBA wants you to know Real World Experience: Integrating DB2 with XPages Real World Experience: Integrating DB2 with XPages Why Use DB2? Performance Why is this important to NFCU? References Real World Experience: Integrating DB2 with XPages Why Use DB2? Performance DB2 z/OS, DB2 LUW, Oracle, SQL Server, Teradata, and Notes Navy Federal uses all these, but chose DB2 for XPages back-end Timestamp data type to the one millionth place Both Notes and Java only use one thousandth Notes/Java: 07:50:25.123000 DB2: 07:50:25.123456 Real World Experience: Integrating DB2 with XPages Why Use DB2? Performance cont’d… 10 or 10,000,000 rows irrelevant Don’t try this using a Notes database Physical storage is allocated for future growth This means you never encounter an out of space condition Moves large quantities of data and manages high volume of transaction Potential for large volumes of transactions DB2 has data sharing which is similar to replication/clustering Know that this exists, DBA should already be using this Real World Experience: Integrating DB2 with XPages Why Use DB2? Why is this important to Navy FCU you ask Navy FCU measures success as “No Perceived Downtime” XPages uses DB2 as a back-end due to the existing transactional member/customer facing applications Auditing Security Concerns Real World Experience: Integrating DB2 with XPages Why Use DB2? Comparison with Oracle http://www-01.ibm.com/software/info/rte/breakfree/tw.html More information about the benefits of DB2 http://www-01.ibm.com/software/data/db2/zos/family/ Real World Experience: Integrating DB2 with XPages Application Overview Real World Experience: Integrating DB2 with XPages Application Overview In a nutshell, the application manages ATM by providing a web browser frontend to a mainframe application This application replaces having a person use the green screen, and it eliminates tedious data entry into an MS Access database All actions that take place whether user initiated or scheduled are recorded in DB The data is then used for reporting and searching Real World Experience: Integrating DB2 with XPages Real World Experience: Integrating DB2 with XPages Application Overview Real World Experience: Integrating DB2 with XPages Application Design Real World Experience: Integrating DB2 with XPages Application Design Employ Best Practices learned by personal and collective experiences Minimize SSJS. Use Java for business logic whenever feasible Try to follow the MVC design pattern Considered using object relational mapping (i.e. Hibernate) Considered other developers who later will work on the application Real World Experience: Integrating DB2 with XPages Application Design View Layer – UI • XPages • Custom Controls via ??? Controller Layer – Business Logic • Managed Beans • POJOs • Jars (server JVM/LIB/EXT folder) via SQL Model Layer – Data • DB2 running on mainframe Real World Experience: Integrating DB2 with XPages Application Design How is the DB2 tied to the UI elements? viewScope is the glue that ties it all together. IMO it is easier to code than managed bean members/fields Load it when you need it, no values are remembered when you leave the page All purpose… Binds UI fields or grid data No need to initialize numeric data type, everything is treated like a String in a scoped variable Real World Experience: Integrating DB2 with XPages Demo Go to the blog by Steve Zavocki at http://notesspeak.blogspot.com/ Real World Experience: Integrating DB2 with XPages DB2 Configuration Real World Experience: Integrating DB2 with XPages DB2 Configuration Device Drivers Extension Library java.policy WinSQL Custom Connection Manager Real World Experience: Integrating DB2 with XPages DB2 Configuration Device Drivers It depends on your DB2 version which drivers you use. Your DBA or Middleware team will provide these for you We installed on the server in the jvm/lib/ext location. The choice was not ours to make (IBM does not recommend this approach but instead recommends installing as OSGI plugin) You do not need to install DB2 drivers locally, unless you are writing Java or LS agents that will access DB2, and you want to test them locally. If you do then they need to be in your local jvm/lib/ext Real World Experience: Integrating DB2 with XPages DB2 Configuration Extension Library The XPages Extension Library is of course required The version that is bundled with 9.0 is not enough We couldn’t get the database connection to work using a 9.0.1 at all until we installed at least the Dec 19, 2014 version from OpenNTF Real World Experience: Integrating DB2 with XPages DB2 Configuration java.policy You should be aware that this file exists on your domino server This file is used to control security permissions for specific actions and locations If you put your jars in the jvm/lib/ext directory then you will want to make sure your java.policy file grants full access: grant codeBase "file:${java.home}/lib/ext/*" { permission java.security.AllPermission; }; Real World Experience: Integrating DB2 with XPages DB2 Configuration WinSQL – You will certainly need a tool for easily testing your SQL. Our company has standardized on WinSQL for this task. This product is offered by Synametrics and info can be found at: http://web.synametrics.com/WinSQL.htm Cost is $99 for a developer license Comparable to Toad, SQL Developer (Oracle) Real World Experience: Integrating DB2 with XPages DB2 Configuration WinSQL Real World Experience: Integrating DB2 with XPages DB2 Configuration Custom Connection Manager NFCU has a policy that usernames and passwords are not to be kept in XML files We created a custom ConnectionManager class that allows us to look to a secure database for credentials and still allow the use of Connection Pooling More information on how to do this can be found on Steve’s blog at http://notesspeak.blogspot.com/ Real World Experience: Integrating DB2 with XPages Lessons Learned Real World Experience: Integrating DB2 with XPages Lessons Learned Know what you need from your DBA Take the time ahead of time to understand your application requirement Be sure that column widths and types are correct before coding Mimic what Notes databases give you by default by having system columns for Created Date, Last Updated, Author, Last Updated By Do not let DBA arbitrarily specify columns to be se to NOT NULL Ask your DBA to consider using a stored procedure or trigger to update intermediate tables for that are needed for many-to-many data relationships Real World Experience: Integrating DB2 with XPages Lessons Learned Know what you need from your DBA Ask your DBA to consider using a stored procedure or trigger to update intermediate tables for that are needed for many-to-many data relationships Real World Experience: Integrating DB2 with XPages Lessons Learned Use the PreparedStatement class The PreparedStatement is a class in the java.sql package that makes it easy to generate SQL statements This class protects against SQL Injection, use of this coding class is a company standard This class protects against bad data causing errors Real World Experience: Integrating DB2 with XPages Lessons Learned Yes this really happened String userCity = “D'Iberville”); int userTaxDue = 0; Date userTaxDue = taxDueDate; String userID = “12345”; String sqlUpdate = "UPDATE USER_DETAIL SET USER_CITY = ‘” + userCity + “’, USER_TAX_DUE_AMT = “ + userTaxDue + “, USER_TAX_DUE_DT = “ + userTaxDue + “ WHERE USER_ID = “ + userID; Real World Experience: Integrating DB2 with XPages Lessons Learned Using the PreparedStatement class String sqlUpdate = "UPDATE USER_DETAIL SET USER_CITY = ?, USER_TAX_DUE_AMT = ?, USER_TAX_DUE_DT = ? WHERE USER_ID = ?"; PreparedStatement ps = null; ps = conn.prepareStatement(sqlUpdate); ps.setString(1, “D'Iberville”); ps.setInt(2, 0); ps.setDate(3, new Date()); ps.setString(4, “12345”); ps.executeUpdate(); Real World Experience: Integrating DB2 with XPages Lessons Learned Bonus Lesson (if time allows, game time decision) This doesn’t have anything to do with DB2, but one major issues we had was sporadic 403 errors when we deployed from our UNIT to INTG environment. The issue turned out to be resources that the server was trying to load on the anonymous login page. This is the code from theme that was set to load on every page. <resource> <content-type>application/x-javascript</content-type> <href>js/jquery.datepick.min.js</href> <!-- http://keith-wood.name/datepick.HTML --> </resource> <resource> <content-type>application/x-javascript</content-type> <href>js/jquery.datepick.validation.js</href> <!-- http://keith-wood.name/datepick.HTML --> </resource> Real World Experience: Integrating DB2 with XPages Lessons Learned Resolution to the evil 403 problem (thanks @edm00se) Fix was to change the theme to skip loading the resources on the login page <resource rendered="#{javascript:view.getPageName() !== '/login.xsp'}"> <content-type>application/x-javascript</content-type> <href>js/jquery.datepick.min.js</href> <!-- http://keith-wood.name/datepick.HTML --> </resource> <resource rendered="#{javascript:view.getPageName() !== '/login.xsp'}“> <content-type>application/x-javascript</content-type> <href>js/jquery.datepick.validation.js</href> <!-- http://keith-wood.name/datepick.HTML --> </resource> Real World Experience: Integrating DB2 with XPages What your DBA wants you to know… Real World Experience: Integrating DB2 with XPages What your DBA wants you to know DB2 Explain (Optimizer) Understand requirements prior to approaching DBA You and you alone own your data Take time upfront to save time/frustration in the end Maintain data integrity Table structure and their relationship Real World Experience: Integrating DB2 with XPages What your DBA wants you to know DB2 Explain Shows the strength/weakness of your SQL Shows cost of running SQL Checks syntax Displays path taken to obtain data IBM Data Studio is the product used to display DB2 Explain results Real World Experience: Integrating DB2 with XPages What your DBA wants you to know DB2 Explain using IBM Data Studio Real World Experience: Integrating DB2 with XPages What your DBA wants you to know Understand requirements prior to approaching DBA All existing views shouldn’t become a table in DB2 Final decision out of your hands now that you have to deal with a DBA You and you alone own your data Don’t ask DBA for help with data issues until you check your code Decimal datatype allows for setting decimal places before and after (xxx.xxxxx) Real World Experience: Integrating DB2 with XPages What your DBA wants you to know Take time upfront to save time/frustration in the end You don’t have total control over design so take time to think about it Insert timestamp has always been available with DB2 Update timestamp is called a DB2 RowChangeTimestamp that was new in v9 Insert/Update timestamp have zero cost for including in tables Real World Experience: Integrating DB2 with XPages What your DBA wants you to know Maintain data integrity Ensure data elements for dates are a date/time not text Number data elements contain numbers not text DB2 won’t allow incorrect data DBA does build as many safeguards possible to prevent erroneous data Table structure and their relationship DBA’s have knowledge so utilize that and don’t be afraid of them Drop-downs will be made into a table to maintain data integrity Real World Experience: Integrating DB2 with XPages Blog: http://notesspeak.blogspot.com/ Email: zavocki@hotmail.com Twitter: @szavocki Questions??? Blog: www.xpagesnewbie.wordpress.org Email: dwainwuerfel@gmail.com Twitter: @dwainwuerfel