Persistence – Iteration 4 Vancouver Bootcamp

Slides:



Advertisements
Similar presentations
Introduction to NHibernate By Andrew Smith. The Basics Object Relation Mapper Maps POCOs to database tables Based on Java Hibernate. V stable Generates.
Advertisements

Connecting to Databases. relational databases tables and relations accessed using SQL database -specific functionality –transaction processing commit.
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai Tool Naming Tips Aaron Zeckoski
Apache Struts Technology
Rapid Persistence Layer Development with Hibernate Rapid Persistence Layer Development with Hibernate Tyler Mendenhall E-gineering,
Spring, Hibernate and Web Services 13 th September 2014.
.NET Database Technologies: Open-Source Frameworks.
Web Applications Development Using Coldbox Platform Eddie Johnston.
Hibernate 1. Introduction ORM goal: Take advantage of the things SQL databases do well, without leaving the Java language of objects and classes. ORM.
Performed by:Gidi Getter Svetlana Klinovsky Supervised by:Viktor Kulikov 08/03/2009.
Session-02.
Session-01. Hibernate Framework ? Why we use Hibernate ?
Discover, Master, InfluenceSlide 1 SQL Server Compact Edition and the Entity Framework Rob Sanders Readify.
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Configuring Sakai from Outside the Web Application Tony Atkins.
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai Montreal CRIM Workshop Data Persistence and Intro to Hibernate.
Task Manager Software Engineering: CS 673 Spring 2009 John Spencer, Parag Shah, Rich Moffitt, Hassan Sobhie May 4, 2009.
Hibernatification! Roadmap for Migrating from Plain Old SQL on JDBC to JPA on Hibernate Duke Banerjee Senior Developer, DrillingInfo.com.
Creative Commons Attribution- ShareAlike 2.5 License Sakai Programmer's Café Sakai Oxford Tetra ELF Workshop Sakai Persistence and Intro to Hibernate Aaron.
Oracle9 i JDeveloper for Database Developers and DBAs Brian Fry Principal Product Manager Oracle JDeveloper Oracle Corporation.
DATABASE PROGRAMMING Lecture on 16 – 05 – PREVIOUS LECTURE QUIZ: - Some students were very creative in transforming 2NF to 3NF. Excellent! - Some.
CHAPTER 14 USING RELATIONAL DATABASES TO PROVIDE OBJECT PERSISTENCE (ONLINE) © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database.
JBoss at Work JAW Motors Application Chapter 1-3 Jeff Schmitt October 9, 2006.
Seminar on. Overview Hibernate. What is it? Hibernate. How does it work? Hibernate Tools.
Designing and Developing WS B. Ramamurthy. Plans We will examine the resources available for development of JAX-WS based web services. We need an IDE,
Lecturer: Prof. Piero Fraternali, Teaching Assistant: Alessandro Bozzon, Advanced Web Technologies: Struts–
Spring Data Access By, Srinivas Reddy.S
Object Oriented Analysis and Design 1 Chapter 7 Database Design  UML Specification for Data Modeling  The Relational Data Model and Object Model  Persistence.
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai Persistence and Hibernate Aaron Zeckoski
Overview: 1. Discussion of the basic architecture of a web application. 2. Discussion of the relevance of using MySQL and PHP in a web application.
Spring Database Access Ojitha Kumanayaka Copyright © Virtusa, 2007.
Hibernate 3.0. What is Hibernate Hibernate is a free, open source Java package that makes it easy to work with relational databases. Hibernate makes it.
JPA / HIBERNATE CSCI 6370 Nilayan Bhattacharya Sanket Sable.
Creative Commons Attribution- NonCommercial-ShareAlike 2.5 License Sakai Programmer's Café Sakai development and app/tool tips Aaron Zeckoski
Persistence – Iteration 4 Vancouver Bootcamp Aaron Zeckoski
Fall CIS 764 Database Systems Engineering L18.2 : Object Relational Mapping … ….Object persistence.
Sakai WebApp Structure
Text 16 de mayo de 2009 Spring Framework Part III. Portable Service Abstractions Buenos Aires, June 2009.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool The problem fixed by ORM Advantage Hibernate Hibernate Basic –Hibernate sessionFactory –Hibernate Session.
Persistence – Iteration 4 Vancouver Bootcamp Aaron Zeckoski
Copyright 2007 SpringSource. Copying, publishing or distributing without express written permission is prohibited. Introduction to Data Access with Spring.
Text 16 de mayo de 2009 Spring Framework Part III. Portable Service Abstractions Buenos Aires, June 2009.
Topic : Hibernate 1 Kaster Nurmukan. An ORM tool Used in data layer of applications Implements JPA.
Introduction – ORM, Helloworld Application
Copyright 2007, Information Builders. Slide 1 iWay Web Services and WebFOCUS Consumption Michael Florkowski Information Builders.
Configuration & Management for Joachim Flammer Integration Team EGEE is a project funded by the European Union under contract IST JRA1 all-hands-meeting,
Introduction to ORM Hibernate Hibernate vs JDBC. May 12, 2011 INTRODUCTION TO ORM ORM is a programming technique for converting data between relational.
CS422 Principles of Database Systems Object-Relational Mapping (ORM) Chengyu Sun California State University, Los Angeles.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
Hibernate Java Persistence API. What is Persistence Persistence: The continued or prolonged existence of something. Most Applications Achieve Persistence.
Fall CIS 764 Database Systems Engineering L11: Object Relational Mapping … (a) ORM, Object persistence (b) Pets sequence.
HIBERNATE/Java Overview of technology for Hibernate by محمد حسن کاظمی پوران Master : M.M.Nematollahi.
The Holmes Platform and Applications
Running a Forms Developer Application
A very brief introduction
Spark Presentation.
Sakai Persistence and Intro to Hibernate
Entity Framework By: Casey Griffin.
Multitier Architecture, MySQL & PHP
COSC-4840 Software Engineering
Aaron Zeckoski Sakai Tool Naming Tips Aaron Zeckoski
Sakai WebApp Structure
Auditing in SQL Server 2008 DBA-364-M
Configuring Sakai from Outside the Web Application
Hibernate Bayu Priyambadha, S.Kom.
asset: Academic Survey System & Evaluation Tool
Using JDeveloper.
Developing and testing enterprise Java applications
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Enterprise Java Beans.
Oracle SQL Developer Data Modeler
Presentation transcript:

Persistence – Iteration 4 Vancouver Bootcamp Aaron Zeckoski aaronz@vt.edu

What is persistence? Taking temporary data (like in-memory program data) and storing it in a more permanent form Putting program data somewhere so you can retrieve it later (e.g. after a restart) Writing the information in your Java objects somewhere so you can get to it again after they are destroyed

How do we persist data in Sakai? Pretty much always use the database Some file system storage for tools like resources so data is accessible via WebDav You should probably use the database

# DATABASE CONFIGURATION Databases and Sakai Settings to control the database that is used are stored in sakai.properties The sakai.properties file is located in your sakai home (this is configurable but is normally your tomcat home) in the sakai directory Look for the following line in the file # DATABASE CONFIGURATION

Some DB config tips Always leave auto.dll=true HSQLDB is turned on by default, it only stores data in memory by default HSQLDB works well for development and for demos You cannot look at the HSQLDB database without some serious trickery

More DB config tips MySQL is easy to setup and use and runs pretty efficiently Allows you to look at the database to see if things are working Seems to have trouble working with Sakai in Windows sometimes If all else fails, switch to HSQLDB file storage

HSQLDB file storage To use HSQLDB in file mode (where it stores data on the filesystem), comment out this line: url@javax.sql.BaseDataSource=jdbc:hsqldb:. and uncomment this one url@javax.sql.BaseDataSource= jdbc:hsqldb:${sakai.home}/db/sakai.db

MySQL config To use MySQL, uncomment the six lines under this line: ## MySQL settings Comment out the 7 lines under this one: ## HSQLDB settings Update the username and password lines

One last DB tip You can turn on verbose Hibernate logging in the sakai.properties file Change the following from false to true # enable hibernate SQL debugging output hibernate.show_sql=false

3 ways to persist data to the DB JDBC http://java.sun.com/products/jdbc/ Spring JDBC http://www.springframework.org/docs/reference/jdbc.html Hibernate http://www.hibernate.org/

JDBC Info Java Database Connectivity Industry standard but has some issues: The developer needs to deal with lot of plumbing and infrastructure, such as endless try-catch-finally-try-catch blocks. Applications need complex error handling to ensure that connections are properly closed after they're used, which makes the code verbose, bloated, and repetitive. JDBC uses the rather uninformative SQLException. JDBC has no exception hierarchy From: http://java.sun.com/products/jdbc/

Spring JDBC Info Abstraction framework for JDBC i.e. It does lots of stuff for you! Some features of Spring JDBC JdbcDaoSupport – super class, provides JdbcTemplate access Spring provides an abstract exception layer, moving verbose and error-prone exception handling out of application code into the framework. The framework takes care of all exception handling; application code can concentrate on extracting results by using appropriate SQL. Spring provides a significant exception hierarchy for your application code to work with in place of SQLException. For creating instances of oracle.sql.BLOB (binary large object) and oracle.sql.CLOB(character large object), Spring provides the class org.springframework.jdbc.support.lob.OracleLobHandler. From: http://www.springframework.org/docs/reference/jdbc.html

Hibernate Info Object / Relational mapping (ORM) and persistence / query framework i.e. It does even more stuff for you! Some features of Hibernate HibernateDaoSupport – super class, easy HibernateTemplate access Database independence - sits between the database and your java code, easy database switch without changing any code Object / Relational Mapping (ORM) - Allows a developer to treat a database like a collection of Java objects Object oriented query language (HQL) - Fully supports polymorphic queries, native SQL, and Criteria queries Hibernate Mapping - Uses HBM XML files to map value objects (POJOs) to database tables Transparent persistence - Allows easy saves/delete/retrieve for simple value objects High performance because it is such a lightweight framework From: http://www.hibernate.org/

More Hibernate Info Hibernate basically sits between the DB and your code Can map persistent objects to tables In Sakai, the Hibernate configuration is set for you already From: http://www.hibernate.org/hib_docs/v3/reference/en/html/architecture.html

Even more Hibernate Info Hibernate 2-tier web architecture Can send data to JDBC or XML files Best to just use it the way Sakai does (JDBC) From: http://www.hibernate.org/354.html

Hibernate Development 4 methods of development using Hibernate Top down (good for existing code, we will use it for this exercise) implement a Java (JavaBeans) object model write a mapping document by hand, or generate it from XDoclet tags export the database tables using the hbm2ddl (SchemaExport) tool Bottom up (good for existing database or code conversion) start with an existing data model use the Hibernate Tools to generate the mapping documents use the hbm2java (CodeGenerator) tool to generate skeletal Java code fill in the business logic by hand Middle out (good for new development) express your conceptual object model directly as a mapping document use the hbm2java tool to generate skeletal Java code export the database tables using the hbm2ddl tool Meet in the middle (good for existing JDBC to Hibernate switch) start with an existing data model and existing Java classes write a mapping document to adapt between the two models From: http://www.hibernate.org/355.html

Hibernate Tools Hibernate provides a set of Eclipse tools http://www.hibernate.org/255.html Mapping Editor: An editor for Hibernate XML mapping files, supporting auto-completion and syntax highlighting Console: a view in Eclipse. Provides a tree overview of console configurations and interactive view of persistent classes and relationships. Also allows the execution of HQL queries against your database and browsing of results in Eclipse. Development Wizards: Includes the Hibernate configuration (cfg.xml) files wizard and reverse engineering wizard for turning an existing database schema into POJO source files and HBM files. We will work without the tools for this exercise From: http://www.hibernate.org/255.html

Other Hibernate Tools Hibernate Synchronizer http://hibernatesynch.sourceforge.net/ Actively developed plugin for Eclipse Works with Hibernate 3 (so does Sakai 2.2!) Can generate value objects, subclasses, components, and DAOs from HBM files Works well for new large scale code projects Use Hibernate Tools for smaller projects From: http://hibernatesynch.sourceforge.net/

Hibernate in Sakai 3 ways of using Hibernate in Sakai Create a SessionFactory using settings inside your tool Create a session factory from the global Sakai sessionFactoryBase Add our HBMs to the global Sakai sessionFactory From: http://bugs.sakaiproject.org/confluence/display/BOOT/Hibernate+in+Sakai

Method 1 Create a Hibernate SessionFactory using config settings in your tool You should use this when connecting to an external database Don’t use this method to connect to the internal Sakai database! More info on session configuration: http://www.hibernate.org/hib_docs/reference/en/html/session-configuration.html

Method 2 Create a session factory from the global Sakai SessionFactoryBase We will use this method for the workshop and the Task List Tool Exercise This method works well for simple tools More complex tools should use method 3 Making a connection this way does not always work on Windows with MySQL From: http://bugs.sakaiproject.org/confluence/display/BOOT/Creating+sessions+from+the+Sakai+SessionFactoryBase

Method 3 Add our HBMs to the global Sakai sessionFactory This is the preferred method Works best for more complex applications Requires the tool to deploy portions to shared and components so cannot be used for simple tools Demonstrated in tasklist-complex From: http://bugs.sakaiproject.org/confluence/display/BOOT/Using+the+Sakai+global+sessionFactory

Let’s write some code! Should have iteration3 code complete If not, check out the iteration3 code: https://source.sakaiproject.org/contrib/programmerscafe/tags/sakai-2.2/tasklist-iteration3-CSS/