Homework 3
CS520, Fall 2010
Due: Thursday, October 21
Package all the source files of your project into a zip file using the zip Ant target you
developed in Homework 1, and
upload the zip file to CSNS.
Note that file
uploading will be disabled automatically after 11:59PM
of the due date, so please turn in your work on time.
[Reading]
- Hibernate Book (Java
Persistence with Hibernate)
- Chapter 1-6 (or corresponding chapters in Hibernate in Action).
You may skip anything related to XDoclet,
Annotation, JPA, and EJB.
- Hibernate
Documentation
- CSNS Source Code
- Model classes under src/csns/model.
- Hibernate mapping files under src/hbm.
[CSNS File Manager]
CSNS File Manager is a
new component of CSNS which you will develop in this quarter. An online file manager allows users to store and manage their
files online using a web browser. For functionality typically provided
by an online file manager, you can check out some commercial offerings
such as www.box.net.
[Model and Hibernate Mapping] (10pt)
Add the following property to the csns.model.User class:
- long diskQuota - each user will have a disk quota, which is the maximum number of bytes the user can upload to CSNS.
Add the following property to the csns.model.File class:
- boolean regular - files and folders created by the file manager
are considered regular, while files uploaded through
other means (e.g. homework submission, files attached to a forum post etc.) are
considered non-regular. File management operations such as
rename, copy, move, and so on, only apply to regular files and folders, and only
regular files are counted toward a user's disk quota.
Modify the Hibernate mapping files for User and File accordingly. Run the hbm2ddl Ant task to verify the mapping.
[Database Scripts] (15pt)
Modify db/csns-create.sql to reflect the changes to the data models.
Modify db/csns-test-insert.sql so that
- The disk quota for each user is 2000.
- user s0001 owns the following files and folders:
Folder1\
Folder2\
File1
File2
File3
File4
The sizes of the four files should be 100, 200, 300, and 400 bytes, respectively.
[Data Access] (25pt)
Add the declarations of the following methods to the interface csns.model.dao.FileDao and implement them in csns.model.dao.hibernate.FileDaoImpl:
- public List<File> getTopLevelFiles( User user ) - this method should return all the top level (i.e. with no parent) regular files and folders owned by the given user.
- public List<File> getTopLevelFolders( User user ) - this method should return only the top level regular folders owned by the given user.
- public List<File> listFolders( File folder ) - this method should return all the regular folders under the given folder.
- public long getDiskUsage( User user ) - this method should return the total size of the regular files owned by the given user.
[Testing] (10pt)
Add FileTest.java to the src/csns/test/
folder. The folder does not exist so you need to create it first.
Add filetest.xml to src/ folder. You need to modify filetest.xml so the the database URL, username, and password match your setup.
Modify build.xml to create a new target called filetest.
This target should run FileTest.java, and if everything works properly, you should see the following output:
Folder1
File4
Folder1
Folder2
1000
[Subversion]
Commit all the changes to your Subversion repository, and
create a tag called cs520-hw3.