1 intro to business components for java (bc4j) matt fierst computer resource team...
TRANSCRIPT
1
INTRO TO
BUSINESS COMPONENTS
FOR JAVA (BC4J)
Matt FierstComputer Resource Team
OracleWorld 2003 - Session 36321
2
Why Should I Care?
• Efficiency
• Productivity
• Maintainability
3
Topics
• What is BC4J?
• Why use BC4J?
• BC4J Architecture and Components
• Demo - BC4J in action
4
What is BC4J?
Database
BC4J
Java Application
• It is a bridge from the Relational world (database) to the Object world (Java)
5
What is BC4J?
“Business Components for Java is JDeveloper’s programming framework for building multi-tier database applications from reusable business components.”
6
What is JDeveloper?• Oracle’s Java and XML development suite• Language-sensitive editors• Java Compiler• UML modeling tool• Tools, frameworks, and utilities to help write your
code• Built-in web server and OC4J server to help test
your code• Debuggers and profilers to help perfect your code• Wizards and utilities to help bundle and deploy
your code
7
What is a Business Component?• Code that implements functionality associated with an
application object– Java and XML– May interact with a database– May implement business rules
• Encapsulates your business logic• Therefore, your presentation layer is much “cleaner”• Reusable• Flexible deployment
– Deploy to client (e.g., application, applet)– Deploy to middle tier or database (e.g., servlet, JSP, Web
Service, EJB, CORBA)
8
BC4J is Part of JDeveloper• “Programming Framework”• Wizards and tools for defining, customizing and
testing components• Class library and custom JSP tags for developing
your applications• Use any front end you wish
– JSP, Struts, etc– Swing– XML
• Deploy on any J2EE server
9
Why Use BC4J?
• I could just as well do it all myself!– JDBC to connect to the database– java.sql.* or SQLJ to interact with the database
• Besides, Java itself promotes encapsulation, reusability, etc.
• True, but why re-invent the wheel?
10
Why use BC4J? (cont.)
• Wizards let you declaratively define your business components– Specify the data you want (table, column)– BC4J generates the “plumbing” to interact with
that table– You can focus on implementing your
application-specifics
11
Why use BC4J? (cont.)• Tools help you use the components
– oracle.jbo: library of classes to directly interact with them
– Custom tag library to use in your JSPs• Tags tied to Java classes• Include the tag in your JSP, class methods are
automatically invoked
– BC4J can also generate a JSP app for you• This is NOT magic, though!• Quite simplistic• However, it could be a great starting point
12
Why use BC4J? (cont.)• Gives you the option to better divide
development responsibility– Java-savvy developers can focus on
components– Web-savvy developers can focus on
presentation layer• Easier to learn the custom tags than to learn Java
• BC4J handles all the database connection details for you
• Built-in connection pooling
13
Why use BC4J? (cont.)• The downside: setting up these components takes
time - planning and building– Depending on the application, and how it evolves, this
could be time well spent– Isolation of business logic improves maintainability
• Of the business logic• Of the presentation layer• Of the back-end database
• The bottom line: Is BC4J right for EVERY application?– No– But, it’s a great tool to have in your toolbox!
14
BC4J Architecture
Database
BC4J
AM
Application
15
BC4J Architecture (cont.)
• Types of Components:– Application Module (AM)
• Container for organizing and deploying other components
• Provides run-time context for defining and executing transactions
• Takes care of database connections
• Takes care of Master-Detail coordination
• Takes care of row locking
16
BC4J Architecture (cont.)
Database
BC4JAM
Application
EO EO EO EO EO
VO VO VO VO
17
BC4J Architecture (cont.)– Entity Object (EO)
• Provides a wrapper for database structures• Create an EO for each table, view, or stored procedure• EOs contain Attributes, corresponding to columns or
procedure parameters
– View Object (VO)• Your application’s interface to the BC4J layer• Hide the complexity of the database from the application• Uses SQL query to specify filtered subsets of data from one or
more EO• VO Attributes correspond to EO Attributes• Provide cached, navigable, modifiable result sets• Provide runtime dynamic linking, sorting, and filtering
18
BC4J Architecture (cont.)– Association
• Relationships between EOs• Automatically created based on Foreign Keys• Manually created based on common Attributes
– View Link• Relationships between VOs• Enforce Master-Detail filtering
– Domain• User-defined data types for EO and VO Attributes• Define in a central location:
– Validation rules– Default values– Error messages
19
DEMO• Our JSP application:
– Uses the “scott” schema– Displays employee/department data– We want to build a page to list “worker bees”
• Those employees who are not managers
• First, we’ll try a JDBC approach• Then we’ll try two BC4J approaches
– Create the components, manually write a JSP– Have JDeveloper generate a JSP application for us
• For instructions for this demo, and code snippets, download paper - Session 36321
20
To Learn More
• JDeveloper on-line help is a great place to start
• JDeveloper samples– c:\jdev\BC4J\samples
• OTN - sample code– http://otn.oracle.com/sample-code/products/jdev/
content.html