Presentation is loading. Please wait.

Presentation is loading. Please wait.

Persistence – Iteration 4 Vancouver Bootcamp Aaron Zeckoski

Similar presentations


Presentation on theme: "Persistence – Iteration 4 Vancouver Bootcamp Aaron Zeckoski"— Presentation transcript:

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

2 2 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

3 3 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

4 4 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

5 5 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

6 6 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

7 7 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

8 8 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

9 9 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

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

11 11 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

12 12 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.

13 13 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

14 14 More Hibernate Info


Download ppt "Persistence – Iteration 4 Vancouver Bootcamp Aaron Zeckoski"

Similar presentations


Ads by Google