Oracle Toy Store Example

Download Report

Transcript Oracle Toy Store Example

Oracle Toy Store Example
(short version)
CIS 764
Neal Godsey
2005
Overview
This presentation involves a walkthrough of the Oracle Toy Store
example, found on the internet at:
http://www.oracle.com/technology/sample_code/products/jdev/bc4jtoystore/index.html
Layout:
– Discuss the technology used, concentrate on BC4J (ADF).
– Walk through the tutorial.
– Conclusion
Key Technology in ToyStore
• Jakarta Struts Framework
• Oracle Business Components for Java (BC4J) Framework
– Currently referred to as ADF Business Components, but BC4J was the
name when tutorial (1) was released.
• Internationalization Features
• JUnit Framework
• Oracle Containers for Java (OC4J) web application server
MVC Architecture
Model / View / Controller
Architecture
(4)
BC4J Overview
Implements the model (business logic) layer of MVC architecture.
Oracle claim BC4J
– Provides a set of best practice design patterns. They list a few:
•
•
•
•
•
Data Access Objects Pattern (avoid unnecessary marshalling)
MVC Pattern
Session Façade (wrap Entity beans with a Session bean)
Value Object (caches remote objects on client, less network activity)
Page-by-page Iterator (don’t send all data over network initially, client
may not need it all.)
• Fast-lane Reader (for read-only data, access JDBC APIs directly)
(7)
BC4J Overview
Some core objects:
– ApplicationModule = implements the data model. Manages entity objects.
Services requests for changing entity objects (and
underlying data).
– ViewObject = generic SQL query bean
• Patterns: fast-lane reader, data access objects, page-by-page iterators.
– RowObject = generic component that implements Value Object pattern.
– EntityObject = generic business logic bean.
(8)
BC4J (Store Catalog Impl. Diagram)
(8)
JUnit
“JUnit is a regression testing framework…[to perform] unit tests in Java.”
(10)
Definition of regression testing:
Retesting a previously tested program following modification to ensure
that faults have not been introduced or uncovered as a result of the
changes made. (11)
Toy Store Screen Shots
Screen Shots
Screen Shots
Screen Shots
Screen Shots
Installing Toy Store
1.
2.
3.
Download bc4jtoystore.zip, and put in convenient location on your
hard drive.
The student space quota will be exceeded while creating the tables.
Lobby the administrator for a higher quota.
Set up the database tables.
•
•
Run script ToyStore.sql located in the directory
bc4jtoystore/setup/
Don’t run CreateToyStoreUsers.sql because student Oracle accounts do
not have the proper permissions to set up new users.
(1)
Installing JUnit
Download JUnit from:
http://www.oracle.com/technology/software/products/jdev/index.html
Do not download the JUnit from the JUnit website, because it won’t work
with JDeveloper.
To install JUnit in JDeveloper, exit JDeveloper, and then extract the
downloaded zip file into the JDeveloper folder
<jdev-home>/jdev/lib/ext
Installing JUnit
Next, start a console window. Navigate to <jdev-home> and type the
following:
jar xvf jdev/lib/ext/junit_addin.jar junit3.8.1.zip
Start JDeveloper, which will automatically load the new extension.
Check for installation by clicking on menu FileNew
Expand the General node, and as an option you should see
Unit Tests(JUnit)
(1)
Change Data Sources
Because we can’t install new users on CIS Oracle, we must map both
users to the student account used to access the DB.
Select on menu View  Connection Navigator.
Right click on Database and choose Import Connections.
Navigate to bc4jtoystore/setup directory and choose
jdev_toystore_connections.xml
(1)
Change Data Sources
The data sources are now included in the project, but have incorrect user
names and passwords.
Double click on each data source and change the authentication properties
to the student (your) login name and password.
The names of the data sources should remain toystore and
toystore_statemgmt respectively.
Now, what used to be two separate logins are mapped to the single student
login.
(1)
Run the App. In JDeveloper
To run the application in JDeveloper:
– In the application file tree, expand
ToyStoreView  WebContent  WEB-INF  jsp
– Find the file index.jsp and right click on it.
– Choose menu option run.
Deploy to Stand-Alone OC4J
To deploy to stand-alone OC4J server:
Create connection
to stand-alone server
By choosing menu
View  Connection
Navigator
Double click
or right click
on Application
Server
Deploy to Stand-Alone OC4J
After using the connection wizard to set up a connection to the standalone OC4J server:
– In the Applications Navigator, expand the Deployment  Resources
folders.
– Right click on BC4JToyStore.deploy
– Select Deploy to … your connection.
Deployment Notes
When deploying to JDeveloper OC4J:
– The application web browser spawned by JDeveloper pointed to
http://localhost:8988/BC4JToyStore/WEB-INF/jsp/index.jsp
Each time I ran the example I deleted the WEB-INF/jsp/index.jsp portion
of the url, and the application starts.
Toy Store Application Organization
(1)
Toy Store Model
Data model = “named collections of data transfer objects exposed to the
client”
(1)
Toy Store Model
View objects may be composed of the following, depending on requirements:
–
–
–
–
–
XML object definition file
Java view object interface file (expose custom view object methods)
Java implementation file
Java view row interface file
Java view row implementation file (customize behavior of data transfer object
associated with the view object)
– Java view row message bundle
(1)
Toy Store Model
(1)
Toy Store Model
(1)
Toy Store Model
“When the view object produces collections of data transfer objects
after executing a query, each object in the collection is an
instance of the view object row class.”
(1)
Toy Store Model
The default view row object (oracle.jbo.row) accesses query results in a
non type-safe manner, i.e. getAttribute(“Attrib-Name”), but the view
object editor enables type safe attribute access via creation of an
interface.
Example to get query result attribute Quantity when we already have an
instance of a view row vr:
vr.getQuantity( )
versus
vr.getAttribute(“Quantity”)
Example Message Bundle
(1)
Implementing Business Rules
Business rules implement interface jbiValidator
3 options for validating business rules:
– Use OC4J pre-defined business rules (i.e. UniquePKValidationBean)
– Use a custom (reusable) business rule written by a developer.
– Use custom methods written in the entity class (not as a general rule).
Example
of method and
rule validation.
(1)
Implementing Business Rules
Example of writing a custom method to validate a business rule:
(1)
Toy Store Model Overview
(1)
BC4J Domain Types
BC4J Domain types include:
–
–
–
–
–
–
Number
Date
DBSequence
ClobDomain
BlobDomain
Array
These are included to increase performance when working with
corresponding types in an Oracle DB.
(1)
Toy Store Controller
Model-View-Controller interaction:
(1)
Toy Store Struts Action Flow
(1)
Toy Store View
An example of jbo tags used in the Toy Store Example:
– <jbo:RowsetIterate>
• Iterate through a collection of data transfer objects
– <jbo:ShowValue>
• Output unformatted value of attribute
– <jbo:RenderValue>
• Output formatted value per format mask specified at design time
(1)
Conclusion
BC4J (ADF Business Objects) seems like a viable framework to create
EJB/non-EJB applications.
Some downsides:
– Somewhat limited documentation. Some articles, how-to’s and the Toy
Store demo.
– Learning curve, transparency
– Tied to JDeveloper (may/may not be downside)
Upsides:
– Overall, it saves a lot of time writing/debugging code.
– At present, Oracle seems committed to the product.
References
1.
2.
3.
4.
5.
6.
Building a Web Store with Struts & BC4J Frameworks. Muench, Steve.
[online]
http://www.oracle.com/technology/sample_code/products/jdev/bc4jtoystore
/readme.html . 2003.
Java Frameworks and Components. Nash, Michael. Cambridge University
Press. 2003.
[online] http://e-docs.bea.com/wle/tuxedo/glossary/glossary.htm
Stepping Through Jakarta Struts. Hansen, Keld. [Online]
http://javaboutique.internet.com/tutorials/Struts/ .
Understanding JavaServer Pages Model 2 Architecture. Seshadri, Govind.
[Online] http://www.javaworld.com/javaworld/jw-12-1999/jw-12-ssjjspmvc.html .
Demystifying Jakarta Struts. [Online]
http://www.coreservlets.com/Apache-Struts-Tutorial/ . 2004.
References
7.
8.
9.
10.
11.
Simplifying J2EE and EJB Development with BC4J. Muench, Steve.
[Online]
http://www.oracle.com/technology/products/jdev/collateral/tutorials/903/j2e
e_bc4j/prnt/j2ee_bc4j.html . 2002.
Simplifying J2EE and EJB Development with BC4J. [Online]
http://www.oracle.com/technology/products/ids/daily/feb12.html.
Trail: Internationalization. Green, Dale. [Online]
http://java.sun.com/docs/books/tutorial/i18n/intro/index.html
[Online] http://www.junit.org/index.htm
[Online] www.aptest.com/glossary.html