SlideShare a Scribd company logo
eBusiness & Application Development
UUSINGSING OORACLERACLE PPLL/SQL/SQL ANDAND JDBCJDBC TOTO MMANAGEANAGE FFILEILE UUPLOADSPLOADS
WWITHINITHIN TTHEHE DDATABASEATABASE - A H- A HANDSANDS--ONON EEXAMPLEXAMPLE
Mary Wagner, Delaware Department of Transportation
WHAT ARE BLOBS?
A BLOB is an Oracle data type that can be used to store binary data within an Oracle database. The term BLOB is an
abbreviation for Binary Large Object and is a type of internal Large Object (LOB). An internal LOB is stored within the
database, whereas an external LOB is stored outside of the database (i.e. BFILE). Many different types of binary files,
including spreadsheets, word processor documents, images and other files can be stored within the database, using the BLOB
data type.
WHY USE THEM?
Storing binary files within the database has many advantages over storing them within a server’s operating system.
REMOVES FILE SYSTEM / SERVER DEPENDENCE
If you store binary files inside the database, you no longer have to depend on your server administrator to manage access to
the server or files. You don’t have to worry about files getting accidentally deleted or other server security issues.
FILES ARE BACKED UP VIA DATABASE BACKUPS
If you store binary files inside the database, then they will be backed up as part of the database when doing your regular
database backups and exports.
FILES ARE MORE SECURE
If you store binary files inside the database, then security and access to the files can now be managed within the database.
There is now more than one level of security (server OS). In other words, a user also needs database access and access to the
database object where the files reside in order to access the files.
FILES RECOVERABILITY IS HIGHER
If you store binary files inside the database, then they are recoverable just like other data that is stored within the database.
For example, when a file is uploaded to the database, it is part of an Oracle transaction and can be recovered, in the event of a
media failure, just like any other type of data stored in an Oracle database.
AN EXAMPLE - MY DOCUMENT MANAGEMENT SYSTEM (MYDMS)
OVERVIEW
myDMS is a small java web application used for managing and viewing documents (binary files) by topic. The maximum file
upload size for this application is 50mb. The application uses JDBC and PL/SQL to upload, view and delete binary files from
within an Oracle 9i database. Within the application, topics are used to categorize the uploaded documents. Topics can be
added, modified and deleted. The application uses an Oracle 9i database to house the data and BEA Weblogic 8.1 as the
Java Application Server. A JDBC connection pool and JNDI datasource are implemented within the Weblogic server
instance.
The user interface is written using the Java Model – View – Controller (MVC) architecture. There is a controller and process
request servlet that handle the flow and process designated action classes, which are related to each task that can be
completed within the application. The action classes call methods in the Data Access Object (DAO) classes. These DAO
1 Paper #604
eBusiness & Application Development
methods call the PL/SQL procedures that complete all of the related database transactions from within the database. Java
Server Pages are used for the various user interface views and call getter methods in the related Value Object (VO) classes,
which are set within the executed DAO methods.
FUNCTIONALITY AND RELATED SCREENS
Screenshots and brief explanations of the functionality of myDMS are displayed below. The detailed explanations of each
phase of developing the application will then follow.
LOGGING IN
There are 2 initial users in the myDMS application. To test the application functionality, either of these users can be used to
log into the system (Figure 1):
• MANAGER – this user can view, upload and delete documents as well as view, edit and delete topics.
• USER – this user can view and upload documents and view and add topics, but cannot delete documents or edit or
delete topics.
Figure 1 (myDMS - Log In Screen)
VIEW DOCUMENT LIST
Once logged in, a current list of documents is displayed (Figure 2).
Figure 2 (myDMS - View Document List)
VIEW A DOCUMENT
While viewing the document list, the “VIEW” link can be clicked to view the actual binary file representing the document.
This will retrieve the BLOB from the database and display it in it’s originally uploaded file type on the screen (Figure 3).
2 Paper #604
eBusiness & Application Development
Figure 3 (myDMS – View a Document)
UPLOAD A NEW DOCUMENT
A new document can be uploaded by clicking the “UPLOAD NEW DOCUMENT” link, while viewing the document list.
After clicking the link, the upload form is displayed and once completed and submitted, the file and related data is saved to
the database. The file is saved as a BLOB within the oracle database (Figure 4).
Figure 4 (myDMS – Upload a New Document)
DELETE A DOCUMENT
If the logged in user is the MANAGER user, then the “DELETE” link can be clicked on to delete the related document from
the database (Figure 5).
Figure 5 (myDMS – Delete a Document)
3 Paper #604
eBusiness & Application Development
VIEW TOPIC LIST
The “TOPIC LIST” link can be clicked on to view a list of topics that can be assigned to documents when they are uploaded
(Figure 6).
Figure 6 (myDMS - View Topic List)
ADD A NEW TOPIC
The “ADD NEW TOPIC” link can be clicked to add a new topic to the database. The new topic will display in the topic
dropdown list, which displays on the “UPLOAD NEW DOCUMENT” form (Figure 7).
Figure 7 (myDMS – Add a New Topic)
DELETE A TOPIC
The “DELETE” link can be clicked to delete the related topic. The deleted topic will no longer appear in the topic list or in
the topic dropdown list on the “UPLOAD NEW DOCUMENT” form (Figure 8).
Figure 8 (myDMS – Delete a Topic)
EDIT A TOPIC
The “EDIT” link can be clicked to edit the related topic. The updated topic will then be displayed in the topic list and in the
topic dropdown list on the “UPLOAD NEW DOCUMENT” form (Figure 9).
4 Paper #604
eBusiness & Application Development
Figure 9 (myDMS – Edit a Topic)
MYDMS - PHASE I. CREATING DATABASE TABLESPACES, USERS, TABLES / SETTING UP
TABLESPACES
There are 2 tablespaces that house the myDMS data, MYDMS_DATA and MYDMS_BLOB.
MYDMS_DATA
The MYDMS_DATA tablespace houses the NON-BLOB application data, including Document Details, Topics and User
information. Below are the SQL PLUS commands that can be run to create this tablespace (Figure 10).
Figure 10 (MYDMS_DATA tablespace)
--create tablespace
CREATE TABLESPACE MYDMS_DATA
LOGGING
DATAFILE 'C:ORACLEORADATAMW92MYDMS_DATA01.DBF' SIZE
10304K REUSE EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO
MYDMS_BLOB
The MYDMS_BLOB tablespace houses the DOCUMENTS, which has the BLOB column, containing the binary files that are
uploaded. Below are the SQL PLUS commands that can be run to create this tablespace (Figure 11).
5 Paper #604
eBusiness & Application Development
Figure 11(MYDMS_BLOB tablespace)
--create tablespace
CREATE TABLESPACE MYDMS_BLOB
LOGGING DATAFILE 'C:ORACLEORADATAMW92MYDMS_BLOB01.DBF'
SIZE 51264K EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO;
USERS
There are 2 database users that support the myDMS application, the schema owner, MYDMS, and the application user,
MYDMS_USER.
MYDMS
The MYDMS account is the schema owner for the application. This user houses all of the tables, PL/SQL packages and
other database objects that are called by the Java user interface (Figure 12).
Figure 12(MYDMS Schema Account)
--create user
CREATE USER MYDMS IDENTIFIED BY MYDMS
DEFAULT TABLESPACE MYDMS_DATA
TEMPORARY TABLESPACE TEMP
QUOTA UNLIMITED ON MYDMS_BLOB
QUOTA UNLIMITED ON MYDMS_DATA;
--grant rights
GRANT CONNECT TO MYDMS;
GRANT CREATE PROCEDURE TO MYDMS;
GRANT CREATE TRIGGER TO MYDMS;
MYDMS_USER
The MYDMS_USER account is the application end user account and is used by the JDBC connection pool. All data access
within the application takes place through PL/SQL packages within the MYDMS schema. The execute privilege is granted to
MYDMS_USER on the required PL/SQL packages only. The MYDMS_USER account also has a logon trigger that sets the
current schema to MYDMS, whenever the MYDMS_USER account connects to the database. There are no synonyms
currently being used within the application (Figure 13).
Figure 13(MYDMS_USER Database Account)
6 Paper #604
eBusiness & Application Development
--create user
CREATE USER MYDMS_USER IDENTIFIED BY MYDMS_USER
DEFAULT TABLESPACE USERS
TEMPORARY TABLESPACE TEMP;
GRANT CONNECT TO MYDMS_USER;
--create logon trigger
CREATE OR REPLACE TRIGGER MYDMS_USER.TRG_LOGON_SET_SCHEMA
AFTER LOGON ON MYDMS_USER.SCHEMA
BEGIN
EXECUTE IMMEDIATE 'ALTER SESSION SET CURRENT_SCHEMA=MYDMS';
END TRG_LOGON_SET_SCHEMA;
/
NAVIGATION AND SECURITY OBJECTS
After the tablespaces and users are created, some system related tables and objects need to be created. These objects are used
by the application for navigation flow, access and login verification.
TABLES
• ACTIONS – Houses meta data related to action class and the resulting success and failure JSP views.
• USERTYPE – Houses system user types, which are assigned to each user account and used to manage user access to
the application actions.
• USERS – Houses system user account information
• USERACCESS – Controls user access to specific application actions
The below script, which is included with the download script and web archive files, will create the required tables.
@create_tables_action_and_user.sql
PL/SQL PACKAGE – PKG_MVC
• PKG_MVC – Houses procedures and functions related to determining the next JSP view, verifying whether the
logged in user has access to the requested action and verifying usernames and passwords when users log into the
system. There are 3 procedures – get_action_info, get_password_hash and verify_user. (Figure 14).
7 Paper #604
eBusiness & Application Development
Figure 14(PKG_MVC Package)
The below script, which is included with the download script and web archive files, will create the PKG_MVC package.
@create_package_mvc.sql
APPLICATION TABLES
There are 3 main application tables, used to store document information and topics. These tables are named DOCUMENTS,
TOPICS AND DOCUMENTDETAILS.
DOCUMENTS (THE BLOB TABLE)
The documents table houses the binary file (BLOB column) which is saved to the database when the “UPLOAD NEW
DOCUMENT” form is submitted. This table is assigned to the MYDMS_BLOB tablespace. The BLOB column within the
table is called BINARYFILE. BLOB columns have unique settings that are further discussed below. (Figure 15).
Figure 15(DOCUMENTS Table)
8 Paper #604
eBusiness & Application Development
INITIALIZATION OF LOB
In order to access the contents of a LOB column, a LOB locator is used by Oracle. If a null value is stored in a LOB
column, the locator is not stored in the row, instead the null value is stored in the row. To remedy this, the LOB column is
initialized. To accommodate this requirement in myDMS, the default value of the BINARYFILE column is set to
EMPTY_BLOB(). This will allow the BLOB column to be initialized upon insertion and then we will be able to return the
newly inserted empty blob locator and write the uploaded binary data to the BINARYFILE column when the “UPLOAD
NEW DOCUMENT” form is submitted.
If the UPLOAD form within myDMS was not going to always be inserting a BLOB, upon submission, I may want to have
null values allowed within the BLOB column. Since this isn’t the case with this application, however, I am initializing the
column with every insert.
ENABLE LOB STORAGE IN ROW (INLINE STORAGE)
For this example, the default setting of enabling LOB storage in row is being accepted (also known as inline storage). By
enabling inline storage, if the BLOB length is less than 4mb, it’s contents will be stored within the table row. If the BLOB
length is more than 4 mb, then the contents will be stored in the designated tablespace, however, the LOB locator will still be
stored within the table row.
LOB TABLESPACE
For this example, we have created a separate tablespace, called MYDMS_BLOB, to house BLOB contents in each row that
are larger than 4mb and therefore, cannot be stored within the table row. By storing the larger BLOBs in their own
tablespace, we will be able to keep them separate from other data and also be able to monitor the growth, as it relates to the
binary files, themselves.
CHUNK SIZE
In this example, we are accepting the default chunk size of 8192 bytes, which is the block size of our database. Our files are
all going to be fairly small, nothing over 50mb, so this size should be sufficient.
LOB CACHE
In this example, we are accepting the default of off for the LOB cache. In our example, the same documents are not going to
be viewed several times a day by several different useres, but only infrequently, therefore, they do not need to be cached. If
you choose to cache your LOB, make sure to adjust the buffer cache settings appropriately.
The below commands can be run in SQL PLUS as the MYDMS user to create the DOCUMENTS table and it’s related
objects and to insert sample records.
--create table
CREATE TABLE DOCUMENTS (
DOCUMENTID NUMBER(10) NOT NULL,
BINARYFILE BLOB DEFAULT EMPTY_BLOB() NOT NULL,
DATESTAMP DATE DEFAULT SYSDATE NOT NULL,
CONSTRAINT PK_DOCUMENTS_DOCUMENTID PRIMARY KEY(DOCUMENTID))
TABLESPACE MYDMS_BLOB;
--create sequence to populate primary key
9 Paper #604
eBusiness & Application Development
CREATE SEQUENCE SEQ_DOCUMENTS_DOCUMENTID;
TOPICS (NO BLOBS)
The topics table houses a list of document topics that can be used to categorize a document when uploading it through the
application. The below commands can be run in SQL PLUS as the MYDMS user to create the TOPICS table and it’s related
objects and to insert sample records (Figure 16).
Figure 16(TOPICS Table)
--create table
CREATE TABLE TOPICS (
TOPICID NUMBER(2) NOT NULL,
TOPICNAME VARCHAR2(128) NOT NULL,
USERID NUMBER(3) NOT NULL,
DATESTAMP DATE DEFAULT SYSDATE NOT NULL,
CONSTRAINT FK_TOPICS_USERID FOREIGN KEY(USERID) REFERENCES USERS(USERID),
CONSTRAINT PK_TOPICS_TOPICID PRIMARY KEY(TOPICID),
CONSTRAINT UN_TOPICS_TOPICNAME UNIQUE(TOPICNAME))
TABLESPACE MYDMS_DATA;
--create additional index
CREATE INDEX FK_TOPICS_USERID ON TOPICS(USERID);
--create sequence to populate primary key
CREATE SEQUENCE SEQ_TOPICS_TOPICID;
--create trigger to automatically update datestamp when record is modified
CREATE OR REPLACE TRIGGER TRG_TOPICS_DATESTAMP
BEFORE UPDATE ON TOPICS FOR EACH ROW
BEGIN
:new.DATESTAMP := SYSDATE;
END TRG_TOPICS_DATESTAMP;
/
--insert sample records
INSERT INTO TOPICS (TOPICID, TOPICNAME, USERID) VALUES (0, 'NONE', 1);
INSERT INTO TOPICS (TOPICID, TOPICNAME, USERID) VALUES (SEQ_TOPICS_TOPICID.NEXTVAL, 'DISASTER
RECOVERY', 1);
10 Paper #604
eBusiness & Application Development
INSERT INTO TOPICS (TOPICID, TOPICNAME, USERID) VALUES (SEQ_TOPICS_TOPICID.NEXTVAL, 'STANDARD
OPERATING PROCEDURES', 1);
INSERT INTO TOPICS (TOPICID, TOPICNAME, USERID) VALUES (SEQ_TOPICS_TOPICID.NEXTVAL, 'SERVICE LEVEL
AGREEMENTS', 1);
COMMIT;
DOCUMENTDETAILS (NO BLOBS)
The documentdetails table houses all of the non-blob data regarding uploaded documents, including a title, description, filename,
file size and file content type. The below commands can be run in SQL PLUS as the MYDMS user to create the
DOCUMENTDETAILS table and it’s related objects (Figure 17).
Figure 17(DOCUMENTDETAILS Table)
--create table
CREATE TABLE DOCUMENTDETAILS (
DOCUMENTDETAILID NUMBER(10) NOT NULL,
TOPICID NUMBER(2) NOT NULL,
DOCUMENTID NUMBER(10) NOT NULL,
TITLE VARCHAR2(512) NOT NULL,
DESCRIPTION VARCHAR2(1024 byte) NOT NULL,
FILENAME VARCHAR2(256) NOT NULL,
FILESIZE NUMBER(9) NOT NULL,
CONTENTTYPE VARCHAR2(128) NOT NULL,
USERID NUMBER(3) NOT NULL,
DATESTAMP DATE DEFAULT SYSDATE NOT NULL,
CONSTRAINT FK_DOCUMENTDETAILS_DOCUMENTID FOREIGN KEY(DOCUMENTID) REFERENCES DOCUMENTS(DOCUMENTID),
CONSTRAINT FK_DOCUMENTDETAILS_TOPICID FOREIGN KEY(TOPICID) REFERENCES TOPICS(TOPICID),
CONSTRAINT FK_DOCUMENTDETAILS_USERID FOREIGN KEY(USERID) REFERENCES USERS(USERID),
CONSTRAINT PK_DOCUMENTDETAILS_DDID PRIMARY KEY(DOCUMENTDETAILID),
CONSTRAINT UN_DOCUMENTDETAILS_FN_TID UNIQUE(FILENAME, TOPICID))
TABLESPACE MYDMS_DATA;
--create additional indexes
CREATE INDEX FK_DOCUMENTDETAILS_DOCUMENTID ON DOCUMENTDETAILS(DOCUMENTID);
CREATE INDEX FK_DOCUMENTDETAILS_TOPICID ON DOCUMENTDETAILS(TOPICID);
11 Paper #604
eBusiness & Application Development
CREATE INDEX FK_DOCUMENTDETAILS_USERID ON DOCUMENTDETAILS(USERID);
--create sequence to populate primary key
CREATE SEQUENCE SEQ_DOCUMENTDETAILS_DDID;
--create trigger to automatically update datestamp when record is modified
CREATE OR REPLACE TRIGGER TRG_DOCUMENTDETAILS_DATESTAMP
BEFORE UPDATE ON DOCUMENTDETAILS FOR EACH ROW
BEGIN
:new.DATESTAMP := SYSDATE;
END TRG_DOCUMENTDETAILS_DATESTAMP;
/
MYDMS - PHASE 2. PL/SQL API
DATABASE API – PL/SQL PACKAGE (PKG_DMS)
All database related transactions are completed through functions and procedures within a PL/SQL package, called
PKG_DMS. This package includes procedures to upload documents, delete documents, view a document listing, add a
topic, edit a topic, delete a topic and view a topic listing. It also contains functions and global variables used within these
procedures. The MYDMS_USER account is granted execute on this package.
Below are details related to just the Document / BLOB related procedures that are housed within the PKG_DMS package.
VIEW_DOCUMENT_LIST
This procedure returns a ref cursor, which is used by the related Java Data Access Object to display a current list of uploaded
documents. The DOCUMENTDETAILS table is queried and the resulting data is stored in the ref cursor and returned as an
out parameter. The DOCUMENTS table (and the related BLOB column) are not touched for this query, as the BLOB is not
needed to display a listing of documents.
UPLOAD_DOCUMENT
This procedure takes care of inserting an initial record into the DOCUMENTS table, inserting a record into the
DOCUMENTDETAILS table, returning the LOB locator to Java for use in streaming the uploaded document into the
database and returning an updated document list, via a ref cursor, to the calling Java Data Access Object.
VIEW_DOCUMENT
This procedure is for displaying the BLOB within the client’s browser. The BLOB column is returned through a ref cursor,
to the related Java Data Access Object. Java streaming is then used to display the file via the web browser.
DELETE_DOCUMENT
This procedure is for deleting the related uploaded file from the database and returning an updated document list to the
related Java Data Access Object for display to the user. Related records from the DOCUMENTS and
DOCUMENTDETAILS tables are removed from the database for the related uploaded file.
12 Paper #604
eBusiness & Application Development
MYDMS - PHASE 3. CREATE JAVA OBJECTS
MODEL – VIEW – CONTROLLER (MVC) ARCHITECTURE
myDMS uses the Java MVC architecture--
• Model - Business / Value Object (VO) (also known as Java Bean) – Value objects are place holders for data that is
displayed on JSP views. Value Objects have getter and setter methods. Data Access Objects call the setter methods
to store the data that is retrieved from the database and JSP Views call the getter methods to display the stored data
within the client’s browser.
• View (also known as Java Server Page, JSP) - Views are the web pages that are displayed within the client’s browser.
They could also be described as the user interface. These are the screens that the end user interfaces with to submit
and retrieve information from the application.
• Controller – The controller is a servlet and is responsible for the navigation of the web application. It routes to the
application to the appropriate action and then is responsible for forwarding the user to the appropriate success or
failure view (JSP).
• Actions – Actions are Java classes that are called by the controller to complete specific tasks within the application.
They execute the data access and other methods that make up the application. There is an action for each piece of
functionality within the application.
• Data Access Objects (DAO) – Data Access Objects contain all of the database access methods. The database access
methods are responsible for handling any database related transactions, including inserting new records, updating
existing records, deleting existing records and selecting a set of records to be displayed within the client’s browser.
Below, I will discuss the Java objects related to the BLOB portion of the myDMS application. Although myDMS allows
Topics to be added, edited and deleted, since these are non-BLOB tasks I’m not going to discuss the corresponding MVC
objects for them, but only for the MVC objects for the Document / BLOB related tasks.
VALUE OBJECTS (BLOB RELATED ONLY)
DOCUMENTVO
This java bean is the main bean for the application and includes the getter and setter methods that are used to get and set data
to be displayed on the resulting JSP views (Figure 18).
Figure 18(DOCUMENTVO Value Object / Java Bean)
13 Paper #604
eBusiness & Application Development
VIEWS – JAVA SERVER PAGES(BLOB RELATED ONLY)
VIEWDOCUMENTLIST.JSP
This view displays the current list of documents that have been uploaded to the database, within the client’s browser.
VIEWDOCUMENTSERVLET
This view is really a servlet, but is the designated success view for displaying a queried document (binary file) within the
requesting client’s browser.
FORMUPLOADDOCUMENT.JSP
This view displays the form within the client’s browser that is used for uploading a new document into the database.
SERVLETS
CONTROLLERSERVLET
This servlet controls the flow of the application. All actions (URLs with a .do extension) are routed through this servlet,
which then processes the action request and returns the appropriate success or failure JSP view. The
PROCESSREQUESTSERVLET
This servlet is called by the Controller servlet and handles the guts of the requested action class processing. It instantiates the
action and then determines whether the action was processed successfully. Once the result is determined, it then returns the
appropriate JSP view to the Controller servlet.
ACTION CLASSES (BLOB RELATED ONLY)
VIEWDOCUMENTLISTACTION
This action class calls the related DAO method to display a list of uploaded documents that are currently in the database. At
this point, the BLOB is not touched at all, only the table which houses the details behind the uploaded file. This action
queries only the DOCUMENTDETAILS table.
VIEWDOCUMENTACTION
This action class is responsible for displaying an uploaded binary file (BLOB) within the client’s browser. Request attributes
for the queried document, including the file name and content type are set by this action. The related DAO method is called
to retrieve the BLOB locator and then stream the binary file to the client’s browser. This action queries only the
DOCUMENTS table.
FORMUPLOADDOCUMENTACTION
This action class calls the related DAO method to display the form for uploading a new document. There is a drop down list
of Topics that is displayed on this form, which is retrieved and set via this action and the related DAO method. This action
queries the TOPICS table.
SAVEUPLOADDOCUMENTACTION
This action class calls the related DAO method to save the submitted data from the upload form to the database. The initial
BLOB locator is returned to the DAO method and then Java streaming is used to upload the binary data to the database.
This action inserts into the DOCUMENTS and DOCUMENTDETAILS tables and then queries the
DOCUMENTDETAILS table.
14 Paper #604
eBusiness & Application Development
SAVEDELETEDOCUMENTACTION
This action class calls the related DAO method to delete the related document from the database and then displays an
updated document list to the client’s browser. This action deletes from the DOCUMENTS and DOCUMENTSDETAILS
tables and queries the DOCUMENTDETAILS table.
DATA ACCESS OBJECTS (BLOB RELATED ONLY)
BASEDAO
This data access class includes database connectivity methods used by all DAO objects, including retrieving and releasing
connections, closing statements and result sets, committing and rolling back transactions (Figure 19).
Figure 19(BASEDAO Data Access Object)
DOCUMENTDAO
This data access class is the data access object that calls all of the PL/SQL procedures related to uploading, viewing and
deleting documents in the database (Figure 20).
Figure 20(DOCUMENTDAO Data Access Object)
MYDMS - PHASE 4. PUTTING IT TOGETHER
Now that we have the database objects and the Java objects defined, we can build the application, based on the myDMS
BLOB related functionality that we have outlined at the beginning of the paper. The flow is the same for each piece of
functionality.
An ACTION class is processed which executes a DATA ACCESS OBJECT method within the DocumentDAO class, which
in turn executes the related PL/SQL stored procedure within the PKG_DMS package. Data can be passed as out parameters
back to the DocumentDAO class, which then can be processed or used to set the DocumentVO object as a request attribute.
The resulting Java Server Page view then calls the DocumentVO getter methods to display data to the client’s browser.
Below I will go over the pieces that make up the core DOCUMENT functionality of the myDMS application, including:
• Viewing a Document Listing
• Viewing a Binary Document File
• Displaying the Upload Form
15 Paper #604
eBusiness & Application Development
• Saving the Upload Form to the Database
• Deleting an Uploaded File from the Database
The code snippets displayed below are the key pieces that make up each part of each illustrated function, however, the
complete working code, including PL/SQL, Java and other files is available for download (see “Where to Get the myDMS
scripts, Java files and Web Archive” section at the end of the paper).
VIEWING A DOCUMENT LISTING
The document listing is a listing of all of the uploaded documents that are in the DOCUMENTDETAILS table. The BLOB
column, which is stored in the DOCUMENTS table, is not touched for this query, as we do not need to display the BLOB
data at this point. The file size is calculated upon BLOB insertion and then stored as a number within the
DOCUMENTDETAILS table, so that it does not have to be calculated every time that the Document List is viewed (Figure
21).
Figure 21(myDMS DOCUMENT LIST hyperlink
ACTION CLASS  VIEWDOCUMENTLISTACTION
This class is processed by the controller and executes the viewDocumentList method within DocumentDAO (Figure 22).
Figure 22(ACTION CLASS --ViewDocumentListAction)
DOCUMENTDAO METHOD  VIEWDOCUMENTLIST
This method executes the view_document_list PL/SQL procedure within the PKG_DMS package (Figure 23).
Figure 23(DOCUMENTDAO – viewDocumentList Method)
PKG_DMS METHOD  VIEW_DOCUMENT_LIST
This procedure returns a ref cursor as an out parameter back to the viewDocumentList method in DocumentDAO.
DocumentDAO then processes the result set to create a DocumentVO object and sets the object as a request attribute which
the JSP view can then reference for displaying to the client’s browser (Figure 24).
16 Paper #604
eBusiness & Application Development
Figure 24(PKG_DMS – view_document_list Procedure)
JSP VIEW  VIEWDOCUMENTLIST.JSP
This view retrieves the document list, which was set as a request attribute by the DAO method, and then iterates through the
list to display the document listing (Figure 25).
Figure 25(VIEW – viewDocumentList.jsp)
VIEWING A BINARY DOCUMENT FILE
To view the actual binary file, while viewing the Document List, the view link can be clicked on. The queried document is
then displayed within the client’s browser in its original uploaded file content type (Figure 26).
Figure 26(myDMS VIEW DOCUMENT hyperlink
ACTION CLASS  VIEWDOCUMENTACTION
This class is processed by the controller and gets and sets file specific information, including the file name and the file content
type as request attributes. These attributes are used by the ViewDocumentServlet to display the file within the client’s browser
(Figure 27).
17 Paper #604
eBusiness & Application Development
Figure 27(ACTION CLASS --ViewDocumentAction)
DOCUMENTDAO METHOD  VIEWDOCUMENT
This method retrieves the BLOB from the database, using the view_document PL/SQL procedure and then uses Java streaming
to display the file in the client’s browser. After the length of the file is determined, the java.io.InputStream object is used to
read the file into the stream and the java.io.OutputStream is used to write the file to the screen, using the ViewDocumentServlet
(Figure 28).
Figure 28(DOCUMENTDAO – viewDocument Method)
PKG_DMS METHOD  VIEW_DOCUMENT
This procedure returns a ref cursor as an out parameter back to the viewDocument method in DocumentDAO.
DocumentDAO then processes the BLOB data using Java streaming (Figure 29).
18 Paper #604
eBusiness & Application Development
Figure 29(PKG_DMS – view_document Procedure)
VIEW  VIEWDOCUMENTSERVLET
This view requests and then receives the BLOB data and then displays the binary file to the client’s browser, in the designated
content type (Figure 30).
Figure 30(VIEW – ViewDocumentServlet)
DISPLAYING THE UPLOAD FORM
To begin the file upload process, the upload new document link can be clicked. The upload form is then displayed (Figure 31).
Figure 31(myDMS – UPLOAD NEW DOCUMENT Hyperlink
ACTION CLASS  FORMUPLOADDOCUMENTACTION
This class is processed by the controller and executes the viewTopicList method within TopicDAO. This method returns a list
of Topics that are displayed within the Topic dropdown list on the resulting JSP view (upload form) (Figure 32).
Figure 32(ACTION CLASS --FormUploadDocumentAction)
19 Paper #604
eBusiness & Application Development
DOCUMENTDAO METHOD  VIEWTOPICLIST
This method retrieves a ref cursor from the database by calling the view_topic_list PL/SQL procedure and then sets the
TopicVO java bean as a request attribute so that it can be referenced by the resulting JSP view for display on the form as a
drop down list (Figure 33).
Figure 33(DOCUMENTDAO – viewTopicList Method)
PKG_DMS METHOD  VIEW_TOPIC_LIST
This procedure returns a ref cursor as an out parameter back to the viewDocument method in DocumentDAO., which then
sets the data in the TopicVO object, using the setter methods. The resulting JSP can then retrieve the data from the TopicVO
object, for display, using the getter methods (Figure 34).
Figure 34(PKG_DMS – view_topic_list Procedure)
JSP VIEW  FORMUPLOADDOCUMENT.JSP
This view retrieves the topic list from the VO, which was set as a request attribute by the DAO method, and then iterates
through the list to display the topic dropdown list with the rest of the form. You will notice that the enctype within the form
tags is set to multipart/form-data. This is because when the form is submitted, we will be submitting a file, in addition to
regular form text boxes and dropdown fields (Figure 35).
20 Paper #604
eBusiness & Application Development
Figure 35(VIEW – formUploadDocument.jsp)
SAVING THE UPLOAD FORM
Once the upload document form is filled out, it can then be submitted by clicking the submit now button. This submits the
upload to the database (Figure 36).
Figure 36(myDMS – SUBMITTING UPLOAD FORM)
21 Paper #604
eBusiness & Application Development
ACTION CLASS  SAVEUPLOADDOCUMENTACTION
This class is processed by the controller and executes the uploadDocument method within DocumentDAO. The FileItem,
DiskFileUpload and FileUpload objects within the org.apache.commons.fileupload API are used to process the incoming html
form with the attached file and the text and dropdown form fields. The maximum upload size is set to 50mb, using a context
parameter set in the web.xml file. An org.apache.commons.fileupload.FileItem object houses the submitted file and an input
stream is then created. The file name, file size and content type are then retrieved via methods available through the FileItem
object and are set as variables, along with the input stream and the non-file submitted form fields. These designated variables
are then submitted to the uploadDocument method in DocumentDAO. (Figure 37).
Figure 37(ACTION CLASS --SaveUploadDocumentAction)
DOCUMENTDAO METHOD  UPLOADDOCUMENT
This method accepts all of the action submitted file and non-file variables. It then calls the upload_document PL/SQL
procedure. An updated file list and the newly inserted BLOB locator are returned back to this method. An output stream is
then opened for the returned BLOB locator using the java.io.OutputStream object and the chunk, buffer and length are set.
The input stream then reads the binary file from the buffer and the file is uploaded to the database. In this example, since
Weblogic 8.1 is being used, the recommended casting of weblogic.jdbc.vendor.oracle.OracleThinBlob is executed in order for
the streaming to work with the related JDBC driver. This casting may be different depending on the Java server and the
JDBC driver that you are using (Figure 38).
22 Paper #604
eBusiness & Application Development
Figure 38(DOCUMENTDAO – uploadDocument Method)
PKG_DMS METHOD  UPLOAD_DOCUMENT
This procedure first inserts a record into the DOCUMENTS table, with an empty BLOB (BLOB locator). Next it inserts a
record into the DOCUMENTDETAILS table, which includes all of the descriptive information about the binary file that is
being uploaded. The procedure then returns a ref cursor with an updated document list as well as the BLOB locator, which is
used by the DAO method to finish the process of uploading the binary data into the database (Figure 39).
23 Paper #604
eBusiness & Application Development
Figure 39(PKG_DMS – upload_document Procedure)
JSP VIEW  VIEWDOCUMENTLIST.JSP
This view displays the updated document list to the client’s browser, which was set as a request attribute by the DAO method
(Figure 40).
24 Paper #604
eBusiness & Application Development
Figure 40(VIEW – viewDocumentList.jsp)
DELETING AN UPLOADED DOCUMENT
Deleting an uploaded document is accomplished by clicking the delete hyperlink, while viewing a document listing. Once the
delete hyperlink is clicked, the related database record is permanently removed from the DOCUMENTDETAILS table and
then from the DOCUMENTS table (Figure 41).
Figure 41(myDMS DELETE Hyperlink)
ACTION CLASS  SAVEDELETEDOCUMENTACTION
This class is processed by the controller and executes the deleteDocument method within DocumentDAO to delete the related
document from the database and to then display an updated document list to the client’s browser. (Figure 42)
Figure 42(ACTION CLASS --SaveDeleteDocumentAction)
DOCUMENTDAO METHOD  DELETEDOCUMENT
This method executes the delete_document PL/SQL procedure and receives a ref cursor back which is used to set the
DocumentVO object with the newly updated document list, which is then displayed on the resulting JSP view. (Figure 43)
25 Paper #604
eBusiness & Application Development
Figure 43(DOCUMENTDAO – deleteDocument Method)
PKG_DMS METHOD  DELETE_DOCUMENT
This procedure deletes the related record from the DOCUMENTDETAILS and DOCUMENTS tables and then returns a ref
cursor as an out parameter back to the deleteDocument method in DocumentDAO. DocumentDAO then uses the
DocumentVO object to set the newly updated document list as a request attribute, which is then displayed on the resulting
JSP view (Figure 44).
Figure 44(PKG_DMS – delete_document Procedure)
JSP VIEW  VIEWDOCUMENTLIST.JSP
This view displays the updated document list, which was set as a request attribute by the DAO method (Figure 45).
Figure 45(VIEW – viewDocumentList.jsp)
WEB APPLICATION DEPLOYMENT FOR TESTING
There are 4 main steps to deploying myDMS in your test environment.
26 Paper #604
eBusiness & Application Development
1.) Create a JDBC Connection Pool on your Java server, using the MYDMS_USER as the database user. This procedure
varies depending on the Java server that you use.
2.) Create a JNDI Datasource on your Java server, pointing to the Connection Pool set up in step 1.). This procedure varies
depending on the Java server that you use.
3.) Reference the JNDI Datasource Name that was set up in step 2.) in the context parameter called "dataSource" within the
web.xml file.
4.) Deploy the mydms folder on your Java server as a web application. This procedure varies depending on the Java server
that you use.
SUGGESTIONS
• Be Consistent – When naming tables, PL/SQL packages, procedures, java classes, be consistent with your naming
convention throughout the application.
• Take Your Environment into Account – Modify your application and database for your environment. No one
setting, size, JDBC driver, etc. will work for every environment, no one knows your environment like you..
• Test everything as much as possible. The weirdest things may pop up, just when you think everything is working!
WHERE TO GET THE MYDMS SCRIPTS, JAVA FILES AND WEB ARCHIVE
The complete zip file with all of the myDMS scripts, java classes, etc. can be downloaded at
https://eclouddesk.com/Client/Document/DownloadFile?uploadID=95
MY CONTACT INFORMATION
Mary Wagner, maryx.wagner@state.de.us. Please contact me if you have any questions or encounter any problems with the
download or its contents.
ADDITIONAL RESOURCES
• Oracle 9i Application Developer’s Guide – Large Objects (LOBs)
• Oracle 9i JDBC Developer’s Guide and Reference – Working with LOBs and BFILEs (Chapter 8)
• Oracle 9i Supplied PL/SQL Packages and Types Reference – DBMS_LOB (Chapter 23)
• http://asktom.oracle.com
• http://java.sun.com
• http://jakarta.apache.org (tomcat information and downloads)
• http://struts.apache.org (struts information and downloads)
• http://e-docs.bea.com/wls/docs81/jdbc/
• http://www.jetbrains.com (intellij idea)
• Expert Oracle One on One – Tom Kyte
• Effective Oracle By Design – Tom Kyte
• Mastering Oracle PL/SQL – Connor MacDonald
27 Paper #604
eBusiness & Application Development
• Sun Certified Web Component Developer for J2EE – Sam Dalton, Dan Jepp
• Professional Java Servlets 2.3 – John Bell, et al
28 Paper #604

More Related Content

DOCX
Microsoft access
babyparul
 
PPTX
Ms Access
Swati Sinha
 
PDF
L6-information-systems
smkengkilili2011
 
PDF
Oracle developer interview questions(entry level)
Naveen P
 
PDF
Workload Management with MicroStrategy Software and IBM DB2 9.5
BiBoard.Org
 
PDF
Xml transformation-doc
Amit Sharma
 
PDF
Informatica log files
Amit Sharma
 
PDF
เอกสาร แนวทาง การอินติเกรท Mac OS X เข้ากับ ระบบ Active Directory อย่างไร Bes...
Tũi Wichets
 
Microsoft access
babyparul
 
Ms Access
Swati Sinha
 
L6-information-systems
smkengkilili2011
 
Oracle developer interview questions(entry level)
Naveen P
 
Workload Management with MicroStrategy Software and IBM DB2 9.5
BiBoard.Org
 
Xml transformation-doc
Amit Sharma
 
Informatica log files
Amit Sharma
 
เอกสาร แนวทาง การอินติเกรท Mac OS X เข้ากับ ระบบ Active Directory อย่างไร Bes...
Tũi Wichets
 

What's hot (18)

PPTX
John Burkholder: Disaster Recovery in SharePoint 2010
SharePoint Saturday NY
 
PPT
Docs4Lawyers Functional Guide v1.2
Docs4Lawyers
 
PDF
Ax
csrikanthc
 
PDF
Oracle SQL Part1
Gurpreet singh
 
PPT
Easy Learning Presentation Moss 2007 Usman
Usman Zafar Malik
 
DOCX
OBIEE publisher with Report creation - Tutorial
onlinetrainingplacements
 
PPTX
Ms access
Amrita University
 
DOCX
Application andmulti servermanagementdba-introwhitepaper
Klaudiia Jacome
 
PPTX
12363 database certification
Universitas Bina Darma Palembang
 
PDF
Tutorial%20-%20Content%20Management%20System
tutorialsruby
 
PDF
BI Publisher Data model design document
adivasoft
 
PDF
Web services connector
Jane Kitabayashi
 
PDF
Data upload from flat file to business intelligence 7.0 system
Bhaskar Reddy
 
PDF
PLSQL Standards and Best Practices
Alwyn D'Souza
 
PDF
Office 365 Local File Share Synchronization - Issues Solved.
Layer2
 
PDF
Business Intelligence Technology Presentation
John Paredes
 
DOCX
Introduction to Libraries in SharePoint 2010 - EPC Group
EPC Group
 
PPT
Informatica Power Center - Workflow Manager
ZaranTech LLC
 
John Burkholder: Disaster Recovery in SharePoint 2010
SharePoint Saturday NY
 
Docs4Lawyers Functional Guide v1.2
Docs4Lawyers
 
Oracle SQL Part1
Gurpreet singh
 
Easy Learning Presentation Moss 2007 Usman
Usman Zafar Malik
 
OBIEE publisher with Report creation - Tutorial
onlinetrainingplacements
 
Application andmulti servermanagementdba-introwhitepaper
Klaudiia Jacome
 
12363 database certification
Universitas Bina Darma Palembang
 
Tutorial%20-%20Content%20Management%20System
tutorialsruby
 
BI Publisher Data model design document
adivasoft
 
Web services connector
Jane Kitabayashi
 
Data upload from flat file to business intelligence 7.0 system
Bhaskar Reddy
 
PLSQL Standards and Best Practices
Alwyn D'Souza
 
Office 365 Local File Share Synchronization - Issues Solved.
Layer2
 
Business Intelligence Technology Presentation
John Paredes
 
Introduction to Libraries in SharePoint 2010 - EPC Group
EPC Group
 
Informatica Power Center - Workflow Manager
ZaranTech LLC
 
Ad

Similar to 2005_604_Wagner_ppr (20)

PPTX
Introduction to ms access
vinothinisureshbabu
 
PDF
Operate Database Application UC info sheet.pdf
RemadanMohammed
 
PDF
Data Base
Susan Tullis
 
DOCX
IP PROJECT FILE
Shubham5Oct
 
PPTX
Introduction to database with ms access.hetvii
07HetviBhagat
 
PPTX
Introduction to database with ms access(DBMS)
07HetviBhagat
 
PPTX
Components and Advantages of DBMS
Shubham Joon
 
PPTX
Database fundamentals
Then Murugeshwari
 
PPTX
HRIS UNIT 2 2021.pptx
Dr. V. Karthiga Rajasekaran
 
DOCX
Database Management Systems (Mcom Ecommerce)
Rupen Parte
 
PPTX
DATABASE ADMINSTRATION
Nusrat Gulbarga
 
PPT
Chapter 5 data processing
UMaine
 
PPT
Uses of dbms
MISY
 
PDF
DBT PU BI Lab Manual for ETL Exercise.pdf
JanakiramanS13
 
PPT
Chap1-Introduction to database systems.ppt
LisaMalar
 
PDF
Access 2003 tutorial 3
catacata1976
 
PPTX
Dbms unit i
Arnav Chowdhury
 
PPTX
Lecture 1-Introduction to Database Management Systems.pptx
dude100099
 
Introduction to ms access
vinothinisureshbabu
 
Operate Database Application UC info sheet.pdf
RemadanMohammed
 
Data Base
Susan Tullis
 
IP PROJECT FILE
Shubham5Oct
 
Introduction to database with ms access.hetvii
07HetviBhagat
 
Introduction to database with ms access(DBMS)
07HetviBhagat
 
Components and Advantages of DBMS
Shubham Joon
 
Database fundamentals
Then Murugeshwari
 
HRIS UNIT 2 2021.pptx
Dr. V. Karthiga Rajasekaran
 
Database Management Systems (Mcom Ecommerce)
Rupen Parte
 
DATABASE ADMINSTRATION
Nusrat Gulbarga
 
Chapter 5 data processing
UMaine
 
Uses of dbms
MISY
 
DBT PU BI Lab Manual for ETL Exercise.pdf
JanakiramanS13
 
Chap1-Introduction to database systems.ppt
LisaMalar
 
Access 2003 tutorial 3
catacata1976
 
Dbms unit i
Arnav Chowdhury
 
Lecture 1-Introduction to Database Management Systems.pptx
dude100099
 
Ad

2005_604_Wagner_ppr

  • 1. eBusiness & Application Development UUSINGSING OORACLERACLE PPLL/SQL/SQL ANDAND JDBCJDBC TOTO MMANAGEANAGE FFILEILE UUPLOADSPLOADS WWITHINITHIN TTHEHE DDATABASEATABASE - A H- A HANDSANDS--ONON EEXAMPLEXAMPLE Mary Wagner, Delaware Department of Transportation WHAT ARE BLOBS? A BLOB is an Oracle data type that can be used to store binary data within an Oracle database. The term BLOB is an abbreviation for Binary Large Object and is a type of internal Large Object (LOB). An internal LOB is stored within the database, whereas an external LOB is stored outside of the database (i.e. BFILE). Many different types of binary files, including spreadsheets, word processor documents, images and other files can be stored within the database, using the BLOB data type. WHY USE THEM? Storing binary files within the database has many advantages over storing them within a server’s operating system. REMOVES FILE SYSTEM / SERVER DEPENDENCE If you store binary files inside the database, you no longer have to depend on your server administrator to manage access to the server or files. You don’t have to worry about files getting accidentally deleted or other server security issues. FILES ARE BACKED UP VIA DATABASE BACKUPS If you store binary files inside the database, then they will be backed up as part of the database when doing your regular database backups and exports. FILES ARE MORE SECURE If you store binary files inside the database, then security and access to the files can now be managed within the database. There is now more than one level of security (server OS). In other words, a user also needs database access and access to the database object where the files reside in order to access the files. FILES RECOVERABILITY IS HIGHER If you store binary files inside the database, then they are recoverable just like other data that is stored within the database. For example, when a file is uploaded to the database, it is part of an Oracle transaction and can be recovered, in the event of a media failure, just like any other type of data stored in an Oracle database. AN EXAMPLE - MY DOCUMENT MANAGEMENT SYSTEM (MYDMS) OVERVIEW myDMS is a small java web application used for managing and viewing documents (binary files) by topic. The maximum file upload size for this application is 50mb. The application uses JDBC and PL/SQL to upload, view and delete binary files from within an Oracle 9i database. Within the application, topics are used to categorize the uploaded documents. Topics can be added, modified and deleted. The application uses an Oracle 9i database to house the data and BEA Weblogic 8.1 as the Java Application Server. A JDBC connection pool and JNDI datasource are implemented within the Weblogic server instance. The user interface is written using the Java Model – View – Controller (MVC) architecture. There is a controller and process request servlet that handle the flow and process designated action classes, which are related to each task that can be completed within the application. The action classes call methods in the Data Access Object (DAO) classes. These DAO 1 Paper #604
  • 2. eBusiness & Application Development methods call the PL/SQL procedures that complete all of the related database transactions from within the database. Java Server Pages are used for the various user interface views and call getter methods in the related Value Object (VO) classes, which are set within the executed DAO methods. FUNCTIONALITY AND RELATED SCREENS Screenshots and brief explanations of the functionality of myDMS are displayed below. The detailed explanations of each phase of developing the application will then follow. LOGGING IN There are 2 initial users in the myDMS application. To test the application functionality, either of these users can be used to log into the system (Figure 1): • MANAGER – this user can view, upload and delete documents as well as view, edit and delete topics. • USER – this user can view and upload documents and view and add topics, but cannot delete documents or edit or delete topics. Figure 1 (myDMS - Log In Screen) VIEW DOCUMENT LIST Once logged in, a current list of documents is displayed (Figure 2). Figure 2 (myDMS - View Document List) VIEW A DOCUMENT While viewing the document list, the “VIEW” link can be clicked to view the actual binary file representing the document. This will retrieve the BLOB from the database and display it in it’s originally uploaded file type on the screen (Figure 3). 2 Paper #604
  • 3. eBusiness & Application Development Figure 3 (myDMS – View a Document) UPLOAD A NEW DOCUMENT A new document can be uploaded by clicking the “UPLOAD NEW DOCUMENT” link, while viewing the document list. After clicking the link, the upload form is displayed and once completed and submitted, the file and related data is saved to the database. The file is saved as a BLOB within the oracle database (Figure 4). Figure 4 (myDMS – Upload a New Document) DELETE A DOCUMENT If the logged in user is the MANAGER user, then the “DELETE” link can be clicked on to delete the related document from the database (Figure 5). Figure 5 (myDMS – Delete a Document) 3 Paper #604
  • 4. eBusiness & Application Development VIEW TOPIC LIST The “TOPIC LIST” link can be clicked on to view a list of topics that can be assigned to documents when they are uploaded (Figure 6). Figure 6 (myDMS - View Topic List) ADD A NEW TOPIC The “ADD NEW TOPIC” link can be clicked to add a new topic to the database. The new topic will display in the topic dropdown list, which displays on the “UPLOAD NEW DOCUMENT” form (Figure 7). Figure 7 (myDMS – Add a New Topic) DELETE A TOPIC The “DELETE” link can be clicked to delete the related topic. The deleted topic will no longer appear in the topic list or in the topic dropdown list on the “UPLOAD NEW DOCUMENT” form (Figure 8). Figure 8 (myDMS – Delete a Topic) EDIT A TOPIC The “EDIT” link can be clicked to edit the related topic. The updated topic will then be displayed in the topic list and in the topic dropdown list on the “UPLOAD NEW DOCUMENT” form (Figure 9). 4 Paper #604
  • 5. eBusiness & Application Development Figure 9 (myDMS – Edit a Topic) MYDMS - PHASE I. CREATING DATABASE TABLESPACES, USERS, TABLES / SETTING UP TABLESPACES There are 2 tablespaces that house the myDMS data, MYDMS_DATA and MYDMS_BLOB. MYDMS_DATA The MYDMS_DATA tablespace houses the NON-BLOB application data, including Document Details, Topics and User information. Below are the SQL PLUS commands that can be run to create this tablespace (Figure 10). Figure 10 (MYDMS_DATA tablespace) --create tablespace CREATE TABLESPACE MYDMS_DATA LOGGING DATAFILE 'C:ORACLEORADATAMW92MYDMS_DATA01.DBF' SIZE 10304K REUSE EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO MYDMS_BLOB The MYDMS_BLOB tablespace houses the DOCUMENTS, which has the BLOB column, containing the binary files that are uploaded. Below are the SQL PLUS commands that can be run to create this tablespace (Figure 11). 5 Paper #604
  • 6. eBusiness & Application Development Figure 11(MYDMS_BLOB tablespace) --create tablespace CREATE TABLESPACE MYDMS_BLOB LOGGING DATAFILE 'C:ORACLEORADATAMW92MYDMS_BLOB01.DBF' SIZE 51264K EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO; USERS There are 2 database users that support the myDMS application, the schema owner, MYDMS, and the application user, MYDMS_USER. MYDMS The MYDMS account is the schema owner for the application. This user houses all of the tables, PL/SQL packages and other database objects that are called by the Java user interface (Figure 12). Figure 12(MYDMS Schema Account) --create user CREATE USER MYDMS IDENTIFIED BY MYDMS DEFAULT TABLESPACE MYDMS_DATA TEMPORARY TABLESPACE TEMP QUOTA UNLIMITED ON MYDMS_BLOB QUOTA UNLIMITED ON MYDMS_DATA; --grant rights GRANT CONNECT TO MYDMS; GRANT CREATE PROCEDURE TO MYDMS; GRANT CREATE TRIGGER TO MYDMS; MYDMS_USER The MYDMS_USER account is the application end user account and is used by the JDBC connection pool. All data access within the application takes place through PL/SQL packages within the MYDMS schema. The execute privilege is granted to MYDMS_USER on the required PL/SQL packages only. The MYDMS_USER account also has a logon trigger that sets the current schema to MYDMS, whenever the MYDMS_USER account connects to the database. There are no synonyms currently being used within the application (Figure 13). Figure 13(MYDMS_USER Database Account) 6 Paper #604
  • 7. eBusiness & Application Development --create user CREATE USER MYDMS_USER IDENTIFIED BY MYDMS_USER DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TEMP; GRANT CONNECT TO MYDMS_USER; --create logon trigger CREATE OR REPLACE TRIGGER MYDMS_USER.TRG_LOGON_SET_SCHEMA AFTER LOGON ON MYDMS_USER.SCHEMA BEGIN EXECUTE IMMEDIATE 'ALTER SESSION SET CURRENT_SCHEMA=MYDMS'; END TRG_LOGON_SET_SCHEMA; / NAVIGATION AND SECURITY OBJECTS After the tablespaces and users are created, some system related tables and objects need to be created. These objects are used by the application for navigation flow, access and login verification. TABLES • ACTIONS – Houses meta data related to action class and the resulting success and failure JSP views. • USERTYPE – Houses system user types, which are assigned to each user account and used to manage user access to the application actions. • USERS – Houses system user account information • USERACCESS – Controls user access to specific application actions The below script, which is included with the download script and web archive files, will create the required tables. @create_tables_action_and_user.sql PL/SQL PACKAGE – PKG_MVC • PKG_MVC – Houses procedures and functions related to determining the next JSP view, verifying whether the logged in user has access to the requested action and verifying usernames and passwords when users log into the system. There are 3 procedures – get_action_info, get_password_hash and verify_user. (Figure 14). 7 Paper #604
  • 8. eBusiness & Application Development Figure 14(PKG_MVC Package) The below script, which is included with the download script and web archive files, will create the PKG_MVC package. @create_package_mvc.sql APPLICATION TABLES There are 3 main application tables, used to store document information and topics. These tables are named DOCUMENTS, TOPICS AND DOCUMENTDETAILS. DOCUMENTS (THE BLOB TABLE) The documents table houses the binary file (BLOB column) which is saved to the database when the “UPLOAD NEW DOCUMENT” form is submitted. This table is assigned to the MYDMS_BLOB tablespace. The BLOB column within the table is called BINARYFILE. BLOB columns have unique settings that are further discussed below. (Figure 15). Figure 15(DOCUMENTS Table) 8 Paper #604
  • 9. eBusiness & Application Development INITIALIZATION OF LOB In order to access the contents of a LOB column, a LOB locator is used by Oracle. If a null value is stored in a LOB column, the locator is not stored in the row, instead the null value is stored in the row. To remedy this, the LOB column is initialized. To accommodate this requirement in myDMS, the default value of the BINARYFILE column is set to EMPTY_BLOB(). This will allow the BLOB column to be initialized upon insertion and then we will be able to return the newly inserted empty blob locator and write the uploaded binary data to the BINARYFILE column when the “UPLOAD NEW DOCUMENT” form is submitted. If the UPLOAD form within myDMS was not going to always be inserting a BLOB, upon submission, I may want to have null values allowed within the BLOB column. Since this isn’t the case with this application, however, I am initializing the column with every insert. ENABLE LOB STORAGE IN ROW (INLINE STORAGE) For this example, the default setting of enabling LOB storage in row is being accepted (also known as inline storage). By enabling inline storage, if the BLOB length is less than 4mb, it’s contents will be stored within the table row. If the BLOB length is more than 4 mb, then the contents will be stored in the designated tablespace, however, the LOB locator will still be stored within the table row. LOB TABLESPACE For this example, we have created a separate tablespace, called MYDMS_BLOB, to house BLOB contents in each row that are larger than 4mb and therefore, cannot be stored within the table row. By storing the larger BLOBs in their own tablespace, we will be able to keep them separate from other data and also be able to monitor the growth, as it relates to the binary files, themselves. CHUNK SIZE In this example, we are accepting the default chunk size of 8192 bytes, which is the block size of our database. Our files are all going to be fairly small, nothing over 50mb, so this size should be sufficient. LOB CACHE In this example, we are accepting the default of off for the LOB cache. In our example, the same documents are not going to be viewed several times a day by several different useres, but only infrequently, therefore, they do not need to be cached. If you choose to cache your LOB, make sure to adjust the buffer cache settings appropriately. The below commands can be run in SQL PLUS as the MYDMS user to create the DOCUMENTS table and it’s related objects and to insert sample records. --create table CREATE TABLE DOCUMENTS ( DOCUMENTID NUMBER(10) NOT NULL, BINARYFILE BLOB DEFAULT EMPTY_BLOB() NOT NULL, DATESTAMP DATE DEFAULT SYSDATE NOT NULL, CONSTRAINT PK_DOCUMENTS_DOCUMENTID PRIMARY KEY(DOCUMENTID)) TABLESPACE MYDMS_BLOB; --create sequence to populate primary key 9 Paper #604
  • 10. eBusiness & Application Development CREATE SEQUENCE SEQ_DOCUMENTS_DOCUMENTID; TOPICS (NO BLOBS) The topics table houses a list of document topics that can be used to categorize a document when uploading it through the application. The below commands can be run in SQL PLUS as the MYDMS user to create the TOPICS table and it’s related objects and to insert sample records (Figure 16). Figure 16(TOPICS Table) --create table CREATE TABLE TOPICS ( TOPICID NUMBER(2) NOT NULL, TOPICNAME VARCHAR2(128) NOT NULL, USERID NUMBER(3) NOT NULL, DATESTAMP DATE DEFAULT SYSDATE NOT NULL, CONSTRAINT FK_TOPICS_USERID FOREIGN KEY(USERID) REFERENCES USERS(USERID), CONSTRAINT PK_TOPICS_TOPICID PRIMARY KEY(TOPICID), CONSTRAINT UN_TOPICS_TOPICNAME UNIQUE(TOPICNAME)) TABLESPACE MYDMS_DATA; --create additional index CREATE INDEX FK_TOPICS_USERID ON TOPICS(USERID); --create sequence to populate primary key CREATE SEQUENCE SEQ_TOPICS_TOPICID; --create trigger to automatically update datestamp when record is modified CREATE OR REPLACE TRIGGER TRG_TOPICS_DATESTAMP BEFORE UPDATE ON TOPICS FOR EACH ROW BEGIN :new.DATESTAMP := SYSDATE; END TRG_TOPICS_DATESTAMP; / --insert sample records INSERT INTO TOPICS (TOPICID, TOPICNAME, USERID) VALUES (0, 'NONE', 1); INSERT INTO TOPICS (TOPICID, TOPICNAME, USERID) VALUES (SEQ_TOPICS_TOPICID.NEXTVAL, 'DISASTER RECOVERY', 1); 10 Paper #604
  • 11. eBusiness & Application Development INSERT INTO TOPICS (TOPICID, TOPICNAME, USERID) VALUES (SEQ_TOPICS_TOPICID.NEXTVAL, 'STANDARD OPERATING PROCEDURES', 1); INSERT INTO TOPICS (TOPICID, TOPICNAME, USERID) VALUES (SEQ_TOPICS_TOPICID.NEXTVAL, 'SERVICE LEVEL AGREEMENTS', 1); COMMIT; DOCUMENTDETAILS (NO BLOBS) The documentdetails table houses all of the non-blob data regarding uploaded documents, including a title, description, filename, file size and file content type. The below commands can be run in SQL PLUS as the MYDMS user to create the DOCUMENTDETAILS table and it’s related objects (Figure 17). Figure 17(DOCUMENTDETAILS Table) --create table CREATE TABLE DOCUMENTDETAILS ( DOCUMENTDETAILID NUMBER(10) NOT NULL, TOPICID NUMBER(2) NOT NULL, DOCUMENTID NUMBER(10) NOT NULL, TITLE VARCHAR2(512) NOT NULL, DESCRIPTION VARCHAR2(1024 byte) NOT NULL, FILENAME VARCHAR2(256) NOT NULL, FILESIZE NUMBER(9) NOT NULL, CONTENTTYPE VARCHAR2(128) NOT NULL, USERID NUMBER(3) NOT NULL, DATESTAMP DATE DEFAULT SYSDATE NOT NULL, CONSTRAINT FK_DOCUMENTDETAILS_DOCUMENTID FOREIGN KEY(DOCUMENTID) REFERENCES DOCUMENTS(DOCUMENTID), CONSTRAINT FK_DOCUMENTDETAILS_TOPICID FOREIGN KEY(TOPICID) REFERENCES TOPICS(TOPICID), CONSTRAINT FK_DOCUMENTDETAILS_USERID FOREIGN KEY(USERID) REFERENCES USERS(USERID), CONSTRAINT PK_DOCUMENTDETAILS_DDID PRIMARY KEY(DOCUMENTDETAILID), CONSTRAINT UN_DOCUMENTDETAILS_FN_TID UNIQUE(FILENAME, TOPICID)) TABLESPACE MYDMS_DATA; --create additional indexes CREATE INDEX FK_DOCUMENTDETAILS_DOCUMENTID ON DOCUMENTDETAILS(DOCUMENTID); CREATE INDEX FK_DOCUMENTDETAILS_TOPICID ON DOCUMENTDETAILS(TOPICID); 11 Paper #604
  • 12. eBusiness & Application Development CREATE INDEX FK_DOCUMENTDETAILS_USERID ON DOCUMENTDETAILS(USERID); --create sequence to populate primary key CREATE SEQUENCE SEQ_DOCUMENTDETAILS_DDID; --create trigger to automatically update datestamp when record is modified CREATE OR REPLACE TRIGGER TRG_DOCUMENTDETAILS_DATESTAMP BEFORE UPDATE ON DOCUMENTDETAILS FOR EACH ROW BEGIN :new.DATESTAMP := SYSDATE; END TRG_DOCUMENTDETAILS_DATESTAMP; / MYDMS - PHASE 2. PL/SQL API DATABASE API – PL/SQL PACKAGE (PKG_DMS) All database related transactions are completed through functions and procedures within a PL/SQL package, called PKG_DMS. This package includes procedures to upload documents, delete documents, view a document listing, add a topic, edit a topic, delete a topic and view a topic listing. It also contains functions and global variables used within these procedures. The MYDMS_USER account is granted execute on this package. Below are details related to just the Document / BLOB related procedures that are housed within the PKG_DMS package. VIEW_DOCUMENT_LIST This procedure returns a ref cursor, which is used by the related Java Data Access Object to display a current list of uploaded documents. The DOCUMENTDETAILS table is queried and the resulting data is stored in the ref cursor and returned as an out parameter. The DOCUMENTS table (and the related BLOB column) are not touched for this query, as the BLOB is not needed to display a listing of documents. UPLOAD_DOCUMENT This procedure takes care of inserting an initial record into the DOCUMENTS table, inserting a record into the DOCUMENTDETAILS table, returning the LOB locator to Java for use in streaming the uploaded document into the database and returning an updated document list, via a ref cursor, to the calling Java Data Access Object. VIEW_DOCUMENT This procedure is for displaying the BLOB within the client’s browser. The BLOB column is returned through a ref cursor, to the related Java Data Access Object. Java streaming is then used to display the file via the web browser. DELETE_DOCUMENT This procedure is for deleting the related uploaded file from the database and returning an updated document list to the related Java Data Access Object for display to the user. Related records from the DOCUMENTS and DOCUMENTDETAILS tables are removed from the database for the related uploaded file. 12 Paper #604
  • 13. eBusiness & Application Development MYDMS - PHASE 3. CREATE JAVA OBJECTS MODEL – VIEW – CONTROLLER (MVC) ARCHITECTURE myDMS uses the Java MVC architecture-- • Model - Business / Value Object (VO) (also known as Java Bean) – Value objects are place holders for data that is displayed on JSP views. Value Objects have getter and setter methods. Data Access Objects call the setter methods to store the data that is retrieved from the database and JSP Views call the getter methods to display the stored data within the client’s browser. • View (also known as Java Server Page, JSP) - Views are the web pages that are displayed within the client’s browser. They could also be described as the user interface. These are the screens that the end user interfaces with to submit and retrieve information from the application. • Controller – The controller is a servlet and is responsible for the navigation of the web application. It routes to the application to the appropriate action and then is responsible for forwarding the user to the appropriate success or failure view (JSP). • Actions – Actions are Java classes that are called by the controller to complete specific tasks within the application. They execute the data access and other methods that make up the application. There is an action for each piece of functionality within the application. • Data Access Objects (DAO) – Data Access Objects contain all of the database access methods. The database access methods are responsible for handling any database related transactions, including inserting new records, updating existing records, deleting existing records and selecting a set of records to be displayed within the client’s browser. Below, I will discuss the Java objects related to the BLOB portion of the myDMS application. Although myDMS allows Topics to be added, edited and deleted, since these are non-BLOB tasks I’m not going to discuss the corresponding MVC objects for them, but only for the MVC objects for the Document / BLOB related tasks. VALUE OBJECTS (BLOB RELATED ONLY) DOCUMENTVO This java bean is the main bean for the application and includes the getter and setter methods that are used to get and set data to be displayed on the resulting JSP views (Figure 18). Figure 18(DOCUMENTVO Value Object / Java Bean) 13 Paper #604
  • 14. eBusiness & Application Development VIEWS – JAVA SERVER PAGES(BLOB RELATED ONLY) VIEWDOCUMENTLIST.JSP This view displays the current list of documents that have been uploaded to the database, within the client’s browser. VIEWDOCUMENTSERVLET This view is really a servlet, but is the designated success view for displaying a queried document (binary file) within the requesting client’s browser. FORMUPLOADDOCUMENT.JSP This view displays the form within the client’s browser that is used for uploading a new document into the database. SERVLETS CONTROLLERSERVLET This servlet controls the flow of the application. All actions (URLs with a .do extension) are routed through this servlet, which then processes the action request and returns the appropriate success or failure JSP view. The PROCESSREQUESTSERVLET This servlet is called by the Controller servlet and handles the guts of the requested action class processing. It instantiates the action and then determines whether the action was processed successfully. Once the result is determined, it then returns the appropriate JSP view to the Controller servlet. ACTION CLASSES (BLOB RELATED ONLY) VIEWDOCUMENTLISTACTION This action class calls the related DAO method to display a list of uploaded documents that are currently in the database. At this point, the BLOB is not touched at all, only the table which houses the details behind the uploaded file. This action queries only the DOCUMENTDETAILS table. VIEWDOCUMENTACTION This action class is responsible for displaying an uploaded binary file (BLOB) within the client’s browser. Request attributes for the queried document, including the file name and content type are set by this action. The related DAO method is called to retrieve the BLOB locator and then stream the binary file to the client’s browser. This action queries only the DOCUMENTS table. FORMUPLOADDOCUMENTACTION This action class calls the related DAO method to display the form for uploading a new document. There is a drop down list of Topics that is displayed on this form, which is retrieved and set via this action and the related DAO method. This action queries the TOPICS table. SAVEUPLOADDOCUMENTACTION This action class calls the related DAO method to save the submitted data from the upload form to the database. The initial BLOB locator is returned to the DAO method and then Java streaming is used to upload the binary data to the database. This action inserts into the DOCUMENTS and DOCUMENTDETAILS tables and then queries the DOCUMENTDETAILS table. 14 Paper #604
  • 15. eBusiness & Application Development SAVEDELETEDOCUMENTACTION This action class calls the related DAO method to delete the related document from the database and then displays an updated document list to the client’s browser. This action deletes from the DOCUMENTS and DOCUMENTSDETAILS tables and queries the DOCUMENTDETAILS table. DATA ACCESS OBJECTS (BLOB RELATED ONLY) BASEDAO This data access class includes database connectivity methods used by all DAO objects, including retrieving and releasing connections, closing statements and result sets, committing and rolling back transactions (Figure 19). Figure 19(BASEDAO Data Access Object) DOCUMENTDAO This data access class is the data access object that calls all of the PL/SQL procedures related to uploading, viewing and deleting documents in the database (Figure 20). Figure 20(DOCUMENTDAO Data Access Object) MYDMS - PHASE 4. PUTTING IT TOGETHER Now that we have the database objects and the Java objects defined, we can build the application, based on the myDMS BLOB related functionality that we have outlined at the beginning of the paper. The flow is the same for each piece of functionality. An ACTION class is processed which executes a DATA ACCESS OBJECT method within the DocumentDAO class, which in turn executes the related PL/SQL stored procedure within the PKG_DMS package. Data can be passed as out parameters back to the DocumentDAO class, which then can be processed or used to set the DocumentVO object as a request attribute. The resulting Java Server Page view then calls the DocumentVO getter methods to display data to the client’s browser. Below I will go over the pieces that make up the core DOCUMENT functionality of the myDMS application, including: • Viewing a Document Listing • Viewing a Binary Document File • Displaying the Upload Form 15 Paper #604
  • 16. eBusiness & Application Development • Saving the Upload Form to the Database • Deleting an Uploaded File from the Database The code snippets displayed below are the key pieces that make up each part of each illustrated function, however, the complete working code, including PL/SQL, Java and other files is available for download (see “Where to Get the myDMS scripts, Java files and Web Archive” section at the end of the paper). VIEWING A DOCUMENT LISTING The document listing is a listing of all of the uploaded documents that are in the DOCUMENTDETAILS table. The BLOB column, which is stored in the DOCUMENTS table, is not touched for this query, as we do not need to display the BLOB data at this point. The file size is calculated upon BLOB insertion and then stored as a number within the DOCUMENTDETAILS table, so that it does not have to be calculated every time that the Document List is viewed (Figure 21). Figure 21(myDMS DOCUMENT LIST hyperlink ACTION CLASS  VIEWDOCUMENTLISTACTION This class is processed by the controller and executes the viewDocumentList method within DocumentDAO (Figure 22). Figure 22(ACTION CLASS --ViewDocumentListAction) DOCUMENTDAO METHOD  VIEWDOCUMENTLIST This method executes the view_document_list PL/SQL procedure within the PKG_DMS package (Figure 23). Figure 23(DOCUMENTDAO – viewDocumentList Method) PKG_DMS METHOD  VIEW_DOCUMENT_LIST This procedure returns a ref cursor as an out parameter back to the viewDocumentList method in DocumentDAO. DocumentDAO then processes the result set to create a DocumentVO object and sets the object as a request attribute which the JSP view can then reference for displaying to the client’s browser (Figure 24). 16 Paper #604
  • 17. eBusiness & Application Development Figure 24(PKG_DMS – view_document_list Procedure) JSP VIEW  VIEWDOCUMENTLIST.JSP This view retrieves the document list, which was set as a request attribute by the DAO method, and then iterates through the list to display the document listing (Figure 25). Figure 25(VIEW – viewDocumentList.jsp) VIEWING A BINARY DOCUMENT FILE To view the actual binary file, while viewing the Document List, the view link can be clicked on. The queried document is then displayed within the client’s browser in its original uploaded file content type (Figure 26). Figure 26(myDMS VIEW DOCUMENT hyperlink ACTION CLASS  VIEWDOCUMENTACTION This class is processed by the controller and gets and sets file specific information, including the file name and the file content type as request attributes. These attributes are used by the ViewDocumentServlet to display the file within the client’s browser (Figure 27). 17 Paper #604
  • 18. eBusiness & Application Development Figure 27(ACTION CLASS --ViewDocumentAction) DOCUMENTDAO METHOD  VIEWDOCUMENT This method retrieves the BLOB from the database, using the view_document PL/SQL procedure and then uses Java streaming to display the file in the client’s browser. After the length of the file is determined, the java.io.InputStream object is used to read the file into the stream and the java.io.OutputStream is used to write the file to the screen, using the ViewDocumentServlet (Figure 28). Figure 28(DOCUMENTDAO – viewDocument Method) PKG_DMS METHOD  VIEW_DOCUMENT This procedure returns a ref cursor as an out parameter back to the viewDocument method in DocumentDAO. DocumentDAO then processes the BLOB data using Java streaming (Figure 29). 18 Paper #604
  • 19. eBusiness & Application Development Figure 29(PKG_DMS – view_document Procedure) VIEW  VIEWDOCUMENTSERVLET This view requests and then receives the BLOB data and then displays the binary file to the client’s browser, in the designated content type (Figure 30). Figure 30(VIEW – ViewDocumentServlet) DISPLAYING THE UPLOAD FORM To begin the file upload process, the upload new document link can be clicked. The upload form is then displayed (Figure 31). Figure 31(myDMS – UPLOAD NEW DOCUMENT Hyperlink ACTION CLASS  FORMUPLOADDOCUMENTACTION This class is processed by the controller and executes the viewTopicList method within TopicDAO. This method returns a list of Topics that are displayed within the Topic dropdown list on the resulting JSP view (upload form) (Figure 32). Figure 32(ACTION CLASS --FormUploadDocumentAction) 19 Paper #604
  • 20. eBusiness & Application Development DOCUMENTDAO METHOD  VIEWTOPICLIST This method retrieves a ref cursor from the database by calling the view_topic_list PL/SQL procedure and then sets the TopicVO java bean as a request attribute so that it can be referenced by the resulting JSP view for display on the form as a drop down list (Figure 33). Figure 33(DOCUMENTDAO – viewTopicList Method) PKG_DMS METHOD  VIEW_TOPIC_LIST This procedure returns a ref cursor as an out parameter back to the viewDocument method in DocumentDAO., which then sets the data in the TopicVO object, using the setter methods. The resulting JSP can then retrieve the data from the TopicVO object, for display, using the getter methods (Figure 34). Figure 34(PKG_DMS – view_topic_list Procedure) JSP VIEW  FORMUPLOADDOCUMENT.JSP This view retrieves the topic list from the VO, which was set as a request attribute by the DAO method, and then iterates through the list to display the topic dropdown list with the rest of the form. You will notice that the enctype within the form tags is set to multipart/form-data. This is because when the form is submitted, we will be submitting a file, in addition to regular form text boxes and dropdown fields (Figure 35). 20 Paper #604
  • 21. eBusiness & Application Development Figure 35(VIEW – formUploadDocument.jsp) SAVING THE UPLOAD FORM Once the upload document form is filled out, it can then be submitted by clicking the submit now button. This submits the upload to the database (Figure 36). Figure 36(myDMS – SUBMITTING UPLOAD FORM) 21 Paper #604
  • 22. eBusiness & Application Development ACTION CLASS  SAVEUPLOADDOCUMENTACTION This class is processed by the controller and executes the uploadDocument method within DocumentDAO. The FileItem, DiskFileUpload and FileUpload objects within the org.apache.commons.fileupload API are used to process the incoming html form with the attached file and the text and dropdown form fields. The maximum upload size is set to 50mb, using a context parameter set in the web.xml file. An org.apache.commons.fileupload.FileItem object houses the submitted file and an input stream is then created. The file name, file size and content type are then retrieved via methods available through the FileItem object and are set as variables, along with the input stream and the non-file submitted form fields. These designated variables are then submitted to the uploadDocument method in DocumentDAO. (Figure 37). Figure 37(ACTION CLASS --SaveUploadDocumentAction) DOCUMENTDAO METHOD  UPLOADDOCUMENT This method accepts all of the action submitted file and non-file variables. It then calls the upload_document PL/SQL procedure. An updated file list and the newly inserted BLOB locator are returned back to this method. An output stream is then opened for the returned BLOB locator using the java.io.OutputStream object and the chunk, buffer and length are set. The input stream then reads the binary file from the buffer and the file is uploaded to the database. In this example, since Weblogic 8.1 is being used, the recommended casting of weblogic.jdbc.vendor.oracle.OracleThinBlob is executed in order for the streaming to work with the related JDBC driver. This casting may be different depending on the Java server and the JDBC driver that you are using (Figure 38). 22 Paper #604
  • 23. eBusiness & Application Development Figure 38(DOCUMENTDAO – uploadDocument Method) PKG_DMS METHOD  UPLOAD_DOCUMENT This procedure first inserts a record into the DOCUMENTS table, with an empty BLOB (BLOB locator). Next it inserts a record into the DOCUMENTDETAILS table, which includes all of the descriptive information about the binary file that is being uploaded. The procedure then returns a ref cursor with an updated document list as well as the BLOB locator, which is used by the DAO method to finish the process of uploading the binary data into the database (Figure 39). 23 Paper #604
  • 24. eBusiness & Application Development Figure 39(PKG_DMS – upload_document Procedure) JSP VIEW  VIEWDOCUMENTLIST.JSP This view displays the updated document list to the client’s browser, which was set as a request attribute by the DAO method (Figure 40). 24 Paper #604
  • 25. eBusiness & Application Development Figure 40(VIEW – viewDocumentList.jsp) DELETING AN UPLOADED DOCUMENT Deleting an uploaded document is accomplished by clicking the delete hyperlink, while viewing a document listing. Once the delete hyperlink is clicked, the related database record is permanently removed from the DOCUMENTDETAILS table and then from the DOCUMENTS table (Figure 41). Figure 41(myDMS DELETE Hyperlink) ACTION CLASS  SAVEDELETEDOCUMENTACTION This class is processed by the controller and executes the deleteDocument method within DocumentDAO to delete the related document from the database and to then display an updated document list to the client’s browser. (Figure 42) Figure 42(ACTION CLASS --SaveDeleteDocumentAction) DOCUMENTDAO METHOD  DELETEDOCUMENT This method executes the delete_document PL/SQL procedure and receives a ref cursor back which is used to set the DocumentVO object with the newly updated document list, which is then displayed on the resulting JSP view. (Figure 43) 25 Paper #604
  • 26. eBusiness & Application Development Figure 43(DOCUMENTDAO – deleteDocument Method) PKG_DMS METHOD  DELETE_DOCUMENT This procedure deletes the related record from the DOCUMENTDETAILS and DOCUMENTS tables and then returns a ref cursor as an out parameter back to the deleteDocument method in DocumentDAO. DocumentDAO then uses the DocumentVO object to set the newly updated document list as a request attribute, which is then displayed on the resulting JSP view (Figure 44). Figure 44(PKG_DMS – delete_document Procedure) JSP VIEW  VIEWDOCUMENTLIST.JSP This view displays the updated document list, which was set as a request attribute by the DAO method (Figure 45). Figure 45(VIEW – viewDocumentList.jsp) WEB APPLICATION DEPLOYMENT FOR TESTING There are 4 main steps to deploying myDMS in your test environment. 26 Paper #604
  • 27. eBusiness & Application Development 1.) Create a JDBC Connection Pool on your Java server, using the MYDMS_USER as the database user. This procedure varies depending on the Java server that you use. 2.) Create a JNDI Datasource on your Java server, pointing to the Connection Pool set up in step 1.). This procedure varies depending on the Java server that you use. 3.) Reference the JNDI Datasource Name that was set up in step 2.) in the context parameter called "dataSource" within the web.xml file. 4.) Deploy the mydms folder on your Java server as a web application. This procedure varies depending on the Java server that you use. SUGGESTIONS • Be Consistent – When naming tables, PL/SQL packages, procedures, java classes, be consistent with your naming convention throughout the application. • Take Your Environment into Account – Modify your application and database for your environment. No one setting, size, JDBC driver, etc. will work for every environment, no one knows your environment like you.. • Test everything as much as possible. The weirdest things may pop up, just when you think everything is working! WHERE TO GET THE MYDMS SCRIPTS, JAVA FILES AND WEB ARCHIVE The complete zip file with all of the myDMS scripts, java classes, etc. can be downloaded at https://eclouddesk.com/Client/Document/DownloadFile?uploadID=95 MY CONTACT INFORMATION Mary Wagner, [email protected]. Please contact me if you have any questions or encounter any problems with the download or its contents. ADDITIONAL RESOURCES • Oracle 9i Application Developer’s Guide – Large Objects (LOBs) • Oracle 9i JDBC Developer’s Guide and Reference – Working with LOBs and BFILEs (Chapter 8) • Oracle 9i Supplied PL/SQL Packages and Types Reference – DBMS_LOB (Chapter 23) • http://asktom.oracle.com • http://java.sun.com • http://jakarta.apache.org (tomcat information and downloads) • http://struts.apache.org (struts information and downloads) • http://e-docs.bea.com/wls/docs81/jdbc/ • http://www.jetbrains.com (intellij idea) • Expert Oracle One on One – Tom Kyte • Effective Oracle By Design – Tom Kyte • Mastering Oracle PL/SQL – Connor MacDonald 27 Paper #604
  • 28. eBusiness & Application Development • Sun Certified Web Component Developer for J2EE – Sam Dalton, Dan Jepp • Professional Java Servlets 2.3 – John Bell, et al 28 Paper #604