org.activemath.webapp.notes.db
Class JDBCNotesDatabase

java.lang.Object
  extended by org.activemath.webapp.notes.db.NotesDatabase
      extended by org.activemath.webapp.notes.db.JDBCNotesDatabase

public class JDBCNotesDatabase
extends NotesDatabase

Notes Database using JDBC connectivity This implementation assumes that there will never be more notes stored than min(2^31-1, largest integer writable in database); it generates the primary keys as maximum over the rows in the database. It also assumes that the java.sql API cares for proper quoting itself, that is if PreparedStatement.setString is used, it is assumed that no exploits to the underlying SQL layer should be possible.

Version:
0.1

Field Summary
protected static Category log
          The logger for this class
 
Constructor Summary
JDBCNotesDatabase()
          standard constructor
JDBCNotesDatabase(String databaseURL, String databaseLogin, String databasePasswd)
           
 
Method Summary
 Note createNote(String user, boolean isPublic, String noteTitle, String noteContent, String contentId)
          creates a new note.
 void deleteNote(String user, int noteId)
          deletes note from the database
 Connection getConnection()
           
static NotesDatabase getInstance()
           
 String getStatus()
          only for debugging - returns a String containing a log of what has recently happened
 void init()
          initializes the database.
 Note retrieveNote(String user, int noteId)
          returns the indicated note from the database.
 Iterator selectNotes(String user)
           
 Iterator selectNotes(String user, String contentId)
          selects a group of notes from the database selectNotes selects the notes which belong to the user and refer to the topic indicated by contentId
 void storeNote(String user, Note aNote)
          stores the given note in the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static Category log
The logger for this class

Constructor Detail

JDBCNotesDatabase

public JDBCNotesDatabase()
standard constructor


JDBCNotesDatabase

public JDBCNotesDatabase(String databaseURL,
                         String databaseLogin,
                         String databasePasswd)
Method Detail

getInstance

public static NotesDatabase getInstance()

init

public void init()
initializes the database. It uses the properties Notes.JDBCDatabaseURL and Notes.JDBCDatabaseFile. The actually used URL is made up by concatenation of Notes.JDBCDatabaseURL and Notes.JDBCDatabaseFile. Further properties used are Notes.JDBCDatabaseLogin for the login and Notes.JDBCDatabasePassword for the Password Note that JDBCDatabaseFile is requested using getPath, thus it's value, if starting with a slash, is appended to ActiveMath's Home Directory The Driver - stored in the property Notes.JDBCDatabaseDriver - is registered using Class.forName; note however that this is a dangerous thing with jdk 1.1.x because of a bug in the class Loader! See http//java.sun.com/products/jdbc/jdbc-frequent.html for details. In order to ease installation procedure, if no table named notes is found, a new one will be generated.


storeNote

public void storeNote(String user,
                      Note aNote)
               throws NotesDatabaseAccessException
stores the given note in the database. Note that the statements, although prepared, are recreated for every call to ensure thread safety without need to synchronize static objects.

Parameters:
user - String containing the asserted userId
aNote - Note that is stored in the database
Throws:
NotesDatabaseAccessException, - if the user is not the note's owner, although the note exists
NotesDatabaseAccessException - if the user does not own the note, but it exists

createNote

public Note createNote(String user,
                       boolean isPublic,
                       String noteTitle,
                       String noteContent,
                       String contentId)
creates a new note. The noteId of the note is created uniquely for the entire database. Note that the date of the note will be changed when it is stored in the database. The note Id will be generated as maximum of the notes already in the database + 1, it will be 0 if none is present.

Parameters:
user - String identifying the owner of the note
isPublic - boolean indicating whether other users may access it
noteContent - String with the intended content for the note
contentId - String identifying the content this note refers to
Returns:
void

retrieveNote

public Note retrieveNote(String user,
                         int noteId)
                  throws NotesDatabaseAccessException,
                         NotesDatabaseNoteIdInvalidException
returns the indicated note from the database. Throws an exception if the note does not exist, or if it exists and does not belong to the indicated user.

Parameters:
user - String indicating the user the note's supposed to belong to
noteId - the id of the note
Returns:
Note selected from the database
Throws:
org.activemath.sm.notes.NotesDatabaseAccessException - is thrown if, for a private node, the user is not the same as stored in database
org.activemath.sm.notes.NotesDatabaseNoteIdInvalidException - if the noteId is not valid.
NotesDatabaseAccessException
NotesDatabaseNoteIdInvalidException

selectNotes

public Iterator selectNotes(String user,
                            String contentId)
selects a group of notes from the database selectNotes selects the notes which belong to the user and refer to the topic indicated by contentId

Parameters:
user - String indicating the owner of the notes
contentId - String indicating the content of the note
Returns:
Iterator containing the appropriate notes

selectNotes

public Iterator selectNotes(String user)

deleteNote

public void deleteNote(String user,
                       int noteId)
                throws NotesDatabaseAccessException,
                       NotesDatabaseNoteIdInvalidException
deletes note from the database

Parameters:
user - String containing the asserted userId
noteId - of the note to delete
Throws:
NotesDatabaseAccessException - is thrown if note's user is not the user given
NotesDatabaseNoteIdInvalidException - is thrown if the note is not stored in the database

getStatus

public String getStatus()
only for debugging - returns a String containing a log of what has recently happened

Specified by:
getStatus in class NotesDatabase

getConnection

public Connection getConnection()