Package com.signalapp.dao
Class BaseDAO<T>
- java.lang.Object
-
- com.signalapp.dao.BaseDAO<T>
-
- Type Parameters:
T- The entity type this DAO handles
- Direct Known Subclasses:
CoaxialDAO,ComponenteDAO,ConfiguracionDAO,DerivadorDAO,DistribuidorDAO,EsquematicoDAO,MargenCalidadDAO,ResultadoSimulacionDAO,SimulacionDAO,TiposComponenteDAO,TomaDAO
public abstract class BaseDAO<T> extends java.lang.ObjectBase Data Access Object class that provides common database operations
-
-
Field Summary
Fields Modifier and Type Field Description protected java.sql.Connectionconnection
-
Constructor Summary
Constructors Constructor Description BaseDAO()Constructor that establishes a database connection
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voiddelete(int id)Deletes a record from the databasejava.util.List<T>findAll()Retrieves all records from the database tableTfindById(int id)Retrieves a single record by its IDprotected abstract java.lang.String[]getColumnNames()Gets the column names for the database tableprotected abstract java.lang.StringgetTableName()Gets the name of the database table this DAO operates onvoidinsert(T entity)Inserts a new record into the database Note: Derby uses GENERATED ALWAYS AS IDENTITY for auto-incrementing IDsprotected abstract TmapResultSetToEntity(java.sql.ResultSet rs)Maps a ResultSet row to an entity objectprotected abstract voidsetPreparedStatementParams(java.sql.PreparedStatement ps, T entity)Sets the parameters for a PreparedStatement based on entity propertiesvoidupdate(T entity, int id)Updates an existing record in the database
-
-
-
Method Detail
-
getTableName
protected abstract java.lang.String getTableName()
Gets the name of the database table this DAO operates on- Returns:
- The table name
-
getColumnNames
protected abstract java.lang.String[] getColumnNames()
Gets the column names for the database table- Returns:
- Array of column names
-
mapResultSetToEntity
protected abstract T mapResultSetToEntity(java.sql.ResultSet rs) throws java.sql.SQLException
Maps a ResultSet row to an entity object- Parameters:
rs- The ResultSet containing the database row- Returns:
- The mapped entity object
- Throws:
java.sql.SQLException- if a database error occurs
-
setPreparedStatementParams
protected abstract void setPreparedStatementParams(java.sql.PreparedStatement ps, T entity) throws java.sql.SQLExceptionSets the parameters for a PreparedStatement based on entity properties- Parameters:
ps- The PreparedStatement to set parameters forentity- The entity containing the values to set- Throws:
java.sql.SQLException- if a database error occurs
-
findAll
public java.util.List<T> findAll() throws java.sql.SQLException
Retrieves all records from the database table- Returns:
- A list of all entities
- Throws:
java.sql.SQLException- if a database error occurs
-
findById
public T findById(int id) throws java.sql.SQLException
Retrieves a single record by its ID- Parameters:
id- The ID of the record to retrieve- Returns:
- The entity with the specified ID, or null if not found
- Throws:
java.sql.SQLException- if a database error occurs
-
insert
public void insert(T entity) throws java.sql.SQLException
Inserts a new record into the database Note: Derby uses GENERATED ALWAYS AS IDENTITY for auto-incrementing IDs- Parameters:
entity- The entity to insert- Throws:
java.sql.SQLException- if a database error occurs
-
update
public void update(T entity, int id) throws java.sql.SQLException
Updates an existing record in the database- Parameters:
entity- The entity with updated valuesid- The ID of the record to update- Throws:
java.sql.SQLException- if a database error occurs
-
delete
public void delete(int id) throws java.sql.SQLExceptionDeletes a record from the database- Parameters:
id- The ID of the record to delete- Throws:
java.sql.SQLException- if a database error occurs
-
-