concept.database
Class Jdbc

public class Jdbc

Title: Jdbc

Description:Jdbc -class serves an interface between the software and database using PostgreSQL.

Copyright: Copyright (c) 2006
CONCEPT-lisenssi Tekijänoikeus (c) 2006, Pekka Kuuva, Tatu Repo, Pasi Saari, Anna Seppänen. Kaikki oikeudet pidätetään. Tämän ohjelmiston levittäminen ja käyttö lähdekoodina ja binäärinä, muutettuna tai muuttamattomana, on sallittu edellyttäen, että seuraavat ehdot täytetään: 1. OHJELMISTON LEVITTÄMINEN Lähdekoodikopioissa, dokumentaatiossa ja muussa ohjelmiston mukana tulevassa aineistossa on oltava tämä lisenssi kokonaisuudessaan. 1.2. VIENTIRAJOITUKSET Ohjelmistoa tai sen osia ei saa viedä Amerikan Yhdysvaltoihin ilman tekijöiden erillistä suostumusta. 2. OHJELMISTON KÄYTTÖ (EULA) 2.1 KÄYTTÖEHDOT Ohjelmiston käyttäjän tulee joskus suorittaa vähintään yksi seuraavista toimista: a) Tarjota omalla kustannuksellaan olut tasokkaassa ravintolassa, pubissa tai muussa vastaavassa anniskelua harjoittavassa liikkeessä kullekin tekijöistä, sekä ilmoittaa tästä tarjouksesta. b) Tarjota tekijöille omalla kustannuksellaan pääsy tapahtumaan, jonka yhteydessä sovellusta on käytetty, ja ilmoittaa tästä tarjouksesta tekijöille. Ilmoittamisella tarkoitetaan vähintään viikkoa ennen tarjouk- sen täytäntöönpanoa tekijöille lähetettyä sähköpostia, jossa ilmoitetaan ohjelmiston käyttäjän nimi ja yhteystiedot sekä tarjous ja sen ajankohta. Jos käyttöehdot eivät ole täyttyneet, ohjelmistoa ei saa käyttää. 2.1. TAKUU Tekijänoikeuden haltijat ja ohjelmiston kehittäjät tarjoavat tämän ohjelmiston "sellaisena kuin se on". Sovellukselle ei myönnetä minkäänlaista takuuta kaupallisesti hyväksyttävästä laadusta eikä sen taata soveltuvan mihinkään tarkoitukseen. 2.2. VASTUUNRAJOITUS Tekijänoikeuden haltija ja ohjelmiston kehittäjät eivät ole missään tilanteessa vastuussa suorista, epäsuorista, yleisistä, erityisistä, satunnaisista tai seurauksellisista vahingoista (sisältäen, muttei tyhjentävästi, korvaavan tuotteen tai palvelun hankinnan, käyttömahdollisuuden, tiedon tai voittojen menetykset, tai liiketoiminnan keskeytymisen), jotka aiheutuvat miten tahansa ja millä tahansa vahingonkorvausoikeudellisella perusteella mukaanlukien sopimusvastuu, ankara vastuu ja sopimuksen ulkoinen vastuu (huolimattomuus tai muu), vaikka kyseisten vahinkojen mahdollisuudesta olisi kerrottu.

Version:
1.0
Author:
PS
Constructor Detail

Jdbc

public Jdbc(java.lang.String database,
            java.lang.String username,
            java.lang.String password)
Constructs a jdbc-object with it's parameters.
Parameters:
database - String Address to the database
username - String Username.
password - String Password.

Jdbc

public Jdbc()
Constructs a jdbc-object with specified values.

Method Detail

connection

public java.sql.DatabaseMetaData connection()
Establishes connection to database using PostgreSQL. Locks the database.
Returns:
DatabaseMetaData Info the driver delivers
Throws:
ClassNotFoundException - If there ain't no such class.
SQLException - if operation failed.

isClosed

public boolean isClosed()
Tests if connection to the database is closed.
Returns:
boolean True, if connection is closed.
Throws:
SQLException - if operation failed.

readConference

public concept.structure.Conference readConference()
Reads whole conference.
Returns:
Conference Conference that will be scheduled.
Throws:
SQLException - if operation failed.

readPreference

public boolean readPreference()
Sets preferences.
Returns:
show preferences to user
Throws:
SQLException - if operation failed

readHalls

private void readHalls()
Reads halls from database and makes new Hall-objects.
Throws:
SQLException - if operation failed.

readHallRestrictions

private void readHallRestrictions()
Reads restrictions to halls and makes new objects of them.
Throws:
SQLException - failed

readUsers

private void readUsers(concept.structure.Presenters presenters)
Reads Presenters for the conference.
Parameters:
presenters - Presenters contains all presenters of the conference.
Throws:
SQLException - if operation failed.

readSessionType

private void readSessionType()
Reads sessiontypes for the conference.
Throws:
SQLException - if operation failed.

readTopic

private void readTopic()
Reads topics for the conference.
Throws:
SQLException - if operation failed.

readArticle

private void readArticle(concept.structure.Presentations presentations)
Reads all articles for the conference.
Parameters:
presentations - Presentations contains all presentations of the conference.
Throws:
SQLException - is operation failed.

readPresent

private void readPresent(concept.structure.Presentations presentations,
                         concept.structure.Presenters presenters)
Sets links between presentations and presenters.
Parameters:
presentations - Presentations Adds the link to.
presenters - Presenters Link that is added to presentation.
Throws:
SQLException - if operation failed.

readKeywords

private void readKeywords()
Reads all keywords for the conference.
Throws:
SQLException - if operation failed.

readScheduleType

private void readScheduleType()
Reads all block types of the conference.
Throws:
SQLException - if operation failed.

readSchedule

private void readSchedule()
Reads blocks for the conference-timetable.
Throws:
SQLException - if operation failed.

readSessions

private void readSessions(concept.structure.Sessions sessions)
Reads sessions for the conference.
Parameters:
sessions - Sessions Contains all sessions. Sessions are added to this class.
Throws:
SQLException - if operation failed.

readSessionlinksAtArticle

private void readSessionlinksAtArticle(concept.structure.Sessions sessions,
                                       concept.structure.Presentations presentations)
Reads links between sessions and articles.
Parameters:
sessions - Sessions Adds the links to
presentations - Presentations Links.
Throws:
SQLException - if operation failed.

readChairmen

private void readChairmen(concept.structure.Presenters presenters)
Reads all chairmen for the conference.
Parameters:
presenters - Presenters All presenters of the conference. Presenters that are set to be chairmen get chairman topics and maximum value of chairman duties.
Throws:
SQLException - if operation failed.

readChairman

private void readChairman(concept.structure.Sessions sessions,
                          concept.structure.Presenters presenters)
Sets links between chairmen and sessions.
Parameters:
sessions - Sessions Session link
presenters - Presenters Chairman link.
Throws:
SQLException - if operation failed.

readRestiction

private void readRestiction(concept.structure.Presenters presenters,
                            concept.structure.Sessions sessions)
Reads schedule restrictions of the presenters
Parameters:
presenters - Presenters Contains all the presenters of the conference.
sessions - Sessions Contains all the sessions of the conference.
Throws:
SQLException - if operation failed.

readSpecialty

private void readSpecialty(concept.structure.Presentations presentations,
                           concept.structure.Sessions sessions)
Reads schedule restrictions of presentations.
Parameters:
presentations - Presentations Contains all the presentations of the conference.
sessions - Sessions Contains all the sessions of the conference.
Throws:
SQLException - if operation failed.

addPreference

public void addPreference(concept.structure.Preference preference)
Adds new preference. The new preference is always held by username 'user' because there can be only one preference other than default.
Parameters:
preference - Preference Preferences of the conference.
Throws:
SQLException - if operation failed.

sessionAdd

public void sessionAdd(concept.structure.Session session)
Adds new session to database. Sets id for the session in the structure.
Parameters:
session - Session Session that will be added.
Throws:
SQLException - if operation failed.

sessionDelete

public void sessionDelete(concept.structure.Session session)
Deletes a session from the database.
Parameters:
session - Session Session that will be deleted.
Throws:
SQLException - if operation failed.

sessionUpdate

public void sessionUpdate(concept.structure.Session session)
Updates a session in the database.
Parameters:
session - Session Session that will be updated.
Throws:
SQLException - if operation failed.

sessionUpdateIsReady

public void sessionUpdateIsReady(concept.structure.Session session)
Updates only isready-flag of the session in the database.
Parameters:
session - Session Session that will be updated.
Throws:
SQLException - if operation failed.

presentationUpdateSession

public void presentationUpdateSession(concept.structure.Presentation presentation)
Updates sessionlink of article in database.
Parameters:
presentation - Presentation Article that will be linked.
Throws:
SQLException - if operation failed.

chairmanToSession

public void chairmanToSession(concept.structure.Presenter chairman,
                              concept.structure.Session session)
Places chairman into session.
Parameters:
chairman - Presenter Chairman
session - Session Session that will be cairmanned.
Throws:
SQLException - if operation failed.

chairmanFromSession

public void chairmanFromSession(concept.structure.Presenter chairman,
                                concept.structure.Session session)
Removes chairman from the session.
Parameters:
chairman - Presenter Chairman to remove.
session - Session Removed from.
Throws:
SQLException - if operation failed.

hallAddRestriction

public void hallAddRestriction(concept.structure.Hall hall,
                               concept.structure.ScheduleRestriction r)
Adds new restriction for a hall in the database and sets id for the restriction-object.
Parameters:
hall - Hall
r - ScheduleRestriction
Throws:
SQLException - if operation failed.

hallDeleteRestriction

public void hallDeleteRestriction(concept.structure.Hall hall)
Deletes a restriction of a hall in the database.
Parameters:
hall - Hall
Throws:
SQLException - if operation failed.

addHallToDay

public void addHallToDay(concept.structure.Hall hall,
                         long day)
Adds a hall to a day.
Parameters:
hall - Hall Hall to be added.
day - long Add to.
Throws:
SQLException - if operation failed.

deleteHallFromDay

public void deleteHallFromDay(concept.structure.Hall hall,
                              long day)
Sets a hall not usable for the day.
Parameters:
hall - Hall Hall to delete.
day - long Delete from.
Throws:
SQLException - if operation failed.

blockAdd

public void blockAdd(concept.structure.Block block)
Adds new block into the database and sets id for the block-object.
Parameters:
block - Block
Throws:
SQLException - if operation failed.

blockUpdate

public void blockUpdate(concept.structure.Block block)
Updates a block in the database.
Parameters:
block - Block Block to update
Throws:
SQLException - if operation failed.

blockDelete

public void blockDelete(concept.structure.Block block)
Deletes a block from the database.
Parameters:
block - Block
Throws:
SQLException - if operation failed.

restrictionDelete

public void restrictionDelete(concept.structure.ScheduleRestriction sch)
Deletes a restriction from the database.
Parameters:
sch - ScheduleRestriction
Throws:
SQLException - if operation failed.

restrictionAdd

public void restrictionAdd(concept.structure.ScheduleRestriction sch,
                           boolean isPresenter,
                           int id)
Adds restriction into database.
Parameters:
sch - ScheduleRestriction restriction that will be added.
isPresenter - boolean if restriction is related to presenter. False, if restriction is related to a presentation
id - int Id of presenter or presentation.
Throws:
SQLException - if operation failed.

searchSessions

public java.util.Vector searchSessions(java.lang.String title,
                                       java.lang.String abbrev,
                                       concept.structure.Topic topic,
                                       concept.structure.Type type,
                                       boolean ready,
                                       boolean notready,
                                       boolean limit,
                                       boolean nolimit,
                                       boolean scheduled,
                                       boolean notscheduled)
Searches sessions.
Parameters:
title - String Search by this title.
abbrev - String Search by this abbreviation.
topic - Topic Search by this topic.
type - Type Search by this sessiontype.
ready - boolean Is ready
notready - boolean Isn't ready. If both ready and not ready are of the same value, these values are omitted.
limit - boolean Has limits.
nolimit - boolean Has no limits. If both limits and nolimits are of the same value, these values are omitted.
scheduled - boolean Is scheduled.
notscheduled - boolean Isn't scheduled. If both scheduled and notscheduled are of the same value, these values are omitted.
Returns:
Vector Contains search results.
Throws:
SQLException - if operation failed.

addSessionSearchResult

private java.util.Vector addSessionSearchResult(boolean limit,
                                                boolean nolimit,
                                                boolean scheduled,
                                                boolean notscheduled,
                                                java.util.Vector result,
                                                concept.structure.Session searchresult)
Searches sessions by it's attributes. Called By SearchSessions()
Parameters:
limit - boolean
nolimit - boolean
scheduled - boolean
notscheduled - boolean
result - Vector
searchresult - Session
Returns:
Vector

addSessionSearchResult

private java.util.Vector addSessionSearchResult(boolean scheduled,
                                                boolean notscheduled,
                                                java.util.Vector result,
                                                concept.structure.Session searchresult)
Searches sessions by it's attributes. Called By SearchSessions()
Parameters:
scheduled - boolean
notscheduled - boolean
result - Vector
searchresult - Session
Returns:
Vector result

searchSessions

public java.util.Vector searchSessions(java.lang.String title,
                                       java.lang.String abbrev,
                                       concept.structure.Topic topic,
                                       concept.structure.Type type,
                                       concept.structure.Presenter chairman,
                                       boolean ready,
                                       boolean notready,
                                       boolean limit,
                                       boolean nolimit,
                                       boolean scheduled,
                                       boolean notscheduled)
Searches sessions.
Parameters:
title - String Search by this title.
abbrev - String Search by this abbreviation.
topic - Topic SEarch by this topic.
type - Type Search by this sessiontype.
chairman - Presenter Search by this chairman.
ready - boolean Is ready
notready - boolean Isn't ready. If both ready and not ready are of the same value, these values are omitted.
limit - boolean Has limits.
nolimit - boolean Has no limits. If both limits and nolimits are of the same value, these values are omitted.
scheduled - boolean Is scheduled.
notscheduled - boolean Isn't scheduled. If both scheduled and notscheduled are of the same value, these values are omitted.
Returns:
Vector Contains search results.
Throws:
SQLException - if operation failed.

searchArticles

public java.util.Vector searchArticles(java.lang.String title,
                                       concept.structure.Topic topic,
                                       concept.structure.Type type,
                                       java.lang.String presenter,
                                       java.lang.String key1,
                                       java.lang.String key2,
                                       java.lang.String key3,
                                       boolean registered,
                                       boolean notregistered,
                                       boolean placed,
                                       boolean notplaced,
                                       boolean limits,
                                       boolean nolimits)
Searches articles by it's attributes.
Parameters:
title - String Search by this title
topic - Topic Search b this topic
type - Type Search by this sessiontype.
presenter - String Searsh by this presenter name.
key1 - String keyword.
key2 - String keyword.
key3 - String keyword.
registered - boolean Is registered.
notregistered - boolean Isn't registered. If both registered and notregistered are of the same value, these values are omitted.
placed - boolean Is placed into session.
notplaced - boolean Isn't placed into session. If both placed and nootplaced are of the same value, these values are omitted.
limits - boolean Has limits.
nolimits - boolean Has no limits. If both limits and nolimits are of the same value, these values are omitted.
Returns:
Vector Contains search results.
Throws:
SQLException - if operation failed.

searchArticles

public java.util.Vector searchArticles(java.lang.String title,
                                       concept.structure.Topic topic,
                                       concept.structure.Type type,
                                       java.lang.String presenter,
                                       java.lang.String key1,
                                       java.lang.String key2,
                                       java.lang.String key3,
                                       int grade,
                                       boolean registered,
                                       boolean notregistered,
                                       boolean placed,
                                       boolean notplaced,
                                       boolean limits,
                                       boolean nolimits)
Searches articles by it's attributes incl. grade.
Parameters:
title - String Search by this title
topic - Topic Search b this topic
type - Type Search by this sessiontype.
presenter - String Searsh by this presenter name.
key1 - String keyword.
key2 - String keyword.
key3 - String keyword.
grade - int grade of an article.
registered - boolean Is registered.
notregistered - boolean Isn't registered. If both registered and notregistered are of the same value, these values are omitted.
placed - boolean Is placed into session.
notplaced - boolean Isn't placed into session. If both placed and nootplaced are of the same value, these values are omitted.
limits - boolean Has limits.
nolimits - boolean Has no limits. If both limits and nolimits are of the same value, these values are omitted.
Returns:
Vector Contains search results.
Throws:
SQLException - if operation failed.

addArticleSearchResult

private java.util.Vector addArticleSearchResult(boolean placed,
                                                boolean notplaced,
                                                boolean limits,
                                                boolean nolimits,
                                                java.util.Vector result,
                                                concept.structure.Presentation searchresult)
Searches presentations
Parameters:
placed - boolean
notplaced - boolean
limits - boolean
nolimits - boolean
result - Vector
searchresult - Presentation
Returns:
Vector result

addArticleSearchResult

private java.util.Vector addArticleSearchResult(boolean limits,
                                                boolean nolimits,
                                                java.util.Vector result,
                                                concept.structure.Presentation searchresult)
Searches presentations
Parameters:
limits - boolean
nolimits - boolean
result - Vector
searchresult - Presentation
Returns:
Vector result

getSameTitle

public int getSameTitle(concept.structure.Session session)
Tests if there are sessions with the same title.
Parameters:
session - Session
Returns:
int id of the session with the same name.
Throws:
SQLException - if operation failed

safety

private static java.lang.String safety(java.lang.String s)
Tests safety of strings and transforms them if necessary.
Parameters:
s - String String that is tested
Returns:
String Transformed string.

closeConnection

public void closeConnection()
Close connection to the database and releases locks.
Throws:
SQLException -

lockDatabase

public void lockDatabase()
Locks tables in the database.
Throws:
SQLException - if operation failed.

unlockDatabase

public void unlockDatabase()
Releases the lock.
Throws:
SQLException - if operation failed.

main

public static void main(java.lang.String[] args)
Testingtesting.
Parameters:
args - String[]
Throws:
SQLException - if operation failed
ClassNotFoundException - if class was not found.