




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An assignment for a database systems course where students are required to create a database, enforce constraints using oracle, and develop a java application that interacts with the database using jdbc. The assignment involves creating tables and views, enforcing constraints, and developing a java application that searches for words in multiple files and stores the data in a relational dbms.
Typology: Assignments
1 / 8
This page cannot be seen from the preview
Don't miss anything!





In this assignment, you will extend the functionality of Project 1 to find words in multiple files (kind of like Apple Spotlight or Google Desktop search). Also, you will store your word data in a Relational DBMS (Oracle), rather than in Java data structures. This project has two main goals:
The first part of the assignment is to create and initialize the tables and constraints in the database. You will use SQL*Plus scripts to create, initialize, and destroy your tables and constraints. All of the commands to create and initialize the database should be stored in a single file: DBINIT.txt. Below, we describe the required tables and constraints. You should use the basic constructs of CREATE TABLE (e.g., PRIMARY KEY, FOREIGN KEY, UNIQUE, and NOT NULL) as much as possible to enforce constraints. However, in some cases, you will find that you cannot enforce a constraint using these basic mechanisms. In these cases, you will need to create triggers to enforce the constraints. Your file should include commands to populate the database with the minimum amount of data necessary to satisfy the constraints. You may not create any tables, views, sequence variables, or stored procedures other than those listed below.
At a high level, the entities in your database will be users, files , and words. More specifically, you should use the CREATE command to create the following tables and views.
Your database must also enforce the following constraints. (Please note that these constraints should be enforced by the DBMS, rather than in the Java code you write for Part 2.)
You should write the SQL*Plus commands to destroy the database completely. They should drop all of the tables, views, triggers, etc. that were created by DBINIT.txt. You should put all of these commands in a single file, DBDELETE.txt. There is one easy test for this – Executing the commands in DBINIT.txt, followed by the commands in DBDELETE.txt (and repeating this process) should not give any errors.
on success and false on failure. But for some methods, an exception must be thrown to indicate an error.
We provide you a Makefile that contains the appropriate locations of the Jar files for Oracle’s JDBC driver and the Junit testing module. To compile the program, do: % make all To run the FileFinderTest’s main program, type: % make run To just see what commands are executed, without actually executing them, you can do % make – n all % make – n run The relevant jar files can be found at: /usr/lib64/oracle/10.2.0.3/client/lib64/ojdbc14.jar: Needed for all files. /afs/umich.edu/class/eecs484/public/junit-4.1.jar: Needed if you decide to extend FileFinderTest.java for doing the testing. This file relies on the junit package, which is provided by the jar file. More information on junit is available within Eclipse and at http://www.junit.org. You can also compile and develop your program, including using junit, outside Eclipse using the Makefile.
Each public method must provide “transactional” semantics. In other words, if it interacts with the database system and returns successfully, then all the lookups and updates on the database must commit as one transaction. If the method fails (e.g., SQL constraint violation), then none of the updates should commit. For this assignment, you must ensure the JDBC’s auto-commit mode for the connection is always ON outside the procedures. In other words, if we were to check the mode’s value in the main program at any time, we should find it on. However, within the procedures, you will need to turn auto-commit on and off to provide transactional semantics. For example, if you issue multiple SQL commands from one of the procedures, if you leave auto-commit on, it could happen that the first update commits, but the second fails (or that an intervening transaction occurs from another session).
You can put print statements in your code, as you wish, to help you debug, etc. (Though, please don’t use print statements as you only debugging tool! Eclipse has a nice debugging environment.) But when you are ready to submit the assignment, please remove any debugging print statements.
You will find it useful to use e.printStackTrace(), in the catch blocks for exceptions. That can help identify the problem line quickly. You will need to test your code (this requires significant effort). You do not have to submit tests in this project, but we encourage you to look at JUnit package for writing test cases. It is available within Eclipse. You can use SQL*Plus commands to check integrity constraints.
Finally, you should create a brief design document to accompany your group’s project (in a file named REPORT.pdf) that contains the following:
To summarize, you are expected to hand in the following material for this project:
1: Log on to a campus LINUX machine. 2: Create a new directory and call it "filefinder" (You should already have this directory, as it is the required name for the filefinder package.) 3: In this directory put the following files. Please leave out any other files (.class, etc.) from your submission.
sqlplus does not have command history like the UNIX or DOS shell. Keeping longer commands that you use frequently in a text file is a good idea. sqlplus commands are terminated by a semi-colon. If you don’t type the semi-colon, it will prompt you to enter the remaining command on the next lines, by showing line numbers 2, 3, etc. To change your Oracle password, start sqlplus and then type “password”. Follow the prompts to change the password.
By default, sqlplus does not commit transactions as you type. You either need to issue an explicit COMMIT or quit the session normally for the transactions to be committed. You can also rollback everything since the last commit by issuing the ROLLBACK command. Unfortunately, this means that you can get strange lockup problems if you try to run multiple sqlplus sessions simultaneously. For example, suppose you connect to CAEN via SSH, run sqlplus, and make some updates without issuing a COMMIT. If the SSH connection is dropped, the Oracle server does not always know the sqlplus session is aborted. The commands you issued may still hold locks on tables, which will prevent a new sqlplus session from updating the tables. If this happens to you, you can wait a few hours until the old sqlplus session (and its locks) times out. Be patient in that case, or switch to your partner’s account. If you are frequently accessing the CAEN machines remotely, and are prone to dropped SSH connections, then issuing the following command at the beginning of you session may prevent many lockouts: SQL> SET AUTOCOMMIT ON; The above causes each transaction to commit as soon as it is typed. A commit should cause the database to release any locks. If the AUTOCOMMIT is not on, typing SQL> COMMIT will also release the locks and allow parallel sessions to proceed.
A common problem encountered in this project is the following: You have a table A that references table B with a FOREIGN KEY / CASCADE constraint. In this case, deleting a tuple in table B with a trigger on table B produces a “mutating table” error. There are various ways to fix this. The simplest solution is to not cascade the original foreign key, but to use a trigger instead.
In some commercial DBMS systems, there is a feature allowing you to specify that a column should be incremented automatically for each new record. (This is useful, for example, for generating key values.)
In Oracle, you can accomplish this using a sequence variable and a trigger. When you declare the sequence variable, you can specify the initial start value, as well as amount it is incremented. For example, the following declares a sequence variable with initial value 1, and an increment value of 2. CREATE SEQUENCE myid INCREMENT BY 2 START WITH 1 You can access the next value in the sequence variable with a call to myid.NEXTVAL. Once you have defined your sequence variable, you should be able to create a trigger to populate the key field appropriately each time a new record is inserted.
You will soon discover that SQL is not entirely standard across vendors. You are likely to discover differences between what is supported by Oracle and what is described in the textbook. Nonetheless, you should be able to implement all constraints required for this project using supported features. Here are some examples of differences you might encounter:
Triggers can be used to enforce certain constraints, and errors can be handled via the built-in function RAISE_APPLICATION_ERROR. When this happens, the command that activated the trigger is aborted, and the effects of both the trigger and the triggering statement are rolled back. For example, the following trigger enforces the constraint that Students.age >= 18: CREATE TRIGGER CheckAge AFTER INSERT OR UPDATE OF age ON Students FOR EACH ROW BEGIN IF (:new.age < 18) THEN RAISE_APPLICATION_ERROR(-2000, ‘All students must be at least 18’); END IF; END; . RUN;