org.gswing.components.input
Class DbWriteAccess

java.lang.Object
  extended by org.gswing.components.common.db.DbAccess
      extended by org.gswing.components.common.db.DbReadAccess
          extended by org.gswing.components.input.DbWriteAccess
All Implemented Interfaces:
IConstituencyBrowsing, IDbReadAccess, IDbWriteAccess

public class DbWriteAccess
extends DbReadAccess
implements IDbWriteAccess

Purpose: Provides write access to the database.


Field Summary
 
Fields inherited from interface org.gswing.framework.services.IDbWriteAccess
ALREADY_EXISTS, FAILED, NO_DATA, SUCCESS
 
Constructor Summary
DbWriteAccess(String url, String dbName, String userName, String password)
          Constructor.
 
Method Summary
 void createIndex(DbTable table, String column)
          Create index on a table column.
 boolean createTable(DbTable table)
          Create a new table in the database.
 boolean deleteConstituency(String constituencyName, char type, String parentName)
          Delete a constituency from the database.
 boolean insertCandidate(Candidate candidate)
          Insert a new Candidate into the database.
 boolean insertConstituency(String constituencyName, char type, String parentName)
          Insert a new constituency into the database.
 boolean insertConstituency(String constituencyName, char type, String parentName, boolean isState)
          Insert a new constituency into the database.
 boolean insertElection(Election election)
          Insert a new Election into the database.
 int insertElectorate(Constituency constituency, int electionNo, int electorate)
          Insert the electorate size into the database.
 boolean insertParty(String abbreviation, String name)
          Insert a new Party into the database.
 boolean insertParty(String abbreviation, String name, URL homePage)
          Insert a new Party into the database.
 boolean insertPartyLeader(Election election, Candidate candidate, Constituency constituency)
          Insert a new party leader into the database.
 boolean insertResult(Vector votes)
          Insert a Vector of results into the database.
 boolean renameConstituency(String constituencyName, String newName, char type, String parentName)
          Rename a constituency in the database.
 int updateElectorate(Constituency constituency, int electionNo, int electorate)
          Update the electorate size into the database.
 boolean updateParty(String abbreviation, String name, URL homePage)
          Update the party's details
 
Methods inherited from class org.gswing.components.common.db.DbReadAccess
fixString, getCandidate, getCandidateNo, getCandidates, getConstituencies, getConstituency, getConstituency, getConstituency, getConstituencyList, getElection, getElection, getElectionDates, getElections, getElections, getElectorate, getElectorate, getLatestDate, getLeaders, getLeaders, getNextCandidateNo, getNextConstituencyNo, getNextResult, getNoOfCandidates, getNoOfParties, getParties, getParty, getPartyAbbreviation, getPreviousResult, getPreviousWinner, getRegion, getRegionList, getResult, getState, getVotesCast, hasIllegalChar, partyExists, resultExists, resultExists
 
Methods inherited from class org.gswing.components.common.db.DbAccess
closeConnection, createStatement, getConnection, getDatabaseName, getNumberOfTables, getPassword, getTableList, hasValidConnection, isConnected, setDriverClassName, setPassword, tableExists
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.gswing.framework.services.IDbReadAccess
getCandidateNo, getCandidates, getConstituencies, getConstituency, getConstituency, getElection, getElectionDates, getElections, getElections, getElectorate, getLatestDate, getLeaders, getLeaders, getNextResult, getNoOfCandidates, getNoOfParties, getParties, getParty, getPartyAbbreviation, getPreviousResult, getResult, getVotesCast, partyExists, resultExists, resultExists, tableExists
 
Methods inherited from interface org.gswing.components.common.gui.IConstituencyBrowsing
getConstituencyList, getRegionList, getState
 

Constructor Detail

DbWriteAccess

public DbWriteAccess(String url,
                     String dbName,
                     String userName,
                     String password)
Constructor.

Parameters:
url - The URL of the database.
dbName - The name of the database.
userName - The user name of the database user.
password - The password of the database.
Method Detail

insertResult

public boolean insertResult(Vector votes)
Insert a Vector of results into the database.

Specified by:
insertResult in interface IDbWriteAccess
Parameters:
votes - A Vector of vote objects.
Returns:
True if all votes were inserted successfully.

insertElectorate

public int insertElectorate(Constituency constituency,
                            int electionNo,
                            int electorate)
Description copied from interface: IDbWriteAccess
Insert the electorate size into the database.

Specified by:
insertElectorate in interface IDbWriteAccess
Parameters:
constituency - The constituency reference.
electionNo - The unique election id.
electorate - The size of electorate for this constituency.
Returns:
SUCCESS <\code> if electorate inserted successully, FAILED <\code> if something went wrong and ALREADY_EXISTS if the result already exits.

updateElectorate

public int updateElectorate(Constituency constituency,
                            int electionNo,
                            int electorate)
Description copied from interface: IDbWriteAccess
Update the electorate size into the database.

Specified by:
updateElectorate in interface IDbWriteAccess
Parameters:
constituency - The constituency reference.
electionNo - The unique election id.
electorate - The size of electorate for this constituency.
Returns:
True if the electorate was successfully updated.

createTable

public boolean createTable(DbTable table)
Create a new table in the database.

Specified by:
createTable in interface IDbWriteAccess
Parameters:
table - The table to create in the database.
Returns:
True if the table is successfully created.

createIndex

public void createIndex(DbTable table,
                        String column)
Create index on a table column.

Specified by:
createIndex in interface IDbWriteAccess
Parameters:
table - The table to create the index on.
column - The column to create the index on.

insertElection

public boolean insertElection(Election election)
Insert a new Election into the database.

Specified by:
insertElection in interface IDbWriteAccess
Parameters:
election - The election to insert.

insertConstituency

public boolean insertConstituency(String constituencyName,
                                  char type,
                                  String parentName)
Insert a new constituency into the database.

Specified by:
insertConstituency in interface IDbWriteAccess
Parameters:
constituencyName - The constituency to insert.
type - The constituency type - Result.NATIONAL, REGIONAL, COUNCIL, CONSTITUENCY or LOCAL
parentName - The constituency's parent. (E.g. National is parent of Regional, Regional is parent of Constituency, Regional is parent of Council and Council is the parent of Local)
Returns:
True if the constituency was inserted.

insertConstituency

public boolean insertConstituency(String constituencyName,
                                  char type,
                                  String parentName,
                                  boolean isState)
Insert a new constituency into the database.

Specified by:
insertConstituency in interface IDbWriteAccess
Parameters:
constituencyName - The constituency to insert.
type - The constituency type - Result.NATIONAL, REGIONAL, COUNCIL, CONSTITUENCY or LOCAL
parentName - The constituency's parent. (E.g. National is parent of Regional, Regional is parent of Constituency, Regional is parent of Council and Council is the parent of Local)
isState - Is this constituency the top level state / nation?
Returns:
True if the constituency was inserted.

insertCandidate

public boolean insertCandidate(Candidate candidate)
Insert a new Candidate into the database.

Specified by:
insertCandidate in interface IDbWriteAccess
Parameters:
candidate - The candidate to be inserted.
Returns:
True if the candidate was inserted.

insertParty

public boolean insertParty(String abbreviation,
                           String name)
Insert a new Party into the database.

Specified by:
insertParty in interface IDbWriteAccess
Parameters:
abbreviation - The candidate to be inserted.
name - Party name.
Returns:
True if the candidate was inserted.

insertParty

public boolean insertParty(String abbreviation,
                           String name,
                           URL homePage)
Insert a new Party into the database.

Specified by:
insertParty in interface IDbWriteAccess
Parameters:
abbreviation - The candidate to be inserted.
name - Party name.
homePage - The home page of the party.
Returns:
True if the candidate was inserted.

updateParty

public boolean updateParty(String abbreviation,
                           String name,
                           URL homePage)
Update the party's details

Parameters:
abbreviation - The candidate to be inserted.
name - Party name.
homePage - The home page of the party.
Returns:
True if the entry is updated.

insertPartyLeader

public boolean insertPartyLeader(Election election,
                                 Candidate candidate,
                                 Constituency constituency)
Insert a new party leader into the database.

Specified by:
insertPartyLeader in interface IDbWriteAccess
Parameters:
election - The election reference.
candidate - The candidate to be inserted.
constituency - The constituency object. Used in local elections.
Returns:
True if the candidate was inserted.

deleteConstituency

public boolean deleteConstituency(String constituencyName,
                                  char type,
                                  String parentName)
Description copied from interface: IDbWriteAccess
Delete a constituency from the database.

Specified by:
deleteConstituency in interface IDbWriteAccess
Parameters:
constituencyName - The constituency name.
type - The constituency type - Result.NATIONAL, REGIONAL, COUNCIL, CONSTITUENCY or LOCAL
parentName - The constituency's parent. (E.g. National is parent of Regional, Regional is parent of Constituency, Regional is parent of Council and Council is the parent of Local)
Returns:
True if the constituency was deleted.

renameConstituency

public boolean renameConstituency(String constituencyName,
                                  String newName,
                                  char type,
                                  String parentName)
Description copied from interface: IDbWriteAccess
Rename a constituency in the database.

Specified by:
renameConstituency in interface IDbWriteAccess
Parameters:
constituencyName - The old constituency name.
newName - The new constituency name.
type - The constituency type - Result.NATIONAL, REGIONAL, COUNCIL, CONSTITUENCY or LOCAL
parentName - The constituency's parent. (E.g. National is parent of Regional, Regional is parent of Constituency, Regional is parent of Council and Council is the parent of Local)
Returns:
True if the constituency was renamed.


Copyright © 2008. All Rights Reserved.