• Like
  • Save
Rollin onj Rubyv3
Upcoming SlideShare
Loading in...5
×
 

Rollin onj Rubyv3

on

  • 920 views


Using JPA vs. Activerecord for persistence in Jruby
Chris Bucchere and Pieter Humphrey from Openworld 2009.

Statistics

Views

Total Views
920
Views on SlideShare
919
Embed Views
1

Actions

Likes
0
Downloads
7
Comments
0

1 Embed 1

http://us-w1.rockmelt.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • The Java version is tightly integrated with Java to allow both to script any Java class and to embed the interpreter into any Java application.
  • Integration with Java libraries JRuby classes can extend Java classes implement a single Java interface add methods to existing Java classes (visible from JRuby, but not Java) Native threads JRuby uses native threads, Ruby uses green threads can result in different behaviors between JRuby and Ruby Portability JRuby runs on any machine with a JVM Unicode support JRuby uses the unicode support in Java Ruby has some support for unicode, but it’s not built-in
  • When you start JRuby  starting Java – based ruby interpreter on a JVM. C based or J based Ruby doesn’t care which one (due to how Jruby is implemeted) Rack provides a minimal, modular and adaptable interface for developing web applications in Ruby. By wrapping HTTP requests and responses in the simplest way possible, it unifies and distills the API for web servers, web frameworks, and software in between (the so-called middleware) into a single method call. • An abstract interface on top of HTTP allows for • code reuse • easier testing • new ways of combining code/applications
  • The general architecture for Ruby DBI uses two layers: The database interface (DBI) layer. This layer is database independent and provides a set of common access methods that are used the same way regardless of the type of database server with which you're communicating. The database driver (DBD) layer. This layer is database dependent; different drivers provide access to different database engines. There is one driver for MySQL, another for PostgreSQL, another for InterBase, another for Oracle, and so forth. Each driver interprets requests from the DBI layer and maps them onto requests appropriate for a given type of database server. ADO (ActiveX Data Objects) DB2 Frontbase mSQL MySQL ODBC Oracle OCI8 (Oracle) PostgreSQL Proxy/Server SQLite SQLRelay The database drivers are each hand crafted to access a specific database. They have different method names from each other, meaning that if you switch back end databases, you'll need to rewrite substantial portions of your program. The only reason to use the database specific drivers is to take advantage of database specific features, and possibly to make the program run a little faster and use a little less memory. With the database specific drivers, you manipulate the database by passing SQL statements as strings via the interface methods. Ruby-DBI is a wrapper around all the database drivers, giving you a united method set to do the majority of your database activities. The only remaining database dependencies are caused by the fact that the different databases support slightly different SQL syntaxes. With DBI, you manipulate the database by passing SQL statements as strings via the interface methods. Whereas the database drivers and DBI provide a simple vehicle to use an SQL statement, the ActiveRecord technique provides database access without the need for SQL statements. The ActiveRecord techniques match objects to database rows. The advantages are almost zero database dependencies within the subset of capabilities provided by ActiveRecord, and a set of defaults (such as automatic naming of tables based on class names) that make coding a database app much quicker and easier. If you know SQL, you can pretty much write an app using database drivers or DBI today. With ActiveRecord, you'll need to learn a new set of skills, complete with a set of methods specific to Ruby's ActiveRecord class. You wouldn't do this to create a one-off app, but if you are or plan to be a frequent Ruby programmer and you plan to frequently hit databases from your Ruby programs, learning ActiveRecord will benefit you greatly.  Ruby on Rails uses ActiveRecord for the vast majority of its database access, so if you use or plan to use Ruby on Rails, ActiveRecord is a must.
  • Database.yml – only config file.. Just fill in the value and go! Here you've only scratched the surface of Active Record. It's a powerful framework—much more powerful than other frameworks that implement the Active Record design pattern. It leverages the strengths of the Ruby framework—a simple syntax, metaprogramming, and the ability to open and manipulate classes at run time—to form a marvelously effective and productive environment for green-field development. But Active Record is not for every application. It does not handle legacy schemas nearly as well. For those, you need a mapping framework, not one that merely wraps tables with simple classes. Active Record also is prone to performance problems for those who don't have the discipline or skill to tune it properly. Active Record, and the Ruby on Rails framework, represent what founder David Heinemeier-Hannsen calls opinionated software. Rails, and Active Record by extension, represents hundreds of compromises, with most of them favoring a beautiful, productive programmer experience.
  • Solve WAR file,
  • Oracle TopLink 11g includes EclipseLink 1.0.1 JPA: Object-Relational JPA 1.0 with advanced persistence Simplified configuration of advanced features using annotations and/or XML All leading RDMS with platform specific features, best ORM for the Oracle Database MOXy: Object-XML Binding JAXB and advanced native SDO: Service Data Objects EIS using JCA Resource Adapters Containers WebLogic, OracleAS, WebSphere, GlassFish/SunAS, JBoss
  • This is an example of a scalability problem that can be encountered in JEE applications, and that Coherence can help address.
  • Oracle TopLink 11g (11.1.1.0.0) introduced in 2008 includes the new TopLink Grid feature that addresses the potential scalability problem discussed on the prior slide. TopLinkGrid which offers tight integration with Oracle Coherence that marries the standardization and simplicity of application development using the Java Persistence API (JPA) with the scalability and distributed processing power of Oracle’s Coherence Data Grid. This feature is integrated and included with WebLogic Suite. Developers can use TopLink Grid to easily leverage the Coherence grid as their primary storage for Entities as well as using direct connectivity with the backing data store for some Entity types of for specific operations. This flexibility allows application to easily adjust their usage of Coherence to meet changing requirements and usage patterns. The real focus of TopLink Grid is the delivery of functionality where a developer can easily configure TopLink JPA to use Coherence as the primary data store, execute queries against the grid, and choose to have Coherence manage the persisting of new and modified Entities. This integrated solution involves a layer between JPA and the data store where the grid can be leveraged in order to off-load direct database calls from every application instance and therefore offer these clustered application deployments the capability of scaling beyond and database bound operations. http://www.oracle.com/technology/products/ias/toplink/technical/toplink_grid_intro.html

Rollin onj Rubyv3 Rollin onj Rubyv3 Presentation Transcript

  •  
  • Enterprise Ruby on Rails: Rolling with JRuby on Oracle WebLogic Suite Chris Bucchere CEO of BDG Pieter Humphrey Principal Product Manager, Oracle
  • The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.
  • Intro Slides
    • Chris Bucchere
      • CEO, BDG
      • Oracle ACE Director
    • Pieter Humphrey
      • Principal Product Director, Oracle
  • Ruby 101
  • Ruby Overview
    • Key Features
      • Purely object-oriented
      • Dynamically-typed
      • Compact, yet easy to read syntax
      • Blocks that are closures
      • Open classes and objects
      • Domain Specific Language capabilities
    Strong Weak static dynamic
  • Basics
  • Iteration, Blocks & Closures
  • String Handling & Regular Expressions
  •  
  • Guiding Principles
    • Duck Typing
      • If it walks like a duck and quacks like a duck, then it probably is a duck
    • Convention over Configuration
      • Down with XML!
    • Rapid Prototyping
      • Allows for agile development with short iterations
    • Sustainable Productivity
  • Example Applications
    • Twitter
    • 43Things
    • 37 Signals
      • Basecamp
      • Campfire
      • Backpack
      • Highrise
    • Social Collective, Inc.
      • The Social Collective
      • CrowdCampaign
    • Thousands of others. . . .
  • Migrations
  • ActiveRecord & Validations
  • Scaffolding
  • Built-in MVC
  • UI Helpers
  • Show me the money!
  • JRuby and Database Access
  • What is JRuby?
    • JRuby is a port of Ruby onto Java, written in C & ruby
    • Offers Native Multithreading
    • Full Access to Java Libraries
    Configuration DSL External Systems Static Layer - Static typed legacy Java Libraries Dynamic layer - Application Code
  • Why JRuby?
    • To use Java libraries from code written in Ruby syntax
      • Swing, etc
    • To use Ruby libraries from code written in Java syntax
      • Via ActiveRecord with Bean Scripting Framework (BSF)
      • Via “Scripting for the Java Platform” (JSR 223) in Java 6
    • Performance vs. C-based interpreter is a hot debate
      • Depends who you ask, but it seems performance is surprisingly good
    • Great for the following use cases
      • Agile Methodology shops, small teams
      • REST / Web App for routing data to back end resources
      • Enterprise Deployments
  • Why JRuby cont.
    • Integration with Java libraries:
    • JRuby classes can
        • extend Java classes
        • implement a single Java interface
        • add methods to existing Java classes
    • Native threads
    • Unicode support
    • Portability
    • Can drop in into SQL easily ( find_by_sql )
    • Many DB accees options – this is where Ruby shines
  • JRuby Developer Tool support
    • IDEs
      • Eclipse
      • RDT plug-in supports Ruby development
      • RadRails IDE
      • IntelliJ IDEA
      • NetBeans
    • Editors
      • syntax highlighting (emacs, jEdit and Vim)
    • Spring
      • an IOC + Java EE framework
      • supports beans implemented in Java, JRuby, Groovy
  • Rack
    • Ruby’s CGI / Servlet equivalent
      • In web.xml, a rack servlet filter will dispatch params / requests to the RACK component
    • Rack provides a single API to abstracts multiple webservers ( mongrel, fast-cgi, webrick, fusion passenger )
    • Standardizes the request that a Ruby app expects (get params), wrapping HTTP requests/responses
    • Based on WSGI for Python
  • Ruby DBI <Insert Picture Here> Ruby Script DBI API ADO ODBC Databases DB2, Informix, mySQL, Oracle
  • ActiveRecord
    • ActiveRecord is …
      • a Ruby library for accessing relational databases
      • Simple, yet amazingly powerful / portable DB access
      • Tricky to tune under load, not for use with legacy schemas
    • It can be used from Java through JRuby
      • install the ActiveRecord gem
      • under Java 5 and earlier
        • use Bean Scripting Framework (BSF)
          • classpath must contain bsf.jar, jruby.jar, jvyaml.jar, commons-logging-1.1.jar
      • under Java 6 and later
        • use JSR 223 Scripting API
    • Convention, not configuration
    • Great for greenfield web apps
  • Getting Started with JRuby
    • Getting JRuby
      • http://dist.codehaus.org/jruby/1.3.1/
      • jRuby1.3.1/bin should be in PATH
      • JDK 1.5 or more should be in PATH, JAVA_HOME set
      • Apache Ant (http://jakarta.apache.org/ant/) 1.7 or greater
    • Getting Rails (the web tier for Ruby)
      • Once JRuby environment is set:
      • 'gem install rails -v 2.2.2'
    • Getting Warbler (Java EE deployment unit converter)
      • 'gem install warbler -v 0.9.12‘
      • Make sure you aren’t behind a proxy server
  • Demo Application: Maintain FOD Supplier Catalog FOD SCHEMA WebLogic Server EclipseLink Run WARBLER Ruby App JRuby interpreter Ruby App
  • JRuby, WebLogic, TopLink Database Access
  • JPA—in a Nutshell
    • Concrete classes (POJOs)
    • No required interfaces or inheritance
    • new() for instance creation
    • Mapping using annotations and/or XML
    • “ Managed” by an EntityManager
    • Can leave the Container (“detached”)
  • Where does JPA fit? Relational Database Java SE/EE/OSGi JPA Persistence Provider Design Time Runtime Mapping Metadata Java Classes Database Schema
  • JRuby + JPA = Enterprise friendly Rails
    • JPA is better for working with pre-existing database schemas
    • JRuby/JPA/WebLogic = easy Ops compliance
    • Development tools: Standalone, JDev, Eclipse
    • WebLogic provides connection pooling
    • WebLogic provides Oracle RAC integration
    • WebLogic provides Oracle JPA / Coherence integration
    • WebLogic provides XA with Messaging & DB
    • WebLogic provides easy ways to expose as JAX-WS, JAX-RPC, Spring Beans
    • WebLogic provides SUN RI: EclipseLink, Kodo
    <Insert Picture Here>
  • WebLogic Server JDBC Architecture
  •  
  • JDBC 4.0 - Connection Management
    • Additional enhancements to Connection interface to permit improved connection state tracking in pool environments.
    • Connection new methods
      • isValid
      • Check whether the current connection has not been closed and is still valid.
      • getClientInfo & setClientInfo
      • Get and set current value of client info property supported by the driver. The values supplied to these methods are used for accounting, diagnostics and debugging purposes only.
    • Code example
  • JDBC 4.0 - Statement Management
    • Additional enhancements to Statement interface to get greater flexibility when managing Statement objects in pool environments.
    • Statement new methods
      • isClosed: Check whether this Statement object has been closed.
      • isPoolable & setPoolable: Get and set poolable state of this statement object .
    • Code example
  • JDBC 4.0 - Wrapper Pattern
    • Added the ability to unwrap implementation of JDBC classes to make use of non-standard JDBC methods provided by vendor implementations.
    • New interface java.sql.Wrapper
      • isWrapperFor
      • It can be used to determine if the instance implements the specified interface or if the instance is a wrapper for an object that does.
      • unwrap
      • It is used to return an object that implements the specified interface allowing access to vendor-specific methods.
    • Subinterfaces derived from Wrapper
      • Connection
      • Statement
      • PreparedStatement
      • CallableStatement
      • ResultSet
      • DatabaseMetaData
  • JDBC 4.0 - New data types
    • Add the data type java.sql.RowId. This allows JDBC programs to access a SQL ROWID.
    • Resultset new methods
      • getRowId
      • updateRowId
    • Add new interface java.sql.SQLXML. Additional APIs have been added to allow applications access to this data.
    • Connection new method
      • createSQLXML
    • PreparedStatement new method
      • setSQLXML
    • CallableStatement new methods
      • getSQLXML
      • setSQLXML
    • ResultSet new methods
      • getSQLXML
      • updateSQLXML
  • TopLink 11g (includes EclipseLink 1.0.1) Eclipse Persistence Services Project (EclipseLink)‏ DBWS SDO EIS MOXy JPA XML Data Legacy Systems Databases Java SE Java EE OSGi Spring ADF
  • Scaling with JPA and ActiveCache
    • A clustered Enterprise Java application can experience slower response time due to database latency as it scales its number of instances
      • As the number of concurrent application instance increase the number of read and write requests that must use the database also increase
      • Independent caching in each application node must be minimized where concurrent writing is involved
      • Reduced caching comes at a cost of increasing backend database load
    App Machines WebLogic Cluster Enterprise App JDBC Enterprise App JDBC Web App JDBC Databases Persistence Persistence Persistence
  • Scaling with JPA and ActiveCache
    • TopLink Grid integrates Coherence as shared cache for TopLink 11g JPA between Application Tier and database
    • Single Coherence cache shared by all application nodes supports maximum caching even with concurrent writing
    • Coherence Data Grid caching minimizes database load to allow for predictable scalability
    Named Cache Named Cache Named Cache Cache Store Cache Store Cache Store Cache Store Cache Store Oracle Coherence In Memory Data Grid Database App Machines WebLogic Cluster Enterprise App JDBC Enterprise App JDBC Web App JDBC JPA JPA JPA Named Cache Named Cache
  • TopLink Grid
    • Combines:
      • the simplicity of application development using the Java standard Java Persistence API (JPA) with
      • the scalability and distributed processing power of Oracle’s Coherence Data Grid.
  • TopLink Grid Features
    • Simple configuration using annotations that align with standard JPA, e.g.,
        • @Entity
        • @Customizer (CoherenceReadWriteCustomizer. class )
        • public class Title implements Serializable {
    • Ability to choose which entities are stored in the grid versus those stored directly in the backing data store
    • Support for executing queries against either the Grid or directly against the data store
      • JPQL queries translated into Coherence filters
      • Queries executed in parallel across all members in grid
    • Support for all Coherence distribution schemes
  • TopLink Grid Features (2)
    • Support for sequence generation and locking using either the Grid or the backing data store
      • Optimistic Locking supported against Grid
    • Store entities in their object representation
      • Avoid object building cost when retrieving entity from grid
      • Once in the grid, all member save on building cost, not just initial reader
    • Leverage the power of the Coherence Data Grid, e.g.,
      • Parallel query processing
      • Linear scalability
      • Change listeners, etc.
  • TopLink Grid CacheStore
    • Coherence backed by TopLink Grid for DB Access
    (c) Copyright 2007. Oracle Corporation
  • TopLink Development Tool Support
    • JDeveloper 11g
      • Advanced JPA Tooling
      • Native ORM, OXM, and EIS mapping
    • Eclipse IDE
      • EclipseLink JPA support provided by Dali in Eclipse 3.4 (Ganymede)
      • Oracle Enterprise Pack for Eclipse (OEPE) offers additional support for building and deploying to WebLogic
    • Standalone Workbench
      • TopLink 11g Workbench for using oracle.toplink.* (toplink.jar)
        • Native ORM, OXM, and EIS mapping
      • EclipseLink Workbench (not shipped in 11g) for org.eclipse.persistence.* (eclipselink.jar)
        • Native ORM, OXM, and EIS mapping