Kereta Yarsi Indonesia
Loading...
Searching...
No Matches
controller.Controller Class Reference
Inheritance diagram for controller.Controller:
controller.AdminController controller.PassengerController controller.StationController controller.TicketController controller.TrainController controller.UserController

Public Member Functions

void setFirstStuff (String stasiunAsal, String stasiunAkhir, Date tanggalPergi, Date tanggalPulang)
 
int countFoundTrain (String stasiunAwal, String stasiunAkhir, Date tanggal)
 
ResultSet findSpecificTrain (String stasiunAwal, String stasiunAkhir, Date tanggal)
 
ResultSet findAll (String table)
 
ResultSet findWhere (String table, String columnName, Object keyword)
 
ResultSet executeQuery (String sql)
 
ResultSet executeQuery (String sql, Object... values)
 
boolean executeUpdate (String sql, Object... values)
 
boolean insert (String table, boolean withID, Object... value)
 
void errorMessage (String title, String message) throws HeadlessException
 
void warningMessage (String message) throws HeadlessException
 
void infoMessage (String message) throws HeadlessException
 
String[] getColumnName (String table)
 
int getColumnCount (String table)
 
int getRowCount (String table)
 
boolean checkForDatabase (String database) throws SQLException
 
int getRowCountWhere (String table, String columnName, String keyword)
 
boolean hasWhitespace (String str)
 
boolean hasSpecialChar (String str)
 
boolean hasUpperCase (String str)
 
byte[] generateKey (int keyLength)
 
String hashPassword (String str)
 

Static Public Member Functions

static synchronized Controller getInstance ()
 
static synchronized Session getSession ()
 
static byte[] generateSalt (int saltIteration)
 
static String encryptPBKDF2 (String password, byte[] salt)
 
static boolean verifyPassword (String inputPassword, String storedPassword, byte[] salt)
 
static DefaultTableModel buildTableModel (ResultSet rs) throws SQLException
 
static Statement getSt ()
 
static void setSt (Statement aSt)
 
static ResultSet getRs ()
 
static void setRs (ResultSet aRs)
 
static PreparedStatement getPs ()
 
static void setPs (PreparedStatement aPs)
 

Public Attributes

boolean response = false
 
Session session = Session.getInstance()
 

Static Public Attributes

static Statement st
 
static ResultSet rs
 
static PreparedStatement ps
 

Protected Member Functions

 Controller (DatabaseConnector databaseConnector)
 

Static Protected Attributes

static DatabaseConnector databaseConnector
 
static Connection con
 
static String sql
 

Detailed Description

Controller class handles various operations related to the database and application logic. It includes methods for database connection, encryption, and user session management. This class follows a singleton design pattern to ensure only one instance exists.

This class uses the singleton pattern to ensure that only one instance of the controller exists.

Example usage:

Controller controller = Controller.getInstance();
int userCount = controller.getRowCount("user");
Version
1.0
Author
Muhammad Rizal Anditama Nugraha

Constructor & Destructor Documentation

◆ Controller()

controller.Controller.Controller ( DatabaseConnector  databaseConnector)
inlineprotected

Constructor for Controller. It initializes the DatabaseConnector.

Parameters
databaseConnectorthe DatabaseConnector instance to use

Member Function Documentation

◆ buildTableModel()

static DefaultTableModel controller.Controller.buildTableModel ( ResultSet  rs) throws SQLException
inlinestatic

Builds a DefaultTableModel from a ResultSet.

Parameters
rsthe ResultSet to process
Returns
a DefaultTableModel containing the data from the ResultSet
Exceptions
SQLExceptionif a database access error occurs

◆ checkForDatabase()

boolean controller.Controller.checkForDatabase ( String  database) throws SQLException
inline

Checks if a specified database exists.

Parameters
databasethe database to check
Returns
true if the database exists, false otherwise
Exceptions
SQLExceptionif a database access error occurs

◆ countFoundTrain()

int controller.Controller.countFoundTrain ( String  stasiunAwal,
String  stasiunAkhir,
Date  tanggal 
)
inline

Counts the number of trains matching the specified criteria.

Parameters
stasiunAwalthe starting station
stasiunAkhirthe ending station
tanggalthe date of departure
Returns
the number of matching trains

◆ encryptPBKDF2()

static String controller.Controller.encryptPBKDF2 ( String  password,
byte[]  salt 
)
inlinestatic

Encrypts a password using PBKDF2 with HMAC SHA-256.

Parameters
passwordthe password to encrypt
saltthe salt to use in the encryption
Returns
the encrypted password

◆ errorMessage()

void controller.Controller.errorMessage ( String  title,
String  message 
) throws HeadlessException
inline

Displays an error message dialog.

Parameters
titlethe title of the dialog
messagethe message to display
Exceptions
HeadlessExceptionif an error occurs

◆ executeQuery() [1/2]

ResultSet controller.Controller.executeQuery ( String  sql)
inline

Executes a specified SQL query without parameters.

Parameters
sqlthe SQL query to execute
Returns
a ResultSet containing the results of the query

◆ executeQuery() [2/2]

ResultSet controller.Controller.executeQuery ( String  sql,
Object...  values 
)
inline

Executes a specified SQL query with parameters.

Parameters
sqlthe SQL query to execute
valuesthe parameters to set in the query
Returns
a ResultSet containing the results of the query

◆ executeUpdate()

boolean controller.Controller.executeUpdate ( String  sql,
Object...  values 
)
inline

Executes a specified SQL update (INSERT, UPDATE, DELETE) with parameters.

Parameters
sqlthe SQL update to execute
valuesthe parameters to set in the update
Returns
true if the update affected at least one row, false otherwise

◆ findAll()

ResultSet controller.Controller.findAll ( String  table)
inline

Finds all records from a specified table.

Parameters
tablethe table to query
Returns
a ResultSet containing all records from the table

◆ findSpecificTrain()

ResultSet controller.Controller.findSpecificTrain ( String  stasiunAwal,
String  stasiunAkhir,
Date  tanggal 
)
inline

Finds specific trains matching the criteria.

Parameters
stasiunAwalthe starting station
stasiunAkhirthe ending station
tanggalthe date of departure
Returns
a ResultSet of the matching trains

◆ findWhere()

ResultSet controller.Controller.findWhere ( String  table,
String  columnName,
Object  keyword 
)
inline

Finds records from a table where a specific column matches a keyword.

Parameters
tablethe table to query
columnNamethe column to search
keywordthe keyword to match
Returns
a ResultSet containing the matching records

◆ generateKey()

byte[] controller.Controller.generateKey ( int  keyLength)
inline

Generates a random key of a specified length.

Parameters
keyLengththe length of the key in bytes
Returns
the generated key

◆ generateSalt()

static byte[] controller.Controller.generateSalt ( int  saltIteration)
inlinestatic

Generates a random salt for password hashing.

Parameters
saltIterationthe length of the salt in bytes
Returns
the generated salt

◆ getColumnCount()

int controller.Controller.getColumnCount ( String  table)
inline

Retrieves the column count of a specified table.

Parameters
tablethe table to query
Returns
the number of columns

◆ getColumnName()

String[] controller.Controller.getColumnName ( String  table)
inline

Retrieves the column names of a specified table.

Parameters
tablethe table to query
Returns
an array of column names

◆ getInstance()

static synchronized Controller controller.Controller.getInstance ( )
inlinestatic

Returns the singleton instance of the Controller.

Returns
the singleton instance

Reimplemented in controller.AdminController, controller.PassengerController, controller.StationController, controller.TicketController, controller.TrainController, and controller.UserController.

◆ getPs()

static PreparedStatement controller.Controller.getPs ( )
inlinestatic

Retrieves the current PreparedStatement.

Returns
the current PreparedStatement

◆ getRowCount()

int controller.Controller.getRowCount ( String  table)
inline

Retrieves the row count of a specified table.

Parameters
tablethe table to query
Returns
the number of rows

◆ getRowCountWhere()

int controller.Controller.getRowCountWhere ( String  table,
String  columnName,
String  keyword 
)
inline

Retrieves the row count of a specified table where a column matches a keyword.

Parameters
tablethe table to query
columnNamethe column to search
keywordthe keyword to match
Returns
the number of matching rows

◆ getRs()

static ResultSet controller.Controller.getRs ( )
inlinestatic

Retrieves the current ResultSet.

Returns
the current ResultSet

◆ getSession()

static synchronized Session controller.Controller.getSession ( )
inlinestatic

Returns the singleton instance of the Session.

Returns
the singleton session instance

◆ getSt()

static Statement controller.Controller.getSt ( )
inlinestatic

Retrieves the current Statement.

Returns
the current Statement

◆ hashPassword()

String controller.Controller.hashPassword ( String  str)
inline

Hashes a password using PBKDF2 with HMAC SHA-1.

Parameters
strthe password to hash
Returns
the hashed password

◆ hasSpecialChar()

boolean controller.Controller.hasSpecialChar ( String  str)
inline

Checks if a string contains any special characters.

Parameters
strthe string to check
Returns
true if the string contains special characters, false otherwise

◆ hasUpperCase()

boolean controller.Controller.hasUpperCase ( String  str)
inline

Checks if a string contains any uppercase characters.

Parameters
strthe string to check
Returns
true if the string contains uppercase characters, false otherwise

◆ hasWhitespace()

boolean controller.Controller.hasWhitespace ( String  str)
inline

Checks if a string contains any whitespace characters.

Parameters
strthe string to check
Returns
true if the string contains whitespace, false otherwise

◆ infoMessage()

void controller.Controller.infoMessage ( String  message) throws HeadlessException
inline

Displays an informational message dialog.

Parameters
messagethe message to display
Exceptions
HeadlessExceptionif an error occurs

◆ insert()

boolean controller.Controller.insert ( String  table,
boolean  withID,
Object...  value 
)
inline

Inserts a new record into a specified table.

Parameters
tablethe table to insert into
withIDwhether to include an ID column
valuethe values to insert
Returns
true if the insertion was successful, false otherwise

◆ setFirstStuff()

void controller.Controller.setFirstStuff ( String  stasiunAsal,
String  stasiunAkhir,
Date  tanggalPergi,
Date  tanggalPulang 
)
inline

Sets the initial train information for a session.

Parameters
stasiunAsalthe starting station
stasiunAkhirthe ending station
tanggalPergithe departure date
tanggalPulangthe return date

◆ setPs()

static void controller.Controller.setPs ( PreparedStatement  aPs)
inlinestatic

Sets the current PreparedStatement.

Parameters
aPsthe PreparedStatement to set

◆ setRs()

static void controller.Controller.setRs ( ResultSet  aRs)
inlinestatic

Sets the current ResultSet.

Parameters
aRsthe ResultSet to set

◆ setSt()

static void controller.Controller.setSt ( Statement  aSt)
inlinestatic

Sets the current Statement.

Parameters
aStthe Statement to set

◆ verifyPassword()

static boolean controller.Controller.verifyPassword ( String  inputPassword,
String  storedPassword,
byte[]  salt 
)
inlinestatic

Verifies if the input password matches the stored password.

Parameters
inputPasswordthe password to verify
storedPasswordthe stored hashed password
saltthe salt used in hashing
Returns
true if passwords match, false otherwise

◆ warningMessage()

void controller.Controller.warningMessage ( String  message) throws HeadlessException
inline

Displays a warning message dialog.

Parameters
messagethe message to display
Exceptions
HeadlessExceptionif an error occurs

Member Data Documentation

◆ con

Connection controller.Controller.con
staticprotected

◆ databaseConnector

DatabaseConnector controller.Controller.databaseConnector
staticprotected

◆ ps

PreparedStatement controller.Controller.ps
static

◆ response

boolean controller.Controller.response = false

◆ rs

ResultSet controller.Controller.rs
static

◆ session

Session controller.Controller.session = Session.getInstance()

◆ sql

String controller.Controller.sql
staticprotected

◆ st

Statement controller.Controller.st
static

The documentation for this class was generated from the following file: