Presentation is loading. Please wait.

Presentation is loading. Please wait.

TPTP Data Model 1 Database support for TPTP EMF based data models using Elver/Hibernate Guru Nagarajan July 14, 2006.

Similar presentations

Presentation on theme: "TPTP Data Model 1 Database support for TPTP EMF based data models using Elver/Hibernate Guru Nagarajan July 14, 2006."— Presentation transcript:

1 TPTP Data Model 1 Database support for TPTP EMF based data models using Elver/Hibernate Guru Nagarajan July 14, 2006

2 TPTP Data Model 2 Outline What is Hibernate? Overview of the Elver-Hibernate architecture Source Sample Current TPTP database support Questions

3 TPTP Data Model 3 What is the Problem statement? EMF objects can be persisted in relational databases and retrieved. The persistence and retrieval should support Most used Relational Databases Support the retrieval of the EMF objects using the EMF Resource approach Capitalize on the query and caching capabilities of Relational Databases and use them in building the required EMF Objects

4 TPTP Data Model 4 Challenges of Persistence In-Memory data and Persistence must be kept in sync The Object Model requirements could change and the persistence data store definition must be modified Portability of the persistence is an item not to be ignored Object-Relation Mapping to be seamless Solution: Application should not need to know that its data is being persisted

5 TPTP Data Model 5 What is Hibernate? Basically, a Object-Relational Mapping tool Maps Objects -> Relational Databases Implements those Mappings Knows about the underlying Database and provides an elegant abstraction How does Hibernate work? At runtime, Hibernate reads the mapping and dynamically builds Java classes that manages database-object interaction. Provides an API to manage, query the objects from the database, and create objects Your App Hibernate Mapping Object Database

6 TPTP Data Model 6 What is Elver? EMF Model Hibernate Mapping Object Database Elver basically adds the EMF support to Hibernate OR It consists of primarily two components Mapping Tier Support for EMF annotations Runtime Tier Query, Save, Create objects using EMF EMF Datastore

7 TPTP Data Model 7 Elver Runtime Arch.

8 TPTP Data Model 8 Elver Code Sample // Create the DataStore. final String dataStoreName = YourModelDataStore"; final HbDataStore dataStore = HbHelper.INSTANCE.createRegisterDataStore(dataStoreName); // Configure the EPackages used by this DataStore. dataStore.setEPackages(new EPackage[] { EMFPackagePackage.eINSTANCE }); // Initialize the DataStore. This sets up the Hibernate mapping and creates the corresponding tables in the database. dataStore.initialize(); //start a transaction final SessionFactory sessionFactory = dataStore.getSessionFactory(); // Open a new Session and start Transaction. Session session = sessionFactory.openSession(); session.beginTransaction(); Create and populate Model Model model = ModelFactory.eINSTANCE.createModel(); //Set Model Properties // Make it persistent.; Commit Transaction and close Session session.getTransaction().commit(); session.close();

9 TPTP Data Model 9 Sample – Creating SQL & HQL Queries, Resource SQL Query query = session.createQuery("SELECT count(allbooks) FROM Model model WHERE >= >"); Hibernate Query (HQL) Query query = session.createQuery("FROM Model.member"); List modelmember = query.list(); Creating and Loading Resource String uriStr = "hibernate://?" + YourSessionFactory"; final URI uri = URI.createURI(uriStr); ResourceSet resourceSet = new ResourceSetImpl(); final Resource res = resourceSet.createResource(uri); //Load the resource res.load(Collections.EMPTY_MAP); Iterator it = res.getContents().iterator(); //Iterate through the iyterator to get your model objects

10 TPTP Data Model 10 TPTP Database Support - Overview TPTP database interface is very similar to Hibernate Database Interface TypeMap Paging … Query Builder Object Query – Subset of HQL (Hibernate Query) Reference Query – EMF Query Support for Log database schema For other models you have to extend, provide the schema

11 TPTP Data Model 11 Why Elver? Multi-Database support MySql, Oracle, DB2, Access etc. Database specific SQL (SQL Diaelect) supported Exposes the Database performance via SQL queries (Hibernate ftr) Automatic Schema Generation Provide a EMF model, set its characteristics and Elver/Hibernate creates the mapping, schema for runtime Not Model Specific Exception Handling & Logging Very good exception handling Log4J Logging Annotations Support Preserve the Annotations in the Database Database Transaction support

12 TPTP Data Model 12 Q & A

13 TPTP Data Model 13 Useful Links Elver Page: Hibernate: License: Elver: Apache 2.0 Hibernate: LGPL

Download ppt "TPTP Data Model 1 Database support for TPTP EMF based data models using Elver/Hibernate Guru Nagarajan July 14, 2006."

Similar presentations

Ads by Google